Class: NCMB::User
Constant Summary
Constants included
from NCMB
API_VERSION, DOMAIN
Class Method Summary
collapse
Instance Method Summary
collapse
Methods included from NCMB
CurrentUser, initialize
Methods inherited from Object
#[], #call, #error, #fields, #method_missing, #post, #set
Constructor Details
#initialize(params = {}, alc = nil) ⇒ User
5
6
7
|
# File 'lib/ncmb/user.rb', line 5
def initialize(params = {}, alc = nil)
super('users', params, alc)
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
in the class NCMB::Object
Class Method Details
.login(userid_or_email, password, authType = :id) ⇒ Object
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
|
# File 'lib/ncmb/user.rb', line 47
def self.login(userid_or_email, password, authType = :id)
params = {password: password}
case authType.to_sym
when :id
params[:userName] = userid_or_email
when :email
params[:mailAddres] = userid_or_email
else
raise NCMB::APIError.new("No support #{authType} authentication. We support only id or email.")
end
begin
path = "/#{@@client.api_version}/login"
result = @@client.get path, params
rescue => e
@@last_error = e
return false
end
@@current_user = NCMB::User.new(result)
end
|
Instance Method Details
35
36
37
38
39
40
41
42
43
44
45
|
# File 'lib/ncmb/user.rb', line 35
def delete
path = "/#{@@client.api_version}/#{@name}/#{@fields[:objectId]}"
response = @@client.delete path, {}, @fields[:sessionToken]
if response == true
@@current_user = nil
return true
else
@@last_error = response
return false
end
end
|
#put ⇒ Object
Also known as:
update
22
23
24
25
26
27
28
29
30
31
32
|
# File 'lib/ncmb/user.rb', line 22
def put
path = "/#{@@client.api_version}/#{@name}/#{@fields[:objectId]}"
params = @fields
session_key = params[:sessionToken]
[:objectId, :createDate, :updateDate, :sessionToken, :password].each do |name|
params.delete name
end
result = @@client.put path, params, session_key
@fields[:updateDate] = result[:updateDate]
self
end
|
9
10
11
12
13
14
15
16
17
18
19
20
|
# File 'lib/ncmb/user.rb', line 9
def signUp
path = "/#{@@client.api_version}/#{@name}"
begin
result = @@client.post path, @fields
rescue => e
@@last_error = e
return false
end
@fields.merge!(result)
@@current_user = self
self
end
|