class Bitbot::Blockchain

Public Class Methods

new(id, password1, password2) click to toggle source
# File lib/bitbot/blockchain.rb, line 7
def initialize(id, password1, password2)
  @id = id
  @password1 = password1
  @password2 = password2
end

Public Instance Methods

create_deposit_address_for_user_id(user_id) click to toggle source
# File lib/bitbot/blockchain.rb, line 32
def create_deposit_address_for_user_id(user_id)
  self.request(:merchant, :new_address,
               :password => @password1,
               :second_password => @password2,
               :label => user_id)
end
create_payment(address, amount, fee) click to toggle source
# File lib/bitbot/blockchain.rb, line 56
def create_payment(address, amount, fee)
  response = self.request(:merchant, :payment,
                          :password => @password1,
                          :second_password => @password2,
                          :to => address,
                          :amount => amount,
                          :fee => fee)
  response
end
get_addresses_in_wallet() click to toggle source
# File lib/bitbot/blockchain.rb, line 43
def get_addresses_in_wallet
  response = self.request(:merchant, :list, :password => @password1)
  response["addresses"]
end
get_balance_for_address(address, confirmations = 1) click to toggle source
# File lib/bitbot/blockchain.rb, line 48
def get_balance_for_address(address, confirmations = 1)
  response = self.request(:merchant, :address_balance,
                          :password => @password1,
                          :address => address,
                          :confirmations => confirmations)
  response["balance"]
end
get_details_for_address(address) click to toggle source
# File lib/bitbot/blockchain.rb, line 39
def get_details_for_address(address)
  self.request(:address, address, :format => :json)
end
get_exchange_rates() click to toggle source
# File lib/bitbot/blockchain.rb, line 66
def get_exchange_rates
  self.request(:ticker)
end
request(api, action = nil, params = {}) click to toggle source
# File lib/bitbot/blockchain.rb, line 13
def request(api, action = nil, params = {})
  path = if api == :merchant
           "merchant/#{@id}/#{action}"
         elsif api == :ticker
           "ticker"
         else
           "#{api}/#{action}"
         end
  url = "https://blockchain.info/#{path}?"
  params.each do |key, value|
    url += "#{key}=#{CGI::escape value.to_s}&"
  end

  response = HTTParty.get(url)
  raise "HTTP Error: #{response}" unless response.code == 200

  JSON.parse(response.body)
end