Class: Tide::API::Client
- Inherits:
-
Object
- Object
- Tide::API::Client
- Defined in:
- lib/tide/api/client.rb
Overview
Main interface to Tide API
Constant Summary collapse
- BASE_PATH =
Base path to Tide API version 1
'https://api.tide.co/tide-backend/rest/api/v1'.freeze
Instance Method Summary collapse
-
#fetch_accounts(company_id) ⇒ Error|Array<Transaction>
Retrieves all accounts of a given company.
-
#fetch_companies ⇒ Error|Array<Company>
Retrieves all companies of the authenticated user.
-
#fetch_tokens(auth_grant_code) ⇒ Object
Exchanges an auth nonce for OAuth2 access and refresh tokens.
-
#fetch_transactions(account_id) ⇒ Error|Array<Transaction>
Retrieves all transactions of a given account.
-
#initialize(mapper: Mapper.new, http_client: HTTPClient.new) ⇒ Client
constructor
Instantiates an API client.
Constructor Details
#initialize(mapper: Mapper.new, http_client: HTTPClient.new) ⇒ Client
Instantiates an API client
21 22 23 24 |
# File 'lib/tide/api/client.rb', line 21 def initialize(mapper: Mapper.new, http_client: HTTPClient.new) @mapper = mapper @http_client = http_client end |
Instance Method Details
#fetch_accounts(company_id) ⇒ Error|Array<Transaction>
Retrieves all accounts of a given company
56 57 58 59 |
# File 'lib/tide/api/client.rb', line 56 def fetch_accounts(company_id) response = http_client.get("#{BASE_PATH}/external/companies/#{company_id}/accounts") response.error? && build_error_from(response) || build_accounts_from(response) end |
#fetch_companies ⇒ Error|Array<Company>
Retrieves all companies of the authenticated user
45 46 47 48 |
# File 'lib/tide/api/client.rb', line 45 def fetch_companies response = http_client.get("#{BASE_PATH}/external/companies") response.error? && build_error_from(response) || build_companies_from(response) end |
#fetch_tokens(auth_grant_code) ⇒ Object
Exchanges an auth nonce for OAuth2 access and refresh tokens.
30 31 32 33 34 35 36 37 38 39 |
# File 'lib/tide/api/client.rb', line 30 def fetch_tokens(auth_grant_code) response = http_client.get("#{BASE_PATH}/oauth2/tokens?code=#{auth_grant_code}") return build_error_from(response) if response.error? build_tokens_from(response).tap do |tokens| http_client.refresh_token = tokens.refresh_token http_client.access_token = tokens.access_token end end |
#fetch_transactions(account_id) ⇒ Error|Array<Transaction>
Retrieves all transactions of a given account
67 68 69 70 |
# File 'lib/tide/api/client.rb', line 67 def fetch_transactions(account_id) response = http_client.get("#{BASE_PATH}/external/accounts/#{account_id}/transactions") response.error? && build_error_from(response) || build_transactions_from(response) end |