Skip to content

Commit 9ca031c

Browse files
committed
added Resource.find, moving error handling into the realm of gg, not applications, see ggtracker/esdb#126
1 parent 8c8b82c commit 9ca031c

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

lib/esdb/resource.rb

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,23 @@ def get!(*args)
4040
@response = get(*args)
4141
end
4242

43+
# TODO: prepare to get rid of RestClient potentially, it's not really
44+
# maintained anymore anyway. Don't use RestClient specific calls outside
45+
# of gg itself and give gg an AR-like API.
46+
def self.find(id)
47+
resource = self.new(id: id)
48+
resource.get!
49+
50+
if [200..207].include?(resource.response.code)
51+
return resource
52+
else
53+
return nil
54+
end
55+
56+
rescue
57+
nil
58+
end
59+
4360
# A kind of find_or_create - experimental.
4461
# For example identities should be created and returned if sufficient
4562
# identifying data is submitted, but no identity is found.

0 commit comments

Comments
 (0)