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.
@@ -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
@@ -1,4 +1,5 @@
1
- source :gemcutter
1
+ source 'https://rubygems.org'
2
2
 
3
3
  # Specify your gem's dependencies in prooflink_connect.gemspec
4
4
  gemspec
5
+
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # Prooflink Connect [![Build Status](http://travis-ci.org/prooflink/prooflink_connect.png)](http://travis-ci.org/prooflink/prooflink_connect)
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
 
@@ -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
- # POST /api/v2/activities
7
- # parameters:
8
- # - activity (required) => {:activity_type => {:identifier => "some_identifier", :name => "Some name", :value => "1"}}
9
- # - user => {:email => "foo@bar.com", :first_name => "Foo", :last_name => "Bar"} [for new user]
10
- # - user_token => "123-456-789" [for existing user]
11
- # - extra_info (optional) => {} [extra custom info you like to pass to activity]
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
- # SAMPLE:
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
- # ProoflinkConnect::Activity.log({
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.log(params)
22
- oauth_access_token = ProoflinkConnect.config.oauth_access_token
23
- client = OAuth2::Client.new(nil, nil, {:site => ProoflinkConnect.config.base_uri})
24
- access_token = OAuth2::AccessToken.new(client, oauth_access_token, :header_format => "OAuth %s")
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
- begin
27
- response = access_token.post 'api/v2/activities', :body => {:activity => params}
28
- return MultiJson.decode(response.body)
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
- rescue OAuth2::Error => error
31
- return MultiJson.decode(error.response.body)
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?}
@@ -1,3 +1,3 @@
1
1
  module ProoflinkConnect
2
- VERSION = "0.0.23"
2
+ VERSION = "0.0.24"
3
3
  end
@@ -5,25 +5,44 @@ describe ProoflinkConnect::Activity do
5
5
  reset_configuration
6
6
  end
7
7
 
8
- before do
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 "should log activity as expected" do
19
- params = {:activity_type => {:identifier => "my_identifier", :name => "My name", :value => 1},
20
- :user => {:email => "jon@doe.com", :identity_provider => 'prooflink'}}
21
-
22
- ProoflinkConnect::Activity.log(params).should eq({"status"=>"SUCCESS", "message"=>"activity succesfully created"})
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 "should not log activity when no params are passed" do
27
- ProoflinkConnect::Activity.log({}).should eq({"status"=>"ERROR", "message"=>"no activity specified"})
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
- hash: 49
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: 2012-09-25 00:00:00 Z
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: &id002 !ruby/object:Gem::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: *id002
35
+ version_requirements: *id003
51
36
  - !ruby/object:Gem::Dependency
52
37
  name: activesupport
53
38
  prerelease: false
54
- requirement: &id003 !ruby/object:Gem::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: *id003
43
+ version_requirements: *id004
65
44
  - !ruby/object:Gem::Dependency
66
45
  name: bundler
67
46
  prerelease: false
68
- requirement: &id004 !ruby/object:Gem::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: *id004
53
+ version_requirements: *id005
81
54
  - !ruby/object:Gem::Dependency
82
55
  name: rspec
83
56
  prerelease: false
84
- requirement: &id005 !ruby/object:Gem::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: *id005
61
+ version_requirements: *id006
95
62
  - !ruby/object:Gem::Dependency
96
63
  name: webmock
97
64
  prerelease: false
98
- requirement: &id006 !ruby/object:Gem::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: *id006
69
+ version_requirements: *id007
109
70
  - !ruby/object:Gem::Dependency
110
71
  name: oauth2
111
72
  prerelease: false
112
- requirement: &id007 !ruby/object:Gem::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: *id007
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: 1.8.12
136
+ rubygems_version: 2.0.0
192
137
  signing_key:
193
- specification_version: 3
138
+ specification_version: 4
194
139
  summary: Make a connection to the prooflink connect api
195
140
  test_files: []
196
141