Class: RSimperium::Auth
- Inherits:
-
Object
- Object
- RSimperium::Auth
- Includes:
- ApiHelpers
- Defined in:
- lib/r_simperium/auth.rb
Overview
Example use:
require 'r_simperium'
auth = RSimprium::Auth.new 'myapp', 'cbbae31841ac4d44a93cd82081a5b74f'
access_token = auth.create '[email protected]', 'secret123'
Instance Method Summary collapse
-
#authorize(username, password) ⇒ String
Authorizes an existing Simperium user.
-
#change_password(username, new_password) ⇒ boolean
Resets a Simperium user’s password.
-
#create(username, password) ⇒ String
Creates a new Simperium user and returns its access token.
-
#delete(username) ⇒ Object
Deletes a Simperium user and all user data.
-
#initialize(app_id, api_key, host = nil, scheme = 'https') ⇒ Auth
constructor
A new Auth object that creates and authorizes Simperium users.
Methods included from ApiHelpers
#api_auth_header, #api_meta, #api_request, #api_request_with_auth, #api_url
Constructor Details
#initialize(app_id, api_key, host = nil, scheme = 'https') ⇒ Auth
A new Auth object that creates and authorizes Simperium users.
16 17 18 19 20 21 22 |
# File 'lib/r_simperium/auth.rb', line 16 def initialize(app_id, api_key, host=nil, scheme='https') host ||= ENV['SIMPERIUM_AUTHHOST'] || 'auth.simperium.com' @app_id = app_id @api_key = api_key @host = host @scheme = scheme end |
Instance Method Details
#authorize(username, password) ⇒ String
Authorizes an existing Simperium user.
28 29 30 31 32 33 34 35 |
# File 'lib/r_simperium/auth.rb', line 28 def (username, password) data = { :clientid => @api_key, :username => username, :password => password, } response = api_request_with_auth :post, api_url('/authorize/'), :payload => data response.data['access_token'] end |
#change_password(username, new_password) ⇒ boolean
Resets a Simperium user’s password
59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/r_simperium/auth.rb', line 59 def change_password(username, new_password) data = { :username => username, :new_password => new_password } begin response = api_request_with_auth :post, api_url('/reset_password/'), :payload => data return response.data['status'] == 'success' rescue RestClient::Exception => e puts "The api request failed: #{e.}" false end end |
#create(username, password) ⇒ String
Creates a new Simperium user and returns its access token.
41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/r_simperium/auth.rb', line 41 def create(username, password) data = { :clientid => @api_key, :username => username, :password => password, } begin response = api_request_with_auth :post, api_url('/create/'), :payload => data response.data['access_token'] rescue RestClient::Exception => e puts "The api request failed: #{e.}" nil end end |
#delete(username) ⇒ Object
Deletes a Simperium user and all user data. Requires an API key with admin privileges.
76 77 78 79 80 81 |
# File 'lib/r_simperium/auth.rb', line 76 def delete(username) data = { :clientid => @api_key, :username => username} api_request_with_auth :post, api_url('/delete/'), :payload => data end |