Class: Bitex::Api
- Inherits:
-
Object
- Object
- Bitex::Api
- Defined in:
- lib/bitex/api.rb
Class Method Summary collapse
- .curl(verb, path, options = {}, files = {}) ⇒ Object
-
.deserialize(object) ⇒ Object
Deserialize a single object from a json representation as specified on the bitex API class reference.
- .private(verb, path, options = {}, files = {}) ⇒ Object
- .public(path, options = {}) ⇒ Object
Class Method Details
.curl(verb, path, options = {}, files = {}) ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/bitex/api.rb', line 4 def self.curl(verb, path, ={}, files={}) verb = verb.upcase.to_sym query = verb == :GET ? "?#{.to_query}" : '' prefix = Bitex.sandbox ? 'sandbox.' : '' curl = Curl::Easy.new("https://#{prefix}bitex.la/api-v1/rest#{path}#{query}") curl.ssl_version = Curl::CURL_SSLVERSION_TLSv1 if Bitex.debug curl.on_debug do |t,d| if d.to_s.size < 300 puts "DEBUG SSL #{t}, #{d}" end end end if verb == :POST fields = [] unless files.empty? fields += files.collect{|k, v| Curl::PostField.file(k.to_s, v) } curl.multipart_form_post = true end fields += .collect do |k,v| next unless v Curl::PostField.content(k.to_s, v) end.compact curl.send("http_#{verb.downcase}", *fields) else curl.put_data = .to_query if verb == :PUT curl.http(verb) end code = curl.response_code unless [200, 201, 202].include?(code) raise ApiError.new("Got #{code} fetching #{path} with #{}\n\n#{curl.head}\n\n#{curl.body}") end return curl end |
.deserialize(object) ⇒ Object
Deserialize a single object from a json representation as specified on the bitex API class reference
59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/bitex/api.rb', line 59 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 = {}, files = {}) ⇒ Object
49 50 51 52 53 54 |
# File 'lib/bitex/api.rb', line 49 def self.private(verb, path, ={}, files={}) if Bitex.api_key.nil? raise StandardError.new("No api_key available to make private key calls") end JSON.parse(curl(verb, path, .merge(api_key: Bitex.api_key), files).body) end |
.public(path, options = {}) ⇒ Object
45 46 47 |
# File 'lib/bitex/api.rb', line 45 def self.public(path, ={}) JSON.parse(curl(:GET, path).body) end |