Class: Bitbond::Client

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

Instance Attribute Summary collapse

Instance Method Summary collapse

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_atObject

Returns the value of attribute expires_at.



7
8
9
# File 'lib/bitbond/client.rb', line 7

def expires_at
  @expires_at
end

#refresh_tokenObject

Returns the value of attribute refresh_token.



7
8
9
# File 'lib/bitbond/client.rb', line 7

def refresh_token
  @refresh_token
end

#tokenObject

Returns the value of attribute token.



7
8
9
# File 'lib/bitbond/client.rb', line 7

def token
  @token
end

Instance Method Details

#access_tokenObject



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_type: 'primary')
  require_param :account_type, 
  get "accounts/#{}"
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(rating),
    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(rating),
    term: Array(term),
    page: page
  }
end

#oauth_clientObject



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

#refreshObject



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

#webhooksObject



61
62
63
# File 'lib/bitbond/client.rb', line 61

def webhooks
  get 'webhooks'
end