Class: Beintoo::User

Inherits:
Object
  • Object
show all
Defined in:
lib/beintoo/user.rb

Constant Summary collapse

RESOURCE =
"user"
ATTRIBUTES =
[:email, :address, :country, :gender, :nickname, :name, :password, :sendGreetingsEmail, :guid, :id, :userimg, :usersmallimg, :isverified, :lastupdate, :level, :bedollars, :bescore, :userExt]

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(params = {}) ⇒ User

Returns a new instance of User.



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

def initialize(params = {})
  set_data params
end

Instance Attribute Details

#createdObject

Returns the value of attribute created.



10
11
12
# File 'lib/beintoo/user.rb', line 10

def created
  @created
end

Instance Method Details

#accept_reward(reward) ⇒ Object

User can accept a given reward previously fetched with self.byuser



57
58
59
# File 'lib/beintoo/user.rb', line 57

def accept_reward(reward)
  Beintoo::Vgood.accept(self, reward)
end

#create(params = {}) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/beintoo/user.rb', line 16

def create(params = {})
  set_data params
  return self if created?
  if valid?
    headers = {
      guid: guid
    }
    headers = Beintoo::build_headers headers
    result = Beintoo::post "#{RESOURCE}/set", headers, get_user_params
    set_data result
    self.created = true
    self
  else
    false
  end
end

#created?Boolean

Returns:

  • (Boolean)


33
34
35
# File 'lib/beintoo/user.rb', line 33

def created?
  created
end

#get_user_paramsObject



76
77
78
79
80
81
82
# File 'lib/beintoo/user.rb', line 76

def get_user_params
  params = {}
  ATTRIBUTES.each do |at|
    params[at] = self.send("#{at}") unless self.send(at).nil?
  end
  params
end

#list_rewardsObject

return the vgoods owned by the current user not yet converted.



62
63
64
# File 'lib/beintoo/user.rb', line 62

def list_rewards
  Beintoo::Vgood.showbyuser(self)
end

#potential_rewardsObject

Get a list of POTENTIAL rewards for the user



52
53
54
# File 'lib/beintoo/user.rb', line 52

def potential_rewards
  Beintoo::Vgood.byuser(self)
end

#set_data(params = {}) ⇒ Object

private



68
69
70
71
72
73
74
# File 'lib/beintoo/user.rb', line 68

def set_data(params = {})
  params = params.with_indifferent_access
  ATTRIBUTES.each do |at|
    self.send("#{at}=", params[at]) unless params[at].nil?
  end
  get_user_params
end

#to_hashObject



41
42
43
44
45
46
47
# File 'lib/beintoo/user.rb', line 41

def to_hash
  h = {}
  ATTRIBUTES.each do |a|
    h[a] = self.send(a)
  end
  h
end

#valid?Boolean

Returns:

  • (Boolean)


37
38
39
# File 'lib/beintoo/user.rb', line 37

def valid?
  !email.nil? && !guid.nil?
end