trustpilot-business-links 1.0.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: c6019f007c1fb249a3f9ffbad4a40fa679b6909e93f25f3328f7143e45579024
4
+ data.tar.gz: f35de676468187a17d2fceb5943474d28c97933cde44a82f860e0c87345c232d
5
+ SHA512:
6
+ metadata.gz: 902d8aa44e88cba2cf1c79beadfbf5a922c88da4e3bd8e2f8d525b0d8402219e5e26d08213654f2366ff53ae4f45df2f9b59cb5537dd7097038c0857b432e50f
7
+ data.tar.gz: 2d8abaf2a7b0bd976096ad8c6f1e139593ed88e9176c278fdbbe3d7512cb7aced6543d6227c8bde8630f04002e693bd1bcac52fb669e641aa9d4239ad5445730
@@ -0,0 +1 @@
1
+ .git/
@@ -0,0 +1,3 @@
1
+ coverage/
2
+ *.gem
3
+ Gemfile.lock
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --order=random
@@ -0,0 +1 @@
1
+ 2.5.1
@@ -0,0 +1,12 @@
1
+ language: ruby
2
+
3
+ rvm:
4
+ - 2.3.3
5
+ - 2.4.0
6
+
7
+ before_install:
8
+ - gem update --system # https://github.com/bundler/bundler/issues/5357
9
+ - make install
10
+
11
+ script:
12
+ - make test
@@ -0,0 +1,8 @@
1
+ # Next version
2
+ - Your contribution!
3
+
4
+ # Version 1.0.3
5
+ - Bump minimal ruby version to 2.3.0
6
+
7
+ # Version 1.0.2
8
+ - Initial release
@@ -0,0 +1,31 @@
1
+ FROM ruby:2.4
2
+
3
+ # System dependencies: Add here any librairies needed for certain gems
4
+ RUN apt-get update \
5
+ && apt-get install -y libpq-dev \
6
+ && apt-get clean \
7
+ && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
8
+
9
+ # Application working directory
10
+ WORKDIR /home/trustpilot-business-links
11
+
12
+ # WARNING The following line is important to keep bundle config
13
+ # inside the app directory
14
+ ENV BUNDLE_APP_CONFIG /home/trustpilot-business-links/.bundle/
15
+ # Copy dependency file
16
+ COPY ./trustpilot-business-links-client.gemspec /home/trustpilot-business-links/trustpilot-business-links-client.gemspec
17
+ COPY ./lib/trustpilot-business-links/version.rb /home/trustpilot-business-links/lib/trustpilot-business-links/version.rb
18
+ COPY ./Gemfile /home/trustpilot-business-links/Gemfile
19
+
20
+ # Ensure UTF8 strings can be used
21
+ ENV LANG C.UTF-8
22
+
23
+ # Bundle
24
+ RUN bundle install
25
+
26
+ # Copy code
27
+ COPY ./ /home/trustpilot-business-links
28
+
29
+ # What to launch on container startup
30
+ ENTRYPOINT ["make"]
31
+ CMD ["run"]
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2017 Trainline.com Ltd
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,24 @@
1
+ # Update the specified dependencies
2
+ install:
3
+ @command -v ruby >/dev/null 2>&1 || { echo >&2 "I require ruby but it's not installed. Aborting."; exit 1; }
4
+ @command -v bundle >/dev/null 2>&1 || gem install bundler;
5
+ bundle check || bundle install
6
+
7
+ # Run all the tests
8
+ test: bundler
9
+ bundle exec rake spec
10
+
11
+ # Build a new package file
12
+ build:
13
+ bundle exec gem build trustpilot-business-links.gemspec
14
+
15
+ # Publish a package on https://rubygems.org/gems/trustpilot-business-links
16
+ publish:
17
+ bundle exec gem push $(PACKAGE_FILE)
18
+
19
+ # Private - ensure gems are up-to-date
20
+ bundler:
21
+ bundle check>/dev/null || bundle install
22
+
23
+
24
+ .PHONY: install test build publish bundler
@@ -0,0 +1,43 @@
1
+ [![Build Status](https://travis-ci.org/trainline-eu/trustpilot-business-links.svg?branch=master)](https://travis-ci.org/trainline-eu/trustpilot-business-links)
2
+
3
+ Generate the [Trustpilot Business Generated Links](https://support.trustpilot.com/hc/en-us/articles/115002337108-Trustpilot-s-Business-Generated-Links-) in ruby.
4
+
5
+ # Requirements
6
+ - Ruby 2.3.0 or newer
7
+
8
+ # Installation
9
+ `gem install trustpilot-business-links`
10
+
11
+ # Usage
12
+ ~~~ruby
13
+ require 'json'
14
+ require 'trustpilot-business-links'
15
+
16
+ # Keys generated on https://businessapp.b2b.trustpilot.com/#/invitations/business-generated-links
17
+ encryption_key = 'gn96sJwFRQuQl3bjNIPM0xp+TnK4iBaW0I4DpR0o+cs='
18
+ authentication_key = 'eE4zdEfGNlxjGVjtWpOLAYAM0gKeF5j6Db7ZXd1Bixo='
19
+ trustpilot_bgl = TrustpilotBusinessLinks.new(encryption_key, authentication_key)
20
+
21
+ review_payload = {
22
+ email: "customer1@example.net",
23
+ name: "John Smith",
24
+ ref: "1234",
25
+ }
26
+
27
+ encrypted_payload = trustpilot_bgl.encrypt(review_payload.to_json)
28
+
29
+ puts "https://www.trustpilot.com/evaluate-bgl/www.example.com?p=#{encrypted_payload}"
30
+ ~~~
31
+
32
+ # Test
33
+ ~~~bash
34
+ make test
35
+ ~~~
36
+
37
+ 100% of the source code should be covered.
38
+
39
+ # Contributing
40
+ You are warmly welcome to contribute to the project!
41
+
42
+ # Documentation
43
+ * https://support.trustpilot.com/hc/en-us/articles/115004145087--Business-Generated-Links-for-developers-
@@ -0,0 +1,11 @@
1
+ # Test tasks
2
+ begin
3
+ require "ci/reporter/rake/rspec"
4
+ require "rspec/core/rake_task"
5
+ RSpec::Core::RakeTask.new(:spec)
6
+ task :rspec => "ci:setup:rspec"
7
+
8
+ # Default
9
+ task :default => :spec
10
+ rescue LoadError
11
+ end
@@ -0,0 +1,42 @@
1
+ require 'openssl'
2
+ require 'base64'
3
+ require 'cgi'
4
+
5
+ class TrustpilotBusinessLinks
6
+ ENCRYPTION_CIPHER = 'AES-256-CBC'
7
+ HMAC_DIGEST = 'SHA256'
8
+
9
+ def initialize(encryption_key, authentication_key)
10
+ @encryption_key = Base64.strict_decode64(encryption_key)
11
+ @authentication_key = Base64.strict_decode64(authentication_key)
12
+ end
13
+
14
+ def encrypt(payload)
15
+ encrypted_payload, iv = encrypt_iv(payload)
16
+ hmac = hmac(iv, encrypted_payload)
17
+
18
+ encode(iv + encrypted_payload + hmac)
19
+ end
20
+
21
+ private
22
+
23
+ attr_accessor :encryption_key, :authentication_key
24
+
25
+ def encrypt_iv(data)
26
+ cipher = OpenSSL::Cipher.new(ENCRYPTION_CIPHER)
27
+ cipher.encrypt
28
+ cipher.key = encryption_key
29
+ iv = cipher.random_iv
30
+ encrypted_payload = cipher.update(data) + cipher.final
31
+
32
+ [encrypted_payload, iv]
33
+ end
34
+
35
+ def hmac(iv, encrypted_payload)
36
+ OpenSSL::HMAC.digest(HMAC_DIGEST, authentication_key, iv + encrypted_payload)
37
+ end
38
+
39
+ def encode(payload)
40
+ CGI.escape(Base64.strict_encode64(payload))
41
+ end
42
+ end
@@ -0,0 +1,15 @@
1
+ require "simplecov"
2
+ require "simplecov-rcov"
3
+ SimpleCov.formatters = [
4
+ SimpleCov::Formatter::HTMLFormatter,
5
+ SimpleCov::Formatter::RcovFormatter
6
+ ]
7
+ SimpleCov.start
8
+ require "rspec"
9
+ require "rspec/its"
10
+ require "rack/test"
11
+
12
+ require 'pry'
13
+
14
+ # Load libs
15
+ require "trustpilot-business-links"
@@ -0,0 +1,29 @@
1
+ require "helper"
2
+ require "json"
3
+
4
+ class TrustpilotBusinessLinks
5
+ describe TrustpilotBusinessLinks do
6
+ let(:encryption_key) { 'gn96sJwFRQuQl3bjNIPM0xp+TnK4iBaW0I4DpR0o+cs=' }
7
+ let(:authentication_key) { 'eE4zdEfGNlxjGVjtWpOLAYAM0gKeF5j6Db7ZXd1Bixo=' }
8
+ let(:iv) { Base64.strict_decode64("vjtBtRC6poWv2GrWd2sXDg==") }
9
+ let(:trustpilot_generator) { TrustpilotBusinessLinks.new(encryption_key, authentication_key) }
10
+
11
+ before do
12
+ # Fake the IV generation to get a stable encrypted output
13
+ allow_any_instance_of(OpenSSL::Cipher).to receive(:random_iv).and_return(iv)
14
+ end
15
+
16
+ describe "#encrypt" do
17
+ it "encrypts and URL encodes correctly the payload" do
18
+ payload = {
19
+ email: "test@example.com",
20
+ name: "John Smith",
21
+ ref: "1234",
22
+ }
23
+ encrypted_payload = trustpilot_generator.encrypt(payload.to_json)
24
+
25
+ expect(encrypted_payload).to eq('vjtBtRC6poWv2GrWd2sXDkqw%2FxhXg2kKX7yKDyPPHWyRcdG4gC3YUUFhJ6glpaWcboDO%2FE93H5OCcP20W12rhqcSpQjTcvhcACpiw4awvi0vInbj9PIh8QR00ch%2BsdErA3E1Wy9fEtc5BL8iYWFvgA%3D%3D')
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,32 @@
1
+ $: << File.expand_path("../lib", __FILE__)
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = 'trustpilot-business-links'
5
+ s.licenses = ['MIT']
6
+ s.version = '1.0.3'
7
+ s.platform = Gem::Platform::RUBY
8
+ s.authors = ['Théophile Helleboid']
9
+ s.email = ['theophile.helleboid@trainline.com']
10
+ s.homepage = 'https://github.com/trainline-eu/trustpilot-business-links'
11
+ s.summary = %q(Generate Trustpilot Business Generated Links)
12
+ s.description = %q(This gem generates Trustpilot Business Generated Links described on https://support.trustpilot.com/hc/en-us/articles/115002337108-Trustpilot-s-Business-Generated-Links-)
13
+ s.metadata = { "source_code_uri" => "https://github.com/trainline-eu/trustpilot-business-links" }
14
+
15
+ s.files = `git ls-files`.split("\n")
16
+ s.test_files = `git ls-files -- spec/*`.split("\n")
17
+ s.require_paths = ['lib']
18
+
19
+ s.required_ruby_version = '>= 2.3.0'
20
+
21
+ s.add_dependency 'openssl', '~> 2.1'
22
+
23
+ s.add_development_dependency 'pry', '~> 0.11'
24
+ s.add_development_dependency 'ci_reporter', '~> 2.0'
25
+ s.add_development_dependency 'ci_reporter_rspec', '~> 1.0'
26
+ s.add_development_dependency 'rack-test', '~> 0.7'
27
+ s.add_development_dependency 'rake', '~> 12.2'
28
+ s.add_development_dependency 'rspec', '~> 3.6'
29
+ s.add_development_dependency 'rspec-its', '~> 1.2'
30
+ s.add_development_dependency 'simplecov', '~> 0.15'
31
+ s.add_development_dependency 'simplecov-rcov', '~> 0.2'
32
+ end
metadata ADDED
@@ -0,0 +1,203 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: trustpilot-business-links
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.3
5
+ platform: ruby
6
+ authors:
7
+ - Théophile Helleboid
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2018-07-04 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: openssl
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '2.1'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '2.1'
27
+ - !ruby/object:Gem::Dependency
28
+ name: pry
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '0.11'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '0.11'
41
+ - !ruby/object:Gem::Dependency
42
+ name: ci_reporter
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '2.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '2.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: ci_reporter_rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '1.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '1.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rack-test
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '0.7'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '0.7'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rake
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '12.2'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '12.2'
97
+ - !ruby/object:Gem::Dependency
98
+ name: rspec
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '3.6'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '3.6'
111
+ - !ruby/object:Gem::Dependency
112
+ name: rspec-its
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: '1.2'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: '1.2'
125
+ - !ruby/object:Gem::Dependency
126
+ name: simplecov
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - "~>"
130
+ - !ruby/object:Gem::Version
131
+ version: '0.15'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - "~>"
137
+ - !ruby/object:Gem::Version
138
+ version: '0.15'
139
+ - !ruby/object:Gem::Dependency
140
+ name: simplecov-rcov
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - "~>"
144
+ - !ruby/object:Gem::Version
145
+ version: '0.2'
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - "~>"
151
+ - !ruby/object:Gem::Version
152
+ version: '0.2'
153
+ description: This gem generates Trustpilot Business Generated Links described on https://support.trustpilot.com/hc/en-us/articles/115002337108-Trustpilot-s-Business-Generated-Links-
154
+ email:
155
+ - theophile.helleboid@trainline.com
156
+ executables: []
157
+ extensions: []
158
+ extra_rdoc_files: []
159
+ files:
160
+ - ".dockerignore"
161
+ - ".gitignore"
162
+ - ".rspec"
163
+ - ".ruby-version"
164
+ - ".travis.yml"
165
+ - CHANGELOG.md
166
+ - Dockerfile
167
+ - Gemfile
168
+ - LICENSE.md
169
+ - Makefile
170
+ - README.md
171
+ - Rakefile
172
+ - lib/trustpilot-business-links.rb
173
+ - spec/helper.rb
174
+ - spec/trustpilot_business_links_spec.rb
175
+ - trustpilot-business-links.gemspec
176
+ homepage: https://github.com/trainline-eu/trustpilot-business-links
177
+ licenses:
178
+ - MIT
179
+ metadata:
180
+ source_code_uri: https://github.com/trainline-eu/trustpilot-business-links
181
+ post_install_message:
182
+ rdoc_options: []
183
+ require_paths:
184
+ - lib
185
+ required_ruby_version: !ruby/object:Gem::Requirement
186
+ requirements:
187
+ - - ">="
188
+ - !ruby/object:Gem::Version
189
+ version: 2.3.0
190
+ required_rubygems_version: !ruby/object:Gem::Requirement
191
+ requirements:
192
+ - - ">="
193
+ - !ruby/object:Gem::Version
194
+ version: '0'
195
+ requirements: []
196
+ rubyforge_project:
197
+ rubygems_version: 2.7.6
198
+ signing_key:
199
+ specification_version: 4
200
+ summary: Generate Trustpilot Business Generated Links
201
+ test_files:
202
+ - spec/helper.rb
203
+ - spec/trustpilot_business_links_spec.rb