Skip to content

Instantly share code, notes, and snippets.

@abhisek
Last active April 26, 2017 17:26
Show Gist options
  • Save abhisek/79c602e454ce1620730f7561cd329480 to your computer and use it in GitHub Desktop.
Save abhisek/79c602e454ce1620730f7561cd329480 to your computer and use it in GitHub Desktop.
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