prooflink_connect 0.0.23 → 0.0.24
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/Gemfile +2 -1
- data/README.md +1 -1
- data/lib/prooflink_connect.rb +4 -0
- data/lib/prooflink_connect/activity.rb +47 -21
- data/lib/prooflink_connect/configuration.rb +1 -1
- data/lib/prooflink_connect/version.rb +1 -1
- data/spec/prooflink_connect/activity_spec.rb +27 -8
- data/spec/prooflink_connect_spec.rb +5 -0
- metadata +26 -81
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
data.tar.gz: 4a4386f433dff015a680394626c9240863408d2f
|
4
|
+
metadata.gz: 83982e69932ae141627d9fec1ea9a2bbfd28a11b
|
5
|
+
SHA512:
|
6
|
+
data.tar.gz: c5644c633b8db81086283682629a85c33afd9a2b2502ee4ff17da6d2c3be03acd743523154be77ceffd9a8846421714d5f8b8c2df266efdf58e979e84459d7b6
|
7
|
+
metadata.gz: 45d9a5c894cf91566b7b3d5732c3a7acdd42968b16d579f3b37c67b5d7aef587477756a9c488bd64f4af2a1499042242218a82ed0bdaccffd64d5ce6ef679692
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# Prooflink Connect [![Build Status](
|
1
|
+
# Prooflink Connect [![Build Status](https://travis-ci.org/prooflink/prooflink_connect.png)](http://travis-ci.org/prooflink/prooflink_connect)
|
2
2
|
|
3
3
|
=================
|
4
4
|
|
data/lib/prooflink_connect.rb
CHANGED
@@ -52,4 +52,8 @@ module ProoflinkConnect
|
|
52
52
|
html = "<iframe src='#{frame_url}' style='width: #{options[:width]}; height: #{options[:height]}; border: 0; display: block;' frameborder='0' allowTransparency='true'></iframe>"
|
53
53
|
html.respond_to?(:html_safe) ? html.html_safe : html
|
54
54
|
end
|
55
|
+
|
56
|
+
def self.track_activity(identifier, user, options = {})
|
57
|
+
Activity.track(identifier, user, options)
|
58
|
+
end
|
55
59
|
end
|
@@ -2,34 +2,60 @@ require 'oauth2'
|
|
2
2
|
|
3
3
|
module ProoflinkConnect
|
4
4
|
class Activity
|
5
|
+
def self.track(identifier, user, options = {})
|
6
|
+
return if !perform_request?
|
5
7
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
8
|
+
activity = build_request(identifier, user, options)
|
9
|
+
response = access_token.post('api/v2/activities', :body => {:activity => activity})
|
10
|
+
MultiJson.decode(response.body)
|
11
|
+
rescue OAuth2::Error => error
|
12
|
+
MultiJson.decode(error.response.body)
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.log(params)
|
16
|
+
warn "Activity.log() is deprecated. Please use Activity.track() instead."
|
12
17
|
|
13
|
-
|
18
|
+
response = access_token.post('api/v2/activities', :body => {:activity => params})
|
19
|
+
MultiJson.decode(response.body)
|
20
|
+
rescue OAuth2::Error => error
|
21
|
+
MultiJson.decode(error.response.body)
|
22
|
+
end
|
14
23
|
|
15
|
-
|
16
|
-
# activity_type: {identifier: 'some_identifier', name: 'some_name', value: '1'},
|
17
|
-
# user: {first_name: 'jon', last_name: 'doe', email: 'jon@doe.com', identity_provider: 'prooflink'},
|
18
|
-
# extra_info: {your_id: '1234'}
|
19
|
-
# })
|
24
|
+
private
|
20
25
|
|
21
|
-
def self.
|
22
|
-
|
23
|
-
|
24
|
-
|
26
|
+
def self.build_request(identifier, user, options)
|
27
|
+
activity = {:activity_type => {:identifier => identifier}}
|
28
|
+
activity[:activity_type][:name] = options[:activity_name] if options[:activity_name]
|
29
|
+
activity[:activity_type][:value] = options[:activity_value] if options[:activity_value]
|
30
|
+
activity[:extra_info] = options[:extra_info] if options[:extra_info]
|
31
|
+
activity[:user] = {:identity_provider => 'prooflink'}
|
32
|
+
|
33
|
+
# In case of a new user that has no identifier yet
|
34
|
+
if user.is_a?(Hash)
|
35
|
+
activity[:user].merge!(user)
|
36
|
+
else
|
37
|
+
activity[:user][:identifier] = user
|
38
|
+
end
|
39
|
+
|
40
|
+
activity
|
41
|
+
end
|
25
42
|
|
26
|
-
|
27
|
-
|
28
|
-
|
43
|
+
def self.access_token
|
44
|
+
@access_token ||= begin
|
45
|
+
oauth_access_token = ProoflinkConnect.config.oauth_access_token
|
46
|
+
client = OAuth2::Client.new(nil, nil, {:site => ProoflinkConnect.config.base_uri})
|
47
|
+
access_token = OAuth2::AccessToken.new(client, oauth_access_token, :header_format => "OAuth %s")
|
48
|
+
end
|
49
|
+
end
|
29
50
|
|
30
|
-
|
31
|
-
|
51
|
+
def self.perform_request?
|
52
|
+
if !ProoflinkConnect.config.enable_activity_tracking.nil?
|
53
|
+
return ProoflinkConnect.config.enable_activity_tracking
|
32
54
|
end
|
55
|
+
return false if defined?(Rails) && !Rails.env.production?
|
56
|
+
return false if ENV['RACK_ENV'] && ENV['RACK_ENV'] != "production"
|
57
|
+
true
|
33
58
|
end
|
34
59
|
end
|
35
60
|
end
|
61
|
+
|
@@ -14,7 +14,7 @@ module ProoflinkConnect
|
|
14
14
|
@@defaults.each_pair{|k,v| self.send("#{k}=",v)}
|
15
15
|
end
|
16
16
|
|
17
|
-
attr_accessor :provider_endpoint, :subdomain, :api_key, :protocol, :locale, :oauth_access_token
|
17
|
+
attr_accessor :provider_endpoint, :subdomain, :api_key, :protocol, :locale, :oauth_access_token, :enable_activity_tracking
|
18
18
|
|
19
19
|
def validate!
|
20
20
|
raise InvalidConfigurationError if [:provider_endpoint, :subdomain, :api_key, :protocol].any?{|option|send(option).blank?}
|
@@ -5,25 +5,44 @@ describe ProoflinkConnect::Activity do
|
|
5
5
|
reset_configuration
|
6
6
|
end
|
7
7
|
|
8
|
-
|
8
|
+
it "should log activity as expected" do
|
9
9
|
stub_request(:post, "https://example.prooflink.com/api/v2/activities").
|
10
10
|
with(:body => {"activity"=>{"activity_type"=>{"name"=>"My name", "value"=>"1", "identifier"=>"my_identifier"}, "user"=>{"identity_provider"=>"prooflink", "email"=>"jon@doe.com"}}}, :headers => {'Accept'=>'*/*', 'Authorization'=>'OAuth 4321', 'Content-Type'=>'application/x-www-form-urlencoded'}).
|
11
11
|
to_return(:status => 200, :body => MultiJson.encode({"status"=>"SUCCESS", "message"=>"activity succesfully created"}), :headers => {})
|
12
|
+
params = {:activity_type => {:identifier => "my_identifier", :name => "My name", :value => 1},
|
13
|
+
:user => {:email => "jon@doe.com", :identity_provider => 'prooflink'}}
|
12
14
|
|
15
|
+
ProoflinkConnect::Activity.log(params).should eq({"status"=>"SUCCESS", "message"=>"activity succesfully created"})
|
16
|
+
end
|
17
|
+
|
18
|
+
it "rescues OAuth2::Error exceptions" do
|
13
19
|
stub_request(:post, "https://example.prooflink.com/api/v2/activities").
|
14
20
|
with(:body => "", :headers => {'Accept'=>'*/*', 'Authorization'=>'OAuth 4321', 'Content-Type'=>'application/x-www-form-urlencoded'}).
|
15
21
|
to_return(:status => 406, :body => MultiJson.encode({"status"=>"ERROR", "message"=>"no activity specified"}), :headers => {})
|
22
|
+
ProoflinkConnect::Activity.log({}).should eq({"status"=>"ERROR", "message"=>"no activity specified"})
|
16
23
|
end
|
17
24
|
|
18
|
-
it "
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
25
|
+
it "new user" do
|
26
|
+
stub_request(:post, "https://example.prooflink.com/api/v2/activities").
|
27
|
+
with(:body => {"activity" => {"activity_type" => {"identifier" => "follow", "name" => "Following", "value" => "1"}, "user" => {"identity_provider" => "prooflink", "email" => "jon@doe.com"}}}).
|
28
|
+
to_return(:status => 200, :body => MultiJson.encode({"status" => "SUCCESS", "message" => "activity succesfully created"}), :headers => {})
|
29
|
+
user = {:email => "jon@doe.com", :identity_provider => 'prooflink'}
|
30
|
+
options = {:activity_name => "Following", :activity_value => 1}
|
31
|
+
ProoflinkConnect::Activity.track("follow", user, options)
|
32
|
+
end
|
23
33
|
|
34
|
+
it "existing user" do
|
35
|
+
stub_request(:post, "https://example.prooflink.com/api/v2/activities").
|
36
|
+
with(:body => {"activity" => {"activity_type" => {"identifier" => "follow", "name" => "Following", "value" => "1"}, "user" => {"identifier" => "12345", "identity_provider" => "prooflink"}}}).
|
37
|
+
to_return(:status => 200, :body => MultiJson.encode({"status" => "SUCCESS", "message" => "activity succesfully created"}), :headers => {})
|
38
|
+
options = {:activity_name => "Following", :activity_value => 1}
|
39
|
+
ProoflinkConnect::Activity.track("follow", "12345", options)
|
24
40
|
end
|
25
41
|
|
26
|
-
it "
|
27
|
-
ProoflinkConnect
|
42
|
+
it "allows disabling of activity tracking" do
|
43
|
+
ProoflinkConnect.config.enable_activity_tracking = false
|
44
|
+
ProoflinkConnect::Activity.should_not_receive(:build_request)
|
45
|
+
ProoflinkConnect::Activity.track("follow", "12345")
|
28
46
|
end
|
29
47
|
end
|
48
|
+
|
@@ -96,4 +96,9 @@ describe ProoflinkConnect do
|
|
96
96
|
ProoflinkConnect.embedded(:scenario => "split_screen").should == result
|
97
97
|
end
|
98
98
|
end
|
99
|
+
|
100
|
+
it "tracks activities" do
|
101
|
+
ProoflinkConnect::Activity.should_receive(:track).with("follow", "12345", {})
|
102
|
+
ProoflinkConnect.track_activity("follow", "12345")
|
103
|
+
end
|
99
104
|
end
|
metadata
CHANGED
@@ -1,13 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: prooflink_connect
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
prerelease:
|
6
|
-
segments:
|
7
|
-
- 0
|
8
|
-
- 0
|
9
|
-
- 23
|
10
|
-
version: 0.0.23
|
4
|
+
version: 0.0.24
|
11
5
|
platform: ruby
|
12
6
|
authors:
|
13
7
|
- Chiel Wester
|
@@ -18,108 +12,69 @@ autorequire:
|
|
18
12
|
bindir: bin
|
19
13
|
cert_chain: []
|
20
14
|
|
21
|
-
date:
|
15
|
+
date: 2013-04-22 00:00:00 Z
|
22
16
|
dependencies:
|
23
17
|
- !ruby/object:Gem::Dependency
|
24
18
|
name: multi_json
|
25
19
|
prerelease: false
|
26
20
|
requirement: &id001 !ruby/object:Gem::Requirement
|
27
|
-
none: false
|
28
21
|
requirements:
|
29
|
-
-
|
22
|
+
- &id002
|
23
|
+
- ">="
|
30
24
|
- !ruby/object:Gem::Version
|
31
|
-
hash: 3
|
32
|
-
segments:
|
33
|
-
- 0
|
34
25
|
version: "0"
|
35
26
|
type: :runtime
|
36
27
|
version_requirements: *id001
|
37
28
|
- !ruby/object:Gem::Dependency
|
38
29
|
name: httparty
|
39
30
|
prerelease: false
|
40
|
-
requirement: &
|
41
|
-
none: false
|
31
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
42
32
|
requirements:
|
43
|
-
-
|
44
|
-
- !ruby/object:Gem::Version
|
45
|
-
hash: 3
|
46
|
-
segments:
|
47
|
-
- 0
|
48
|
-
version: "0"
|
33
|
+
- *id002
|
49
34
|
type: :runtime
|
50
|
-
version_requirements: *
|
35
|
+
version_requirements: *id003
|
51
36
|
- !ruby/object:Gem::Dependency
|
52
37
|
name: activesupport
|
53
38
|
prerelease: false
|
54
|
-
requirement: &
|
55
|
-
none: false
|
39
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
56
40
|
requirements:
|
57
|
-
-
|
58
|
-
- !ruby/object:Gem::Version
|
59
|
-
hash: 3
|
60
|
-
segments:
|
61
|
-
- 0
|
62
|
-
version: "0"
|
41
|
+
- *id002
|
63
42
|
type: :runtime
|
64
|
-
version_requirements: *
|
43
|
+
version_requirements: *id004
|
65
44
|
- !ruby/object:Gem::Dependency
|
66
45
|
name: bundler
|
67
46
|
prerelease: false
|
68
|
-
requirement: &
|
69
|
-
none: false
|
47
|
+
requirement: &id005 !ruby/object:Gem::Requirement
|
70
48
|
requirements:
|
71
49
|
- - ">="
|
72
50
|
- !ruby/object:Gem::Version
|
73
|
-
hash: 23
|
74
|
-
segments:
|
75
|
-
- 1
|
76
|
-
- 0
|
77
|
-
- 0
|
78
51
|
version: 1.0.0
|
79
52
|
type: :development
|
80
|
-
version_requirements: *
|
53
|
+
version_requirements: *id005
|
81
54
|
- !ruby/object:Gem::Dependency
|
82
55
|
name: rspec
|
83
56
|
prerelease: false
|
84
|
-
requirement: &
|
85
|
-
none: false
|
57
|
+
requirement: &id006 !ruby/object:Gem::Requirement
|
86
58
|
requirements:
|
87
|
-
-
|
88
|
-
- !ruby/object:Gem::Version
|
89
|
-
hash: 3
|
90
|
-
segments:
|
91
|
-
- 0
|
92
|
-
version: "0"
|
59
|
+
- *id002
|
93
60
|
type: :development
|
94
|
-
version_requirements: *
|
61
|
+
version_requirements: *id006
|
95
62
|
- !ruby/object:Gem::Dependency
|
96
63
|
name: webmock
|
97
64
|
prerelease: false
|
98
|
-
requirement: &
|
99
|
-
none: false
|
65
|
+
requirement: &id007 !ruby/object:Gem::Requirement
|
100
66
|
requirements:
|
101
|
-
-
|
102
|
-
- !ruby/object:Gem::Version
|
103
|
-
hash: 3
|
104
|
-
segments:
|
105
|
-
- 0
|
106
|
-
version: "0"
|
67
|
+
- *id002
|
107
68
|
type: :development
|
108
|
-
version_requirements: *
|
69
|
+
version_requirements: *id007
|
109
70
|
- !ruby/object:Gem::Dependency
|
110
71
|
name: oauth2
|
111
72
|
prerelease: false
|
112
|
-
requirement: &
|
113
|
-
none: false
|
73
|
+
requirement: &id008 !ruby/object:Gem::Requirement
|
114
74
|
requirements:
|
115
|
-
-
|
116
|
-
- !ruby/object:Gem::Version
|
117
|
-
hash: 3
|
118
|
-
segments:
|
119
|
-
- 0
|
120
|
-
version: "0"
|
75
|
+
- *id002
|
121
76
|
type: :runtime
|
122
|
-
version_requirements: *
|
77
|
+
version_requirements: *id008
|
123
78
|
description: Make a connection to the prooflink connect api for single sign on authentication
|
124
79
|
email:
|
125
80
|
- chiel.wester@holder.nl
|
@@ -160,37 +115,27 @@ files:
|
|
160
115
|
homepage: https://github.com/prooflink/prooflink_connect
|
161
116
|
licenses: []
|
162
117
|
|
118
|
+
metadata: {}
|
119
|
+
|
163
120
|
post_install_message:
|
164
121
|
rdoc_options: []
|
165
122
|
|
166
123
|
require_paths:
|
167
124
|
- lib
|
168
125
|
required_ruby_version: !ruby/object:Gem::Requirement
|
169
|
-
none: false
|
170
126
|
requirements:
|
171
|
-
-
|
172
|
-
- !ruby/object:Gem::Version
|
173
|
-
hash: 3
|
174
|
-
segments:
|
175
|
-
- 0
|
176
|
-
version: "0"
|
127
|
+
- *id002
|
177
128
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
178
|
-
none: false
|
179
129
|
requirements:
|
180
130
|
- - ">="
|
181
131
|
- !ruby/object:Gem::Version
|
182
|
-
hash: 23
|
183
|
-
segments:
|
184
|
-
- 1
|
185
|
-
- 3
|
186
|
-
- 6
|
187
132
|
version: 1.3.6
|
188
133
|
requirements: []
|
189
134
|
|
190
135
|
rubyforge_project: prooflink_connect
|
191
|
-
rubygems_version:
|
136
|
+
rubygems_version: 2.0.0
|
192
137
|
signing_key:
|
193
|
-
specification_version:
|
138
|
+
specification_version: 4
|
194
139
|
summary: Make a connection to the prooflink connect api
|
195
140
|
test_files: []
|
196
141
|
|