module Shapeshiftio

Constants

VERSION

Public Class Methods

cancel(deposit_address) click to toggle source
# File lib/shapeshiftio.rb, line 104
def self.cancel(deposit_address)
  params= { "address" => "#{deposit_address}"}
  api_call(params,"cancelpending")
end
fixed(amount, wallet_address, coin_pair, options = {}) click to toggle source
# File lib/shapeshiftio.rb, line 87
def self.fixed(amount, wallet_address, coin_pair, options = {})
  
  params = {
    "amount" => "#{amount}",
    "withdrawal" => "#{wallet_address}",
    "pair" => "#{coin_pair}",
    "apiKey" => "c354645558d70364fbc6a6dc85679e602036cbabeb42c91b3e268e817dd3494c7a1304cd08e2499dfebd8b8d34c219a514ec66d5d013c190e4b82ea2d6f42437"
  }.merge!(options)
  api_call(params,"sendamount")
end
get(path_name, value = nil, p2 = nil) click to toggle source
# File lib/shapeshiftio.rb, line 20
def self.get(path_name, value = nil, p2 = nil)
  route = ""
  route = route + (path_name.to_s + "/")
  if !(value.nil?)
    route = route + (value.to_s + "/")
  end
  
  if !(p2.nil?)
    route = route + (p2.to_s + "/")
  end
  uri = URI("https://shapeshift.io/#{route}")
  response = Net::HTTP.get(uri)
  check_response(response)
end
get_coins() click to toggle source
# File lib/shapeshiftio.rb, line 35
def self.get_coins
  coins = get("getcoins")
  all_coins = []
  coins.each do |coin|
    all_coins << coin[1]['name']
  end
  all_coins
end
limit(coin_pair) click to toggle source
# File lib/shapeshiftio.rb, line 44
def self.limit(coin_pair)
   get("limit", coin_pair)
end
market_info(coin_pair) click to toggle source
# File lib/shapeshiftio.rb, line 48
def self.market_info(coin_pair)
   get("marketinfo", coin_pair)
end
quote(amount, coin_pair) click to toggle source
# File lib/shapeshiftio.rb, line 98
def self.quote(amount, coin_pair)
  
  params = { "amount" => "#{amount}", "pair" => "#{coin_pair}"}
  api_call(params,"sendamount")
end
rate(coin_pair) click to toggle source
# File lib/shapeshiftio.rb, line 52
def self.rate(coin_pair)
   get("rate", coin_pair)
end
receipt(email, txid) click to toggle source
# File lib/shapeshiftio.rb, line 81
def self.receipt(email, txid)
  params = { "email" => "#{email}", "txid" => "#{txid}"}
  
  api_call(params,"mail")
end
recent_tx(max) click to toggle source
# File lib/shapeshiftio.rb, line 56
def self.recent_tx(max)
  get("recenttx", max)
end
shift(withdrawal, coin_pair, options = {}) click to toggle source
# File lib/shapeshiftio.rb, line 72
def self.shift(withdrawal, coin_pair, options = {})
  params = {"withdrawal" => "#{withdrawal}",
    "pair" => "#{coin_pair}",
    "apiKey" => "c354645558d70364fbc6a6dc85679e602036cbabeb42c91b3e268e817dd3494c7a1304cd08e2499dfebd8b8d34c219a514ec66d5d013c190e4b82ea2d6f42437"
  }.merge!(options)
  
  api_call(params,"shift")
end
time_remaining(deposit_address) click to toggle source
# File lib/shapeshiftio.rb, line 64
def self.time_remaining(deposit_address)
   get("timeremaining", deposit_address)
end
tx_stat(deposit_address) click to toggle source
# File lib/shapeshiftio.rb, line 60
def self.tx_stat(deposit_address)
   get("txStat", deposit_address)
end
validate(address,coin_symbol) click to toggle source
# File lib/shapeshiftio.rb, line 68
def self.validate(address,coin_symbol)
  get("validateAddress",address,coin_symbol)
end

Private Class Methods

api_call(params,url_method) click to toggle source
# File lib/shapeshiftio.rb, line 7
def self.api_call(params,url_method)
  url = URI.parse("https://shapeshift.io/#{url_method}")
  req = Net::HTTP::Post.new(url.request_uri)
  
  req.set_form_data(params)
  http = Net::HTTP.new(url.host, url.port)
  http.use_ssl = (url.scheme == "https")
  response = http.request(req)
  result = JSON.parse(response.body)
end
check_response(response) click to toggle source
# File lib/shapeshiftio.rb, line 111
def self.check_response(response)
  begin
    value = JSON.parse(response)
  rescue JSON::ParserError
    return puts "The API is not responding"
  end
end