Class: Rotessa::Client

Inherits:
Object
  • Object
show all
Includes:
HTTParty
Defined in:
lib/rotessa/client.rb

Constant Summary collapse

PAGE_SIZE =

Rotessa’s default page size

1000

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(api_key: nil, environment: nil) ⇒ Client

Returns a new instance of Client.



10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/rotessa/client.rb', line 10

def initialize(api_key: nil, environment: nil)
  api_key ||= ENV["ROTESSA_API_KEY"]
  environment ||= ENV["ROTESSA_ENVIRONMENT"]&.to_sym || :production

  raise "Invalid environment: #{environment}. Only :production and :sandbox are accepted." unless [:production, :sandbox].include?(environment)
  raise "Invalid API key: #{api_key}. API key must be a string." unless api_key.to_s != ""

  @api_key = api_key
  @environment = environment

  set_base_uri
end

Instance Attribute Details

#api_keyObject (readonly)

Returns the value of attribute api_key.



6
7
8
# File 'lib/rotessa/client.rb', line 6

def api_key
  @api_key
end

#environmentObject (readonly)

Returns the value of attribute environment.



6
7
8
# File 'lib/rotessa/client.rb', line 6

def environment
  @environment
end

Instance Method Details

#customer(id:, **query) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/rotessa/client.rb', line 30

def customer(id:, **query)
  options = base_options.clone
  options[:query].merge!(query)

  unless id.is_a?(Integer) || id.to_i.to_s == id.to_s
    options[:query][:custom_identifier] = id
    id = "show_with_custom_identifier"
  end

  path = build_path("/customers", id)

  self.class.get(path, options)
end

#customers(**query) ⇒ Object



23
24
25
26
27
28
# File 'lib/rotessa/client.rb', line 23

def customers(**query)
  options = base_options.clone
  options[:query].merge!(query)

  get_all_pages("/customers", options)
end

#transactions(**query) ⇒ Object



44
45
46
47
48
# File 'lib/rotessa/client.rb', line 44

def transactions(**query)
  options = base_options.clone
  options[:query].merge!(query)
  get_all_pages("/transaction_report", options)
end