<commit_before>module Plivo
  module Base
    class Resource
      attr_reader :id
      include Plivo::Utils

      def initialize(client, options = nil)
        configure_client(client)
        configure_options(options) if options
        configure_resource_uri
      end

      private

      def configure_client(client)
        valid_param?(:client, client, [RestClient, Phlo], true)
        @_client = client
      end

      def configure_options(options)
        valid_param?(:options, options, Hash, false)
        @id = options[:resource_id] if options.key?(:resource_id)
        parse_and_set(options[:resource_json]) if options.key?(:resource_json)
      end

      def configure_resource_uri
        to_join = @id ? [@_client.auth_id, @_name, @id] : [@_client.auth_id, @_name]
        to_join = ['', 'v1', 'Account'] << to_join

        if @_name == 'Account'
          @id = @_client.auth_id
          to_join = ['', 'v1', 'Account', @id]
        end

        to_join << ''
        @_resource_uri = to_join.join('/')
      end

      def parse_and_set(resource_json)
        return unless resource_json

        valid_param?(:resource_json, resource_json, Hash, true)

        resource_json.each do |k, v|
          instance_variable_set("@#{k}", v)
          self.class.send(:attr_reader, k)
        end

        return unless @_identifier_string && (resource_json.key? @_identifier_string)
        @id = resource_json[@_identifier_string]
      end

      def perform_update(params, use_multipart_conn = false)
        unless @id
          raise_invalid_request("Cannot update a #{@_name} resource "\
          'without an identifier')
        end

        response_json = @_client.send_request(@_resource_uri, 'POST', params, nil, use_multipart_conn)

        parse_and_set(params)
        parse_and_set(response_json)
        self
      end

      def perform_action(action = nil, method = 'GET', params = nil, parse = false)
        resource_path = action ? @_resource_uri + action + '/' : @_resource_uri
        response = @_client.send_request(resource_path, method, params)
        parse ? parse_and_set(response) : self
        method == 'POST' ? parse_and_set(params) : self
        self
      end

      def perform_custome_action(action = nil, method = 'GET', params = nil, parse = false)
        resource_path = action ? @_resource_uri + action + '/' : @_resource_uri
        response = @_client.send_request(resource_path, method, params)
        parse ? parse_and_set(response) : self
        method == 'POST' ? parse_and_set(params) : self
        self
      end
      
      def perform_action_apiresponse(action = nil, method = 'GET', params = nil, parse = false)
        resource_path = action ? @_resource_uri + action + '/' : @_resource_uri
        response = @_client.send_request(resource_path, method, params)
        parse ? parse_and_set(response) : self
        method == 'POST' ? parse_and_set(params) : self
        return response
      end

      def perform_custom_action_apiresponse(action = nil, method = 'GET', params = nil, parse = false)
        resource_path = action ? '/v1/Account/' + @_client.auth_id + '/'+ action + '/' : @_resource_uri
        response = @_client.send_request(resource_path, method, params)
        parse ? parse_and_set(response) : self
        method == 'POST' ? parse_and_set(params) : self
        return response
      end

      def perform_delete(params=nil)
        unless @id
          raise_invalid_request("Cannot delete a #{@_name} resource "\
          'without an identifier')
        end

        Response.new(@_client.send_request(@_resource_uri, 'DELETE', params),
                     @_identifier_string)
      end
<commit_msg>delete param pass<commit_after>module Plivo
  module Base
    class Resource
      attr_reader :id
      include Plivo::Utils

      def initialize(client, options = nil)
        configure_client(client)
        configure_options(options) if options
        configure_resource_uri
      end

      private

      def configure_client(client)
        valid_param?(:client, client, [RestClient, Phlo], true)
        @_client = client
      end

      def configure_options(options)
        valid_param?(:options, options, Hash, false)
        @id = options[:resource_id] if options.key?(:resource_id)
        parse_and_set(options[:resource_json]) if options.key?(:resource_json)
      end

      def configure_resource_uri
        to_join = @id ? [@_client.auth_id, @_name, @id] : [@_client.auth_id, @_name]
        to_join = ['', 'v1', 'Account'] << to_join

        if @_name == 'Account'
          @id = @_client.auth_id
          to_join = ['', 'v1', 'Account', @id]
        end

        to_join << ''
        @_resource_uri = to_join.join('/')
      end

      def parse_and_set(resource_json)
        return unless resource_json

        valid_param?(:resource_json, resource_json, Hash, true)

        resource_json.each do |k, v|
          instance_variable_set("@#{k}", v)
          self.class.send(:attr_reader, k)
        end

        return unless @_identifier_string && (resource_json.key? @_identifier_string)
        @id = resource_json[@_identifier_string]
      end

      def perform_update(params, use_multipart_conn = false)
        unless @id
          raise_invalid_request("Cannot update a #{@_name} resource "\
          'without an identifier')
        end

        response_json = @_client.send_request(@_resource_uri, 'POST', params, nil, use_multipart_conn)

        parse_and_set(params)
        parse_and_set(response_json)
        self
      end

      def perform_action(action = nil, method = 'GET', params = nil, parse = false)
        resource_path = action ? @_resource_uri + action + '/' : @_resource_uri
        response = @_client.send_request(resource_path, method, params)
        parse ? parse_and_set(response) : self
        method == 'POST' ? parse_and_set(params) : self
        self
      end

      def perform_custome_action(action = nil, method = 'GET', params = nil, parse = false)
        resource_path = action ? @_resource_uri + action + '/' : @_resource_uri
        response = @_client.send_request(resource_path, method, params)
        parse ? parse_and_set(response) : self
        method == 'POST' ? parse_and_set(params) : self
        self
      end
      
      def perform_action_apiresponse(action = nil, method = 'GET', params = nil, parse = false)
        resource_path = action ? @_resource_uri + action + '/' : @_resource_uri
        response = @_client.send_request(resource_path, method, params)
        parse ? parse_and_set(response) : self
        method == 'POST' ? parse_and_set(params) : self
        method == 'DELETE' ? parse_and_set(params) : self
        return response
      end

      def perform_custom_action_apiresponse(action = nil, method = 'GET', params = nil, parse = false)
        resource_path = action ? '/v1/Account/' + @_client.auth_id + '/'+ action + '/' : @_resource_uri
        response = @_client.send_request(resource_path, method, params)
        parse ? parse_and_set(response) : self
        method == 'POST' ? parse_and_set(params) : self
        method == 'DELETE' ? parse_and_set(params) : self
        return response
      end

      def perform_delete(params=nil)
        unless @id
          raise_invalid_request("Cannot delete a #{@_name} resource "\
          'without an identifier')
        end

        Response.new(@_client.send_request(@_resource_uri, 'DELETE', params),
                     @_identifier_string)
      end

{'fraction_non_alphanumeric': 0.1065855593758265, 'fraction_numerical': 0.0007934408886537953, 'mean_word_length': 2.5657708628005658, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6929101', 'n_tokens_mistral': 2249, 'n_tokens_neox': 2206, 'n_words': 514}