Class: Evri::RPX::Session

Inherits:
Object
  • Object
show all
Defined in:
lib/evri/rpx/session.rb

Defined Under Namespace

Classes: APICallError, ServiceUnavailableError

Constant Summary collapse

API_VERSION =
'v2'
API_HOST =
'rpxnow.com'
ROOT_CA_PATH =
File.expand_path(File.join(File.dirname(__FILE__),
'..', '..', '..', 'certs',
'cacert.pem'))

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(api_key) ⇒ Session

Returns a new instance of Session.


20
21
22
# File 'lib/evri/rpx/session.rb', line 20

def initialize(api_key)
  @api_key = api_key
end

Instance Attribute Details

#api_keyObject (readonly)

Returns the current RPX api_key attached to the session.


18
19
20
# File 'lib/evri/rpx/session.rb', line 18

def api_key
  @api_key
end

Instance Method Details

#all_mappingsObject

Get all stored mappings for a particular application.

Returns a hash in this form:

{ 'identifier1' => ['mapping1', 'mapping2'],
  'identifier2' => ['mapping3', 'mapping4'],
  ... }

53
54
55
56
57
# File 'lib/evri/rpx/session.rb', line 53

def all_mappings
  json = parse_response(get("/api/#{API_VERSION}/all_mappings",
                            :apiKey => @api_key))
  json['mappings']
end

#auth_info(token, options = {}) ⇒ Object

Returns an auth_info User response from RPXNow. Options:

:tokenUrl => 'http://...'
  RPX will validate that the tokenUrl that you received
  a login redirect from matches the tokenUrl they have on
  file. This is extra security to guard against spoofing.

  Default: nil
:extended => (true|false)
  If you are a Plus/Pro customer, RPX will return extended
  data.

  Default: false

37
38
39
40
41
42
43
44
45
# File 'lib/evri/rpx/session.rb', line 37

def auth_info(token, options = {})
  params = { 'apiKey' => @api_key,
             'token' => token }
  params.merge!(options)

  json = parse_response(get("/api/#{API_VERSION}/auth_info",
                            params))
  User.new(json)
end

#get_contacts(user_or_identifier) ⇒ Object

Retrieve a list of contacts for an identifier in the Portable Contacts format.

Takes either a string identifier, or a User object that responds to :identifier.

This feature is only available for RPX Pro customers.


66
67
68
69
70
71
72
# File 'lib/evri/rpx/session.rb', line 66

def get_contacts(user_or_identifier)
  identifier = identifier_param(user_or_identifier)
  json = parse_response(get("/api/#{API_VERSION}/get_contacts",
                            :apiKey => @api_key,
                            :identifier => identifier))
  ContactList.new(json)
end

#map(user_or_identifier, primary_key, options = {}) ⇒ Object

Map an OpenID to a primary key. Future logins by this owner of this OpenID will return the mapped primaryKey in the auth_info API response, which you may use to sign the user in.

Returns true.


98
99
100
101
102
103
104
105
106
107
108
# File 'lib/evri/rpx/session.rb', line 98

def map(user_or_identifier, primary_key, options = {})
  params = { 'apiKey' => @api_key,
             'primaryKey' => primary_key,
             'overwrite' => true }
  params.merge!(options)
  params['identifier'] = identifier_param(user_or_identifier)
  json = parse_response(get("/api/#{API_VERSION}/map",
                            params))

  json['stat'] == 'ok'
end

#mappings(user_or_primary_key) ⇒ Object

Returns the mappings for a given user's primary key, as a Evri::RPX::Mappings object.

Takes either a string of the user's primary key:

m = session.mappings('dbalatero')

or a User object with an attached primary key:

user = session.auth_info(params[:token])
m = session.mappings(user)

82
83
84
85
86
87
88
89
90
# File 'lib/evri/rpx/session.rb', line 82

def mappings(user_or_primary_key)
  params = { 'apiKey' => @api_key }
  params['primaryKey'] = user_or_primary_key.respond_to?(:primary_key) ?
      user_or_primary_key.primary_key : user_or_primary_key
  
  json = parse_response(get("/api/#{API_VERSION}/mappings",
                            params))
  Mappings.new(json)
end

#unmap(user_or_identifier, primary_key) ⇒ Object

Remove (unmap) an OpenID from a primary key.

Returns true.


113
114
115
116
117
118
119
120
121
122
# File 'lib/evri/rpx/session.rb', line 113

def unmap(user_or_identifier, primary_key)
  params = { 'apiKey' => @api_key,
             'primaryKey' => primary_key }
  params['identifier'] = identifier_param(user_or_identifier)

  json = parse_response(get("/api/#{API_VERSION}/unmap",
                            params))

  json['stat'] == 'ok'
end