Module: Bitstamp::Net

Defined in:
lib/bitstamp/net.rb

Constant Summary collapse

HTTPI_ADAPTER =
:net_http

Class Method Summary collapse

Class Method Details

.delete(path, options = {}) ⇒ Object



44
45
46
# File 'lib/bitstamp/net.rb', line 44

def self.delete(path, options={})
  self.req(:delete, path, options)
end

.get(path, options = {}) ⇒ Object



32
33
34
# File 'lib/bitstamp/net.rb', line 32

def self.get(path, options={})
  self.req(:get, path, options)
end

.nonce_parameterObject



28
29
30
# File 'lib/bitstamp/net.rb', line 28

def self.nonce_parameter
  Bitstamp.nonce_parameter
end

.patch(path, options = {}) ⇒ Object



40
41
42
# File 'lib/bitstamp/net.rb', line 40

def self.patch(path, options={})
  self.req(:patch, path, options)
end

.post(path, options = {}) ⇒ Object



36
37
38
# File 'lib/bitstamp/net.rb', line 36

def self.post(path, options={})
  self.req(:post, path, options)
end

.req(verb, path, options = {}) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/bitstamp/net.rb', line 9

def self.req(verb, path, options={})
  r = HTTPI::Request.new(self.to_uri(path))

  if Bitstamp.conn_timeout
    r.open_timeout = Bitstamp.conn_timeout
    r.read_timeout = Bitstamp.conn_timeout
  end

  if Bitstamp.configured?
    options[:key] = Bitstamp.key
    options[:nonce] = self.nonce_parameter
    options[:signature] = HMAC::SHA256.hexdigest(Bitstamp.secret, options[:nonce]+Bitstamp.client_id.to_s+options[:key]).upcase
  end

  r.body = options

  HTTPI.request(verb, r, HTTPI_ADAPTER)
end

.to_uri(path) ⇒ Object



5
6
7
# File 'lib/bitstamp/net.rb', line 5

def self.to_uri(path)
  return "https://www.bitstamp.net/api#{path}/"
end