esp_sdk 1.0.3 → 1.0.4

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: c52d23d423160230bb03f5d2b126c428f5d8b100
4
- data.tar.gz: acebf34428219913ae23155ba4f273307c3c66d9
3
+ metadata.gz: 5aa714df3a847288324a32ae65bba48ed237af47
4
+ data.tar.gz: 8e197b5f6243a21242ef6c2031a880e0443fe3d9
5
5
  SHA512:
6
- metadata.gz: 8c61bdcd07beca80268a66b01c12d7be7ab1aec31a7d3522f3e425804a6096936683e358930f4304dde5b68b95597ec16f608c527719a1b13fb5ac2b164e1682
7
- data.tar.gz: 641b7be183bae8eec78d9bf70c314563b213793d651f78ad7934e7aa5f41474d05c105fad4ecc8f68e4a667c37b16511d732d27b8e86bf6ff0fc792888365233
6
+ metadata.gz: c968f9a4ed69d7a4d66a50b9b22bf72925dac0140818f6b93a0f05168a509223e466057d3881f0fd7de1bd572c8743835a9fcd93d75aa9330a246af5d2e14aaf
7
+ data.tar.gz: db6a83e184df987dba7eef7938a55b2c6065b822e6bec79228b1979c8a6367e58e49e7f793c98087cd5149f67453a694d7f4de4d5483750e272f051b5141dadd
@@ -16,7 +16,7 @@ module EspSdk
16
16
  elsif EspSdk.release?
17
17
  @uri = 'https://api-rel.evident.io/api'
18
18
  else
19
- @uri = 'http://0.0.0.0:3001/api'
19
+ @uri = 'http://0.0.0.0:3000/api'
20
20
  end
21
21
  end
22
22
 
@@ -78,12 +78,24 @@ module EspSdk
78
78
  @current_record = ActiveSupport::HashWithIndifferentAccess.new(JSON.load(response.body))
79
79
  end
80
80
 
81
+ # Converts the link header into a hash of links
82
+ #
83
+ # "<http://test.host/api/v1/custom_signatures?page=2>; rel=\"last\", <http://test.host/api/v1/custom_signatures?page=2>; rel=\"next\""
84
+ # => { "last" => "http://test.host/api/v1/custom_signatures?page=2",
85
+ # "next" => "http://test.host/api/v1/custom_signatures?page=2" }
81
86
  def pagination_links(response)
82
87
  @page_links = ActiveSupport::HashWithIndifferentAccess.new(JSON.load(response.headers[:link]))
88
+ rescue JSON::ParserError
89
+ @page_links = ActiveSupport::HashWithIndifferentAccess.new.tap do |page_links|
90
+ response.headers[:link].to_s.split(',').each do |link|
91
+ /<(?<link>.*)>; rel="(?<key>\w*)"/ =~ link
92
+ page_links[key] = link
93
+ end
94
+ end
83
95
  end
84
96
 
85
- def current_page=(value)
86
- @current_page = ActiveSupport::HashWithIndifferentAccess.new(value)
97
+ def current_page=(values)
98
+ @current_page = values.map(&:with_indifferent_access)
87
99
  end
88
100
  end
89
101
  end
@@ -1,3 +1,3 @@
1
1
  module EspSdk
2
- VERSION = '1.0.3'
2
+ VERSION = '1.0.4'
3
3
  end
@@ -29,7 +29,7 @@ class ConfigureTest < ActiveSupport::TestCase
29
29
  should 'return the development URI when the environment is not release or production' do
30
30
  EspSdk.expects(:production?).returns(false)
31
31
  EspSdk.expects(:release?).returns(false)
32
- assert_equal 'http://0.0.0.0:3001/api', @config.uri
32
+ assert_equal 'http://0.0.0.0:3000/api', @config.uri
33
33
  end
34
34
  end
35
35
 
@@ -46,4 +46,4 @@ class ConfigureTest < ActiveSupport::TestCase
46
46
  end
47
47
  end
48
48
  end
49
- end
49
+ end
@@ -10,28 +10,39 @@ class BaseTest < ActiveSupport::TestCase
10
10
  end
11
11
 
12
12
  context '#next_page' do
13
- setup do
14
- # Setup fakeweb
15
- FakeWeb.register_uri(:get, /api\/v1\/base/,
16
- :body => { stub: 'Stub' }.to_json)
17
- end
18
-
19
13
  should 'call list if @current_page is blank' do
14
+ FakeWeb.register_uri(:get, %r{api/v1/base}, body: [{ stub: 'Stub' }].to_json)
20
15
  @base.expects(:list)
16
+
21
17
  @base.next_page
22
18
  end
23
19
 
24
20
  should "return the current page if @page_links['links']' are blank" do
21
+ FakeWeb.register_uri(:get, %r{api/v1/base}, body: [{ stub: 'Stub' }].to_json)
25
22
  @base.expects(:current_page)
23
+
26
24
  @base.next_page
27
25
  end
26
+
27
+ should 'request next page and set current_page' do
28
+ FakeWeb.register_uri(:get, 'http://0.0.0.0:3000/api/v1/base',
29
+ :body => [{ stub: 'page1' }].to_json,
30
+ :link => %(<http://0.0.0.0:3000/api/v1/base?page=5>; rel="last", <http://0.0.0.0:3000/api/v1/base?page=2>; rel="next"))
31
+ FakeWeb.register_uri(:get, 'http://0.0.0.0:3000/api/v1/base?page=2',
32
+ :body => [{ stub: 'page2' }].to_json)
33
+
34
+ @base = EspSdk::EndPoints::Base.new(@config)
35
+ @base.list
36
+ @base.next_page
37
+
38
+ assert_equal 'page2', @base.current_page.first[:stub]
39
+ end
28
40
  end
29
41
 
30
42
  context '#prev_page' do
31
43
  setup do
32
- # Setup fakeweb
33
- FakeWeb.register_uri(:get, /api\/v1\/base/,
34
- :body => { stub: 'Stub' }.to_json)
44
+ FakeWeb.register_uri(:get, %r{api/v1/base},
45
+ :body => [{ stub: 'Stub' }].to_json)
35
46
  end
36
47
 
37
48
  should 'call list if @current_page is blank' do
@@ -46,30 +57,26 @@ class BaseTest < ActiveSupport::TestCase
46
57
  end
47
58
 
48
59
  context '#list' do
49
- setup do
50
- # Setup fakeweb
51
- FakeWeb.register_uri(:get, /api\/v1\/base/,
52
- :body => { stub: 'Stub' }.to_json)
53
- end
54
-
55
60
  should 'set the current page and setup link pagination' do
61
+ FakeWeb.register_uri(:get, %r{api/v1/base},
62
+ :body => [{ stub: 'Stub' }].to_json)
56
63
  @base.expects(:pagination_links)
64
+
57
65
  response = @base.list
58
- assert response.key?('stub')
66
+
67
+ assert response.first.key?('stub')
59
68
  assert_equal response, @base.current_page
60
69
  end
61
70
  end
62
71
 
63
72
  context '#show' do
64
- setup do
65
- # Setup fakeweb
66
- FakeWeb.register_uri(:get, /api\/v1\/base\/1/,
67
- :body => { stub: 'Stub' }.to_json)
68
- end
69
-
70
73
  should 'call validate id and return the stub response, and set the current_record' do
74
+ FakeWeb.register_uri(:get, %r{api/v1/base/1},
75
+ :body => { stub: 'Stub' }.to_json)
71
76
  payload = { id: 1 }
77
+
72
78
  @base.expects(:validate_id).with(payload)
79
+
73
80
  response = @base.show(payload)
74
81
  assert response.key?('stub')
75
82
  assert_equal response, @base.current_record
@@ -77,15 +84,13 @@ class BaseTest < ActiveSupport::TestCase
77
84
  end
78
85
 
79
86
  context '#update' do
80
- setup do
81
- # Setup fakeweb
82
- FakeWeb.register_uri(:get, /api\/v1\/base\/1/,
83
- :body => { stub: 'Stub' }.to_json)
84
- end
85
-
86
87
  should 'call validate id and return the stub response, and set the current_record' do
88
+ FakeWeb.register_uri(:get, %r{api/v1/base/1},
89
+ :body => { stub: 'Stub' }.to_json)
87
90
  payload = { id: 1, name: 'Test' }
91
+
88
92
  @base.expects(:validate_id).with(payload)
93
+
89
94
  response = @base.show(payload)
90
95
  assert response.key?('stub')
91
96
  assert_equal response, @base.current_record
@@ -93,15 +98,13 @@ class BaseTest < ActiveSupport::TestCase
93
98
  end
94
99
 
95
100
  context '#destroy' do
96
- setup do
97
- # Setup fakeweb
101
+ should 'call validate id and return the stub response, and set the current_record' do
98
102
  FakeWeb.register_uri(:get, /api\/v1\/base\/1/,
99
103
  :body => { success: 'Stub has been destroyed' }.to_json)
100
- end
101
-
102
- should 'call validate id and return the stub response, and set the current_record' do
103
104
  payload = { id: 1 }
105
+
104
106
  @base.expects(:validate_id).with(payload)
107
+
105
108
  response = @base.show(payload)
106
109
  assert response.key?('success')
107
110
  assert_equal response, @base.current_record
@@ -127,7 +130,7 @@ class BaseTest < ActiveSupport::TestCase
127
130
  # Test through a different endpoint to get a valid URL
128
131
  EspSdk.instance_variable_set(:@env, :development)
129
132
  external_account = EspSdk::EndPoints::ExternalAccounts.new(@config)
130
- assert_equal 'http://0.0.0.0:3001/api/v1/external_accounts/1', external_account.send(:id_url, 1)
133
+ assert_equal 'http://0.0.0.0:3000/api/v1/external_accounts/1', external_account.send(:id_url, 1)
131
134
  end
132
135
 
133
136
  should 'return a valid id url for the release environment' do
@@ -152,7 +155,7 @@ class BaseTest < ActiveSupport::TestCase
152
155
  # Test through a different endpoint to get a valid URL
153
156
  EspSdk.instance_variable_set(:@env, :development)
154
157
  external_account = EspSdk::EndPoints::ExternalAccounts.new(@config)
155
- assert_equal 'http://0.0.0.0:3001/api/v1/external_accounts', external_account.send(:base_url)
158
+ assert_equal 'http://0.0.0.0:3000/api/v1/external_accounts', external_account.send(:base_url)
156
159
  end
157
160
 
158
161
  should 'return a valid base url for the release environment' do
@@ -173,39 +176,55 @@ class BaseTest < ActiveSupport::TestCase
173
176
  end
174
177
 
175
178
  context 'current_page' do
176
- setup do
177
- # Setup fakeweb
178
- FakeWeb.register_uri(:get, /api\/v1\/base/, body: { stub: 'Stub' }.to_json)
179
+ should 'convert hashes to ActiveSupport::HashWithIndifferentAccess' do
180
+ FakeWeb.register_uri(:get, %r{api/v1/base}, body: [{stub: 'Stub'}, {}].to_json)
181
+
179
182
  @base.list
180
- end
181
183
 
182
- should 'be ActiveSupport::HashWithIndifferentAccess' do
183
- assert @base.current_page.is_a?(ActiveSupport::HashWithIndifferentAccess)
184
+ assert @base.current_page.first.is_a?(ActiveSupport::HashWithIndifferentAccess)
185
+ assert @base.current_page.last.is_a?(ActiveSupport::HashWithIndifferentAccess)
184
186
  end
185
187
  end
186
188
 
187
189
  context 'current_record' do
188
- setup do
189
- # Setup fakeweb
190
- FakeWeb.register_uri(:get, /api\/v1\/base\/1/, body: { stub: 'Stub' }.to_json)
190
+ should 'be ActiveSupport::HashWithIndifferentAccess' do
191
+ FakeWeb.register_uri(:get, %r{api/v1/base/1}, body: [{ stub: 'Stub' }].to_json)
192
+
191
193
  @base.show(id: 1)
192
- end
193
194
 
194
- should 'be ActiveSupport::HashWithIndifferentAccess' do
195
195
  assert @base.current_record.is_a?(ActiveSupport::HashWithIndifferentAccess)
196
196
  end
197
197
  end
198
198
 
199
199
  context 'page_links' do
200
- setup do
201
- # Setup fakeweb
202
- FakeWeb.register_uri(:get, /api\/v1\/base/, body: { stub: 'Stub' }.to_json)
200
+ should 'be ActiveSupport::HashWithIndifferentAccess' do
201
+ FakeWeb.register_uri(:get, %r{api/v1/base}, body: [{ stub: 'Stub' }].to_json)
202
+
203
203
  @base.list
204
- end
205
204
 
206
- should 'be ActiveSupport::HashWithIndifferentAccess' do
207
205
  assert @base.instance_variable_get(:@page_links).is_a?(ActiveSupport::HashWithIndifferentAccess)
208
206
  end
207
+
208
+ should 'set @page_links to hash with URLs if in JSON format' do
209
+ FakeWeb.register_uri(:get, %r{api/v1/base}, body: [{ stub: 'Stub' }].to_json,
210
+ link: %({"next": "http://test.host/api/v1/custom_signatures?page=2", "last": "http://test.host/api/v1/custom_signatures?page=5"}))
211
+
212
+ @base.list
213
+
214
+ links = @base.instance_variable_get(:@page_links)
215
+ assert_equal 'http://test.host/api/v1/custom_signatures?page=5', links[:last]
216
+ assert_equal 'http://test.host/api/v1/custom_signatures?page=2', links[:next]
217
+ end
218
+
219
+ should 'set @page_links to hash with URLs if in HTTP format' do
220
+ FakeWeb.register_uri(:get, %r{api/v1/base}, body: [{ stub: 'Stub' }].to_json,
221
+ link: %(<http://test.host/api/v1/custom_signatures?page=5>; rel="last", <http://test.host/api/v1/custom_signatures?page=2>; rel="next"))
222
+ @base.list
223
+
224
+ links = @base.instance_variable_get(:@page_links)
225
+ assert_equal 'http://test.host/api/v1/custom_signatures?page=5', links[:last]
226
+ assert_equal 'http://test.host/api/v1/custom_signatures?page=2', links[:next]
227
+ end
209
228
  end
210
229
  end
211
230
  end
@@ -34,7 +34,7 @@ class CustomSignaturesTest < ActiveSupport::TestCase
34
34
  context '#run_url' do
35
35
  should 'have the correct run_url for development environment' do
36
36
  EspSdk.instance_variable_set(:@env, :development)
37
- assert_equal 'http://0.0.0.0:3001/api/v1/custom_signatures/run', @custom_signatures.send(:run_url)
37
+ assert_equal 'http://0.0.0.0:3000/api/v1/custom_signatures/run', @custom_signatures.send(:run_url)
38
38
  end
39
39
 
40
40
  should 'have the correct run_url for the release environment' do
@@ -22,7 +22,7 @@ class DashboardTest < ActiveSupport::TestCase
22
22
  context '#timewarp_url' do
23
23
  should 'have the correct run_url for development environment' do
24
24
  EspSdk.instance_variable_set(:@env, :development)
25
- assert_equal 'http://0.0.0.0:3001/api/v1/dashboard/timewarp', @dashboard.send(:timewarp_url)
25
+ assert_equal 'http://0.0.0.0:3000/api/v1/dashboard/timewarp', @dashboard.send(:timewarp_url)
26
26
  end
27
27
 
28
28
  should 'have the correct run_url for the release environment' do
@@ -30,7 +30,7 @@ class SignaturesTest < ActiveSupport::TestCase
30
30
  context '#run_url' do
31
31
  should 'have the correct run_url for development environment' do
32
32
  EspSdk.instance_variable_set(:@env, :development)
33
- assert_equal 'http://0.0.0.0:3001/api/v1/signatures/run', @signatures.send(:run_url)
33
+ assert_equal 'http://0.0.0.0:3000/api/v1/signatures/run', @signatures.send(:run_url)
34
34
  end
35
35
 
36
36
  should 'have the correct run_url for the release environment' do
@@ -47,7 +47,7 @@ class SignaturesTest < ActiveSupport::TestCase
47
47
  context '#name_url' do
48
48
  should 'have the correct run_url for development environment' do
49
49
  EspSdk.instance_variable_set(:@env, :development)
50
- assert_equal 'http://0.0.0.0:3001/api/v1/signatures/signature_names', @signatures.send(:name_url)
50
+ assert_equal 'http://0.0.0.0:3000/api/v1/signatures/signature_names', @signatures.send(:name_url)
51
51
  end
52
52
 
53
53
  should 'have the correct run_url for the release environment' do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: esp_sdk
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.3
4
+ version: 1.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Evident.io
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-12-17 00:00:00.000000000 Z
11
+ date: 2015-01-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -245,7 +245,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
245
245
  version: '0'
246
246
  requirements: []
247
247
  rubyforge_project:
248
- rubygems_version: 2.4.3
248
+ rubygems_version: 2.4.5
249
249
  signing_key:
250
250
  specification_version: 4
251
251
  summary: SDK for interacting with the ESP API.