Files
2025-10-18 09:29:55 -05:00

51 lines
1.3 KiB
Ruby

# frozen_string_literal: true
module StrikeMe
module API
# Factory helper object connecting the client to the models
class Account
include BaseClient
autoload_default :Profile
autoload_default :Balances
autoload_default :Balance
def profile
return @profile if @profile.present?
url = profile_url
response = client.get url
# body = response.body.presence
# body = JSON.parse(body) if body.is_a? String
raise ResponseError.new(url, response.body) unless response.success?
@profile = Profile.new response.body.merge(account: self)
# if you see this, something went wrong, this is test code
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'
raise ResponseError.new('balances', response.body) unless response.success?
@balances = Balances.new self, response.body
end
def inspect
"#<StrikeMe::API::Account profile: #{@profile}, balances: #{@balances}>"
end
end
end
end