doyoubuzz-showcase 0.0.2 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2ca622ca780c6a6ae46844f5dc79b9829853d762
4
- data.tar.gz: ed83ff11c9e0a86112031b411d917e5332465287
3
+ metadata.gz: 2aceb417792c107337b13ac22cfe4226fcddd93b
4
+ data.tar.gz: 6bbf214f97889a7439ed418b6e30d9761d54d426
5
5
  SHA512:
6
- metadata.gz: 690bc10606bfcca681a22504807f92c49f5a42b19a8ec9cf6baa66c06b11db0106d379e70802939d3d07eba8f7396d277c2caf52f2a8f724d6279e9b074daae0
7
- data.tar.gz: 7df9e9526cc9b5cabb51b50bf031ee8696fecf095e854de3ff233ff288ad9cfb48e685a643d04465c5ef5ef2753db122611a92a0d153146bd99bacfa4cc57cd5
6
+ metadata.gz: 464aee41aa33f7a9fcef0cae09e9864fcafcbbcd32efc6928ddebac83596474836b6d503920273a46611b34649b3b2f0d3c123f881ad08f5bd561b0cc7acb277
7
+ data.tar.gz: b2e5ef907ef149ac4dad612837edbd09be5196bad01aef7ef3b4db88eef96a17c7bb386926ab97a93d5b9c27b496a257db0dd2ad9aa9e3705cb46464982af1cd
File without changes
@@ -0,0 +1,8 @@
1
+ language: ruby
2
+
3
+ rvm:
4
+ - 2.1.0
5
+ - 2.0.0
6
+ - 1.9.3
7
+
8
+ script: bundle exec rspec spec
@@ -0,0 +1,9 @@
1
+ ## 0.3
2
+
3
+ ### Breaking Updates
4
+ * require HTTParty >= 0.13
5
+ * require hashie >= 3.3.2
6
+
7
+ ### CHANGELOG
8
+ * [DEV] Update rspec to v3
9
+ * Add Travis and Coveralls integration
data/Gemfile CHANGED
@@ -1,9 +1,12 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
3
  # Developpement dependencies
4
- gem 'rspec', '~> 2.13'
5
- gem 'webmock', '~> 1.11'
6
- gem 'vcr', '~> 2.5'
4
+ gem 'rspec', '~> 3.1'
5
+ gem 'webmock', '~> 1.20'
6
+ gem 'vcr', '~> 2.9'
7
+
8
+ # CI
9
+ gem 'coveralls', :require => false
7
10
 
8
11
  # Specify the gem's dependencies in doyoubuzz-showcase.gemspec
9
12
  gemspec
data/README.md CHANGED
@@ -1,3 +1,6 @@
1
+
2
+ [![Gem Version](https://badge.fury.io/rb/doyoubuzz-showcase.svg)](http://badge.fury.io/rb/doyoubuzz-showcase) [![Build Status](https://api.travis-ci.org/mru2/doyoubuzz-showcase.svg)](https://travis-ci.org/mru2/doyoubuzz-showcase) [![Coverage Status](https://coveralls.io/repos/mru2/doyoubuzz-showcase/badge.png?branch=master)](https://coveralls.io/r/mru2/doyoubuzz-showcase?branch=master) [![Code Climate](https://codeclimate.com/github/mru2/doyoubuzz-showcase/badges/gpa.svg)](https://codeclimate.com/github/mru2/doyoubuzz-showcase)
3
+
1
4
  # Doyoubuzz::Showcase
2
5
 
3
6
  ## Description
@@ -21,6 +21,6 @@ Gem::Specification.new do |spec|
21
21
  spec.add_development_dependency "bundler", "~> 1.3"
22
22
  spec.add_development_dependency "rake"
23
23
 
24
- spec.add_dependency "httparty", "~> 0.11"
25
- spec.add_dependency "hashie", "~> 2.0"
24
+ spec.add_dependency "httparty", "~> 0.13"
25
+ spec.add_dependency "hashie", ">= 2.1.2"
26
26
  end
@@ -1,6 +1,8 @@
1
1
  require 'httparty'
2
2
  require 'hashie/mash'
3
3
 
4
+ require 'doyoubuzz/showcase/error'
5
+
4
6
  module Doyoubuzz
5
7
  class Showcase
6
8
 
@@ -20,6 +22,19 @@ module Doyoubuzz
20
22
  end
21
23
  end
22
24
 
25
+ # SSO redirection
26
+ def sso_redirect_url(application_name, timestamp, sso_key, user_attributes)
27
+ # Check mandatory attributes are given
28
+ missing_attributes = [:email, :external_id, :firstname, :lastname].reject{|key| user_attributes[key]}
29
+
30
+ if missing_attributes.length > 0
31
+ raise ArgumentError, "Missing mandatory attributes for SSO : #{missing_attributes.join(', ')}"
32
+ end
33
+
34
+ params = sign_sso_params(user_attributes.merge(timestamp: timestamp), sso_key)
35
+
36
+ "http://showcase.doyoubuzz.com/p/fr/#{application_name}/sso?#{URI.encode_www_form(params)}"
37
+ end
23
38
 
24
39
 
25
40
  private
@@ -33,7 +48,7 @@ module Doyoubuzz
33
48
  # Process the HTTParty response, checking for errors
34
49
  def process_response(res)
35
50
  if !res.success?
36
- raise HTTParty::ResponseError.new(res.response)
51
+ raise Error.new(res.code, res.body)
37
52
  end
38
53
 
39
54
  if res.is_a? Hash
@@ -51,35 +66,36 @@ module Doyoubuzz
51
66
 
52
67
  # GET, DELETE requests : the parameters are in the request query
53
68
  if [:get, :delete].include? verb
54
- return {:query => sign_params(params.merge additional_parameters)}
69
+ return {:query => sign_api_params(params.merge additional_parameters)}
55
70
 
56
71
  # Otherwise, they are in the body
57
72
  else
58
- return {:body => params, :query => sign_params(additional_parameters)}
73
+ return {:body => params, :query => sign_api_params(additional_parameters)}
59
74
  end
60
75
  end
61
76
 
62
77
 
63
78
  # The arguments processing and signing
64
- def sign_params(params)
65
- params[:hash] = compute_signature(params)
66
- params
67
- end
68
-
69
- # Computing the parameters signature hash
70
- # Algorithm :
71
- # - Order parameters by key
72
- # - Concatenate their values
73
- # - Append the current timestamp
74
- # - Append the api secret
75
- # - MD5 the resulting string
76
- def compute_signature(params)
79
+ def sign_api_params(params)
77
80
  ordered_params_values = params.sort.map{|k,v|v}
78
81
  concatenated_params_string = ordered_params_values.join
79
- concatenated_params_string << @api_secret
82
+ concatenated_params_string << secret_key
83
+
84
+ hash = Digest::MD5.hexdigest(concatenated_params_string)
85
+ params.merge(hash: hash)
86
+ end
80
87
 
81
- return Digest::MD5.hexdigest(concatenated_params_string)
88
+ # Different ordering
89
+ def sign_sso_params(params, sso_key)
90
+ # Custom ordering
91
+ tosign = params.values_at(:email, :firstname, :lastname, :external_id, :"group[]", :user_type, :timestamp).compact.join
92
+ tosign += sso_key
93
+
94
+ hash = Digest::MD5.hexdigest(tosign)
95
+
96
+ params.merge(hash: hash)
82
97
  end
83
98
 
99
+
84
100
  end
85
101
  end
@@ -0,0 +1,25 @@
1
+ module Doyoubuzz
2
+ class Showcase
3
+ class Error < ::StandardError
4
+ attr_reader :status
5
+
6
+ def initialize(status, response_body)
7
+ # Try to extract a meaningful message from the error
8
+ message = begin
9
+ parsed_body = JSON.parse(response_body)
10
+ parsed_body['error']['message']
11
+ rescue => e
12
+ response_body
13
+ end
14
+
15
+ super(message)
16
+ @status = status
17
+ end
18
+
19
+ def inspect
20
+ "#<Doyoubuzz::Showcase::Error #{status}: #{message}>"
21
+ end
22
+
23
+ end
24
+ end
25
+ end
@@ -1,3 +1,3 @@
1
1
  module Doyoubuzz
2
- VERSION = "0.0.2"
2
+ VERSION = "0.1.0"
3
3
  end
@@ -6,6 +6,7 @@ describe Doyoubuzz::Showcase do
6
6
 
7
7
  let(:api_key){ 'an_api_key' }
8
8
  let(:api_secret){ 'an_api_secret' }
9
+ let(:showcase){ Doyoubuzz::Showcase.new(api_key, api_secret) }
9
10
 
10
11
  describe '#new' do
11
12
  it 'should require an api key and secret key' do
@@ -16,29 +17,28 @@ describe Doyoubuzz::Showcase do
16
17
  end
17
18
 
18
19
  describe '#call' do
19
- let(:showcase){ Doyoubuzz::Showcase.new(api_key, api_secret) }
20
20
  let(:arguments){ {:foo => 'bar', :zab => 'baz'} }
21
21
  let(:timestamp){ 1370534334 }
22
22
 
23
23
  # The timestamp is important in the request generation and the VCR handling. Here it is set at a fixed date
24
24
  before(:each) do
25
25
  time = Time.at(timestamp)
26
- Time.stub!(:now).and_return time
26
+ allow(Time).to receive(:now).and_return time
27
27
  end
28
28
 
29
29
  it "should compute a valid signature" do
30
- Doyoubuzz::Showcase.new('IuQSDLKQLSDK344590Li987', 'IuJyt42BnUiOlPM8FvB67tG').send(:compute_signature, {:apikey => 'IuQSDLKQLSDK344590Li987', :timestamp => timestamp}).should == '1dd33466d71275d06c9e17e18235c9f0'
30
+ Doyoubuzz::Showcase.new('IuQSDLKQLSDK344590Li987', 'IuJyt42BnUiOlPM8FvB67tG').send(:compute_signature, {:apikey => 'IuQSDLKQLSDK344590Li987', :timestamp => timestamp}, 'IuJyt42BnUiOlPM8FvB67tG').should == '1dd33466d71275d06c9e17e18235c9f0'
31
31
  end
32
32
 
33
33
  it "should generate a valid signed api call" do
34
- showcase.stub!(:process_response) # We only want to check the sent parameters here
34
+ allow(showcase).to receive(:process_response) # We only want to check the sent parameters here
35
35
  showcase.class.should_receive(:get).with("/path", {:query => {:foo => "bar", :zab => "baz", :apikey => "an_api_key", :timestamp => timestamp, :hash => "757b04a866f1d02f077471589341ff7a"}})
36
36
 
37
37
  showcase.get('/path', arguments)
38
38
  end
39
39
 
40
40
  it "should put the parameters in the body for PUT requests" do
41
- showcase.stub!(:process_response) # We only want to check the sent parameters here
41
+ allow(showcase).to receive(:process_response) # We only want to check the sent parameters here
42
42
  showcase.class.should_receive(:put).with("/path", {:query => {:apikey => "an_api_key", :timestamp => timestamp, :hash => "11a68a1bb9e23c681438efb714c9ad4d"}, :body => {:foo => "bar", :zab => "baz"}})
43
43
 
44
44
  showcase.put('/path', arguments)
@@ -75,12 +75,46 @@ describe Doyoubuzz::Showcase do
75
75
  it "should raise an exception on a failed call" do
76
76
  VCR.use_cassette("failed_call") do
77
77
  expect{ res = showcase.get('/users') }.to raise_error do |error|
78
- error.should be_a(HTTParty::ResponseError)
79
- error.response.should == Net::HTTPForbidden
78
+ error.should be_a(Doyoubuzz::Showcase::Error)
79
+ error.status.should == 403
80
+ error.message.should == "Forbidden"
81
+ error.inspect.should == "#<Doyoubuzz::Showcase::Error 403: Forbidden>"
80
82
  end
81
83
  end
82
84
  end
83
85
 
84
86
  end
85
87
 
88
+
89
+ describe '#sso_redirect_url' do
90
+
91
+ let(:company_name){ 'my_company' }
92
+ let(:timestamp){ 1370534334 }
93
+ let(:user_attributes){
94
+ {
95
+ email: 'email@host.tld',
96
+ firstname: 'John',
97
+ lastname: 'Doe',
98
+ external_id: 12345
99
+ }
100
+ }
101
+ let(:sso_key){ 'vpsdihgfdso' }
102
+
103
+ it "should verify all the mandatory user attributes are given" do
104
+
105
+ user_attributes.keys.each do |mandatory_key|
106
+
107
+ incomplete_attributes = user_attributes.dup.tap{|attrs|attrs.delete mandatory_key}
108
+ expect { showcase.sso_redirect_url(company_name, timestamp, sso_key, incomplete_attributes) }.to raise_error ArgumentError, "Missing mandatory attributes for SSO : #{mandatory_key}"
109
+
110
+ end
111
+
112
+ end
113
+
114
+ it "should compute the right url" do
115
+ showcase.sso_redirect_url(company_name, timestamp, sso_key, user_attributes).should == 'http://showcase.doyoubuzz.com/p/fr/my_company/sso?email=email%40host.tld&firstname=John&lastname=Doe&external_id=12345&timestamp=1370534334&hash=d6bbfc7ead803a3578887d6429d60047'
116
+ end
117
+
118
+ end
119
+
86
120
  end
@@ -3,6 +3,9 @@ require 'bundler/setup'
3
3
 
4
4
  require 'vcr'
5
5
 
6
+ require 'coveralls'
7
+ Coveralls.wear!
8
+
6
9
  VCR.configure do |conf|
7
10
  conf.cassette_library_dir = 'spec/fixtures/vcr_cassettes'
8
11
  conf.hook_into :webmock
metadata CHANGED
@@ -1,71 +1,71 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: doyoubuzz-showcase
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - David RUYER
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-06-14 00:00:00.000000000 Z
11
+ date: 2015-01-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ~>
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
19
  version: '1.3'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ~>
24
+ - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: '1.3'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - '>='
31
+ - - ">="
32
32
  - !ruby/object:Gem::Version
33
33
  version: '0'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - '>='
38
+ - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: httparty
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - ~>
45
+ - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: '0.11'
47
+ version: '0.13'
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - ~>
52
+ - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: '0.11'
54
+ version: '0.13'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: hashie
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - ~>
59
+ - - ">="
60
60
  - !ruby/object:Gem::Version
61
- version: '2.0'
61
+ version: 2.1.2
62
62
  type: :runtime
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - ~>
66
+ - - ">="
67
67
  - !ruby/object:Gem::Version
68
- version: '2.0'
68
+ version: 2.1.2
69
69
  description: Wrapper around the DoYouBuzz showcase API
70
70
  email:
71
71
  - david.ruyer@gmail.com
@@ -73,14 +73,18 @@ executables: []
73
73
  extensions: []
74
74
  extra_rdoc_files: []
75
75
  files:
76
- - .gitignore
77
- - .rspec
76
+ - ".coveralls.yml"
77
+ - ".gitignore"
78
+ - ".rspec"
79
+ - ".travis.yml"
80
+ - CHANGELOG.md
78
81
  - Gemfile
79
82
  - LICENSE.txt
80
83
  - README.md
81
84
  - Rakefile
82
85
  - doyoubuzz-showcase.gemspec
83
86
  - lib/doyoubuzz/showcase.rb
87
+ - lib/doyoubuzz/showcase/error.rb
84
88
  - lib/doyoubuzz/showcase/version.rb
85
89
  - spec/fixtures/vcr_cassettes/failed_call.yml
86
90
  - spec/fixtures/vcr_cassettes/good_call.yml
@@ -96,17 +100,17 @@ require_paths:
96
100
  - lib
97
101
  required_ruby_version: !ruby/object:Gem::Requirement
98
102
  requirements:
99
- - - '>='
103
+ - - ">="
100
104
  - !ruby/object:Gem::Version
101
105
  version: '0'
102
106
  required_rubygems_version: !ruby/object:Gem::Requirement
103
107
  requirements:
104
- - - '>='
108
+ - - ">="
105
109
  - !ruby/object:Gem::Version
106
110
  version: '0'
107
111
  requirements: []
108
112
  rubyforge_project:
109
- rubygems_version: 2.0.3
113
+ rubygems_version: 2.2.2
110
114
  signing_key:
111
115
  specification_version: 4
112
116
  summary: Wrapper around the DoYouBuzz showcase API
@@ -115,3 +119,4 @@ test_files:
115
119
  - spec/fixtures/vcr_cassettes/good_call.yml
116
120
  - spec/showcase_spec.rb
117
121
  - spec/spec_helper.rb
122
+ has_rdoc: