grosser-rpx_now 0.5.3 → 0.5.4

Sign up to get free protection for your applications and to get access to all the features.
data/README.markdown CHANGED
@@ -37,10 +37,16 @@ View
37
37
 
38
38
  `popup_code` can also be called with `:unobstrusive=>true`
39
39
 
40
- Controller
41
- ----------
40
+ Environment
41
+ -----------
42
+ Rails::Initializer.run do |config|
43
+ config.gem "grosser-rpx_now", :lib => "rpx_now", :source => "http://gems.github.com/"
44
+ ...
45
+ end
42
46
  RPXNow.api_key = "YOU RPX API KEY"
43
47
 
48
+ Controller
49
+ ----------
44
50
  # user_data
45
51
  # found: {:name=>'John Doe', :username => 'john', :email=>'john@doe.com', :identifier=>'blug.google.com/openid/dsdfsdfs3f3'}
46
52
  # not found: nil (can happen with e.g. invalid tokens)
@@ -82,6 +88,10 @@ A identifyer can only belong to one user (in doubt the last one it was mapped to
82
88
  user.rpx.map(identifier) == RPXNow.map(identifier, user.id)
83
89
  user.rpx.unmap(identifier) == RPXNow.unmap(identifier, user.id)
84
90
 
91
+ ###Contacts
92
+ Retrieve all contacts for a given user:
93
+ RPXNow.contacts(identifier).each {|c| puts "#{c['displayName']}: #{c['emails']}}
94
+
85
95
  TODO
86
96
  ====
87
97
  - add provider?
data/VERSION.yml CHANGED
@@ -1,4 +1,4 @@
1
1
  ---
2
2
  :minor: 5
3
- :patch: 3
3
+ :patch: 4
4
4
  :major: 0
@@ -0,0 +1,19 @@
1
+ module RPXNow
2
+ class ContactsCollection < Array
3
+ def initialize(list)
4
+ @raw = list
5
+ @additional_info = list.reject{|k,v|k=='entry'}
6
+ list['entry'].each{|item| self << parse_data(item)}
7
+ end
8
+
9
+ def additional_info;@additional_info;end
10
+ def raw;@raw;end
11
+
12
+ private
13
+
14
+ def parse_data(entry)
15
+ entry['emails'] = entry['emails'].map{|email| email['value']}
16
+ entry
17
+ end
18
+ end
19
+ end
@@ -1,4 +1,3 @@
1
- require 'rpx_now/user_proxy'
2
1
  module RPXNow
3
2
  module UserIntegration
4
3
  def rpx
data/lib/rpx_now.rb CHANGED
@@ -1,4 +1,7 @@
1
1
  require 'json'
2
+ require 'rpx_now/contacts_collection'
3
+ require 'rpx_now/user_integration'
4
+ require 'rpx_now/user_proxy'
2
5
 
3
6
  module RPXNow
4
7
  extend self
@@ -49,10 +52,18 @@ module RPXNow
49
52
 
50
53
  def all_mappings(*args)
51
54
  api_key, version, options = extract_key_version_and_options!(args)
52
- data = secure_json_post("/api/v#{version}/all_mappings", :apiKey => api_key).merge(options)
55
+ data = secure_json_post("/api/v#{version}/all_mappings", {:apiKey => api_key}.merge(options))
53
56
  data['mappings']
54
57
  end
55
58
 
59
+ def contacts(identifier, *args)
60
+ api_key, version, options = extract_key_version_and_options!(args)
61
+ options = {:apiKey => api_key, :identifier=> identifier}.merge(options)
62
+ data = secure_json_post("/api/v#{version}/get_contacts", options)
63
+ RPXNow::ContactsCollection.new(data['response'])
64
+ end
65
+ alias get_contacts contacts
66
+
56
67
  def embed_code(subdomain,url)
57
68
  <<EOF
58
69
  <iframe src="https://#{subdomain}.#{HOST}/openid/embed?token_url=#{url}"
@@ -0,0 +1,58 @@
1
+ {
2
+ "response": {
3
+ "itemsPerPage": 5,
4
+ "totalResults": 5,
5
+ "entry": [
6
+ {
7
+ "displayName": "Bob Johnson",
8
+ "emails": [
9
+ {
10
+ "type": "other",
11
+ "value": "bob@example.com"
12
+ }
13
+ ]
14
+ },
15
+ {
16
+ "displayName": "Cindy Smith",
17
+ "emails": [
18
+ {
19
+ "type": "other",
20
+ "value": "cindy.smith@example.com"
21
+ }
22
+ ]
23
+ },
24
+ {
25
+ "displayName": "Fred Williams",
26
+ "emails": [
27
+ {
28
+ "type": "other",
29
+ "value": "fred.williams@example.com"
30
+ },
31
+ {
32
+ "type": "other",
33
+ "value": "fred@example.com"
34
+ }
35
+ ]
36
+ },
37
+ {
38
+ "emails": [
39
+ {
40
+ "type": "other",
41
+ "value": "j.lewis@example.com"
42
+ }
43
+ ]
44
+ },
45
+ {
46
+ "displayName": "Mary Jones",
47
+ "emails": [
48
+ {
49
+ "type": "other",
50
+ "value": "mary.jones@example.com"
51
+ }
52
+ ]
53
+ }
54
+ ],
55
+ "startIndex": 1
56
+ },
57
+ "stat": "ok"
58
+ }
@@ -0,0 +1,32 @@
1
+ require File.expand_path("../spec_helper", File.dirname(__FILE__))
2
+
3
+ describe RPXNow::ContactsCollection do
4
+ before do
5
+ data = JSON.parse(File.read('spec/fixtures/get_contacts_response.json'))['response']
6
+ @collection = RPXNow::ContactsCollection.new(data)
7
+ end
8
+
9
+ it "behaves like an array" do
10
+ @collection.size.should == 5
11
+ @collection[0] = "1"
12
+ @collection[0].should == "1"
13
+ end
14
+
15
+ it "parses entry to items" do
16
+ @collection[0]['displayName'].should == "Bob Johnson"
17
+ end
18
+
19
+ it "parses emails to list" do
20
+ @collection[0]['emails'].should == ["bob@example.com"]
21
+ end
22
+
23
+ it "parses emails to list with multiple emails" do
24
+ @collection[2]['emails'].should == ["fred.williams@example.com","fred@example.com"]
25
+ end
26
+
27
+ it "holds additional_info" do
28
+ @collection.additional_info['startIndex'].should == 1
29
+ @collection.additional_info['itemsPerPage'].should == 5
30
+ @collection.additional_info['totalResults'].should == 5
31
+ end
32
+ end
@@ -1,5 +1,4 @@
1
1
  require File.expand_path("../spec_helper", File.dirname(__FILE__))
2
- require 'rpx_now/user_integration'
3
2
 
4
3
  class User
5
4
  include RPXNow::UserIntegration
data/spec/rpx_now_spec.rb CHANGED
@@ -138,6 +138,14 @@ describe RPXNow do
138
138
  end
139
139
  end
140
140
 
141
+ describe :contacts do
142
+ it "finds all contacts" do
143
+ response = JSON.parse(File.read('spec/fixtures/get_contacts_response.json'))
144
+ RPXNow.expects(:secure_json_post).with('/api/v2/get_contacts',:identifier=>'xx', :apiKey=>API_KEY).returns response
145
+ RPXNow.contacts('xx').size.should == 5
146
+ end
147
+ end
148
+
141
149
  describe :parse_response do
142
150
  it "parses json when status is ok" do
143
151
  response = mock(:code=>'200', :body=>%Q({"stat":"ok","data":"xx"}))
data/spec/spec_helper.rb CHANGED
@@ -10,10 +10,6 @@ require File.expand_path("../init", File.dirname(__FILE__))
10
10
  API_KEY = '4b339169026742245b754fa338b9b0aebbd0a733'
11
11
  API_VERSION = RPXNow.api_version
12
12
 
13
-
14
-
15
-
16
-
17
13
  # ---- rspec
18
14
  Spec::Runner.configure do |config|
19
15
  config.mock_with :mocha
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: grosser-rpx_now
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.3
4
+ version: 0.5.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael Grosser
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-06-17 00:00:00 -07:00
12
+ date: 2009-06-18 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -35,8 +35,11 @@ files:
35
35
  - Rakefile
36
36
  - VERSION.yml
37
37
  - lib/rpx_now.rb
38
+ - lib/rpx_now/contacts_collection.rb
38
39
  - lib/rpx_now/user_integration.rb
39
40
  - lib/rpx_now/user_proxy.rb
41
+ - spec/fixtures/get_contacts_response.json
42
+ - spec/rpx_now/contacts_collection_spec.rb
40
43
  - spec/rpx_now/user_proxy_spec.rb
41
44
  - spec/rpx_now_spec.rb
42
45
  - spec/spec_helper.rb
@@ -68,5 +71,6 @@ specification_version: 2
68
71
  summary: Helper to simplify RPX Now user login/creation
69
72
  test_files:
70
73
  - spec/rpx_now_spec.rb
74
+ - spec/rpx_now/contacts_collection_spec.rb
71
75
  - spec/rpx_now/user_proxy_spec.rb
72
76
  - spec/spec_helper.rb