class RSimperium::Auth
Example use:
require 'r_simperium' auth = RSimprium::Auth.new 'myapp', 'cbbae31841ac4d44a93cd82081a5b74f' access_token = auth.create 'johnny@company.com', 'secret123'
Public Class Methods
A new Auth
object that creates and authorizes Simperium users. @param [String] app_id Your Simperium app id @param [String] api_key Your Simperium app api key @param [String] host The host to send requests to @param [String] scheme The scheme to use for requests
# 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
Public Instance Methods
Resets a Simperium user’s password @param [String] username The user’s username @param [String] password The user’s new password (optional) @return [boolean] True if reset was a success
# 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.message}" false end end
Creates a new Simperium user and returns its access token. @param [String] username The new user’s username @param [String] password The new user’s password @return [String] The new user’s access token
# 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.message}" nil end end
Deletes a Simperium user and all user data. Requires an API key with admin privileges. @param [String] username The new user’s username
# 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