sageone_api_request_signer 1.0.1 → 1.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: 85eba0ca1d6de0e8d6bfc0e5e9eb91f064e82928
4
- data.tar.gz: 67e9e61dc7de0b8a9047f6550038cea2d75b620f
3
+ metadata.gz: 7ee694bdf80abcf67c8ed334cf38760cc3bf67ed
4
+ data.tar.gz: 1781b4db7c262a996660a22a5bcd29a52ade7f8f
5
5
  SHA512:
6
- metadata.gz: 012a0b7e170e9b7d3e49b68fa659a8a504f85cedcde3266674a3ea503393ee9b576f69b0e6c2e6b15f5c14151ef6dc32e3bb48b0ace89a9d17e2c486c38293b2
7
- data.tar.gz: e3e1dd196af24336c44487617352a2e8a9e724ecece682771428bd5561add30afa84d8763ab1032b516beafa509d226de587a64e7acffc556cfb8af6d5bf553a
6
+ metadata.gz: 56a0e39d35f0470e9c4e9cdc358a62cd072252e0d49f1570f4ed883b3a8603480bc5a810f616a32bbb24a5cccd4e91358e7d9d5b90cc38364d1629d5dbc2cea5
7
+ data.tar.gz: a3e49db37f115b116eca1a947ffb2c3ce6c6bc4975fb0edc53a0c11f07c101f50b8780b99ef5e05c805181cde932519691f3cb1c9195b150f45f8965cd4f0c26
@@ -1,4 +1,6 @@
1
1
  require "sageone_api_request_signer/version"
2
+ require "active_support"
3
+ require "active_support/core_ext"
2
4
  require "base64"
3
5
 
4
6
  # "Sign" an Sageone API request call following the steps detailed here:
@@ -41,8 +43,7 @@ class SageoneApiRequestSigner
41
43
 
42
44
  def parameter_string
43
45
  @parameter_string ||= (
44
- key_value_pair = percent_encode_pair(url_params.merge(body_params).sort)
45
- key_value_pair.map{|pair| pair.join('=') }.join('&')
46
+ url_params.merge(body_params).sort.to_h.to_query.gsub('+','%20')
46
47
  )
47
48
  end
48
49
 
@@ -80,10 +81,4 @@ class SageoneApiRequestSigner
80
81
  def percent_encode(str)
81
82
  URI.escape(str.to_s, /[^0-9A-Za-z\-._~]/)
82
83
  end
83
-
84
- def percent_encode_pair(pair)
85
- pair.map! do |k,v|
86
- [percent_encode(k), percent_encode(v)]
87
- end
88
- end
89
84
  end
@@ -1,3 +1,3 @@
1
1
  class SageoneApiRequestSigner
2
- VERSION = "1.0.1"
2
+ VERSION = "1.1.0"
3
3
  end
@@ -18,6 +18,8 @@ Gem::Specification.new do |spec|
18
18
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
19
  spec.require_paths = ["lib"]
20
20
 
21
+ spec.add_dependency "activesupport"
22
+
21
23
  spec.add_development_dependency "bundler", "~> 1.7"
22
24
  spec.add_development_dependency "rake", "~> 10.0"
23
25
  spec.add_development_dependency 'fudge'
@@ -0,0 +1,82 @@
1
+ require 'rest_client'
2
+ require 'json'
3
+
4
+ RSpec.describe 'testing complex body params' do
5
+ subject do
6
+ SageoneApiRequestSigner.new({
7
+ request_method: 'post',
8
+ url: 'https://api.sageone.com/test/accounts/v1/contacts',
9
+ signing_secret: 'TestSigningSecret',
10
+ access_token: 'TestToken',
11
+ })
12
+ end
13
+
14
+ let(:headers) do
15
+ subject.request_headers.merge({
16
+ 'Accept' => '*/*',
17
+ 'Content-Type' => 'application/x-www-form-urlencoded',
18
+ 'User-Agent' => 'NPSS'
19
+ })
20
+ end
21
+
22
+ it 'with multi-level hashes' do
23
+ subject.body_params = {
24
+ first: 'level',
25
+ second: {
26
+ multi: 'level',
27
+ third: {
28
+ level: 'the last one'
29
+ },
30
+ ok: 'this is enough'
31
+ }
32
+ }
33
+
34
+ check_signature!
35
+ end
36
+
37
+ it 'with arrays' do
38
+ subject.body_params = {
39
+ simple: 'param',
40
+ complex: [
41
+ {one:11, two:12, three:13},
42
+ {one:21, two:22, three:23},
43
+ ]
44
+ }
45
+ end
46
+
47
+ it 'hardcore one' do
48
+ subject.body_params = {
49
+ hardcore: [
50
+ {one:11, two:12, three:13},
51
+ {four:4, two:22, three:23},
52
+ {
53
+ fuck_all: {
54
+ i_am: 'really nested',
55
+ no: {
56
+ i_am: 'damm more'
57
+ }
58
+ }
59
+ }
60
+ ]
61
+ }
62
+ end
63
+
64
+ describe
65
+
66
+ def check_signature!
67
+ RestClient.post subject.url, subject.body_params, headers
68
+
69
+ rescue => e
70
+ raise e unless e.respond_to? :response
71
+
72
+ response = JSON.parse(e.response.to_s)
73
+
74
+ expect(subject.nonce).to eql(response['nonce'])
75
+ expect(subject.request_method).to eql(response['request_method'])
76
+ expect(subject.access_token).to eql(response['token'])
77
+ expect(subject.base_url).to eql(response['base_url'])
78
+ expect(subject.parameter_string).to eql(response['parameter_string'])
79
+ expect(subject.signature_base_string).to eql(response['signature_base_string'])
80
+ expect(subject.signing_secret).to eql(response['signing_secret'])
81
+ end
82
+ end
@@ -104,6 +104,12 @@ RSpec.describe SageoneApiRequestSigner do
104
104
 
105
105
  expect(subject.parameter_string).to eql 'aaa=1&bee=2&dee=3&zee=4'
106
106
  end
107
+
108
+ it 'cant have +, should have %20' do
109
+ subject.url = 'https://api.sageone.com/accounts/v1/contacts?in_the_url=i+cant+have+pluses'
110
+ subject.body_params = {'in_the_body_param' => 'cant have pluses here too'}
111
+ expect(subject.parameter_string).to eql 'in_the_body_param=cant%20have%20pluses%20here%20too&in_the_url=i%20cant%20have%20pluses'
112
+ end
107
113
  end
108
114
 
109
115
  describe '#signature_base_string' do
metadata CHANGED
@@ -1,15 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sageone_api_request_signer
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rudiney Altair Franceschi
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-12-19 00:00:00.000000000 Z
11
+ date: 2014-12-26 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: activesupport
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'
13
27
  - !ruby/object:Gem::Dependency
14
28
  name: bundler
15
29
  requirement: !ruby/object:Gem::Requirement
@@ -183,6 +197,7 @@ files:
183
197
  - lib/sageone_api_request_signer/version.rb
184
198
  - sageone_api_request_signer.gemspec
185
199
  - spec/integration/check_signature_data_spec.rb
200
+ - spec/integration/complex_body_params_spec.rb
186
201
  - spec/sageone_api_request_signer_spec.rb
187
202
  - spec/spec_helper.rb
188
203
  homepage: ''
@@ -205,12 +220,13 @@ required_rubygems_version: !ruby/object:Gem::Requirement
205
220
  version: '0'
206
221
  requirements: []
207
222
  rubyforge_project:
208
- rubygems_version: 2.2.2
223
+ rubygems_version: 2.3.0
209
224
  signing_key:
210
225
  specification_version: 4
211
226
  summary: Sign requests call to SageOne API.
212
227
  test_files:
213
228
  - spec/integration/check_signature_data_spec.rb
229
+ - spec/integration/complex_body_params_spec.rb
214
230
  - spec/sageone_api_request_signer_spec.rb
215
231
  - spec/spec_helper.rb
216
232
  has_rdoc: