spark_api 1.3.27 → 1.3.28

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- NDVkM2ZjNzEwMTE4ZDQ5ODE0MjY5NjUxZjNiMjEzNDViMjdhMmM3Mg==
4
+ MDM4YWU2MmViMjdlY2JmYTMyM2I3M2I0MWRmNTMwYTM5N2Q1M2NhOQ==
5
5
  data.tar.gz: !binary |-
6
- ZTA0NGE5NWRmNmI1Mzc4Y2Y3NDRhMzBjMjQ2MzgzZWFhNDNhNWFmMg==
6
+ MzZkZTM3YmJiOGZjZWU1ZDJjN2FlNGE2OTdjZTI4M2M4YTA5MWNhNw==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- YTVlMmNiZjVlNDcyYzBmMDBlY2RjNzY2MzMyY2Q3YTRhZWU2OTE3MmFkMzcz
10
- MDk3YzZjNmE5MzBiNWRiOGFjY2QxYWJlZWJiZmJmMzg5NmVkZDkzOTI3OTQ1
11
- OTZmYWI5NTFiYjNhZjliNzhmYTJiMjBmMDhhMzE3NDhjMzllMWI=
9
+ MzA5NDdmMjExNWQyMzhiMzM2ZTkxMTYxN2VjMzljYTZmZWE1YzdiNDk4NzVl
10
+ ZGU3NmQ1MDY2NjU3OGZjYjhjY2ZmMWI5YjljN2Y0NGZlNjE4NTViYTE0ZTM5
11
+ NWQwZTM2NmYyY2EyYmM0OWI1YjA4MDBlZmVmZDQzOTEyOGE0MGU=
12
12
  data.tar.gz: !binary |-
13
- NzM2ZmY1NTZhNzgxYjZhMTlmM2Y0Nzg1Y2Q2M2ZmZDVmZDBjM2M2YjMyNGJi
14
- Nzg4Mjc0MWZlNDI3ODczMDY0NTdhYWRhZjlhM2JjMjg4NjJiMDM1MzJlYjI4
15
- MDc0MGQxZmZhYmIwNzM4MjVhYTM4YzBhNzljMzA4NDQxZmQ1ZDA=
13
+ NDdhMjU4MGRlNjdlZTZjODJhNDYxYTFiNGE1ZmE1ODg2OTMyNWU4ZDBlNWZm
14
+ NGQ2ZGQ3MGQ4OGExMzUzMmIyZTVhMTIzYzIyMDQ3MTM5YTRhZTY3MGRlYjg5
15
+ OGY5ZGU4Mzk0ZWUwNjg2OGE4ZWIyZjE2MDE2NTZmNDBhMjdjZjM=
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.3.27
1
+ 1.3.28
@@ -27,7 +27,7 @@ module SparkApi
27
27
  # OAuth2 implementations and wouldn't hurt to log.
28
28
  auth_header_error = env[:request_headers]["WWW-Authenticate"]
29
29
  SparkApi.logger.warn { "Authentication error #{auth_header_error}" } unless auth_header_error.nil?
30
- raise ClientError, {:message => body["error"], :code =>0, :status => env[:status]}
30
+ raise ClientError, {:message => body["error"], :code =>0, :status => env[:status], :request_path => env[:url]}
31
31
  end
32
32
  SparkApi.logger.debug { "[oauth2] Session=#{session.inspect}" }
33
33
  env[:body] = session
@@ -58,7 +58,7 @@ module SparkApi
58
58
  return
59
59
  end
60
60
  end
61
- raise ClientError, {:message => "Unable to process sparkbar token #{body.inspect}", :code =>0, :status => env[:status]}
61
+ raise ClientError, {:message => "Unable to process sparkbar token #{body.inspect}", :code =>0, :status => env[:status], :request_path => env[:url]}
62
62
  end
63
63
 
64
64
  end
@@ -21,13 +21,14 @@ module SparkApi
21
21
  # Errors built from API responses
22
22
  class InvalidResponse < StandardError; end
23
23
  class ClientError < StandardError
24
- attr_reader :code, :status, :details
24
+ attr_reader :code, :status, :details, :request_path
25
25
  def initialize (options = {})
26
26
  # Support the standard initializer for errors
27
27
  opts = options.is_a?(Hash) ? options : {:message => options.to_s}
28
28
  @code = opts[:code]
29
29
  @status = opts[:status]
30
30
  @details = opts[:details]
31
+ @request_path = opts[:request_path]
31
32
  super(opts[:message])
32
33
  end
33
34
 
@@ -45,4 +46,4 @@ module SparkApi
45
46
  "set 'ssl_verify' to false in the configuration or add '--no_verify' to the CLI command."
46
47
  end
47
48
  end
48
- end
49
+ end
@@ -15,7 +15,6 @@ module SparkApi
15
15
  # Handles pretty much all the api response parsing and error handling. All responses that
16
16
  # indicate a failure will raise a SparkApi::ClientError exception
17
17
  def on_complete(env)
18
-
19
18
  env[:body] = decompress_body(env)
20
19
 
21
20
  body = MultiJson.decode(env[:body])
@@ -25,6 +24,7 @@ module SparkApi
25
24
  end
26
25
  response = ApiResponse.new body
27
26
  paging = response.pagination
27
+
28
28
  if paging.nil?
29
29
  results = response
30
30
  else
@@ -35,34 +35,40 @@ module SparkApi
35
35
  results = paginate_response(response, paging)
36
36
  end
37
37
  end
38
+
39
+ error_hash = {
40
+ :request_path => env[:url],
41
+ :message => response.message,
42
+ :code => response.code,
43
+ :status => env[:status]
44
+ }
45
+
38
46
  case env[:status]
39
47
  when 400
40
- hash = {:message => response.message, :code => response.code, :status => env[:status]}
41
-
42
48
  # constraint violation
43
49
  if response.code == 1053
44
50
  details = body['D']['Details']
45
- hash[:details] = details
51
+ error_hash[:details] = details
46
52
  end
47
- raise BadResourceRequest,hash
53
+ raise BadResourceRequest, error_hash
48
54
  when 401
49
55
  # Handle the WWW-Authenticate Response Header Field if present. This can be returned by
50
56
  # OAuth2 implementations and wouldn't hurt to log.
51
57
  auth_header_error = env[:request_headers]["WWW-Authenticate"]
52
58
  SparkApi.logger.warn("Authentication error #{auth_header_error}") unless auth_header_error.nil?
53
- raise PermissionDenied, {:message => response.message, :code => response.code, :status => env[:status]}
59
+ raise PermissionDenied, error_hash
54
60
  when 404
55
- raise NotFound, {:message => response.message, :code => response.code, :status => env[:status]}
61
+ raise NotFound, error_hash
56
62
  when 405
57
- raise NotAllowed, {:message => response.message, :code => response.code, :status => env[:status]}
63
+ raise NotAllowed, error_hash
58
64
  when 409
59
- raise BadResourceRequest, {:message => response.message, :code => response.code, :status => env[:status]}
65
+ raise BadResourceRequest, error_hash
60
66
  when 500
61
- raise ClientError, {:message => response.message, :code => response.code, :status => env[:status]}
67
+ raise ClientError, error_hash
62
68
  when 200..299
63
69
  SparkApi.logger.debug { "Success!" }
64
70
  else
65
- raise ClientError, {:message => response.message, :code => response.code, :status => env[:status]}
71
+ raise ClientError, error_hash
66
72
  end
67
73
  env[:body] = results
68
74
  end
@@ -2,7 +2,7 @@ require './spec/spec_helper'
2
2
 
3
3
  describe SparkApi do
4
4
  describe SparkApi::ClientError do
5
- subject { SparkApi::ClientError.new({:message=>"OMG FAIL", :code=>1234, :status=>500}) }
5
+ subject { SparkApi::ClientError.new({:message=>"OMG FAIL", :code=>1234, :status=>500, :request_path => '/v1/foo'}) }
6
6
  it "should print a helpful to_s" do
7
7
  subject.to_s.should == "OMG FAIL"
8
8
  subject.message.should == "OMG FAIL"
@@ -13,6 +13,11 @@ describe SparkApi do
13
13
  it "should have an http status" do
14
14
  subject.status.should == 500
15
15
  end
16
+
17
+ it "should have a request_path" do
18
+ subject.request_path.should == '/v1/foo'
19
+ end
20
+
16
21
  it "should raise and exception with attached message" do
17
22
  expect { raise subject.class, {:message=>"My Message", :code=>1000, :status=>404}}.to raise_error(SparkApi::ClientError) do |e|
18
23
  e.message.should == "My Message"
@@ -339,12 +344,19 @@ describe SparkApi do
339
344
  r
340
345
  end
341
346
  it "should fail horribly on a get" do
342
- expect { subject.get('/system')}.to raise_error(SparkApi::PermissionDenied){ |e| e.code.should == SparkApi::ResponseCodes::SESSION_TOKEN_EXPIRED }
347
+ expect { subject.get('/system')}.to raise_error(SparkApi::PermissionDenied) do |e|
348
+ e.code.should == SparkApi::ResponseCodes::SESSION_TOKEN_EXPIRED
349
+ e.request_path.should == '/system'
350
+ end
343
351
  subject.reauthenticated.should == 2
352
+
344
353
  end
345
354
  it "should fail horribly on a post" do
346
355
  data = {"Contacts" => [{"DisplayName"=>"Wades Contact","PrimaryEmail"=>"wade11@fbsdata.com"}]}
347
- expect { subject.post('/contacts', data)}.to raise_error(SparkApi::PermissionDenied){ |e| e.code.should == SparkApi::ResponseCodes::SESSION_TOKEN_EXPIRED }
356
+ expect { subject.post('/contacts', data)}.to raise_error(SparkApi::PermissionDenied) do |e|
357
+ e.code.should == SparkApi::ResponseCodes::SESSION_TOKEN_EXPIRED
358
+ e.request_path.should == '/contacts'
359
+ end
348
360
  subject.reauthenticated.should == 2
349
361
  end
350
362
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: spark_api
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.27
4
+ version: 1.3.28
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brandon Hornseth
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2016-03-31 00:00:00.000000000 Z
12
+ date: 2016-04-01 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: faraday