53 lines
1.4 KiB
Ruby
53 lines
1.4 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
module StrikeMe
|
|
module API
|
|
class Account
|
|
include BaseClient
|
|
|
|
autoload_default :Profile
|
|
autoload_default :Balances
|
|
autoload_default :Balance
|
|
|
|
def profile
|
|
return @profile if @profile.present?
|
|
|
|
response = client.get profile_url
|
|
if response.success?
|
|
body = response.body
|
|
body = JSON.parse(body) if body.is_a? String
|
|
@profile = Profile.new body.merge(account: self)
|
|
else
|
|
# if you see this, something went wrong, this is test code
|
|
@profile = ResponseError.new(profile_url, response)
|
|
end
|
|
end
|
|
|
|
def profile_url
|
|
if (account_id = ENV['STRIKE_ACCOUNT_ID'].presence)
|
|
"accounts/#{account_id}/profile"
|
|
else
|
|
account_handle = ENV.fetch('STRIKE_ACCOUNT_HANDLE')
|
|
"accounts/handles/#{account_handle}/profile"
|
|
end
|
|
end
|
|
|
|
def balances
|
|
return @balances if @balances.present?
|
|
|
|
response = client.get 'balances'
|
|
@balances = if response.success?
|
|
Balances.new self, response.body
|
|
else
|
|
# if you see this, something went wrong, this is test code
|
|
ResponseError.new('balances', response)
|
|
end
|
|
end
|
|
|
|
def inspect
|
|
"#<StrikeMe::API::Account profile: #{@profile}, balances: #{@balances}>"
|
|
end
|
|
end
|
|
end
|
|
end
|