class GrowViral::Keystore::AccountFetcher

Attributes

application_id[R]
config[R]
uid[R]

Public Class Methods

exists?(*args) click to toggle source
# File lib/keystore/account_fetcher.rb, line 8
def self.exists?(*args)
  new(*args).exists?
end
fetch(*args) click to toggle source
# File lib/keystore/account_fetcher.rb, line 4
def self.fetch(*args)
  new(*args).fetch
end
new(application_id, uid, deps) click to toggle source
# 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

Public Instance Methods

exists?() click to toggle source
# File lib/keystore/account_fetcher.rb, line 21
def exists?
  fetch
rescue GrowViral::NoAccountError
  false
end
fetch() click to toggle source
# 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() click to toggle source
# File lib/keystore/account_fetcher.rb, line 36
def uri
  @uri ||= URI.parse("#{config.host}/applications/#{application_id}/accounts/#{uid}")
end