Class: Bitex::Api
- Inherits:
-
Object
- Object
- Bitex::Api
- Defined in:
- lib/bitex/api.rb
Class Method Summary collapse
- .curl(verb, path, options = {}) ⇒ Object
-
.deserialize(object) ⇒ Object
Deserialize a single object from a json representation as specified on the bitex API class reference.
- .private(verb, path, options = {}) ⇒ Object
- .public(path, options = {}) ⇒ Object
Class Method Details
.curl(verb, path, options = {}) ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/bitex/api.rb', line 4 def self.curl(verb, path, ={}) verb = verb.upcase.to_sym query = verb == :GET ? "?#{.to_query}" : '' curl = Curl::Easy.new("https://bitex.la/api-v1/rest#{path}#{query}") curl.post_body = .to_query if verb == :POST curl.http(verb) code = curl.response_code unless [200, 201, 202].include?(code) raise ApiError.new("Got #{code} fetching #{path} with #{}") end return curl end |
.deserialize(object) ⇒ Object
Deserialize a single object from a json representation as specified on the bitex API class reference
34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/bitex/api.rb', line 34 def self.deserialize(object) { 1 => Bid, 2 => Ask, 3 => Buy, 4 => Sell, 5 => SpecieDeposit, 6 => SpecieWithdrawal, 7 => UsdDeposit, 8 => UsdWithdrawal, }[object.first].from_json(object) end |
.private(verb, path, options = {}) ⇒ Object
24 25 26 27 28 29 |
# File 'lib/bitex/api.rb', line 24 def self.private(verb, path, ={}) if Bitex.api_key.nil? raise Exception.new("No api_key available to make private key calls") end JSON.parse(curl(verb, path, .merge(api_key: Bitex.api_key)).body) end |
.public(path, options = {}) ⇒ Object
20 21 22 |
# File 'lib/bitex/api.rb', line 20 def self.public(path, ={}) JSON.parse(curl(:GET, path).body) end |