Class: Buttercoin::Client
- Inherits:
-
Object
- Object
- Buttercoin::Client
- Includes:
- AccountQueryMethods, OrderMethods, TransactionMethods, UnauthMethods, HTTParty
- Defined in:
- lib/buttercoin/client.rb,
lib/buttercoin/client/order_methods.rb,
lib/buttercoin/client/unauth_methods.rb,
lib/buttercoin/client/transaction_methods.rb,
lib/buttercoin/client/account_query_methods.rb
Defined Under Namespace
Modules: AccountQueryMethods, OrderMethods, TransactionMethods, UnauthMethods
Constant Summary collapse
- CONFIG =
{ :mode => "production" }
- PRODUCTION_URI =
'https://api.buttercoin.com/v1'
- SANDBOX_URI =
'https://sandbox.buttercoin.com/v1'
- CA_CERT =
'cert/ca-cert.crt'
Instance Attribute Summary collapse
-
#mode ⇒ Object
Returns the value of attribute mode.
-
#public_key ⇒ Object
Returns the value of attribute public_key.
-
#secret_key ⇒ Object
Returns the value of attribute secret_key.
Instance Method Summary collapse
- #delete(path, timestamp = nil, options = {}, authenticate = true) ⇒ Object
-
#get(path, timestamp = nil, options = {}, authenticate = true) ⇒ Object
Wrappers for the main HTTP verbs.
- #http_request(verb, path, timestamp = nil, options = {}, authenticate = true) ⇒ Object
-
#initialize(*args) ⇒ Client
constructor
A new instance of Client.
- #post(path, timestamp = nil, options = {}, authenticate = true) ⇒ Object
Methods included from TransactionMethods
#cancel_transaction, #create_deposit, #create_withdrawal, #get_transaction_by_id, #get_transaction_by_url, #get_transactions, #send_bitcoin
Methods included from OrderMethods
#cancel_order, #create_order, #get_order_by_id, #get_order_by_url, #get_orders
Methods included from AccountQueryMethods
#get_balances, #get_deposit_address, #get_key
Methods included from UnauthMethods
#get_order_book, #get_ticker, #get_trade_history
Constructor Details
#initialize(*args) ⇒ Client
Returns a new instance of Client.
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/buttercoin/client.rb', line 30 def initialize(*args) = args[0] unless .is_a?(Hash) # deprecated, pass a hash of options instead = { :public_key => args[0], :secret_key => args[1], :mode => args[2] } end self.public_key, self.secret_key = .values_at(:public_key, :secret_key) self.mode = [:mode] || CONFIG[:mode] self.class.base_uri (self.mode == 'production') ? PRODUCTION_URI : SANDBOX_URI end |
Instance Attribute Details
#mode ⇒ Object
Returns the value of attribute mode.
19 20 21 |
# File 'lib/buttercoin/client.rb', line 19 def mode @mode end |
#public_key ⇒ Object
Returns the value of attribute public_key.
19 20 21 |
# File 'lib/buttercoin/client.rb', line 19 def public_key @public_key end |
#secret_key ⇒ Object
Returns the value of attribute secret_key.
19 20 21 |
# File 'lib/buttercoin/client.rb', line 19 def secret_key @secret_key end |
Instance Method Details
#delete(path, timestamp = nil, options = {}, authenticate = true) ⇒ Object
57 58 59 |
# File 'lib/buttercoin/client.rb', line 57 def delete(path, =nil, ={}, authenticate=true) http_request :delete, path, , , authenticate end |
#get(path, timestamp = nil, options = {}, authenticate = true) ⇒ Object
Wrappers for the main HTTP verbs
48 49 50 51 |
# File 'lib/buttercoin/client.rb', line 48 def get(path, =nil, ={}, authenticate=true) path = "#{path}?#{URI.encode_www_form()}" if !.empty? http_request :get, path, , , authenticate end |
#http_request(verb, path, timestamp = nil, options = {}, authenticate = true) ⇒ Object
61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/buttercoin/client.rb', line 61 def http_request(verb, path, =nil, ={}, authenticate=true) = {} if (authenticate) ||= ((Time.now.to_f * 1e3).round).to_i = (verb, path, , ) signature = get_signature() = {body: .to_json} if [:post].include? verb [:headers] = get_headers(signature, ) end set_cert() r = self.class.send(verb, path, ) process_response(r.code, r.body, r.headers) end |
#post(path, timestamp = nil, options = {}, authenticate = true) ⇒ Object
53 54 55 |
# File 'lib/buttercoin/client.rb', line 53 def post(path, =nil, ={}, authenticate=true) http_request :post, path, , , authenticate end |