Module: RPXNow

Extended by:
RPXNow
Included in:
RPXNow
Defined in:
lib/rpx_now.rb,
lib/rpx_now/user_proxy.rb,
lib/rpx_now/user_integration.rb,
lib/rpx_now/contacts_collection.rb

Defined Under Namespace

Modules: UserIntegration Classes: ApiError, ContactsCollection, ServerError, ServiceUnavailableError, UserProxy

Constant Summary collapse

HOST =
'rpxnow.com'
SSL_CERT =
File.join(File.dirname(__FILE__), '..', 'certs', 'ssl_cert.pem')

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#api_keyObject

Returns the value of attribute api_key.



12
13
14
# File 'lib/rpx_now.rb', line 12

def api_key
  @api_key
end

#api_versionObject

Returns the value of attribute api_version.



13
14
15
# File 'lib/rpx_now.rb', line 13

def api_version
  @api_version
end

Instance Method Details

#all_mappings(*args) ⇒ Object



66
67
68
69
70
# File 'lib/rpx_now.rb', line 66

def all_mappings(*args)
  api_key, version, options = extract_key_version_and_options!(args)
  data = secure_json_post("/api/v#{version}/all_mappings", {:apiKey => api_key}.merge(options))
  data['mappings']
end

#contacts(identifier, *args) ⇒ Object Also known as: get_contacts



72
73
74
75
76
77
# File 'lib/rpx_now.rb', line 72

def contacts(identifier, *args)
  api_key, version, options = extract_key_version_and_options!(args)
  options = {:apiKey => api_key, :identifier=> identifier}.merge(options)
  data = secure_json_post("/api/v#{version}/get_contacts", options)
  RPXNow::ContactsCollection.new(data['response'])
end

#embed_code(subdomain, url, options = {}) ⇒ Object



80
81
82
83
84
85
86
87
# File 'lib/rpx_now.rb', line 80

def embed_code(subdomain,url,options={})
  options = {:width => '400', :height => '240', :language => 'en'}.merge(options)
<<EOF
<iframe src="https://#{subdomain}.#{HOST}/openid/embed?token_url=#{url}&language_preference=#{options[:language]}"
scrolling="no" frameBorder="no" style="width:#{options[:width]}px;height:#{options[:height]}px;">
</iframe>
EOF
end

#map(identifier, primary_key, *args) ⇒ Object

maps an identifier to an primary-key (e.g. user.id)



45
46
47
48
49
# File 'lib/rpx_now.rb', line 45

def map(identifier, primary_key, *args)
  api_key, version, options = extract_key_version_and_options!(args)
  options = {:identifier=>identifier,:primaryKey=>primary_key,:apiKey=>api_key}.merge options
  secure_json_post("/api/v#{version}/map", options)
end

#mappings(primary_key, *args) ⇒ Object

returns an array of identifiers which are mapped to one of your primary-keys (e.g. user.id)



59
60
61
62
63
64
# File 'lib/rpx_now.rb', line 59

def mappings(primary_key, *args)
  api_key, version, options = extract_key_version_and_options!(args)
  options = {:primaryKey=>primary_key,:apiKey=>api_key}.merge options
  data = secure_json_post("/api/v#{version}/mappings", options)
  data['identifiers']
end


89
90
91
92
93
94
95
# File 'lib/rpx_now.rb', line 89

def popup_code(text, subdomain, url, options = {})
  if options[:unobtrusive]
    unobtrusive_popup_code(text, subdomain, url, options)
  else
    obtrusive_popup_code(text, subdomain, url, options)
  end
end

#set_status(identifier, status, *args) ⇒ Object

set the users status



32
33
34
35
36
37
38
39
40
41
42
# File 'lib/rpx_now.rb', line 32

def set_status(identifier, status, *args)
  api_key, version, options = extract_key_version_and_options!(args)
  options = {:identifier => identifier, :status => status, :apiKey => api_key}.merge options

  begin
    data = secure_json_post("/api/v#{version}/set_status", options)
  rescue ServerError
    return nil if $!.to_s=~/Data not found/
    raise
  end
end

#unmap(identifier, primary_key, *args) ⇒ Object

un-maps an identifier to an primary-key (e.g. user.id)



52
53
54
55
56
# File 'lib/rpx_now.rb', line 52

def unmap(identifier, primary_key, *args)
  api_key, version, options = extract_key_version_and_options!(args)
  options = {:identifier=>identifier,:primaryKey=>primary_key,:apiKey=>api_key}.merge options
  secure_json_post("/api/v#{version}/unmap", options)
end

#user_data(token, *args) ⇒ Object

retrieve the users data, or return nil when nothing could be read/token was invalid or data was not found



18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/rpx_now.rb', line 18

def user_data(token, *args)
  api_key, version, options = extract_key_version_and_options!(args)
  options = {:token=>token,:apiKey=>api_key}.merge options

  begin
    data = secure_json_post("/api/v#{version}/auth_info", options)
  rescue ServerError
    return nil if $!.to_s=~/Data not found/
    raise
  end
  if block_given? then yield(data) else read_user_data_from_response(data) end
end