Class: Colppy::User

Inherits:
Resource show all
Includes:
Digest
Defined in:
lib/colppy/resources/user.rb

Constant Summary

Constants included from Digest

Digest::MD5_DIGEST

Constants included from Utils

Colppy::Utils::ATTRIBUTES_MAPPER, Colppy::Utils::DATA_KEYS_SETTERS

Instance Attribute Summary collapse

Attributes inherited from Resource

#data

Instance Method Summary collapse

Methods included from Digest

md5, valid_md5?

Methods inherited from Resource

#[]=, #inspect

Methods included from Utils

rename_params_hash

Constructor Details

#initialize(username, password, key = nil) ⇒ User

Returns a new instance of User.



53
54
55
56
57
# File 'lib/colppy/resources/user.rb', line 53

def initialize(username, password, key = nil)
  @username = username
  @password = md5(password)
  @key = key
end

Instance Attribute Details

#keyObject (readonly)

Returns the value of attribute key.



51
52
53
# File 'lib/colppy/resources/user.rb', line 51

def key
  @key
end

#usernameObject (readonly)

Returns the value of attribute username.



51
52
53
# File 'lib/colppy/resources/user.rb', line 51

def username
  @username
end

Instance Method Details

#sign_in(client) ⇒ Object



59
60
61
62
63
64
65
66
67
68
69
# File 'lib/colppy/resources/user.rb', line 59

def (client)
  response = client.call(
    :user,
    :sign_in,
    {
      usuario: @username,
      password: @password
    }
  )
  save_session(response[:data]) if response[:success]
end

#sign_out(client) ⇒ Object



71
72
73
74
75
76
77
78
79
80
81
# File 'lib/colppy/resources/user.rb', line 71

def sign_out(client)
  response = client.call(
    :user,
    :sign_out,
    sesion: {
      usuario: @username,
      claveSesion: key
    }
  )
  destroy_session if response[:success]
end