Class: Bitbond::Client
- Inherits:
-
Object
- Object
- Bitbond::Client
- Defined in:
- lib/bitbond/client.rb
Instance Attribute Summary collapse
-
#expires_at ⇒ Object
Returns the value of attribute expires_at.
-
#refresh_token ⇒ Object
Returns the value of attribute refresh_token.
-
#token ⇒ Object
Returns the value of attribute token.
Instance Method Summary collapse
- #access_token ⇒ Object
- #account(account_type: 'primary') ⇒ Object
- #bid(loan_id:, amount:) ⇒ Object
- #create_webhook(callback_url:) ⇒ Object
- #delete(endpoint) ⇒ Object
- #delete_webhook(webhook_id:) ⇒ Object
- #get(endpoint, params = {}) ⇒ Object
-
#initialize(access_token:, refresh_token: nil, expires_at: nil) ⇒ Client
constructor
A new instance of Client.
- #investment(investment_id:) ⇒ Object
- #investments(base_currency: [], rating: [], term: [], status: []) ⇒ Object
- #loan(loan_id:) ⇒ Object
- #loans(status: [], base_currency: [], rating: [], term: [], page: 0) ⇒ Object
- #oauth_client ⇒ Object
- #post(endpoint, params = {}) ⇒ Object
- #profile(profile_id:) ⇒ Object
- #refresh ⇒ Object
- #url(endpoint) ⇒ Object
- #webhooks ⇒ Object
Constructor Details
#initialize(access_token:, refresh_token: nil, expires_at: nil) ⇒ Client
Returns a new instance of Client.
9 10 11 12 13 |
# 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 |
Instance Attribute Details
#expires_at ⇒ Object
Returns the value of attribute expires_at.
7 8 9 |
# File 'lib/bitbond/client.rb', line 7 def expires_at @expires_at end |
#refresh_token ⇒ Object
Returns the value of attribute refresh_token.
7 8 9 |
# File 'lib/bitbond/client.rb', line 7 def refresh_token @refresh_token end |
#token ⇒ Object
Returns the value of attribute token.
7 8 9 |
# File 'lib/bitbond/client.rb', line 7 def token @token end |
Instance Method Details
#access_token ⇒ Object
102 103 104 |
# 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') ⇒ Object
35 36 37 38 |
# 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:) ⇒ Object
55 56 57 58 59 |
# 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:) ⇒ Object
65 66 67 68 |
# 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) ⇒ Object
86 87 88 |
# File 'lib/bitbond/client.rb', line 86 def delete(endpoint) access_token.delete(url(endpoint)) end |
#delete_webhook(webhook_id:) ⇒ Object
70 71 72 73 |
# 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 = {}) ⇒ Object
75 76 77 78 |
# 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:) ⇒ Object
25 26 27 28 |
# 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: []) ⇒ Object
16 17 18 19 20 21 22 23 |
# 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(), term: Array(term) } end |
#loan(loan_id:) ⇒ Object
50 51 52 53 |
# 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) ⇒ Object
40 41 42 43 44 45 46 47 48 |
# 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(), term: Array(term), page: page } end |
#oauth_client ⇒ Object
94 95 96 97 98 99 100 |
# 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 = {}) ⇒ Object
81 82 83 84 |
# 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:) ⇒ Object
30 31 32 33 |
# File 'lib/bitbond/client.rb', line 30 def profile(profile_id:) require_param :profile_id, profile_id get "profiles/#{profile_id}" end |
#refresh ⇒ Object
106 107 108 |
# File 'lib/bitbond/client.rb', line 106 def refresh access_token.refresh! end |
#url(endpoint) ⇒ Object
90 91 92 |
# File 'lib/bitbond/client.rb', line 90 def url(endpoint) [Bitbond.configuration.api_host, endpoint].join("/") end |
#webhooks ⇒ Object
61 62 63 |
# File 'lib/bitbond/client.rb', line 61 def webhooks get 'webhooks' end |