Class: GrowViral::Keystore::AccountFetcher
- Inherits:
-
Object
- Object
- GrowViral::Keystore::AccountFetcher
- Defined in:
- lib/keystore/account_fetcher.rb
Instance Attribute Summary collapse
-
#application_id ⇒ Object
readonly
Returns the value of attribute application_id.
-
#config ⇒ Object
readonly
Returns the value of attribute config.
-
#uid ⇒ Object
readonly
Returns the value of attribute uid.
Class Method Summary collapse
Instance Method Summary collapse
- #exists? ⇒ Boolean
- #fetch ⇒ Object
-
#initialize(application_id, uid, deps) ⇒ AccountFetcher
constructor
A new instance of AccountFetcher.
- #uri ⇒ Object
Constructor Details
#initialize(application_id, uid, deps) ⇒ AccountFetcher
Returns a new instance of AccountFetcher.
13 14 15 16 17 18 19 |
# File 'lib/keystore/account_fetcher.rb', line 13 def initialize(application_id, uid, deps) raise HandleNotUidError unless uid.is_a? Numeric @application_id = application_id @uid = uid @config = deps[:config] end |
Instance Attribute Details
#application_id ⇒ Object (readonly)
Returns the value of attribute application_id.
12 13 14 |
# File 'lib/keystore/account_fetcher.rb', line 12 def application_id @application_id end |
#config ⇒ Object (readonly)
Returns the value of attribute config.
12 13 14 |
# File 'lib/keystore/account_fetcher.rb', line 12 def config @config end |
#uid ⇒ Object (readonly)
Returns the value of attribute uid.
12 13 14 |
# File 'lib/keystore/account_fetcher.rb', line 12 def uid @uid end |
Class Method Details
.exists?(*args) ⇒ Boolean
8 9 10 |
# File 'lib/keystore/account_fetcher.rb', line 8 def self.exists?(*args) new(*args).exists? end |
.fetch(*args) ⇒ Object
4 5 6 |
# File 'lib/keystore/account_fetcher.rb', line 4 def self.fetch(*args) new(*args).fetch end |
Instance Method Details
#exists? ⇒ Boolean
21 22 23 24 25 |
# File 'lib/keystore/account_fetcher.rb', line 21 def exists? fetch rescue GrowViral::NoAccountError false end |
#fetch ⇒ Object
27 28 29 30 31 32 33 34 |
# File 'lib/keystore/account_fetcher.rb', line 27 def fetch response = Net::HTTP.get_response(uri) if response.code.to_i == 200 Account.new JSON.parse(response.body) else raise GrowViral::NoAccountError.new(uid) end end |
#uri ⇒ Object
36 37 38 |
# File 'lib/keystore/account_fetcher.rb', line 36 def uri @uri ||= URI.parse("#{config.host}/applications/#{application_id}/accounts/#{uid}") end |