Class: LC::User

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

Instance Attribute Summary

Attributes inherited from Object

#class_name, #created_at, #parse_object_id, #updated_at

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Object

#array_add, #array_add_relation, #array_add_unique, #array_remove, #array_remove_relation, #decrement, #eql?, #get, #hash, #increment, #inspect, #new?, #parse_delete, #pointer, #refresh, #rest_api_hash, #safe_hash, #save, #should_call_to_h?, #to_h, #to_json, #to_s, #update_attributes

Constructor Details

#initialize(data = nil) ⇒ User

Returns a new instance of User.



33
34
35
36
37
# File 'lib/leancloud/user.rb', line 33

def initialize(data = nil)
  data["username"] = data[:username] if data[:username]
  data["password"] = data[:password] if data[:password]
  super(LC::Protocol::CLASS_USER, data)
end

Class Method Details

.authenticate(username, password) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
# File 'lib/leancloud/user.rb', line 16

def self.authenticate(username, password)
  body = {
    "username" => username,
    "password" => password
  }

  response = LC.client.request(LC::Protocol::, :get, nil, body)
  LC.client.session_token = response[LC::Protocol::KEY_USER_SESSION_TOKEN]

  new(response)
end

.become(token) ⇒ Object



10
11
12
13
14
# File 'lib/leancloud/user.rb', line 10

def self.become(token)
  response = LC.client._request(uri: LC::Protocol::USER_CURRENT_URI, session_token: token)
  LC.client.session_token = response[LC::Protocol::KEY_USER_SESSION_TOKEN]
  new(response)
end

.reset_password(email) ⇒ Object



28
29
30
31
# File 'lib/leancloud/user.rb', line 28

def self.reset_password(email)
  body = {"email" => email}
  LC.client.post(LC::Protocol::PASSWORD_RESET_URI, body.to_json)
end

Instance Method Details

#uriObject



39
40
41
# File 'lib/leancloud/user.rb', line 39

def uri
  Protocol.user_uri @parse_object_id
end