class AlterEgo

Constants

API_URL
AUTH_URL

Public Class Methods

authorization_url(app_id, redirect_url) click to toggle source

Generate an AlterEgo authorization_url. Returns a URL to redirect users to so that they will be prompted to enter their AlterEgo username and password to authorize a connection between your application and their AlterEgo account.

If authorized successfully, a POST request will be sent to the redirect_url with a “key” parameter containing the API key for that user’s AlterEgo account. Be sure to store this key somewhere, as you will need it to run API requests later.

If authorization fails for some reason, an “error” parameter will be present in the POST request, containing an error message.

A note about callback URL’s:

AlterEgo imposes the following requirements on the redirect_url value to ensure security. Be sure that your redirect_url meets the following requirements:

  • Must be served via HTTPS.

  • Must be under the same domain (or a subdomain of) the website entered when registering your application with AlterEgo.

Example

redirect_to AlterEgo.authorization_url(“12345”,“example.com/callback”)

# File lib/alterego.rb, line 38
def self.authorization_url(app_id, redirect_url)
  # TODO: Encode the redirect_url.
  "#{AUTH_URL}?id=#{app_id}&redirect_url=#{URI.escape(redirect_url, Regexp.new("[^#{URI::PATTERN::UNRESERVED}]"))}"
end
password(key, passcode) click to toggle source

Check an AlterEgo passcode. Returns true if the passcode if valid, and false if the passcode is not valid.

Example

AlterEgo.password(“valid_api_key”, “passcode”)

# File lib/alterego.rb, line 63
def self.password(key, passcode)
  call("#{API_URL}/check/password.json?key=#{key}&pass=#{passcode}")
end
ping(key) click to toggle source

Ping the AlterEgo API. Returns either “PONG!” (indicating a successful connection to the API) or an error.

Example

AlterEgo.ping(“valid_api_key”)

# File lib/alterego.rb, line 51
def self.ping(key)
  call("#{API_URL}/check/ping.json?key=#{key}")
end