Class: AlterEgo

Inherits:
Object
  • Object
show all
Defined in:
lib/alterego.rb

Defined Under Namespace

Classes: APIError

Constant Summary collapse

API_URL =
"https://alteregoapp.com/api"
AUTH_URL =
"http://alteregoapp.com/account/authorize-app"

Class Method Summary collapse

Class Method Details

.authorization_url(app_id, redirect_url) ⇒ Object

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”)



38
39
40
41
# 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) ⇒ Object

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”)



63
64
65
# File 'lib/alterego.rb', line 63

def self.password(key, passcode)
  call("#{API_URL}/check/password.json?key=#{key}&pass=#{passcode}")
end

.ping(key) ⇒ Object

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

Example

AlterEgo.ping(“valid_api_key”)



51
52
53
# File 'lib/alterego.rb', line 51

def self.ping(key)
  call("#{API_URL}/check/ping.json?key=#{key}")
end