class Middlecoin::Core::MiddlecoinAPI
Bitcoin Address
Attributes
report[RW]
Public Instance Methods
fetch(uri_str, limit = 10)
click to toggle source
Simple function for following redirects, found it on stackexchange
# File lib/middlecoin/core/middlecoinapi.rb, line 34 def fetch(uri_str, limit = 10) raise ArgumentError, 'HTTP redirect too deep' if limit == 0 url = URI.parse(uri_str) req = Net::HTTP::Get.new(url.path, { 'User-Agent' => "Agent" }) response = Net::HTTP.start(url.host, url.port) do |http| http.request(req) end case response when Net::HTTPSuccess then response when Net::HTTPRedirection then fetch(response['location'], limit - 1) else response.error! end end
fetch_report()
click to toggle source
Downloads and caches the report JSON from middlecoin.com
# File lib/middlecoin/core/middlecoinapi.rb, line 55 def fetch_report begin report = fetch("#{Middlecoin::MIDDLECOIN_URL}/json") @report = JSON.parse(report.body)["report"] rescue => e raise Middlecoin::MiddlecoinAPIError, "Unable to collect JSON report from middlecoin.com" end end
lookup(btc_address)
click to toggle source
Looks up a specific btc address in the JSON report from middlecoin.com
# File lib/middlecoin/core/middlecoinapi.rb, line 66 def lookup btc_address @report.each do |address| if address[0].eql?(btc_address) result = { :address => address[0], :lastHourShares => address[1]["lastHourShares"], :immatureBalance => address[1]["immatureBalance"], :lastHourRejectedShares => address[1]["lastHourRejectedShares"], :paidOut => address[1]["paidOut"], :unexchangedBalance => address[1]["unexchangedBalance"], :megahashesPerSecond => address[1]["megahashesPerSecond"], :bitcoinBalance => address[1]["bitcoinBalance"], :rejectedMegahashesPerSecond => address[1]["rejectedMegahashesPerSecond"] } return result end end return nil end