Class: NCMB::User
Constant Summary
Constants included
from NCMB
API_VERSION, DOMAIN, SCRIPT_API_VERSION, SCRIPT_DOMAIN
Class Method Summary
collapse
Instance Method Summary
collapse
Methods included from NCMB
CurrentUser, initialize
Methods inherited from Object
#ClassName, #[], #call, #convert_params, #deletable?, #error, #fields, #method_missing, #path, #post, #saved?, #set
Constructor Details
#initialize(params = {}) ⇒ User
7
8
9
|
# File 'lib/ncmb/user.rb', line 7
def initialize(params = {})
super('users', params)
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
|
# File 'lib/ncmb/user.rb', line 50
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
#base_path ⇒ Object
23
24
25
|
# File 'lib/ncmb/user.rb', line 23
def base_path
path = "/#{@@client.api_version}/#{@name}"
end
|
39
40
41
42
43
44
45
46
47
48
|
# File 'lib/ncmb/user.rb', line 39
def delete
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
27
28
29
30
31
32
33
34
35
36
|
# File 'lib/ncmb/user.rb', line 27
def put
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
|
11
12
13
14
15
16
17
18
19
20
21
|
# File 'lib/ncmb/user.rb', line 11
def signUp
begin
result = @@client.post path, @fields
rescue => e
@@last_error = e
return false
end
@fields.merge!(result)
@@current_user = self
self
end
|