Last active
April 26, 2017 17:26
-
-
Save abhisek/79c602e454ce1620730f7561cd329480 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
class DataServiceClient | |
def initialize(customer_id) | |
raise "Invalid Customer Id" if customer_id.to_i.zero? | |
@customer_id = customer_id.to_i | |
@client = RestClient::Resource.new(ENV['DATA_API_URL'] + '/customers/' + @customer_id.to_s, | |
:headers => { 'X-Access-Token' => ENV['DATA_API_KEY'], 'Accept' => 'application/json' }) | |
end | |
def info | |
{ | |
:assets => handle_response(@client['assets'].get(), [ :id, :asset_type, :value ]), | |
:projects => handle_response(@client['projects'].get(), [ :id, :type, :name ]) | |
} | |
end | |
private | |
def handle_response(res, whitelist=[]) | |
if res.code == 200 | |
do_whitelist(JSON.parse(res.body), whitelist) | |
else | |
{ :error => 'UpstreamError', :message => 'Failed to fetch resource from upstream' } | |
end | |
end | |
def do_whitelist(h, w) | |
# Do whitelisting of hash keys | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment