Module: Parse::API::Users

Included in:
Client
Defined in:
lib/parse/api/users.rb

Overview

Defines the User class interface for the Parse REST API

Instance Method Summary collapse

Instance Method Details

#create_user(body, headers: {}, **opts) ⇒ Parse::Response

Create a new user.

Parameters:

  • body (Hash)

    a hash of values related to your _User schema.

  • opts (Hash)

    additional options to pass to the Client request.

  • headers (Hash)

    additional HTTP headers to send with the request.

Returns:


56
57
58
59
60
61
62
63
64
# File 'lib/parse/api/users.rb', line 56

def create_user(body, headers: {}, **opts)
  headers.merge!({ Parse::Protocol::REVOCABLE_SESSION => '1'})
  if opts[:session_token].present?
    headers.merge!({ Parse::Protocol::SESSION_TOKEN => opts[:session_token]})
  end
  response = request :post, USER_PATH_PREFIX, body: body, headers: headers, opts: opts
  response.parse_class = Parse::Model::CLASS_USER
  response
end

#current_user(session_token, headers: {}, **opts) ⇒ Parse::Response

Find user matching this active session token.

Parameters:

  • opts (Hash)

    additional options to pass to the Client request.

  • headers (Hash)

    additional HTTP headers to send with the request.

Returns:


44
45
46
47
48
49
# File 'lib/parse/api/users.rb', line 44

def current_user(session_token, headers: {}, **opts)
  headers.merge!({Parse::Protocol::SESSION_TOKEN => session_token})
  response = request :get, "#{USER_PATH_PREFIX}/me", headers: headers, opts: opts
  response.parse_class = Parse::Model::CLASS_USER
  response
end

#delete_user(id, headers: {}, **opts) ⇒ Parse::Response

Delete a User record given an objectId.

Parameters:

  • id (String)

    the Parse user objectId.

  • opts (Hash)

    additional options to pass to the Client request.

  • headers (Hash)

    additional HTTP headers to send with the request.

Returns:


96
97
98
# File 'lib/parse/api/users.rb', line 96

def delete_user(id, headers: {}, **opts)
  request :delete, "#{USER_PATH_PREFIX}/#{id}", headers: headers, opts: opts
end

#fetch_user(id, headers: {}, **opts) ⇒ Parse::Response

Fetch a User for a given objectId.

Parameters:

  • id (String)

    the user objectid

  • opts (Hash)

    additional options to pass to the Client request.

  • headers (Hash)

    additional HTTP headers to send with the request.

Returns:


25
26
27
# File 'lib/parse/api/users.rb', line 25

def fetch_user(id, headers: {}, **opts)
  request :get, "#{USER_PATH_PREFIX}/#{id}", headers: headers, opts: opts
end

#find_users(query = {}, headers: {}, **opts) ⇒ Parse::Response

Find users matching a set of constraints.

Parameters:

  • query (Hash) (defaults to: {})

    query parameters.

  • opts (Hash)

    additional options to pass to the Client request.

  • headers (Hash)

    additional HTTP headers to send with the request.

Returns:


34
35
36
37
38
# File 'lib/parse/api/users.rb', line 34

def find_users(query = {}, headers: {}, **opts)
  response = request :get, USER_PATH_PREFIX, query: query, headers: headers, opts: opts
  response.parse_class = Parse::Model::CLASS_USER
  response
end

#login(username, password, headers: {}, **opts) ⇒ Parse::Response

Login a user.

Parameters:

  • username (String)

    the Parse user username.

  • password (String)

    the Parse user's associated password.

  • headers (Hash)

    additional HTTP headers to send with the request.

  • opts (Hash)

    additional options to pass to the Client request.

Returns:


116
117
118
119
120
121
122
123
124
# File 'lib/parse/api/users.rb', line 116

def (username, password, headers: {}, **opts)
  # Probably pass Installation-ID as header
  query = { username: username, password: password }
  headers.merge!({ Parse::Protocol::REVOCABLE_SESSION => '1'})
  # headers.merge!( { Parse::Protocol::INSTALLATION_ID => ''} )
  response = request :get, LOGIN_PATH, query: query, headers: headers, opts: opts
  response.parse_class = Parse::Model::CLASS_USER
  response
end

#logout(session_token, headers: {}, **opts) ⇒ Parse::Response

Logout a user by deleting the associated session.

Parameters:

  • session_token (String)

    the Parse user session token to delete.

  • headers (Hash)

    additional HTTP headers to send with the request.

  • opts (Hash)

    additional options to pass to the Client request.

Returns:


131
132
133
134
135
# File 'lib/parse/api/users.rb', line 131

def logout(session_token, headers: {}, **opts)
  headers.merge!({ Parse::Protocol::SESSION_TOKEN => session_token})
  opts.merge!({use_master_key: false, session_token: session_token})
  request :post, LOGOUT_PATH, headers: headers, opts: opts
end

#request_password_reset(email, headers: {}, **opts) ⇒ Parse::Response

Request a password reset for a registered email.

Parameters:

  • email (String)

    the Parse user email.

  • opts (Hash)

    additional options to pass to the Client request.

  • headers (Hash)

    additional HTTP headers to send with the request.

Returns:


105
106
107
108
# File 'lib/parse/api/users.rb', line 105

def request_password_reset(email,  headers: {}, **opts)
  body = {email: email}
  request :post, REQUEST_PASSWORD_RESET, body: body, opts: opts, headers: headers
end

#set_service_auth_data(id, service_name, auth_data, headers: {}, **opts) ⇒ Parse::Response

Set the authentication service OAUth data for a user. Deleting or unlinking is done by setting the authData of the service name to nil.

Parameters:

  • id (String)

    the Parse user objectId.

  • service_name (Symbol)

    the name of the OAuth service.

  • auth_data (Hash)

    the hash data related to the third-party service.

  • opts (Hash)

    additional options to pass to the Client request.

  • headers (Hash)

    additional HTTP headers to send with the request.

Returns:


86
87
88
89
# File 'lib/parse/api/users.rb', line 86

def set_service_auth_data(id, service_name, auth_data, headers: {}, **opts)
  body = { authData: { service_name => auth_data } }
  update_user(id, body, opts)
end

#signup(username, password, email = nil, body: {}, **opts) ⇒ Parse::Response

Signup a user given a username, password and, optionally, their email.

Parameters:

  • username (String)

    the Parse user username.

  • password (String)

    the Parse user's associated password.

  • email (String) (defaults to: nil)

    the desired Parse user's email.

  • body (Hash)

    additional property values to pass when creating the user record.

  • opts (Hash)

    additional options to pass to the Client request.

Returns:


144
145
146
147
148
# File 'lib/parse/api/users.rb', line 144

def (username, password, email = nil, body: {}, **opts)
  body = body.merge({ username: username, password: password })
  body[:email] = email || body[:email]
  create_user(body, opts)
end

#update_user(id, body = {}, headers: {}, **opts) ⇒ Parse::Response

Update a User record given an objectId.

Parameters:

  • id (String)

    the Parse user objectId.

  • body (Hash) (defaults to: {})

    the body of the API request.

  • opts (Hash)

    additional options to pass to the Client request.

  • headers (Hash)

    additional HTTP headers to send with the request.

Returns:


72
73
74
75
76
# File 'lib/parse/api/users.rb', line 72

def update_user(id, body = {}, headers: {}, **opts)
  response = request :put, "#{USER_PATH_PREFIX}/#{id}", body: body, opts: opts
  response.parse_class = Parse::Model::CLASS_USER
  response
end