Empact-rpx_now 0.7.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,32 @@
1
+ require 'spec/spec_helper'
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
@@ -0,0 +1,33 @@
1
+ require 'spec/spec_helper'
2
+ require 'rpx_now/user_integration'
3
+
4
+ class User
5
+ include RPXNow::UserIntegration
6
+
7
+ def id
8
+ 5
9
+ end
10
+ end
11
+
12
+ describe RPXNow::UserProxy do
13
+ before { @user = User.new }
14
+
15
+ it "has a proxy" do
16
+ @user.rpx.class.should == RPXNow::UserProxy
17
+ end
18
+
19
+ it "has identifiers" do
20
+ RPXNow.should_receive(:mappings).with(@user.id).and_return(['identifiers'])
21
+ @user.rpx.identifiers.should == ['identifiers']
22
+ end
23
+
24
+ it "can map" do
25
+ RPXNow.should_receive(:map).with('identifier', @user.id)
26
+ @user.rpx.map('identifier')
27
+ end
28
+
29
+ it "can unmap" do
30
+ RPXNow.should_receive(:unmap).with('identifier', @user.id)
31
+ @user.rpx.unmap('identifier')
32
+ end
33
+ end
@@ -0,0 +1,361 @@
1
+ require 'spec/spec_helper'
2
+
3
+ describe RPXNow do
4
+ def fake_response(replace={})
5
+ body = {'stat' => 'ok'}.merge(replace)
6
+ mock({:code => "200", :body => body.to_json})
7
+ end
8
+
9
+ describe :api_key= do
10
+ before do
11
+ RPXNow.api_key='XX'
12
+ end
13
+
14
+ it "is stored" do
15
+ RPXNow.api_key.should == 'XX'
16
+ end
17
+
18
+ it "stores the api key, so i do not have to supply everytime" do
19
+ RPXNow::Api.should_receive(:request).
20
+ with(anything, hash_including(:apiKey => 'XX')).
21
+ and_return fake_response
22
+ RPXNow.mappings(1)
23
+ end
24
+
25
+ it "is not overwritten when overwriting for a single request" do
26
+ RPXNow::Api.should_receive(:request).
27
+ with(anything, hash_including(:apiKey => 'YY')).
28
+ and_return fake_response
29
+ RPXNow.mappings(1, :apiKey => 'YY')
30
+ RPXNow.api_key.should == 'XX'
31
+ end
32
+ end
33
+
34
+ describe :api_version= do
35
+ it "is 2 by default" do
36
+ RPXNow.api_version.should == 2
37
+ end
38
+
39
+ it "is stored" do
40
+ RPXNow.api_version='XX'
41
+ RPXNow.api_version.should == 'XX'
42
+ end
43
+
44
+ it "used for every request" do
45
+ RPXNow.api_version='XX'
46
+ RPXNow::Api.should_receive(:request).
47
+ with('/api/vXX/mappings', anything).
48
+ and_return fake_response
49
+ RPXNow.mappings(1)
50
+ end
51
+
52
+ it "is not overwritten when overwriting for a single request" do
53
+ RPXNow.api_version='XX'
54
+ RPXNow::Api.should_receive(:request).
55
+ with('/api/vYY/mappings', anything).
56
+ and_return fake_response
57
+ RPXNow.mappings(1, :api_version => 'YY')
58
+ RPXNow.api_version.should == 'XX'
59
+ end
60
+
61
+ it "is not passed in data for request" do
62
+ RPXNow.api_version='XX'
63
+ RPXNow::Api.should_receive(:request).
64
+ with(anything, hash_not_including(:api_version => 'YY')).
65
+ and_return fake_response
66
+ RPXNow.mappings(1, :api_version => 'YY')
67
+ end
68
+ end
69
+
70
+ describe :embed_code do
71
+ it "contains the subdomain" do
72
+ RPXNow.embed_code('xxx','my_url').should =~ /xxx/
73
+ end
74
+
75
+ it "contains the url" do
76
+ RPXNow.embed_code('xxx','my_url').should =~ /token_url=my_url/
77
+ end
78
+
79
+ it "defaults to no language" do
80
+ RPXNow.embed_code('xxx', 'my_url').should_not =~ /language_preference/
81
+ end
82
+
83
+ it "has a changeable language" do
84
+ RPXNow.embed_code('xxx', 'my_url', :language => 'es').should =~ /language_preference=es/
85
+ end
86
+
87
+ it "defaults to 400px width" do
88
+ RPXNow.embed_code('xxx', 'my_url').should =~ /width:400px;/
89
+ end
90
+
91
+ it "has a changeable width" do
92
+ RPXNow.embed_code('xxx', 'my_url', :width => '300').should =~ /width:300px;/
93
+ end
94
+
95
+ it "defaults to 240px height" do
96
+ RPXNow.embed_code('xxx', 'my_url').should =~ /height:240px;/
97
+ end
98
+
99
+ it "has a changeable height" do
100
+ RPXNow.embed_code('xxx', 'my_url', :height => '500').should =~ /height:500px;/
101
+ end
102
+ end
103
+
104
+ describe :popup_code do
105
+ it "defaults to obtrusive output" do
106
+ RPXNow.popup_code('sign on', 'subdomain', 'http://fake.domain.com/').should =~ /script src=/
107
+ end
108
+
109
+ it "does not change supplied options" do
110
+ options = {:xxx => 1}
111
+ RPXNow.popup_code('a','b','c', options)
112
+ options.should == {:xxx => 1}
113
+ end
114
+
115
+ describe 'obstrusive' do
116
+ it "does not encode token_url for popup" do
117
+ expected = %Q(RPXNOW.token_url = 'http://fake.domain.com/')
118
+ RPXNow.popup_code('sign on', 'subdomain', 'http://fake.domain.com/').should include(expected)
119
+ end
120
+ it "encodes token_url for unobtrusive fallback link" do
121
+ expected = %Q(<a class="rpxnow" href="https://subdomain.rpxnow.com/openid/v2/signin?token_url=http%3A%2F%2Ffake.domain.com%2F">sign on</a>)
122
+ RPXNow.popup_code('sign on', 'subdomain', 'http://fake.domain.com/').should include(expected)
123
+ end
124
+ end
125
+
126
+ describe 'unobstrusive' do
127
+ it "can build an unobtrusive widget with encoded token_url" do
128
+ expected = %Q(<a class="rpxnow" href="https://subdomain.rpxnow.com/openid/v2/signin?token_url=http%3A%2F%2Ffake.domain.com%2F">sign on</a>)
129
+ actual = RPXNow.popup_code('sign on', 'subdomain', 'http://fake.domain.com/', :unobtrusive => true)
130
+ actual.should == expected
131
+ end
132
+
133
+ it "can change api version" do
134
+ RPXNow.popup_code('x', 'y', 'z', :unobtrusive => true, :api_version => 'XX').should include("openid/vXX/signin?")
135
+ end
136
+
137
+ it "can change language" do
138
+ RPXNow.popup_code('x', 'y', 'z', :unobtrusive => true, :language => 'XX').should include("language_preference=XX")
139
+ end
140
+
141
+ it "can add flags" do
142
+ RPXNow.popup_code('x', 'y', 'z', :unobtrusive => true, :flags => 'test').should include("flags=test")
143
+ end
144
+
145
+ it "can add default_provider" do
146
+ RPXNow.popup_code('x', 'y', 'z', :unobtrusive => true, :default_provider => 'test').should include("default_provider=test")
147
+ end
148
+ end
149
+
150
+ it "allows to specify the version of the widget" do
151
+ RPXNow.popup_code('x','y','z', :api_version => 300).should =~ %r(/openid/v300/signin)
152
+ end
153
+
154
+ it "defaults to widget version 2" do
155
+ RPXNow.popup_code('x','y','z').should =~ %r(/openid/v2/signin)
156
+ end
157
+
158
+ describe 'language' do
159
+ it "defaults to no language" do
160
+ RPXNow.popup_code('x','y','z').should_not =~ /RPXNOW.language_preference/
161
+ end
162
+
163
+ it "has a changeable language" do
164
+ RPXNow.popup_code('x','y','z', :language=>'de').should =~ /RPXNOW.language_preference = 'de'/
165
+ end
166
+ end
167
+
168
+ describe 'flags' do
169
+ it "defaults to no language" do
170
+ RPXNow.popup_code('x','y','z').should_not =~ /RPXNOW.flags/
171
+ end
172
+
173
+ it "can have flags" do
174
+ RPXNow.popup_code('x','y','z', :flags=>'test').should =~ /RPXNOW.flags = 'test'/
175
+ end
176
+ end
177
+
178
+ describe 'default_provider' do
179
+ it "defaults to no provider" do
180
+ RPXNow.popup_code('x','y','z').should_not =~ /RPXNOW.default_provider/
181
+ end
182
+
183
+ it "can have default_provider" do
184
+ RPXNow.popup_code('x','y','z', :default_provider=>'test').should =~ /RPXNOW.default_provider = 'test'/
185
+ end
186
+ end
187
+ end
188
+
189
+ describe :user_data do
190
+ before do
191
+ @response_body = {
192
+ "profile" => {
193
+ "verifiedEmail" => "grosser.michael@googlemail.com",
194
+ "displayName" => "Michael Grosser",
195
+ "preferredUsername" => "grosser.michael",
196
+ "identifier" => "https:\/\/www.google.com\/accounts\/o8\/id?id=AItOawmaOlyYezg_WfbgP_qjaUyHjmqZD9qNIVM",
197
+ "email" => "grosser.michael@gmail.com"
198
+ }
199
+ }
200
+ @response = fake_response(@response_body)
201
+ @fake_user_data = {'profile'=>{}}
202
+ end
203
+
204
+ it "raises ApiError when used with an invalid token" do
205
+ lambda{
206
+ RPXNow.user_data('xxxx')
207
+ }.should raise_error(RPXNow::ApiError)
208
+ end
209
+
210
+ it "is empty when used with an unknown token" do
211
+ RPXNow.user_data('60d8c6374f4e9d290a7b55f39da7cc6435aef3d3').should == nil
212
+ end
213
+
214
+ it "parses JSON response to user data" do
215
+ expected = {
216
+ :name => 'Michael Grosser',
217
+ :email => 'grosser.michael@googlemail.com',
218
+ :identifier => 'https://www.google.com/accounts/o8/id?id=AItOawmaOlyYezg_WfbgP_qjaUyHjmqZD9qNIVM',
219
+ :username => 'grosser.michael',
220
+ }
221
+ RPXNow::Api.should_receive(:request).and_return @response
222
+ RPXNow.user_data('').should == expected
223
+ end
224
+
225
+ it "adds raw if i want it" do
226
+ RPXNow::Api.should_receive(:request).and_return @response
227
+ RPXNow.user_data('',:additional => [:raw])[:raw]["verifiedEmail"].should == "grosser.michael@googlemail.com"
228
+ end
229
+
230
+ it "adds a :id when primaryKey was returned" do
231
+ @response_body['profile']['primaryKey'] = "2"
232
+ response = fake_response(@response_body)
233
+ RPXNow::Api.should_receive(:request).and_return response
234
+ RPXNow.user_data('')[:id].should == '2'
235
+ end
236
+
237
+ it "handles primaryKeys that are not numeric" do
238
+ @response_body['profile']['primaryKey'] = "dbalatero"
239
+ response = fake_response(@response_body)
240
+ RPXNow::Api.should_receive(:request).and_return response
241
+ RPXNow.user_data('')[:id].should == 'dbalatero'
242
+ end
243
+
244
+ it "can fetch additional fields" do
245
+ @response_body['profile']['xxxy'] = "test"
246
+ response = fake_response(@response_body)
247
+ RPXNow::Api.should_receive(:request).and_return response
248
+ RPXNow.user_data('', :additional => [:xxxy])[:xxxy].should == 'test'
249
+ end
250
+
251
+ it "hands JSON response to supplied block" do
252
+ RPXNow::Api.should_receive(:request).and_return @response
253
+ response = nil
254
+ RPXNow.user_data(''){|data| response = data}
255
+ response.delete('stat') # dunno why it happens, but is not important...
256
+ response.should == @response_body
257
+ end
258
+
259
+ it "returns what the supplied block returned" do
260
+ RPXNow::Api.should_receive(:request).and_return @response
261
+ RPXNow.user_data(''){|data| "x"}.should == 'x'
262
+ end
263
+
264
+ it "can send additional parameters" do
265
+ RPXNow::Api.should_receive(:request).
266
+ with(anything, hash_including(:extended => 'true')).
267
+ and_return @response
268
+ RPXNow.user_data('',:extended=>'true')
269
+ end
270
+
271
+ # these 2 tests are kind of duplicates of the api_version/key tests,
272
+ # but i want to be extra-sure user_data works
273
+ it "works with api version as option" do
274
+ RPXNow::Api.should_receive(:request).
275
+ with('/api/v123/auth_info', anything).
276
+ and_return @response
277
+ RPXNow.user_data('id', :extended=>'abc', :api_version=>123)
278
+ RPXNow.api_version.should == API_VERSION
279
+ end
280
+
281
+ it "works with apiKey as option" do
282
+ RPXNow::Api.should_receive(:request).
283
+ with('/api/v2/auth_info', hash_including(:apiKey=>'THE KEY')).
284
+ and_return @response
285
+ RPXNow.user_data('id', :extended=>'abc', :apiKey=>'THE KEY')
286
+ RPXNow.api_key.should == API_KEY
287
+ end
288
+ end
289
+
290
+ describe :set_status do
291
+ it "sets the status" do
292
+ RPXNow::Api.should_receive(:request).
293
+ with("/api/v2/set_status", :identifier=>"identifier", :status=>"Chillen...", :apiKey=>API_KEY).
294
+ and_return fake_response
295
+ RPXNow.set_status('identifier', 'Chillen...')
296
+ end
297
+ end
298
+
299
+ describe :activity do
300
+ it "does a api call with the right arguments" do
301
+ RPXNow::Api.should_receive(:request).with("/api/v2/activity", :identifier=>"identifier", :activity=>'{"test":"something"}', :apiKey=>API_KEY).and_return fake_response
302
+ RPXNow.activity('identifier', :test => 'something')
303
+ end
304
+
305
+ it "can pass identifier/apiKey" do
306
+ RPXNow::Api.should_receive(:request).with("/api/v66666/activity", hash_including(:apiKey=>'MYKEY')).and_return fake_response
307
+ RPXNow.activity('identifier', {:test => 'something'}, :apiKey => 'MYKEY', :api_version => '66666')
308
+ end
309
+ end
310
+
311
+ describe :parse_user_data do
312
+ it "reads secondary names" do
313
+ RPXNow.send(:parse_user_data,{'profile'=>{'preferredUsername'=>'1'}}, {})[:name].should == '1'
314
+ end
315
+
316
+ it "parses email when no name is found" do
317
+ RPXNow.send(:parse_user_data,{'profile'=>{'email'=>'1@xxx.com'}}, {})[:name].should == '1'
318
+ end
319
+ end
320
+
321
+ describe :contacts do
322
+ it "finds all contacts" do
323
+ response = fake_response(JSON.parse(File.read('spec/fixtures/get_contacts_response.json')))
324
+ RPXNow::Api.should_receive(:request).
325
+ with('/api/v2/get_contacts',:identifier=>'xx', :apiKey=>API_KEY).
326
+ and_return response
327
+ RPXNow.contacts('xx').size.should == 5
328
+ end
329
+ end
330
+
331
+ describe :mappings do
332
+ it "shows all mappings" do
333
+ RPXNow::Api.should_receive(:request).
334
+ with("/api/v2/mappings", :apiKey=>API_KEY, :primaryKey=>1).
335
+ and_return fake_response("identifiers" => ["http://test.myopenid.com/"])
336
+ RPXNow.mappings(1).should == ["http://test.myopenid.com/"]
337
+ end
338
+ end
339
+
340
+ describe :map do
341
+ it "maps a identifier" do
342
+ RPXNow::Api.should_receive(:request).
343
+ with("/api/v2/map", :apiKey=>API_KEY, :primaryKey=>1, :identifier=>"http://test.myopenid.com").
344
+ and_return fake_response
345
+ RPXNow.map('http://test.myopenid.com',1)
346
+ end
347
+ end
348
+
349
+ describe :unmap do
350
+ it "unmaps a indentifier" do
351
+ RPXNow::Api.should_receive(:request).
352
+ with("/api/v2/unmap", :apiKey=>API_KEY, :primaryKey=>1, :identifier=>"http://test.myopenid.com").
353
+ and_return fake_response
354
+ RPXNow.unmap('http://test.myopenid.com', 1)
355
+ end
356
+ end
357
+
358
+ it "has a VERSION" do
359
+ RPXNow::VERSION.should =~ /^\d+\.\d+\.\d+$/
360
+ end
361
+ end
@@ -0,0 +1,18 @@
1
+ # ---- requirements
2
+ require 'rubygems'
3
+ require 'spec'
4
+
5
+ $LOAD_PATH << File.expand_path("../lib", File.dirname(__FILE__))
6
+
7
+ # ---- setup environment/plugin
8
+ require File.expand_path("../init", File.dirname(__FILE__))
9
+ API_KEY = '4b339169026742245b754fa338b9b0aebbd0a733'
10
+ API_VERSION = RPXNow.api_version
11
+
12
+ # ---- rspec
13
+ Spec::Runner.configure do |config|
14
+ config.before :each do
15
+ RPXNow.api_key = API_KEY
16
+ RPXNow.api_version = API_VERSION
17
+ end
18
+ end
metadata ADDED
@@ -0,0 +1,98 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: Empact-rpx_now
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 7
8
+ - 0
9
+ version: 0.7.0
10
+ platform: ruby
11
+ authors:
12
+ - Michael Grosser
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2010-03-09 00:00:00 -05:00
18
+ default_executable:
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: json_pure
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ">="
26
+ - !ruby/object:Gem::Version
27
+ segments:
28
+ - 0
29
+ version: "0"
30
+ type: :runtime
31
+ version_requirements: *id001
32
+ description:
33
+ email: grosser.michael@gmail.com
34
+ executables: []
35
+
36
+ extensions: []
37
+
38
+ extra_rdoc_files:
39
+ - README.markdown
40
+ files:
41
+ - .gitignore
42
+ - CHANGELOG
43
+ - Empact-rpx_now.gemspec
44
+ - MIGRATION
45
+ - README.markdown
46
+ - Rakefile
47
+ - VERSION
48
+ - certs/ssl_cert.pem
49
+ - init.rb
50
+ - lib/rpx_now.rb
51
+ - lib/rpx_now/api.rb
52
+ - lib/rpx_now/contacts_collection.rb
53
+ - lib/rpx_now/user_integration.rb
54
+ - lib/rpx_now/user_proxy.rb
55
+ - spec/fixtures/get_contacts_response.json
56
+ - spec/integration/mapping_spec.rb
57
+ - spec/rpx_now/api_spec.rb
58
+ - spec/rpx_now/contacts_collection_spec.rb
59
+ - spec/rpx_now/user_proxy_spec.rb
60
+ - spec/rpx_now_spec.rb
61
+ - spec/spec_helper.rb
62
+ has_rdoc: true
63
+ homepage: http://github.com/Empact/rpx_now
64
+ licenses: []
65
+
66
+ post_install_message:
67
+ rdoc_options:
68
+ - --charset=UTF-8
69
+ require_paths:
70
+ - lib
71
+ required_ruby_version: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ segments:
76
+ - 0
77
+ version: "0"
78
+ required_rubygems_version: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ segments:
83
+ - 0
84
+ version: "0"
85
+ requirements: []
86
+
87
+ rubyforge_project:
88
+ rubygems_version: 1.3.6
89
+ signing_key:
90
+ specification_version: 3
91
+ summary: Helper to simplify RPX Now user login/creation
92
+ test_files:
93
+ - spec/integration/mapping_spec.rb
94
+ - spec/rpx_now/api_spec.rb
95
+ - spec/rpx_now/contacts_collection_spec.rb
96
+ - spec/rpx_now/user_proxy_spec.rb
97
+ - spec/rpx_now_spec.rb
98
+ - spec/spec_helper.rb