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



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

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 = { "Sign" => sign(query, private_key), "Key" => public_key } if auth
  params = {}
  params[:headers] = headers unless headers.nil?
  params[:query] = query unless query.empty?
  case method
  when "POST"
    params[:body] = options
    response = HTTParty.post(url, params)
  when "DELETE"
    response = HTTParty.delete(url, params)
  else
    response = HTTParty.get(url, params)
  end
  output = JSON.parse(response.body)
  return output['data'] if output['success']
  return output
rescue JSON::ParserError => e
  return response.body
end