Class: Cryptsy::API2::Request

Inherits:
Object
  • Object
show all
Defined in:
lib/cryptsy/api2.rb

Class Method Summary collapse

Class Method Details

.send(path, query = {}, public_key = nil, private_key = nil, method = "GET") ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/cryptsy/api2.rb', line 33

def self.send(path, query={}, public_key=nil, private_key=nil, method="GET")
  auth = !public_key.nil? && !private_key.nil?
  url = "https://api.cryptsy.com/api/v2/#{path}"
  query[:nonce] = nonce if auth
  options = URI.encode_www_form(query) unless query.empty?
  headers = {}
  headers["Sign"] = sign(query, private_key) if auth
  headers["Key"] = public_key if auth
  case method
  when "POST"
    response = HTTParty.post(url, headers: headers, body: query)
  when "DELETE"
    response = HTTParty.delete(url, headers: headers, body: query)
  else
    response = HTTParty.get(url, headers: headers, query: query)
  end

  return JSON.parse(response.body)
rescue JSON::ParserError => e
  return response.body
end