Class: Hungry::User

Inherits:
Resource show all
Defined in:
lib/hungry/user.rb

Instance Attribute Summary collapse

Attributes inherited from Resource

#attributes, #data_source

Class Method Summary collapse

Methods inherited from Resource

all, belongs_to, #canonical_data_source, collection, each, find, first, get, has_many, #initialize, lazy_load, #reload

Constructor Details

This class inherits a constructor from Hungry::Resource

Instance Attribute Details

#activated_atObject

Preview:



65
66
67
# File 'lib/hungry/user.rb', line 65

def activated_at
  @activated_at
end

#adminObject

Preview:



65
66
67
# File 'lib/hungry/user.rb', line 65

def admin
  @admin
end

#avatarObject

Preview:



65
66
67
# File 'lib/hungry/user.rb', line 65

def avatar
  @avatar
end

#bioObject

Preview:



65
66
67
# File 'lib/hungry/user.rb', line 65

def bio
  @bio
end

#birth_dateObject

Preview:



65
66
67
# File 'lib/hungry/user.rb', line 65

def birth_date
  @birth_date
end

#connectionsObject

Preview:



65
66
67
# File 'lib/hungry/user.rb', line 65

def connections
  @connections
end

#countersObject

Preview:



65
66
67
# File 'lib/hungry/user.rb', line 65

def counters
  @counters
end

#created_atObject

Preview:



65
66
67
# File 'lib/hungry/user.rb', line 65

def created_at
  @created_at
end

#device_tokensObject

Preview:



65
66
67
# File 'lib/hungry/user.rb', line 65

def device_tokens
  @device_tokens
end

#emailObject

Preview:



65
66
67
# File 'lib/hungry/user.rb', line 65

def email
  @email
end

#genderObject

Preview:



65
66
67
# File 'lib/hungry/user.rb', line 65

def gender
  @gender
end

#idObject

Preview:



65
66
67
# File 'lib/hungry/user.rb', line 65

def id
  @id
end

#locationObject

Preview:



65
66
67
# File 'lib/hungry/user.rb', line 65

def location
  @location
end

#maintainer_ofObject

Preview:



65
66
67
# File 'lib/hungry/user.rb', line 65

def maintainer_of
  @maintainer_of
end

#nameObject

Preview:



65
66
67
# File 'lib/hungry/user.rb', line 65

def name
  @name
end

#persistence_tokenObject

Preview:



65
66
67
# File 'lib/hungry/user.rb', line 65

def persistence_token
  @persistence_token
end

#profile_urlObject

Preview:



65
66
67
# File 'lib/hungry/user.rb', line 65

def profile_url
  @profile_url
end

#resourcesObject

Preview:



65
66
67
# File 'lib/hungry/user.rb', line 65

def resources
  @resources
end

#scoreObject

Preview:



65
66
67
# File 'lib/hungry/user.rb', line 65

def score
  @score
end

#single_access_tokenObject

Preview:



65
66
67
# File 'lib/hungry/user.rb', line 65

def single_access_token
  @single_access_token
end

#slugObject

Preview:



65
66
67
# File 'lib/hungry/user.rb', line 65

def slug
  @slug
end

#updated_atObject

Preview:



65
66
67
# File 'lib/hungry/user.rb', line 65

def updated_at
  @updated_at
end

#website_urlObject

Preview:



65
66
67
# File 'lib/hungry/user.rb', line 65

def website_url
  @website_url
end

Class Method Details

.authenticate_via_api(options = {}) ⇒ Object



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/hungry/user.rb', line 36

def self.authenticate_via_api(options = {})
  options = {
    path:  '/account.json',
    query: nil
  }.merge(options)

  url = URI.parse(Hungry.api_url)
  url.path  = options.delete(:path)
  url.query = options.delete(:query)

  http = Net::HTTP.new(url.host, url.port)
  if url.scheme == 'https'
    http.use_ssl     = true
    http.verify_mode = OpenSSL::SSL::VERIFY_NONE
  end

  request  = Net::HTTP::Get.new(url.request_uri, options)
  response = http.request request

  if response.code.to_i == 200
    response.body
  else
    false
  end
end

.authenticate_with_perishable_token(perishable_token) ⇒ Object



25
26
27
28
29
30
# File 'lib/hungry/user.rb', line 25

def self.authenticate_with_perishable_token(perishable_token)
  result = authenticate_via_api query: "perishable_token=#{perishable_token}"
  return false unless result.present?

  from_json(result)
end

.authenticate_with_persistence_token(persistence_token) ⇒ Object

CLASS METHODS:



18
19
20
21
22
23
# File 'lib/hungry/user.rb', line 18

def self.authenticate_with_persistence_token(persistence_token)
  result = authenticate_via_api 'Cookie' => "persistence_token=#{persistence_token}"
  return false unless result.present?

  from_json(result)
end

.from_json(json) ⇒ Object



32
33
34
# File 'lib/hungry/user.rb', line 32

def self.from_json(json)
  new Util.parse_json(json)
end

.with_ip(ip_address) ⇒ Object

FINDERS:



12
13
14
# File 'lib/hungry/user.rb', line 12

def self.with_ip(ip_address)
  collection.all(ip: ip_address)
end