Design updates with error handling
This commit is contained in:
1 parent
4c73608549
commit
4b84df0af9
9 files changed
+124
-38
No files matched your search
@@ -2,6 +2,8 @@
|
||||
|
||||
module StrikeMe
|
||||
module API
|
||||
|
||||
# Factory helper object connecting the client to the models
|
||||
class Account
|
||||
include BaseClient
|
||||
|
||||
@@ -12,14 +14,15 @@ module StrikeMe
|
||||
def profile
|
||||
return @profile if @profile.present?
|
||||
|
||||
response = client.get profile_url
|
||||
url = profile_url
|
||||
response = client.get url
|
||||
#body = response.body.presence
|
||||
#body = JSON.parse(body) if body.is_a? String
|
||||
if response.success?
|
||||
body = response.body
|
||||
body = JSON.parse(body) if body.is_a? String
|
||||
@profile = Profile.new body.merge(account: self)
|
||||
@profile = Profile.new response.body.merge(account: self)
|
||||
else
|
||||
# if you see this, something went wrong, this is test code
|
||||
@profile = ResponseError.new(profile_url, response)
|
||||
raise ResponseError.new(url, response.body)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -36,12 +39,11 @@ module StrikeMe
|
||||
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
|
||||
if response.success?
|
||||
@balances = Balances.new self, response.body
|
||||
else
|
||||
raise ResponseError.new('balances', response.body)
|
||||
end
|
||||
end
|
||||
|
||||
def inspect
|
||||
|
||||
Reference in new issue
Block a user