rpx_now 0.5.11 → 0.6.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/CHANGELOG +4 -0
- data/README.markdown +2 -1
- data/VERSION +1 -1
- data/lib/rpx_now.rb +45 -85
- data/lib/rpx_now/contacts_collection.rb +1 -0
- data/lib/rpx_now/request.rb +5 -2
- data/pkg/rpx_now-0.5.11.gem +0 -0
- data/rpx_now.gemspec +1 -1
- data/spec/rpx_now_spec.rb +48 -44
- metadata +1 -1
data/CHANGELOG
CHANGED
data/README.markdown
CHANGED
@@ -109,7 +109,8 @@ Author
|
|
109
109
|
- [Amunds](http://github.com/Amunds)
|
110
110
|
- [DBA](http://github.com/DBA)
|
111
111
|
- [dbalatero](http://github.com/dbalatero)
|
112
|
-
- [jackdempsey](http://jackndempsey.blogspot.com
|
112
|
+
- [jackdempsey](http://jackndempsey.blogspot.com)
|
113
|
+
- [Patrick Reagan (reagent)](http://sneaq.net)
|
113
114
|
|
114
115
|
[Michael Grosser](http://pragmatig.wordpress.com)
|
115
116
|
grosser.michael@gmail.com
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.6.1
|
data/lib/rpx_now.rb
CHANGED
@@ -14,79 +14,63 @@ module RPXNow
|
|
14
14
|
attr_accessor :api_version
|
15
15
|
self.api_version = 2
|
16
16
|
|
17
|
+
VERSION = File.read( File.join(File.dirname(__FILE__),'..','VERSION') ).strip
|
18
|
+
|
17
19
|
# retrieve the users data
|
18
20
|
# - cleaned Hash
|
19
21
|
# - complete/unclean response when block was given user_data{|response| ...; return hash }
|
20
22
|
# - nil when token was invalid / data was not found
|
21
|
-
def user_data(token,
|
22
|
-
api_key, version, options = extract_key_version_and_options!(args)
|
23
|
-
options = {:token=>token,:apiKey=>api_key}.merge options
|
24
|
-
|
23
|
+
def user_data(token, options={})
|
25
24
|
begin
|
26
|
-
data =
|
25
|
+
data = Request.post("auth_info", options.merge(:token => token))
|
26
|
+
if block_given? then yield(data) else parse_user_data(data) end
|
27
27
|
rescue ServerError
|
28
28
|
return nil if $!.to_s=~/Data not found/
|
29
29
|
raise
|
30
30
|
end
|
31
|
-
if block_given? then yield(data) else parse_user_data(data) end
|
32
31
|
end
|
33
32
|
|
34
33
|
# set the users status
|
35
|
-
def set_status(identifier, status,
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
rescue ServerError
|
42
|
-
return nil if $!.to_s=~/Data not found/
|
43
|
-
raise
|
44
|
-
end
|
34
|
+
def set_status(identifier, status, options={})
|
35
|
+
options = options.merge(:identifier => identifier, :status => status)
|
36
|
+
data = Request.post("set_status", options)
|
37
|
+
rescue ServerError
|
38
|
+
return nil if $!.to_s=~/Data not found/
|
39
|
+
raise
|
45
40
|
end
|
46
41
|
|
47
42
|
# maps an identifier to an primary-key (e.g. user.id)
|
48
|
-
def map(identifier, primary_key,
|
49
|
-
|
50
|
-
options = {:identifier=>identifier,:primaryKey=>primary_key,:apiKey=>api_key}.merge options
|
51
|
-
secure_json_post("/api/v#{version}/map", options)
|
43
|
+
def map(identifier, primary_key, options={})
|
44
|
+
Request.post("map", options.merge(:identifier => identifier, :primaryKey => primary_key))
|
52
45
|
end
|
53
46
|
|
54
47
|
# un-maps an identifier to an primary-key (e.g. user.id)
|
55
|
-
def unmap(identifier, primary_key,
|
56
|
-
|
57
|
-
options = {:identifier=>identifier,:primaryKey=>primary_key,:apiKey=>api_key}.merge options
|
58
|
-
secure_json_post("/api/v#{version}/unmap", options)
|
48
|
+
def unmap(identifier, primary_key, options={})
|
49
|
+
Request.post("unmap", options.merge(:identifier => identifier, :primaryKey => primary_key))
|
59
50
|
end
|
60
51
|
|
61
52
|
# returns an array of identifiers which are mapped to one of your primary-keys (e.g. user.id)
|
62
|
-
def mappings(primary_key,
|
63
|
-
|
64
|
-
options = {:primaryKey=>primary_key,:apiKey=>api_key}.merge options
|
65
|
-
data = secure_json_post("/api/v#{version}/mappings", options)
|
66
|
-
data['identifiers']
|
53
|
+
def mappings(primary_key, options={})
|
54
|
+
Request.post("mappings", options.merge(:primaryKey => primary_key))['identifiers']
|
67
55
|
end
|
68
56
|
|
69
|
-
def all_mappings(
|
70
|
-
|
71
|
-
data = secure_json_post("/api/v#{version}/all_mappings", {:apiKey => api_key}.merge(options))
|
72
|
-
data['mappings']
|
57
|
+
def all_mappings(options={})
|
58
|
+
Request.post("all_mappings", options)['mappings']
|
73
59
|
end
|
74
60
|
|
75
|
-
def contacts(identifier,
|
76
|
-
|
77
|
-
options = {:apiKey => api_key, :identifier=> identifier}.merge(options)
|
78
|
-
data = secure_json_post("/api/v#{version}/get_contacts", options)
|
61
|
+
def contacts(identifier, options={})
|
62
|
+
data = Request.post("get_contacts", options.merge(:identifier => identifier))
|
79
63
|
RPXNow::ContactsCollection.new(data['response'])
|
80
64
|
end
|
81
65
|
alias get_contacts contacts
|
82
66
|
|
83
67
|
def embed_code(subdomain,url,options={})
|
84
68
|
options = {:width => '400', :height => '240', :language => 'en'}.merge(options)
|
85
|
-
|
86
|
-
<iframe src="https://#{subdomain}.#{Request::HOST}/openid/embed?token_url=#{url}&language_preference=#{options[:language]}"
|
87
|
-
|
88
|
-
</iframe>
|
89
|
-
EOF
|
69
|
+
<<-EOF
|
70
|
+
<iframe src="https://#{subdomain}.#{Request::HOST}/openid/embed?token_url=#{url}&language_preference=#{options[:language]}"
|
71
|
+
scrolling="no" frameBorder="no" style="width:#{options[:width]}px;height:#{options[:height]}px;">
|
72
|
+
</iframe>
|
73
|
+
EOF
|
90
74
|
end
|
91
75
|
|
92
76
|
def popup_code(text, subdomain, url, options = {})
|
@@ -97,6 +81,10 @@ EOF
|
|
97
81
|
end
|
98
82
|
end
|
99
83
|
|
84
|
+
def extract_version!(options)
|
85
|
+
options.delete(:api_version) || api_version
|
86
|
+
end
|
87
|
+
|
100
88
|
private
|
101
89
|
|
102
90
|
def self.parse_user_data(response)
|
@@ -117,49 +105,21 @@ EOF
|
|
117
105
|
|
118
106
|
def obtrusive_popup_code(text, subdomain, url, options = {})
|
119
107
|
version = extract_version! options
|
120
|
-
|
121
|
-
<a class="rpxnow" onclick="return false;" href="https://#{subdomain}.#{Request::HOST}/openid/v#{version}/signin?token_url=#{url}">
|
122
|
-
|
123
|
-
</a>
|
124
|
-
<script src="https://#{Request::HOST}/openid/v#{version}/widget" type="text/javascript"></script>
|
125
|
-
<script type="text/javascript">
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
</script>
|
134
|
-
EOF
|
135
|
-
end
|
136
|
-
|
137
|
-
def extract_key_version_and_options!(args)
|
138
|
-
key, options = extract_key_and_options(args)
|
139
|
-
version = extract_version! options
|
140
|
-
[key, version, options]
|
141
|
-
end
|
142
|
-
|
143
|
-
# [API_KEY,{options}] or
|
144
|
-
# [{options}] or
|
145
|
-
# []
|
146
|
-
def extract_key_and_options(args)
|
147
|
-
if args.length == 2
|
148
|
-
[args[0],args[1]]
|
149
|
-
elsif args.length==1
|
150
|
-
if args[0].is_a? Hash then [@api_key,args[0]] else [args[0],{}] end
|
151
|
-
else
|
152
|
-
raise "NO Api Key found!" unless @api_key
|
153
|
-
[@api_key,{}]
|
154
|
-
end
|
155
|
-
end
|
156
|
-
|
157
|
-
def extract_version!(options)
|
158
|
-
options.delete(:api_version) || api_version
|
159
|
-
end
|
160
|
-
|
161
|
-
def secure_json_post(path, data)
|
162
|
-
Request.post(path, data)
|
108
|
+
<<-EOF
|
109
|
+
<a class="rpxnow" onclick="return false;" href="https://#{subdomain}.#{Request::HOST}/openid/v#{version}/signin?token_url=#{url}">
|
110
|
+
#{text}
|
111
|
+
</a>
|
112
|
+
<script src="https://#{Request::HOST}/openid/v#{version}/widget" type="text/javascript"></script>
|
113
|
+
<script type="text/javascript">
|
114
|
+
//<![CDATA[
|
115
|
+
RPXNOW.token_url = "#{url}";
|
116
|
+
|
117
|
+
RPXNOW.realm = "#{subdomain}";
|
118
|
+
RPXNOW.overlay = true;
|
119
|
+
RPXNOW.language_preference = '#{options[:language]||'en'}';
|
120
|
+
//]]>
|
121
|
+
</script>
|
122
|
+
EOF
|
163
123
|
end
|
164
124
|
|
165
125
|
class ServerError < RuntimeError; end #backwards compatibility / catch all
|
data/lib/rpx_now/request.rb
CHANGED
@@ -3,8 +3,11 @@ module RPXNow
|
|
3
3
|
HOST = 'rpxnow.com'
|
4
4
|
SSL_CERT = File.join(File.dirname(__FILE__), '..', '..', 'certs', 'ssl_cert.pem')
|
5
5
|
|
6
|
-
def self.post(
|
7
|
-
|
6
|
+
def self.post(method, data)
|
7
|
+
version = RPXNow.extract_version! data
|
8
|
+
path = "/api/v#{version}/#{method}"
|
9
|
+
response = request(path, {:apiKey => RPXNow.api_key}.merge(data))
|
10
|
+
parse_response(response)
|
8
11
|
end
|
9
12
|
|
10
13
|
private
|
data/pkg/rpx_now-0.5.11.gem
CHANGED
Binary file
|
data/rpx_now.gemspec
CHANGED
data/spec/rpx_now_spec.rb
CHANGED
@@ -1,6 +1,11 @@
|
|
1
1
|
require 'spec/spec_helper'
|
2
2
|
|
3
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
|
+
|
4
9
|
describe :api_key= do
|
5
10
|
it "stores the api key, so i do not have to supply everytime" do
|
6
11
|
RPXNow.api_key='XX'
|
@@ -79,14 +84,19 @@ describe RPXNow do
|
|
79
84
|
|
80
85
|
describe :user_data do
|
81
86
|
before do
|
82
|
-
@response_body =
|
87
|
+
@response_body = {
|
88
|
+
"profile" => {
|
89
|
+
"verifiedEmail" => "grosser.michael@googlemail.com",
|
90
|
+
"displayName" => "Michael Grosser",
|
91
|
+
"preferredUsername" => "grosser.michael",
|
92
|
+
"identifier" => "https:\/\/www.google.com\/accounts\/o8\/id?id=AItOawmaOlyYezg_WfbgP_qjaUyHjmqZD9qNIVM",
|
93
|
+
"email" => "grosser.michael@gmail.com"
|
94
|
+
}
|
95
|
+
}
|
96
|
+
@response = fake_response(@response_body)
|
83
97
|
@fake_user_data = {'profile'=>{}}
|
84
98
|
end
|
85
99
|
|
86
|
-
def fake_response
|
87
|
-
mock(:code=>"200",:body=>@response_body)
|
88
|
-
end
|
89
|
-
|
90
100
|
it "raises ApiError when used with an invalid token" do
|
91
101
|
lambda{
|
92
102
|
RPXNow.user_data('xxxx')
|
@@ -104,69 +114,58 @@ describe RPXNow do
|
|
104
114
|
:identifier => 'https://www.google.com/accounts/o8/id?id=AItOawmaOlyYezg_WfbgP_qjaUyHjmqZD9qNIVM',
|
105
115
|
:username => 'grosser.michael',
|
106
116
|
}
|
107
|
-
RPXNow::Request.should_receive(:request).and_return
|
117
|
+
RPXNow::Request.should_receive(:request).and_return @response
|
108
118
|
RPXNow.user_data('').should == expected
|
109
119
|
end
|
110
120
|
|
111
121
|
it "adds a :id when primaryKey was returned" do
|
112
|
-
@response_body
|
113
|
-
|
122
|
+
@response_body['profile']['primaryKey'] = "2"
|
123
|
+
response = fake_response(@response_body)
|
124
|
+
RPXNow::Request.should_receive(:request).and_return response
|
114
125
|
RPXNow.user_data('')[:id].should == '2'
|
115
126
|
end
|
116
127
|
|
117
128
|
it "handles primaryKeys that are not numeric" do
|
118
|
-
@response_body
|
119
|
-
|
129
|
+
@response_body['profile']['primaryKey'] = "dbalatero"
|
130
|
+
response = fake_response(@response_body)
|
131
|
+
RPXNow::Request.should_receive(:request).and_return response
|
120
132
|
RPXNow.user_data('')[:id].should == 'dbalatero'
|
121
133
|
end
|
122
134
|
|
123
135
|
it "hands JSON response to supplied block" do
|
124
|
-
RPXNow::Request.should_receive(:request).and_return
|
136
|
+
RPXNow::Request.should_receive(:request).and_return @response
|
125
137
|
response = nil
|
126
138
|
RPXNow.user_data(''){|data| response = data}
|
127
|
-
response.
|
139
|
+
response.delete('stat') # dunno why it happens, but is not important...
|
140
|
+
response.should == @response_body
|
128
141
|
end
|
129
142
|
|
130
143
|
it "returns what the supplied block returned" do
|
131
|
-
RPXNow::Request.should_receive(:request).and_return
|
144
|
+
RPXNow::Request.should_receive(:request).and_return @response
|
132
145
|
RPXNow.user_data(''){|data| "x"}.should == 'x'
|
133
146
|
end
|
134
147
|
|
135
148
|
it "can send additional parameters" do
|
136
149
|
RPXNow::Request.should_receive(:request).with{|url,data|
|
137
150
|
data[:extended].should == 'true'
|
138
|
-
}.and_return
|
151
|
+
}.and_return @response
|
139
152
|
RPXNow.user_data('',:extended=>'true')
|
140
153
|
end
|
141
154
|
|
142
|
-
it "works with api
|
143
|
-
RPXNow.should_receive(:
|
144
|
-
RPXNow.user_data('id', '
|
145
|
-
RPXNow.
|
155
|
+
it "works with api version as option" do
|
156
|
+
RPXNow::Request.should_receive(:request).with('/api/v123/auth_info', :apiKey=>API_KEY, :token=>'id', :extended=>'abc').and_return @response
|
157
|
+
RPXNow.user_data('id', :extended=>'abc', :api_version=>123)
|
158
|
+
RPXNow.api_version.should == API_VERSION
|
146
159
|
end
|
147
160
|
|
148
|
-
it "works with
|
149
|
-
RPXNow.should_receive(:
|
150
|
-
RPXNow.user_data('id', '
|
161
|
+
it "works with apiKey as option" do
|
162
|
+
RPXNow::Request.should_receive(:request).with('/api/v2/auth_info', :apiKey=>'THE KEY', :token=>'id', :extended=>'abc').and_return @response
|
163
|
+
RPXNow.user_data('id', :extended=>'abc', :apiKey=>'THE KEY')
|
151
164
|
RPXNow.api_key.should == API_KEY
|
152
165
|
end
|
153
|
-
|
154
|
-
it "works with api version as option (backwards compatibility)" do
|
155
|
-
RPXNow.should_receive(:secure_json_post).with('/api/v123/auth_info', :apiKey=>API_KEY, :token=>'id', :extended=>'abc').and_return @fake_user_data
|
156
|
-
RPXNow.user_data('id', :extended=>'abc', :api_version=>123)
|
157
|
-
RPXNow.api_version.should == API_VERSION
|
158
|
-
end
|
159
166
|
end
|
160
167
|
|
161
168
|
describe :set_status do
|
162
|
-
before do
|
163
|
-
@response_body = %Q({ "stat": "ok" })
|
164
|
-
end
|
165
|
-
|
166
|
-
def fake_response
|
167
|
-
mock(:code=>"200",:body=>@response_body)
|
168
|
-
end
|
169
|
-
|
170
169
|
it "parses JSON response to result hash" do
|
171
170
|
RPXNow::Request.should_receive(:request).and_return fake_response
|
172
171
|
RPXNow.set_status('identifier', 'Chillen...').should == {'stat' => 'ok'}
|
@@ -185,34 +184,35 @@ describe RPXNow do
|
|
185
184
|
|
186
185
|
describe :contacts do
|
187
186
|
it "finds all contacts" do
|
188
|
-
response = JSON.parse(File.read('spec/fixtures/get_contacts_response.json'))
|
189
|
-
RPXNow.should_receive(:
|
187
|
+
response = fake_response(JSON.parse(File.read('spec/fixtures/get_contacts_response.json')))
|
188
|
+
RPXNow::Request.should_receive(:request).with('/api/v2/get_contacts',:identifier=>'xx', :apiKey=>API_KEY).and_return response
|
190
189
|
RPXNow.contacts('xx').size.should == 5
|
191
190
|
end
|
192
191
|
end
|
193
192
|
|
194
193
|
describe :mappings do
|
195
194
|
it "parses JSON response to unmap data" do
|
196
|
-
|
197
|
-
RPXNow.
|
195
|
+
|
196
|
+
RPXNow::Request.should_receive(:request).and_return fake_response("identifiers" => ["http://test.myopenid.com/"])
|
197
|
+
RPXNow.mappings(1).should == ["http://test.myopenid.com/"]
|
198
198
|
end
|
199
199
|
end
|
200
200
|
|
201
201
|
describe :map do
|
202
202
|
it "adds a mapping" do
|
203
|
-
RPXNow::Request.should_receive(:request).and_return
|
204
|
-
RPXNow.map('http://test.myopenid.com',1
|
203
|
+
RPXNow::Request.should_receive(:request).and_return fake_response
|
204
|
+
RPXNow.map('http://test.myopenid.com',1)
|
205
205
|
end
|
206
206
|
end
|
207
207
|
|
208
208
|
describe :unmap do
|
209
209
|
it "unmaps a indentifier" do
|
210
|
-
RPXNow::Request.should_receive(:request).and_return
|
211
|
-
RPXNow.unmap('http://test.myopenid.com', 1
|
210
|
+
RPXNow::Request.should_receive(:request).and_return fake_response
|
211
|
+
RPXNow.unmap('http://test.myopenid.com', 1)
|
212
212
|
end
|
213
213
|
|
214
214
|
it "can be called with a specific version" do
|
215
|
-
RPXNow.should_receive(:
|
215
|
+
RPXNow::Request.should_receive(:request).with{|a,b|a == "/api/v300/unmap"}.and_return fake_response
|
216
216
|
RPXNow.unmap('http://test.myopenid.com', 1, :api_key=>'xxx', :api_version=>300)
|
217
217
|
end
|
218
218
|
end
|
@@ -253,4 +253,8 @@ describe RPXNow do
|
|
253
253
|
RPXNow.all_mappings.sort.should == [["1", ["http://test.myopenid.com"]], ["2", ["http://test-2.myopenid.com"]]]
|
254
254
|
end
|
255
255
|
end
|
256
|
+
|
257
|
+
it "has a VERSION" do
|
258
|
+
RPXNow::VERSION.should =~ /^\d+\.\d+\.\d+$/
|
259
|
+
end
|
256
260
|
end
|