class Bitbond::Client
Attributes
expires_at[RW]
refresh_token[RW]
token[RW]
Public Class Methods
new(access_token:, refresh_token: nil, expires_at: nil)
click to toggle source
# File lib/bitbond/client.rb, line 9 def initialize(access_token:, refresh_token: nil, expires_at: nil) self.token = access_token self.refresh_token = refresh_token self.expires_at = expires_at end
Public Instance Methods
access_token()
click to toggle source
# File lib/bitbond/client.rb, line 102 def access_token @access_token ||= OAuth2::AccessToken.new(oauth_client, token, refresh_token: refresh_token, expires_at: expires_at) end
account(account_type: 'primary')
click to toggle source
# File lib/bitbond/client.rb, line 35 def account(account_type: 'primary') require_param :account_type, account_type get "accounts/#{account_type}" end
bid(loan_id:, amount:)
click to toggle source
# File lib/bitbond/client.rb, line 55 def bid(loan_id:, amount:) require_param :loan_id, loan_id require_param :amount, amount post "loans/#{loan_id}/bids", { bid: { amount: amount } } end
create_webhook(callback_url: )
click to toggle source
# File lib/bitbond/client.rb, line 65 def create_webhook(callback_url: ) require_param :callback_url, callback_url post 'webhooks', { webhook: { callback_url: callback_url }} end
delete(endpoint)
click to toggle source
# File lib/bitbond/client.rb, line 86 def delete(endpoint) access_token.delete(url(endpoint)) end
delete_webhook(webhook_id:)
click to toggle source
# File lib/bitbond/client.rb, line 70 def delete_webhook(webhook_id:) require_param :webhook_id, webhook_id delete "webhooks/#{webhook_id}" end
get( endpoint, params = {})
click to toggle source
# File lib/bitbond/client.rb, line 75 def get( endpoint, params = {}) result = access_token.get( url(endpoint), { params: params } ) result.parsed end
investment(investment_id: )
click to toggle source
# File lib/bitbond/client.rb, line 25 def investment(investment_id: ) require_param :investment_id, investment_id get "investments/#{investment_id}" end
investments(base_currency: [], rating: [], term: [], status: [])
click to toggle source
# File lib/bitbond/client.rb, line 16 def investments(base_currency: [], rating: [], term: [], status: []) get "investments", { status: Array(status), base_currency: Array(base_currency), rating: Array(rating), term: Array(term) } end
loan(loan_id: )
click to toggle source
# File lib/bitbond/client.rb, line 50 def loan(loan_id: ) require_param :loan_id, loan_id get "loans/#{loan_id}" end
loans(status: [], base_currency: [], rating: [], term: [], page: 0)
click to toggle source
# File lib/bitbond/client.rb, line 40 def loans(status: [], base_currency: [], rating: [], term: [], page: 0) get "loans", { status: Array(status), base_currency: Array(base_currency), rating: Array(rating), term: Array(term), page: page } end
oauth_client()
click to toggle source
# File lib/bitbond/client.rb, line 94 def oauth_client @oauth_client ||= OAuth2::Client.new( Bitbond.configuration.app_id, Bitbond.configuration.secret_key, site: Bitbond.configuration.api_host ) end
post( endpoint, params = {})
click to toggle source
# File lib/bitbond/client.rb, line 81 def post( endpoint, params = {}) result = access_token.post( url(endpoint), { body: params.to_json, headers: {'Content-Type' => 'application/json'}}) result.parsed end
profile(profile_id:)
click to toggle source
# File lib/bitbond/client.rb, line 30 def profile(profile_id:) require_param :profile_id, profile_id get "profiles/#{profile_id}" end
refresh()
click to toggle source
# File lib/bitbond/client.rb, line 106 def refresh access_token.refresh! end
url(endpoint)
click to toggle source
# File lib/bitbond/client.rb, line 90 def url(endpoint) [Bitbond.configuration.api_host, endpoint].join("/") end
webhooks()
click to toggle source
# File lib/bitbond/client.rb, line 61 def webhooks get 'webhooks' end
Private Instance Methods
require_param(symbol, val)
click to toggle source
# File lib/bitbond/client.rb, line 112 def require_param(symbol, val) # this is taken from the implementation of rails: blank? if val.respond_to?(:empty?) ? !!val.empty? : !val raise ArgumentError, "Expected #{symbol} to be present, got: '#{val}'" end end