Class: XpensifySDK::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/xpensify_sdk/client.rb

Instance Method Summary collapse

Constructor Details

#initialize(api_key: nil) ⇒ Client

Returns a new instance of Client.



5
6
7
# File 'lib/xpensify_sdk/client.rb', line 5

def initialize(api_key: nil)
  @api_key = api_key || XpensifySDK.config[:api_key]
end

Instance Method Details

#invoice(id) ⇒ Object



13
14
15
16
17
18
# File 'lib/xpensify_sdk/client.rb', line 13

def invoice(id)
  response = HTTPClient.invoice(id, @api_key)
  Error.raise_from_code!(response.code) if response.code != 200
  # TODO: use dry-rb structs instead of OpenStruct
  JSON.parse(response.body.to_s, object_class: OpenStruct) # rubocop:disable Style/OpenStructUse
end

#invoices(params = {}) ⇒ Object



9
10
11
# File 'lib/xpensify_sdk/client.rb', line 9

def invoices(params = {})
  XpensifySDK::Invoices::RequestBuilder.new(@api_key, params)
end

#update_invoice(id, options) ⇒ Object



20
21
22
23
24
# File 'lib/xpensify_sdk/client.rb', line 20

def update_invoice(id, options)
  response = HTTPClient.update_invoice(id, options, @api_key)
  Error.raise_from_code!(response.code) if response.code != 200
  :ok
end