Class: LAA::FeeCalculator::Client

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/laa/fee_calculator/client.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeClient

Returns a new instance of Client.



15
16
17
# File 'lib/laa/fee_calculator/client.rb', line 15

def initialize
  @connection = Connection.instance
end

Instance Attribute Details

#connectionObject (readonly) Also known as: conn

Returns the value of attribute connection.



8
9
10
# File 'lib/laa/fee_calculator/client.rb', line 8

def connection
  @connection
end

#fee_schemeObject

Returns the value of attribute fee_scheme.



11
12
13
# File 'lib/laa/fee_calculator/client.rb', line 11

def fee_scheme
  @fee_scheme
end

Instance Method Details

#fee_schemes(id = nil, **options) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/laa/fee_calculator/client.rb', line 19

def fee_schemes(id = nil, **options)
  uri = 'fee-schemes/'
  id ||= options.fetch(:id, nil)
  uri.concat(id.to_s, "/") if id
  uri = Addressable::URI.parse(uri)
  uri.query_values = options.reject { |k, _v| k.eql?(:id) }

  json = get(uri).body

  fstruct = JSON.parse(json, object_class: FeeScheme)
  return fstruct unless fstruct.respond_to?(:results)
  return fstruct.results.first if fstruct.results.size.eql?(1)
  fstruct.results
end