Skip to content

Instantly share code, notes, and snippets.

@JosephBrianChambers
Last active October 22, 2015 23:09
Show Gist options
  • Save JosephBrianChambers/9576b89f7c707f0df3b3 to your computer and use it in GitHub Desktop.
Save JosephBrianChambers/9576b89f7c707f0df3b3 to your computer and use it in GitHub Desktop.
Fetch PoolProjection from token-service
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
@xjlu
Copy link

xjlu commented Oct 22, 2015

Time.now.beginning_of_day,to_i typo

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment