Module: RPXNow
- Extended by:
- RPXNow
- Included in:
- RPXNow
- Defined in:
- lib/rpx_now.rb,
lib/rpx_now/api.rb,
lib/rpx_now/version.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: Api, ApiError, ContactsCollection, ServerError, ServiceUnavailableError, UserProxy
Constant Summary collapse
- VERSION =
"0.7.1"
Instance Attribute Summary collapse
-
#api_key ⇒ Object
Returns the value of attribute api_key.
-
#api_version ⇒ Object
Returns the value of attribute api_version.
-
#domain ⇒ Object
Returns the value of attribute domain.
Instance Method Summary collapse
-
#activity(identifier, activity_options, options = {}) ⇒ Object
Post an activity update to the user’s activity stream.
- #all_mappings(options = {}) ⇒ Object
-
#auth_info(token, options = {}) ⇒ Object
same data as user_data, but without any kind of post-processing.
- #contacts(identifier, options = {}) ⇒ Object (also: #get_contacts)
-
#embed_code(subdomain, url, options = {}) ⇒ Object
embedded rpx login (via iframe) options: :width, :height, :language, :flags, :api_version, :default_provider.
- #extract_version(options) ⇒ Object
-
#get_user_data(identifier, options = {}) ⇒ Object
same as for auth_info if Offline Profile Access is enabled, but can be called at any time and does not need a token / does not expire.
-
#map(identifier, primary_key, options = {}) ⇒ Object
maps an identifier to an primary-key (e.g. user.id).
-
#mappings(primary_key, options = {}) ⇒ Object
returns an array of identifiers which are mapped to one of your primary-keys (e.g. user.id).
-
#popup_code(text, subdomain, url, options = {}) ⇒ Object
popup window for rpx login options: :language, :flags, :unobtrusive, :api_version, :default_provider, :html.
-
#popup_source(subdomain, url, options = {}) ⇒ Object
javascript for popup only needed in combination with popup_code(x,y,z, :unobtrusive => true).
-
#popup_url(subdomain, url, options = {}) ⇒ Object
url for unobtrusive popup window options: :language, :flags, :api_version, :default_provider.
-
#set_status(identifier, status, options = {}) ⇒ Object
set the users status.
-
#unmap(identifier, primary_key, options = {}) ⇒ Object
un-maps an identifier to an primary-key (e.g. user.id).
-
#user_data(token, options = {}) ⇒ Object
retrieve the users data - cleaned Hash - complete/unclean response when block was given user_data{|response| …; return hash } - nil when token was invalid / data was not found.
Instance Attribute Details
#api_key ⇒ Object
Returns the value of attribute api_key.
9 10 11 |
# File 'lib/rpx_now.rb', line 9 def api_key @api_key end |
#api_version ⇒ Object
Returns the value of attribute api_version.
10 11 12 |
# File 'lib/rpx_now.rb', line 10 def api_version @api_version end |
#domain ⇒ Object
Returns the value of attribute domain.
11 12 13 |
# File 'lib/rpx_now.rb', line 11 def domain @domain end |
Instance Method Details
#activity(identifier, activity_options, options = {}) ⇒ Object
Post an activity update to the user’s activity stream. See more: rpxnow.com/docs#api_activity
59 60 61 62 |
# File 'lib/rpx_now.rb', line 59 def activity(identifier, , ={}) = .merge(:identifier => identifier, :activity => .to_json) Api.call("activity", ) end |
#all_mappings(options = {}) ⇒ Object
79 80 81 |
# File 'lib/rpx_now.rb', line 79 def all_mappings(={}) Api.call("all_mappings", )['mappings'] end |
#auth_info(token, options = {}) ⇒ Object
same data as user_data, but without any kind of post-processing
36 37 38 39 |
# File 'lib/rpx_now.rb', line 36 def auth_info(token, ={}) data = Api.call("auth_info", .merge(:token => token)) with_indifferent_access(data) end |
#contacts(identifier, options = {}) ⇒ Object Also known as: get_contacts
83 84 85 86 |
# File 'lib/rpx_now.rb', line 83 def contacts(identifier, ={}) data = Api.call("get_contacts", .merge(:identifier => identifier)) RPXNow::ContactsCollection.new(data['response']) end |
#embed_code(subdomain, url, options = {}) ⇒ Object
embedded rpx login (via iframe) options: :width, :height, :language, :flags, :api_version, :default_provider
91 92 93 94 95 96 97 98 |
# File 'lib/rpx_now.rb', line 91 def (subdomain, url, ={}) = {:width => '400', :height => '240'}.merge() <<-EOF <iframe src="#{Api.host(subdomain)}/openid/embed?#{(url, )}" scrolling="no" frameBorder="no" style="width:#{[:width]}px;height:#{[:height]}px;" id="rpx_now_embed" allowtransparency="allowtransparency"> </iframe> EOF end |
#extract_version(options) ⇒ Object
142 143 144 |
# File 'lib/rpx_now.rb', line 142 def extract_version() [:api_version] || api_version end |
#get_user_data(identifier, options = {}) ⇒ Object
same as for auth_info if Offline Profile Access is enabled, but can be called at any time and does not need a token / does not expire
43 44 45 46 |
# File 'lib/rpx_now.rb', line 43 def get_user_data(identifier, ={}) data = Api.call("get_user_data", .merge(:identifier => identifier)) with_indifferent_access(data) end |
#map(identifier, primary_key, options = {}) ⇒ Object
maps an identifier to an primary-key (e.g. user.id)
65 66 67 |
# File 'lib/rpx_now.rb', line 65 def map(identifier, primary_key, ={}) Api.call("map", .merge(:identifier => identifier, :primaryKey => primary_key)) end |
#mappings(primary_key, options = {}) ⇒ Object
returns an array of identifiers which are mapped to one of your primary-keys (e.g. user.id)
75 76 77 |
# File 'lib/rpx_now.rb', line 75 def mappings(primary_key, ={}) Api.call("mappings", .merge(:primaryKey => primary_key))['identifiers'] end |
#popup_code(text, subdomain, url, options = {}) ⇒ Object
popup window for rpx login options: :language, :flags, :unobtrusive, :api_version, :default_provider, :html
102 103 104 105 106 107 108 109 |
# File 'lib/rpx_now.rb', line 102 def popup_code(text, subdomain, url, = {}) = .dup if .delete(:unobtrusive) unobtrusive_popup_code(text, subdomain, url, ) else obtrusive_popup_code(text, subdomain, url, ) end end |
#popup_source(subdomain, url, options = {}) ⇒ Object
javascript for popup only needed in combination with popup_code(x,y,z, :unobtrusive => true)
113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 |
# File 'lib/rpx_now.rb', line 113 def popup_source(subdomain, url, ={}) <<-EOF <script src="#{Api.host}/openid/v#{extract_version()}/widget" type="text/javascript"></script> <script type="text/javascript"> //<![CDATA[ RPXNOW.token_url = '#{url}'; RPXNOW.realm = '#{subdomain}'; RPXNOW.overlay = true; #{ "RPXNOW.language_preference = '#{[:language]}';" if [:language] } #{ "RPXNOW.default_provider = '#{[:default_provider]}';" if [:default_provider] } #{ "RPXNOW.flags = '#{[:flags]}';" if [:flags] } //]]> </script> EOF end |
#popup_url(subdomain, url, options = {}) ⇒ Object
url for unobtrusive popup window options: :language, :flags, :api_version, :default_provider
131 132 133 134 135 136 137 138 139 140 |
# File 'lib/rpx_now.rb', line 131 def popup_url(subdomain, url, ={}) case .delete(:fallback_url) when :legacy "#{Api.host(subdomain)}/openid/v#{extract_version()}/signin?#{(url, )}" when :disable "javascript:void(0)" else "#{Api.host(subdomain)}/openid/embed?#{(url, )}" end end |
#set_status(identifier, status, options = {}) ⇒ Object
set the users status
49 50 51 52 53 54 55 |
# File 'lib/rpx_now.rb', line 49 def set_status(identifier, status, ={}) = .merge(:identifier => identifier, :status => status) Api.call("set_status", ) rescue ServerError return nil if $!.to_s=~/Data not found/ raise end |
#unmap(identifier, primary_key, options = {}) ⇒ Object
un-maps an identifier to an primary-key (e.g. user.id)
70 71 72 |
# File 'lib/rpx_now.rb', line 70 def unmap(identifier, primary_key, ={}) Api.call("unmap", .merge(:identifier => identifier, :primaryKey => primary_key)) end |
#user_data(token, options = {}) ⇒ Object
retrieve the users data
-
cleaned Hash
-
complete/unclean response when block was given user_data{|response| …; return hash }
-
nil when token was invalid / data was not found
20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/rpx_now.rb', line 20 def user_data(token, ={}) = .dup return_raw = .delete(:raw_response) data = begin auth_info(token, ) rescue ServerError return nil if $!.to_s=~/Data not found/ raise end result = (block_given? ? yield(data) : (return_raw ? data : parse_user_data(data, ))) with_indifferent_access(result) end |