Last active
October 22, 2015 23:09
-
-
Save JosephBrianChambers/9576b89f7c707f0df3b3 to your computer and use it in GitHub Desktop.
Fetch PoolProjection from token-service
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'active_support/all' | |
require 'faraday' | |
require 'json' | |
AUTH_USERNAME = '' | |
AUTH_PASSWORD = '' | |
def fetch_pp_data(provider_id = 14, token_type = :account, day_epoch = Time.now.beginning_of_day.to_i) | |
pp_id = [provider_id, token_type, day_epoch].join(':') | |
url = "https://token-service.bmasked.info/v1/pool_projections/#{pp_id}" | |
conn = Faraday.new(:url => url) do |faraday| | |
faraday.use Faraday::Request::BasicAuthentication, AUTH_USERNAME, AUTH_PASSWORD | |
faraday.adapter Faraday.default_adapter # make requests with Net::HTTP | |
end | |
return unless (response = conn.get).status == 200 | |
data = JSON.parse(response.body)['projection_data'] | |
data.each { |epoch, pool_size| puts [Time.at(epoch).in_time_zone('Pacific Time (US & Canada)'), pool_size].join("\t") } | |
pp_id | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Time.now.beginning_of_day,to_i typo