class XeroAPI
Constants
- XERO_CONNECTOR_URL
Attributes
xero_guid[R]
Public Class Methods
new(xero_guid)
click to toggle source
# File lib/xero_api.rb, line 7 def initialize(xero_guid) @xero_guid = xero_guid end
Public Instance Methods
accounts(type = nil)
click to toggle source
# File lib/xero_api.rb, line 11 def accounts(type = nil) return cached_accounts if type.nil? cached_accounts.find_all { |account| account.type == type } rescue StandardError # Handles unauthorized case [] end
balance(bank_name)
click to toggle source
# File lib/xero_api.rb, line 30 def balance(bank_name) get('/balance', { bank_name: bank_name }).body end
new_invoice(invoice_data)
click to toggle source
# File lib/xero_api.rb, line 22 def new_invoice(invoice_data) post('/invoices/new', data: invoice_data) end
new_transaction(transaction_data)
click to toggle source
# File lib/xero_api.rb, line 18 def new_transaction(transaction_data) post('/transactions/new', data: transaction_data) end
new_transfer(transfer_data)
click to toggle source
# File lib/xero_api.rb, line 26 def new_transfer(transfer_data) post('/transfers/new', data: transfer_data) end
Private Instance Methods
cached_accounts()
click to toggle source
# File lib/xero_api.rb, line 38 def cached_accounts @cached_accounts ||= get('/accounts/').map do |account_hash| OpenStruct.new(account_hash) end end
get(path, query = {})
click to toggle source
# File lib/xero_api.rb, line 52 def get(path, query = {}) HTTParty.get( request_url(path), query: query.merge(guid: xero_guid) ) end
post(path, body)
click to toggle source
# File lib/xero_api.rb, line 44 def post(path, body) HTTParty.post( request_url(path), body: body.merge(xero_guid: xero_guid).to_json, headers: { 'Content-Type' => 'application/json' } ) end
request_url(path)
click to toggle source
# File lib/xero_api.rb, line 59 def request_url(path) XERO_CONNECTOR_URL + path end