class Bitstampede::Net

Attributes

client[R]

Public Class Methods

new(client) click to toggle source
# File lib/bitstampede/net.rb, line 7
def initialize(client)
  @client = client
end

Public Instance Methods

key() click to toggle source
# File lib/bitstampede/net.rb, line 15
def key
  client.key
end
post(endpoint, options={}) click to toggle source
# File lib/bitstampede/net.rb, line 19
def post(endpoint, options={})
  map_response(raw_post(endpoint, options))
end
secret() click to toggle source
# File lib/bitstampede/net.rb, line 11
def secret
  client.secret
end

Private Instance Methods

auth_options() click to toggle source
# File lib/bitstampede/net.rb, line 32
def auth_options
  {
    user: key,
    password: secret
  }
end
base_url() click to toggle source
# File lib/bitstampede/net.rb, line 28
def base_url
  'https://www.bitstamp.net/api/'
end
map_response(wish_this_were_reliably_json) click to toggle source

For some crazy reason, bitstamp is returning ruby hash strings rather than JSON objects right now ಠ_ಠ I’m just going to gsub ‘=>’ to ‘:’ to ‘solve’ it for now. Not thrilled with this.

# File lib/bitstampede/net.rb, line 42
def map_response(wish_this_were_reliably_json)
  wish_this_were_reliably_json.gsub('=>', ':')
end
raw_post(endpoint, options) click to toggle source
# File lib/bitstampede/net.rb, line 46
def raw_post(endpoint, options)
  uri = URI url_for(endpoint)
  http = ::Net::HTTP::Persistent.new 'bitstampede'
  post = ::Net::HTTP::Post.new uri.path
  post.set_form_data options.merge(auth_options)
  http.request(uri, post).body
end
url_for(endpoint) click to toggle source
# File lib/bitstampede/net.rb, line 24
def url_for(endpoint)
  base_url + endpoint + '/'
end