whiplash-app 0.5.1 → 0.6.0

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
  SHA256:
3
- metadata.gz: d3925f8e5706f3b3a36144ad80df98efa751630299d2bbc8f3c3a942fd75e6c8
4
- data.tar.gz: 522d2ed541e7a6a70140de1967bdcc74c1b4a0b13b329495e60fd4b2cf9c1614
3
+ metadata.gz: 29188ceeacb00228aee15d9f56ab151aac8b491c43b05463d25e648114fbb8ac
4
+ data.tar.gz: 93b8d38a3809d3e30d570f4acfe1ad3007f3754273d2ae1cf7299f3f4ce0f113
5
5
  SHA512:
6
- metadata.gz: ab92fa0ff5e7c87765a03c2097f0a3dd2f0cbf5d757a60cf54353511bf6571fb2811e71000880e1bcd20482b212bcfb47d8a9b8d69dfaff5b5eb1d8772d22a5b
7
- data.tar.gz: 0e3af57cdab4d9956c38dce8cf1eb55e0f1d53b05ab3e21c31a06a4bb4dc13f15ddb1ef7f886d1ea3ac45920ef0dbd3f0ea4f83e37121ce0536cf345cb2eae7f
6
+ metadata.gz: 8a952642f993be0711907cbef3567362f7eb55026c43f22a2d0a1a83e40c24742d5f26db1e9ab0ca36ad7ca8479c9b04e3dc5b930cc8eebfa97b09a7d9e834ca
7
+ data.tar.gz: a2e597b3658c0cdfec8727e44f91a5b6050871ab62d876f59fddcfb8c9412aba62bd0ecac8a4d300ffc5a85002553e746234cde7b70bbdf29c656655fff43a87
@@ -4,6 +4,7 @@ require "whiplash/app/connections"
4
4
  require "whiplash/app/finder_methods"
5
5
  require "whiplash/app/signing"
6
6
  require "whiplash/app/version"
7
+ require "errors/whiplash_api_error"
7
8
  require "oauth2"
8
9
  require "faraday_middleware"
9
10
 
@@ -32,7 +32,12 @@ module Whiplash
32
32
 
33
33
  def app_request!(options = {})
34
34
  begin
35
- app_request(options)
35
+ response = app_request(options)
36
+ return response.body if response.success?
37
+ message = response.body if response.body.is_a? String
38
+ message = response.body.dig('error') if response.body.respond_to?(:dig)
39
+ store_whiplash_error!(response.status)
40
+ error_response(response.status, message)
36
41
  rescue Faraday::ConnectionFailed => e
37
42
  case e.message
38
43
  when 'end of file reached'
@@ -49,11 +54,6 @@ module Whiplash
49
54
  raise ProviderError::InternalServerError, e.message
50
55
  end
51
56
  end
52
- return response.body if response.success?
53
- message = response.body if response.body.is_a? String
54
- message = response.body.dig('error') if response.body.respond_to?(:dig)
55
- store_whiplash_error!(response.status)
56
- error_response(response.status, message)
57
57
  end
58
58
 
59
59
  def delete(endpoint, params = {}, headers = nil)
@@ -112,6 +112,37 @@ module Whiplash
112
112
  headers: headers)
113
113
  end
114
114
 
115
+ def get_body_or_empty(endpoint, params = {}, headers = nil)
116
+ response = get(endpoint, params, headers)
117
+ if !response.success?
118
+ case response.status
119
+ when 500
120
+ Appsignal.send_error(WhiplashApiError::InternalServerError.new(response.body), {raised: false})
121
+ else
122
+ end
123
+
124
+ case get_context(endpoint)
125
+ when 'collection'
126
+ Rails.logger.info "[WhiplashApi] Returned #{response.status}. Returning an empty array..."
127
+ return []
128
+ when 'member'
129
+ Rails.logger.info "[WhiplashApi] Returned #{response.status}. Returning nil..."
130
+ return nil
131
+ when 'aggregate'
132
+ Rails.logger.info "[WhiplashApi] Returned #{response.status}. Returning an empty hash..."
133
+ return {}
134
+ end
135
+ end
136
+ response.body
137
+ end
138
+
139
+ def get_context(endpoint)
140
+ parts = endpoint.split('/').compact
141
+ return 'member' if (parts.last =~ /\d+/).present?
142
+ return 'aggregate' if parts.include?('aggregate')
143
+ 'collection'
144
+ end
145
+
115
146
  def sanitize_headers(headers)
116
147
  if headers
117
148
  {}.tap do |hash|
@@ -1,5 +1,5 @@
1
1
  module Whiplash
2
2
  class App
3
- VERSION = "0.5.1"
3
+ VERSION = "0.6.0"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: whiplash-app
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.1
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Don Sullivan, Mark Dickson
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-05-20 00:00:00.000000000 Z
11
+ date: 2020-05-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: oauth2