grosser-rpx_now 0.3 → 0.3.1
Sign up to get free protection for your applications and to get access to all the features.
- data/README.markdown +8 -3
- data/VERSION.yml +4 -0
- data/lib/rpx_now.rb +25 -8
- data/spec/rpx_now_spec.rb +12 -0
- metadata +10 -29
- data/CHANGELOG +0 -1
- data/Rakefile +0 -21
- data/init.rb +0 -1
- data/rpx_now.gemspec +0 -37
data/README.markdown
CHANGED
@@ -35,10 +35,11 @@ View
|
|
35
35
|
Controller
|
36
36
|
----------
|
37
37
|
# simple: use defaults
|
38
|
+
# user_data returns e.g. {:name=>'John Doe',:email=>'john@doe.com',:identifier=>'blug.google.com/openid/dsdfsdfs3f3'}
|
39
|
+
# when no user_data was found (invalid token supplied), data is empty, you may want to handle that seperatly...
|
40
|
+
# your user model must have an identifier column
|
38
41
|
def rpx_token
|
39
|
-
data = RPXNow.user_data(params[:token],'YOUR RPX API KEY')
|
40
|
-
#when no user_data was found, data is empty, you may want to handle that seperatly...
|
41
|
-
#your user model must have an identifier column
|
42
|
+
data = RPXNow.user_data(params[:token],'YOUR RPX API KEY')
|
42
43
|
self.current_user = User.find_by_identifier(data[:identifier]) || User.create!(data)
|
43
44
|
redirect_to '/'
|
44
45
|
end
|
@@ -49,6 +50,10 @@ Controller
|
|
49
50
|
# request extended parameters (most users and APIs do not supply them)
|
50
51
|
RPXNow.user_data(params[:token],'YOUR RPX API KEY',:extended=>'true'){|raw| ...have a look at the RPX API DOCS...}
|
51
52
|
|
53
|
+
# you can provide the api key once, and leave it out on all following calls
|
54
|
+
RPXNow.api_key = 'YOUR RPX API KEY'
|
55
|
+
RPXNow.user_data(params[:token],:extended=>'true')
|
56
|
+
|
52
57
|
Advanced: Mappings
|
53
58
|
------------------
|
54
59
|
You can map your primary keys (e.g. user.id) to identifiers, so that
|
data/VERSION.yml
ADDED
data/lib/rpx_now.rb
CHANGED
@@ -2,10 +2,13 @@ require 'activesupport'
|
|
2
2
|
module RPXNow
|
3
3
|
extend self
|
4
4
|
|
5
|
+
attr_writer :api_key
|
6
|
+
|
5
7
|
# retrieve the users data, or return nil when nothing could be read/token was invalid or data was not found
|
6
|
-
def user_data(token
|
8
|
+
def user_data(token,*args)
|
9
|
+
api_key, parameters = extract_key_and_options(args)
|
7
10
|
begin
|
8
|
-
data = secure_json_post('https://rpxnow.com/api/v2/auth_info',{:token=>token,:apiKey=>api_key}.merge(parameters))
|
11
|
+
data = secure_json_post('https://rpxnow.com/api/v2/auth_info',{:token=>token,:apiKey=>api_key||@api_key}.merge(parameters))
|
9
12
|
rescue ServerError
|
10
13
|
return nil if $!.to_s =~ /token/ or $!.to_s=~/Data not found/
|
11
14
|
raise
|
@@ -14,18 +17,19 @@ module RPXNow
|
|
14
17
|
end
|
15
18
|
|
16
19
|
# maps an identifier to an primary-key (e.g. user.id)
|
17
|
-
def map(identifier,primary_key
|
18
|
-
|
20
|
+
def map(identifier,primary_key,*args)
|
21
|
+
api_key, options = extract_key_and_options(args)
|
22
|
+
secure_json_post('https://rpxnow.com/api/v2/map',{:identifier=>identifier,:primaryKey=>primary_key,:apiKey=>api_key||@api_key}.merge(options))
|
19
23
|
end
|
20
24
|
|
21
25
|
# un-maps an identifier to an primary-key (e.g. user.id)
|
22
|
-
def unmap(identifier,primary_key,api_key)
|
23
|
-
secure_json_post('https://rpxnow.com/api/v2/unmap',{:identifier=>identifier,:primaryKey=>primary_key,:apiKey=>api_key})
|
26
|
+
def unmap(identifier,primary_key,api_key=nil)
|
27
|
+
secure_json_post('https://rpxnow.com/api/v2/unmap',{:identifier=>identifier,:primaryKey=>primary_key,:apiKey=>api_key||@api_key})
|
24
28
|
end
|
25
29
|
|
26
30
|
# returns an array of identifiers which are mapped to one of your primary-keys (e.g. user.id)
|
27
|
-
def mappings(primary_key,api_key)
|
28
|
-
data = secure_json_post('https://rpxnow.com/api/v2/mappings',{:primaryKey=>primary_key,:apiKey=>api_key})
|
31
|
+
def mappings(primary_key,api_key=nil)
|
32
|
+
data = secure_json_post('https://rpxnow.com/api/v2/mappings',{:primaryKey=>primary_key,:apiKey=>api_key||@api_key})
|
29
33
|
data['identifiers']
|
30
34
|
end
|
31
35
|
|
@@ -56,6 +60,19 @@ EOF
|
|
56
60
|
end
|
57
61
|
|
58
62
|
private
|
63
|
+
# [API_KEY,{options}] or
|
64
|
+
# [{options}] or
|
65
|
+
# []
|
66
|
+
def extract_key_and_options(args)
|
67
|
+
if args.length == 2
|
68
|
+
[args[0],args[1]]
|
69
|
+
elsif args.length==1
|
70
|
+
if args[0].is_a? Hash then [@api_key,args[0]] else [args[0],{}] end
|
71
|
+
else
|
72
|
+
raise unless @api_key
|
73
|
+
[@api_key,{}]
|
74
|
+
end
|
75
|
+
end
|
59
76
|
|
60
77
|
def read_user_data_from_response(response)
|
61
78
|
user_data = response['profile']
|
data/spec/rpx_now_spec.rb
CHANGED
@@ -3,6 +3,18 @@ require File.expand_path("spec_helper", File.dirname(__FILE__))
|
|
3
3
|
API_KEY = '4b339169026742245b754fa338b9b0aebbd0a733'
|
4
4
|
|
5
5
|
describe RPXNow do
|
6
|
+
before do
|
7
|
+
RPXNow.api_key=nil
|
8
|
+
end
|
9
|
+
|
10
|
+
describe :api_key= do
|
11
|
+
it "stores the api key, so i do not have to supply everytime" do
|
12
|
+
RPXNow.api_key='XX'
|
13
|
+
RPXNow.expects(:post).with{|x,data|data[:apiKey]=='XX'}.returns '{"stat":"ok"}'
|
14
|
+
RPXNow.mappings(1)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
6
18
|
describe :embed_code do
|
7
19
|
it "contains the subdomain" do
|
8
20
|
RPXNow.embed_code('xxx','my_url').should =~ /xxx/
|
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:
|
4
|
+
version: 0.3.1
|
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-
|
12
|
+
date: 2009-02-13 00:00:00 -08:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -21,45 +21,26 @@ dependencies:
|
|
21
21
|
- !ruby/object:Gem::Version
|
22
22
|
version: "0"
|
23
23
|
version:
|
24
|
-
|
25
|
-
name: echoe
|
26
|
-
version_requirement:
|
27
|
-
version_requirements: !ruby/object:Gem::Requirement
|
28
|
-
requirements:
|
29
|
-
- - ">="
|
30
|
-
- !ruby/object:Gem::Version
|
31
|
-
version: "0"
|
32
|
-
version:
|
33
|
-
description: Helper to simplify RPX Now user login/creation
|
24
|
+
description:
|
34
25
|
email: grosser.michael@gmail.com
|
35
26
|
executables: []
|
36
27
|
|
37
28
|
extensions: []
|
38
29
|
|
39
|
-
extra_rdoc_files:
|
40
|
-
|
41
|
-
- lib/rpx_now.rb
|
42
|
-
- README.markdown
|
30
|
+
extra_rdoc_files: []
|
31
|
+
|
43
32
|
files:
|
44
|
-
-
|
45
|
-
-
|
33
|
+
- VERSION.yml
|
34
|
+
- README.markdown
|
46
35
|
- lib/rpx_now.rb
|
47
36
|
- spec/rpx_now_spec.rb
|
48
37
|
- spec/spec_helper.rb
|
49
|
-
- rpx_now.gemspec
|
50
|
-
- init.rb
|
51
|
-
- Rakefile
|
52
|
-
- README.markdown
|
53
38
|
has_rdoc: true
|
54
39
|
homepage: http://github.com/grosser/rpx_now
|
55
40
|
post_install_message:
|
56
41
|
rdoc_options:
|
57
|
-
- --line-numbers
|
58
42
|
- --inline-source
|
59
|
-
- --
|
60
|
-
- Rpx_now
|
61
|
-
- --main
|
62
|
-
- README.markdown
|
43
|
+
- --charset=UTF-8
|
63
44
|
require_paths:
|
64
45
|
- lib
|
65
46
|
required_ruby_version: !ruby/object:Gem::Requirement
|
@@ -72,11 +53,11 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
72
53
|
requirements:
|
73
54
|
- - ">="
|
74
55
|
- !ruby/object:Gem::Version
|
75
|
-
version: "
|
56
|
+
version: "0"
|
76
57
|
version:
|
77
58
|
requirements: []
|
78
59
|
|
79
|
-
rubyforge_project:
|
60
|
+
rubyforge_project:
|
80
61
|
rubygems_version: 1.2.0
|
81
62
|
signing_key:
|
82
63
|
specification_version: 2
|
data/CHANGELOG
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
0.3 -- RPXNow::ServerError will be thrown when something is invalid/goes wrong, so watch out (not for invalid tokens in user_data)...
|
data/Rakefile
DELETED
@@ -1,21 +0,0 @@
|
|
1
|
-
require 'rubygems'
|
2
|
-
require 'echoe'
|
3
|
-
|
4
|
-
desc "Run all specs in spec directory"
|
5
|
-
task :test do |t|
|
6
|
-
options = "--colour --format progress --loadby --reverse"
|
7
|
-
files = FileList['spec/**/*_spec.rb']
|
8
|
-
system("spec #{options} #{files}")
|
9
|
-
end
|
10
|
-
|
11
|
-
#Gemspec
|
12
|
-
porject_name = 'rpx_now'
|
13
|
-
Echoe.new(porject_name , '0.3') do |p|
|
14
|
-
p.description = "Helper to simplify RPX Now user login/creation"
|
15
|
-
p.url = "http://github.com/grosser/#{porject_name}"
|
16
|
-
p.author = "Michael Grosser"
|
17
|
-
p.email = "grosser.michael@gmail.com"
|
18
|
-
p.dependencies = %w[activesupport]
|
19
|
-
end
|
20
|
-
|
21
|
-
task :update_gemspec => [:manifest, :build_gemspec]
|
data/init.rb
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
require 'rpx_now'
|
data/rpx_now.gemspec
DELETED
@@ -1,37 +0,0 @@
|
|
1
|
-
# -*- encoding: utf-8 -*-
|
2
|
-
|
3
|
-
Gem::Specification.new do |s|
|
4
|
-
s.name = %q{rpx_now}
|
5
|
-
s.version = "0.3"
|
6
|
-
|
7
|
-
s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
|
8
|
-
s.authors = ["Michael Grosser"]
|
9
|
-
s.date = %q{2009-01-28}
|
10
|
-
s.description = %q{Helper to simplify RPX Now user login/creation}
|
11
|
-
s.email = %q{grosser.michael@gmail.com}
|
12
|
-
s.extra_rdoc_files = ["CHANGELOG", "lib/rpx_now.rb", "README.markdown"]
|
13
|
-
s.files = ["Manifest", "CHANGELOG", "lib/rpx_now.rb", "spec/rpx_now_spec.rb", "spec/spec_helper.rb", "rpx_now.gemspec", "init.rb", "Rakefile", "README.markdown"]
|
14
|
-
s.has_rdoc = true
|
15
|
-
s.homepage = %q{http://github.com/grosser/rpx_now}
|
16
|
-
s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Rpx_now", "--main", "README.markdown"]
|
17
|
-
s.require_paths = ["lib"]
|
18
|
-
s.rubyforge_project = %q{rpx_now}
|
19
|
-
s.rubygems_version = %q{1.3.1}
|
20
|
-
s.summary = %q{Helper to simplify RPX Now user login/creation}
|
21
|
-
|
22
|
-
if s.respond_to? :specification_version then
|
23
|
-
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
24
|
-
s.specification_version = 2
|
25
|
-
|
26
|
-
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
27
|
-
s.add_runtime_dependency(%q<activesupport>, [">= 0"])
|
28
|
-
s.add_development_dependency(%q<echoe>, [">= 0"])
|
29
|
-
else
|
30
|
-
s.add_dependency(%q<activesupport>, [">= 0"])
|
31
|
-
s.add_dependency(%q<echoe>, [">= 0"])
|
32
|
-
end
|
33
|
-
else
|
34
|
-
s.add_dependency(%q<activesupport>, [">= 0"])
|
35
|
-
s.add_dependency(%q<echoe>, [">= 0"])
|
36
|
-
end
|
37
|
-
end
|