cdnetworks-client 1.1.1 → 1.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 50e8eeb665f8b3e41ffd0b0bedde921461054f21
4
- data.tar.gz: 8f98b1be2e0c9c31ea851a7e6766c4640ea4c213
3
+ metadata.gz: 93586b13b1c72ba395781dd8c56667276e23bc43
4
+ data.tar.gz: a07c0c362ac81150bc0a96faae072048fbcf6e50
5
5
  SHA512:
6
- metadata.gz: cc818105a242ade3027b56d928ba3ae2bd6bd2468aa291792358ca1235bf6861e49ada1cf273fbfca66aae26fcc37cb86a5feb8fd33fe458162bcca76b21c515
7
- data.tar.gz: e06898e2bc26113e18f5a101bb8e237b787eaff77785bab245e47e68384f68a747daca1f759f8b1de99ab5e1d986caa8509668446341dc1f955ff10d75331a8b
6
+ metadata.gz: 160c5e5c6aefa8b47d5506def0cb209c9938a534dfaffbd126720b8a3c647059dd9ad4ceaa6ae6db2688b085d0f11242741f00784615882793c03ef98b3c09f1
7
+ data.tar.gz: d746d1004e561a2e4e9e96c9ccae1e863518d0bdb41518d5c666729dfc70f2e60cd465517968d25bed1e03c42cf45a81fc26b520a96ce178bf7a26170ec103ea
@@ -11,21 +11,30 @@ module OpenApiError
11
11
  "999" => "Temporary error"
12
12
  }
13
13
 
14
- class ApiError < StandardError
14
+ class BaseError < StandardError
15
+ attr_accessor :code, :body
15
16
 
17
+ def initialize(error, code = nil, body = nil)
18
+ @code = code
19
+ @body = body
20
+ super(error)
21
+ end
16
22
  end
17
23
 
18
- class CriticalApiError < StandardError
24
+ class ApiError < BaseError
25
+ end
19
26
 
27
+ class CriticalApiError < BaseError
20
28
  end
21
29
 
22
30
  class ErrorHandler
23
31
  def self.handle_error_response(code, body)
24
- if desc = ERROR_CODES[code.to_s]
25
- raise ApiError.new("Open API Error #{code}: #{desc}")
32
+ if ERROR_CODES[code.to_s]
33
+ message = "Open API Error #{code}: #{ERROR_CODES[code.to_s]}"
26
34
  else
27
- raise ApiError.new("Unknown Open API Response Code #{code} (body: #{body})")
35
+ message = "Unknown Open API Response Code #{code} (body: #{body})"
28
36
  end
37
+ raise ApiError.new(message, code, body)
29
38
  end
30
39
  end
31
40
  end
@@ -1,5 +1,5 @@
1
1
  module Cdnetworks
2
2
  module Client
3
- VERSION = "1.1.1"
3
+ VERSION = "1.1.2"
4
4
  end
5
5
  end
@@ -373,7 +373,9 @@ describe CdnetworksClient do
373
373
 
374
374
  before do
375
375
  @good_token, _ = stub_auth_calls
376
- stub_request(:post, "#{@url}/api/rest/getApiKeyList").with(body: {"output"=>"json", "sessionToken"=>bad_token}).to_return(body: expired_session_resp)
376
+ stub_request(:post, "#{@url}/api/rest/getApiKeyList")
377
+ .with(body: {"output"=>"json", "sessionToken"=>bad_token})
378
+ .to_return(body: expired_session_resp)
377
379
  end
378
380
 
379
381
  it "re-establishes session if it expires" do
@@ -384,17 +386,33 @@ describe CdnetworksClient do
384
386
  end
385
387
 
386
388
  it "doesn't infinite loop if session can't be re-established" do
387
- stub_request(:post, "#{@url}/api/rest/login").to_return(body: JSON.pretty_unparse(loginResponse: {resultCode: 101}))
389
+ stub_request(:post, "#{@url}/api/rest/login")
390
+ .to_return(body: JSON.pretty_unparse(loginResponse: {resultCode: 101}))
388
391
  expect { @cdn_api.get_api_key_list(bad_token) }.to raise_error(OpenApiError::ApiError)
389
392
  end
390
393
 
391
394
  it "gives up if session is not re-established after MAX_SESSION_RETRIES tries" do
392
- stub_request(:post, "#{@url}/api/rest/getApiKeyList").with(body: {"output"=>"json", "sessionToken"=>@good_token}).to_return(body: expired_session_resp)
395
+ stub_request(:post, "#{@url}/api/rest/getApiKeyList")
396
+ .with(body: {"output"=>"json", "sessionToken"=>@good_token})
397
+ .to_return(body: expired_session_resp)
393
398
 
394
399
  expect { @cdn_api.get_api_key_list(bad_token) }.to raise_error(OpenApiError::CriticalApiError)
395
400
 
396
401
  expect(a_request(:post, "#{@url}/api/rest/login")).to have_been_made.times(3)
397
402
  end
403
+
404
+ it "keeps code andy body around on the exception" do
405
+ response = JSON.pretty_unparse(loginResponse: { resultCode: 101 })
406
+ stub_request(:post, "#{@url}/api/rest/login")
407
+ .to_return(body: response)
408
+
409
+ begin
410
+ @cdn_api.get_api_key_list(bad_token)
411
+ rescue OpenApiError::ApiError => e
412
+ expect(e.code).to eq(101)
413
+ expect(e.body).to eq(response)
414
+ end
415
+ end
398
416
  end
399
417
 
400
418
  describe ConfigOpenApi do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cdnetworks-client
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.1
4
+ version: 1.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nell Shamrell
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-11-04 00:00:00.000000000 Z
11
+ date: 2015-11-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec