Class: Dailycred::User

Inherits:
Object
  • Object
show all
Includes:
ActiveModel::Serialization, ActiveModel::Validations
Defined in:
lib/dailycred/user.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client, user = {}) ⇒ User

Returns a new instance of User.



10
11
12
13
14
15
16
# File 'lib/dailycred/user.rb', line 10

def initialize client, user = {}
  self.client = client
  self.authorized = false
  user.each do |k,v|
    self[k] = v if self.respond_to(k)
  end
end

Instance Attribute Details

#authorizedObject

Returns the value of attribute authorized.



8
9
10
# File 'lib/dailycred/user.rb', line 8

def authorized
  @authorized
end

#clientObject

Returns the value of attribute client.



8
9
10
# File 'lib/dailycred/user.rb', line 8

def client
  @client
end

#emailObject

Returns the value of attribute email.



8
9
10
# File 'lib/dailycred/user.rb', line 8

def email
  @email
end

#passObject

Returns the value of attribute pass.



8
9
10
# File 'lib/dailycred/user.rb', line 8

def pass
  @pass
end

Instance Method Details

#loginObject



18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/dailycred/user.rb', line 18

def 
  if !self.valid?
    #it didn't work already, return false
    return false
  end

  response = JSON.parse client.(self.to_hash)
  err_parser response

  return false if !self.valid?
  true
end

#to_hashObject



31
32
33
34
35
36
# File 'lib/dailycred/user.rb', line 31

def to_hash
  {
    :email => self.email,
    :pass => self.pass
  }
end