Class: Bitflyer::HTTP::Connection

Inherits:
Object
  • Object
show all
Defined in:
lib/bitflyer/http.rb

Instance Method Summary collapse

Constructor Details

#initialize(key, secret) ⇒ Connection

Returns a new instance of Connection.



18
19
20
21
22
# File 'lib/bitflyer/http.rb', line 18

def initialize(key, secret)
  @key = key
  @secret = secret
  @uri = URI.parse(BASE_URL)
end

Instance Method Details

#get(path, params = {}) ⇒ Object



24
25
26
27
28
29
30
# File 'lib/bitflyer/http.rb', line 24

def get(path, params = {})
  query = URI.encode_www_form(params.compact)
  full_path = query.empty? ? path : "#{path}?#{query}"
  request = Net::HTTP::Get.new(full_path, default_headers)
  sign_request(request, full_path)
  Response.new(execute(request))
end

#post(path, body = {}) ⇒ Object



32
33
34
35
36
37
# File 'lib/bitflyer/http.rb', line 32

def post(path, body = {})
  request = Net::HTTP::Post.new(path, default_headers.merge('Content-Type' => 'application/json'))
  request.body = JSON.generate(body.compact)
  sign_request(request, path, request.body)
  Response.new(execute(request))
end