trust_pilot 0.0.1

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
+ metadata.gz: bd7720cfb96c16bebbd6813b3fc076867f7917be
4
+ data.tar.gz: d7a4872adaa7862f3deb6ed31cfec19f8a4caadb
5
+ SHA512:
6
+ metadata.gz: c76c5f750280ab8234d0e6878aa46e43fedb8b8731b35db76f361c4545dbbdd9286f7e796f20794d2dcdfce12bbc64f0477ea59bc17577390fc7c241c520189f
7
+ data.tar.gz: 79d9964a2e87e89b5cdecb170272ad402aa5d5091dd21e9b34045724c4335424021faeaa82d07995e96d9476be7bd5b101b43cf47b45512c38651d9e36b8cfbc
@@ -0,0 +1,14 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in trust_pilot.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2015 Zaratan
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,60 @@
1
+ # TrustPilot
2
+
3
+ A gem to access Trust Pilot API.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'trust_pilot'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install trust_pilot
20
+
21
+ ## Usage
22
+
23
+ You must set the credentials once:
24
+ ```ruby
25
+ TrustPilot.username = 'test@email.com'
26
+ TrustPilot.password = 'qwerty'
27
+ TrustPilot.key = 'ghfastnsdhvtyew'
28
+ TrustPilot.secret = 'qwertyui'
29
+ ```
30
+
31
+ ### New invitation
32
+
33
+ You must set default options once:
34
+ ```ruby
35
+ TrustPilot::NewInvitation.business_user_id = 'sdjkjkdfhguygasdy'
36
+ TrustPilot::NewInvitation.template_id = 'sddsnfsdoub'
37
+ TrustPilot::NewInvitation.locale = 'en-US'
38
+ TrustPilot::NewInvitation.sender_email = 'blu@yopmail.com'
39
+ TrustPilot::NewInvitation.sender_name = 'blu@yopmail.com'
40
+ TrustPilot::NewInvitation.redirect_uri = 'http://trustpilot.com'
41
+ TrustPilot::NewInvitation.reply_to = 'blu@yopmail.com'
42
+ ```
43
+
44
+ Then call TrustPilot this way:
45
+ ```ruby
46
+ TrustPilot::NewInvitation.call(
47
+ recipient_email: 'blu2@yopmail.com',
48
+ recipient_name: 'charles',
49
+ tags: ['owner'],
50
+ reference_id: 'dfhsgefhjgfeykefwgs',
51
+ preferred_send_time: '2015-01-07T11:00:00'
52
+ ```
53
+
54
+ ## Contributing
55
+
56
+ 1. Fork it ( https://github.com/Skizzk/trust_pilot/fork )
57
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
58
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
59
+ 4. Push to the branch (`git push origin my-new-feature`)
60
+ 5. Create a new Pull Request
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
@@ -0,0 +1,12 @@
1
+ require 'singleton'
2
+ require 'active_support/all'
3
+ require 'httparty'
4
+
5
+ require_relative "trust_pilot/version"
6
+ require_relative "trust_pilot/api/token"
7
+ require_relative "trust_pilot/api/new_invitation"
8
+
9
+ module TrustPilot
10
+ class MissingDefault < StandardError; end
11
+ mattr_accessor :username, :password, :key, :secret
12
+ end
@@ -0,0 +1,56 @@
1
+ require 'singleton'
2
+ require 'recursive-open-struct'
3
+
4
+ module TrustPilot
5
+ class NewInvitation
6
+
7
+ include HTTParty
8
+
9
+ mattr_accessor :business_user_id,
10
+ :template_id,
11
+ :locale,
12
+ :sender_email,
13
+ :sender_name,
14
+ :reply_to,
15
+ :redirect_uri
16
+
17
+ base_uri "https://invitations-api.trustpilot.com/v1/private/business-units/"
18
+
19
+ def self.call(recipient_email: "", recipient_name: "", tags: [], reference_id: "", preferred_send_time: "")
20
+ check_default
21
+ parse_response do_call(recipient_email, recipient_name, tags, reference_id, preferred_send_time)
22
+ end
23
+
24
+ private
25
+
26
+ def self.parse_response(response)
27
+ RecursiveOpenStruct.new(response)
28
+ end
29
+
30
+ def self.do_call(recipient_email, recipient_name, tags, reference_id, preferred_send_time)
31
+ endpoint = "/#{business_user_id}/invitations"
32
+ query = {token: Token.get}
33
+ body = {
34
+ "businessUserId" => business_user_id,
35
+ "recipientEmail" => recipient_email,
36
+ "recipientName" => recipient_name,
37
+ "referenceId" => reference_id,
38
+ "templateId" => template_id,
39
+ "locale" => locale,
40
+ "senderEmail" => sender_email,
41
+ "senderName" => sender_name,
42
+ "replyTo" => reply_to,
43
+ "preferredSendTime" => preferred_send_time,
44
+ "tags" => tags,
45
+ "redirectUri" => redirect_uri
46
+ }
47
+ post endpoint, body: body, query: query
48
+ end
49
+
50
+ def self.check_default
51
+ unless business_user_id && template_id && locale && sender_name && sender_email && reply_to && redirect_uri
52
+ raise MissingDefault
53
+ end
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,61 @@
1
+ require 'singleton'
2
+ require 'base64'
3
+
4
+
5
+ module TrustPilot
6
+ class Token
7
+ include Singleton
8
+ include HTTParty
9
+
10
+ class NoTokenException < StandardError; end
11
+
12
+ base_uri "https://api.trustpilot.com/v1/oauth/oauth-business-users-for-applications"
13
+ attr_reader :validity
14
+
15
+ def initialize
16
+ @validity = 1.second.ago
17
+ end
18
+
19
+ def self.get
20
+ Token.instance.get
21
+ end
22
+
23
+ def get
24
+ new_token unless validity >= Time.now
25
+ @token || raise(NoTokenException)
26
+ end
27
+
28
+ private
29
+
30
+ def check_default
31
+ unless TrustPilot.username && TrustPilot.password && TrustPilot.key && TrustPilot.secret
32
+ raise MissingDefault
33
+ end
34
+ end
35
+
36
+ def new_token
37
+ check_default
38
+ response = do_call
39
+ @token = response.parsed_response["access_token"]
40
+ @validity = 5.minutes.from_now
41
+ end
42
+
43
+ def do_call
44
+ endpoint = '/accesstoken'
45
+ params = {
46
+ grant_type: 'password',
47
+ username: TrustPilot.username,
48
+ password: TrustPilot.password
49
+ }
50
+ headers = {
51
+ 'Authorization' => "Basic #{encoded_key}",
52
+ 'Content-Type' => 'application/x-www-form-urlencoded'
53
+ }
54
+ self.class.post(endpoint, {headers: headers, body: params})
55
+ end
56
+
57
+ def encoded_key
58
+ Base64.urlsafe_encode64("#{TrustPilot.key}:#{TrustPilot.secret}")
59
+ end
60
+ end
61
+ end
@@ -0,0 +1,3 @@
1
+ module TrustPilot
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,28 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'trust_pilot/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "trust_pilot"
8
+ spec.version = TrustPilot::VERSION
9
+ spec.authors = ["Zaratan"]
10
+ spec.email = ["denis.pasin@koolicar.com"]
11
+ spec.summary = %q{Gem to access Trust Pilot API.}
12
+ spec.description = %q{Gem to access Trust Pilot API.}
13
+ spec.homepage = "https://github.com/Skizzk/trust_pilot"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_dependency 'httparty'
22
+ spec.add_dependency 'activesupport'
23
+ spec.add_dependency 'recursive-open-struct'
24
+
25
+ spec.add_development_dependency "bundler", "~> 1.7"
26
+ spec.add_development_dependency "rake", "~> 10.0"
27
+ spec.add_development_dependency "pry"
28
+ end
metadata ADDED
@@ -0,0 +1,138 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: trust_pilot
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Zaratan
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-01-07 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: httparty
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: activesupport
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: recursive-open-struct
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: bundler
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '1.7'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '1.7'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rake
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '10.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '10.0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: pry
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ description: Gem to access Trust Pilot API.
98
+ email:
99
+ - denis.pasin@koolicar.com
100
+ executables: []
101
+ extensions: []
102
+ extra_rdoc_files: []
103
+ files:
104
+ - ".gitignore"
105
+ - Gemfile
106
+ - LICENSE.txt
107
+ - README.md
108
+ - Rakefile
109
+ - lib/trust_pilot.rb
110
+ - lib/trust_pilot/api/new_invitation.rb
111
+ - lib/trust_pilot/api/token.rb
112
+ - lib/trust_pilot/version.rb
113
+ - trust_pilot.gemspec
114
+ homepage: https://github.com/Skizzk/trust_pilot
115
+ licenses:
116
+ - MIT
117
+ metadata: {}
118
+ post_install_message:
119
+ rdoc_options: []
120
+ require_paths:
121
+ - lib
122
+ required_ruby_version: !ruby/object:Gem::Requirement
123
+ requirements:
124
+ - - ">="
125
+ - !ruby/object:Gem::Version
126
+ version: '0'
127
+ required_rubygems_version: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ requirements: []
133
+ rubyforge_project:
134
+ rubygems_version: 2.4.3
135
+ signing_key:
136
+ specification_version: 4
137
+ summary: Gem to access Trust Pilot API.
138
+ test_files: []