Module: RPXNow

Extended by:
RPXNow
Included in:
RPXNow
Defined in:
lib/rpx_now.rb,
lib/rpx_now/api.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 =
File.read( File.join(File.dirname(__FILE__),'..','VERSION') ).strip

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#api_keyObject

Returns the value of attribute api_key.



8
9
10
# File 'lib/rpx_now.rb', line 8

def api_key
  @api_key
end

#api_versionObject

Returns the value of attribute api_version.



9
10
11
# File 'lib/rpx_now.rb', line 9

def api_version
  @api_version
end

#sslObject

Returns the value of attribute ssl.



10
11
12
# File 'lib/rpx_now.rb', line 10

def ssl
  @ssl
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



42
43
44
45
# File 'lib/rpx_now.rb', line 42

def activity(identifier, activity_options, options={})
  options = options.merge(:identifier => identifier, :activity => activity_options.to_json)
  Api.call("activity", options)
end

#all_mappings(options = {}) ⇒ Object



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

def all_mappings(options={})
  Api.call("all_mappings", options)['mappings']
end

#contacts(identifier, options = {}) ⇒ Object Also known as: get_contacts



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

def contacts(identifier, options={})
  data = Api.call("get_contacts", options.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



74
75
76
77
78
79
80
81
# File 'lib/rpx_now.rb', line 74

def embed_code(subdomain, url, options={})
  options = {:width => '400', :height => '240'}.merge(options)
  <<-EOF
    <iframe src="#{Api.host(subdomain)}/openid/embed?#{embed_params(url, options)}"
      scrolling="no" frameBorder="no" style="width:#{options[:width]}px;height:#{options[:height]}px;">
    </iframe>
  EOF
end

#extract_version(options) ⇒ Object



118
119
120
# File 'lib/rpx_now.rb', line 118

def extract_version(options)
  options[:api_version] || api_version
end

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

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



48
49
50
# File 'lib/rpx_now.rb', line 48

def map(identifier, primary_key, options={})
  Api.call("map", options.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)



58
59
60
# File 'lib/rpx_now.rb', line 58

def mappings(primary_key, options={})
  Api.call("mappings", options.merge(:primaryKey => primary_key))['identifiers']
end

popup window for rpx login options: :language, :flags, :unobtrusive, :api_version, :default_provider



85
86
87
88
89
90
91
# File 'lib/rpx_now.rb', line 85

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

javascript for popup only needed in combination with popup_code(x,y,z, :unobtrusive => true)



95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
# File 'lib/rpx_now.rb', line 95

def popup_source(subdomain, url, options={})
  <<-EOF
    <script src="#{Api.host}/openid/v#{extract_version(options)}/widget" type="text/javascript"></script>
    <script type="text/javascript">
      //<![CDATA[
      RPXNOW.token_url = '#{url}';
      RPXNOW.realm = '#{subdomain}';
      RPXNOW.overlay = true;
      RPXNOW.ssl = #{ssl};
      #{ "RPXNOW.language_preference = '#{options[:language]}';" if options[:language] }
      #{ "RPXNOW.default_provider = '#{options[:default_provider]}';" if options[:default_provider] }
      #{ "RPXNOW.flags = '#{options[:flags]}';" if options[:flags] }
      //]]>
    </script>
  EOF
end

url for unobtrusive popup window options: :language, :flags, :api_version, :default_provider



114
115
116
# File 'lib/rpx_now.rb', line 114

def popup_url(subdomain, url, options={})
  "#{Api.host(subdomain)}/openid/v#{extract_version(options)}/signin?#{embed_params(url, options)}"
end

#set_status(identifier, status, options = {}) ⇒ Object

set the users status



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

def set_status(identifier, status, options={})
  options = options.merge(:identifier => identifier, :status => status)
  data = Api.call("set_status", options)
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)



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

def unmap(identifier, primary_key, options={})
  Api.call("unmap", options.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
# File 'lib/rpx_now.rb', line 20

def user_data(token, options={})
  begin
    data = Api.call("auth_info", options.merge(:token => token))
    result = (block_given? ? yield(data) : parse_user_data(data, options))
    result.respond_to?(:with_indifferent_access) ? result.with_indifferent_access : result
  rescue ServerError
    return nil if $!.to_s=~/Data not found/
    raise
  end
end