rest_api_builder 0.0.3 → 0.0.4

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: 1d4b9b80449e04e159ccee0755d38f257bea23151ab22f75bfff6898d4f654f2
4
- data.tar.gz: ca2ccdfc23f2b711c4111db218e50286c60d11b0d58e1a89eb24b1fbc02dcebf
3
+ metadata.gz: a164d75c362c383c5fb6c093f936cae3859143a5bffd3e59d833adcf686a7875
4
+ data.tar.gz: 3a7cb13ef985522132219e0d753c2a04867792325ac38927c48d737198e9360d
5
5
  SHA512:
6
- metadata.gz: b7c67011fc8bb6aca7e9929df9d68efc163e037ec009baa7b306cde638ae7f1d524132886885f70b57e938f2f8444a011f05d5311a645bbec11b68fa6f491d85
7
- data.tar.gz: f475fee5f2ccf4f23b601858663abe3d770fc9a1af0a1cc7e8098f0f1082e8b4e57dd0c58b47d340db322adaa7407a67af8f6cc9929aca4bf64d876d8b279a14
6
+ metadata.gz: e708b1b6b6635db0840387320699b0ada62547e0f408d68ac484249da8cf4c92766f3dd6dac372f041db6e3bcc5ca658f822dbf6caa4f4bf7416da56f773d4c6
7
+ data.tar.gz: 5641d558c45f78b10422b253e49f7b0737d840f0d7dbb28c5386a49c6435d2e5fa08d6f0ae22463f6df872f9e42cb2164bd502613c4e1713635619ec3fa34403
data/README.md CHANGED
@@ -133,6 +133,7 @@ Does not throw on non-200 responses like RestClient does, but will throw on any
133
133
  * **query**: Query hash to be appended to the resulting url. Optional.
134
134
  * **logger**: A `Logger` instance to be passed to RestClient in `log` option. Will also log response details as RestClient does not do this by default. Optional
135
135
  * **parse_json**: Boolean. If `true`, will attempt to parse the response body as JSON. Will return the response body unchanged if it does not contain valid JSON. `false` by default.
136
+ * **raw_response**: Boolean. If `true`, the response returned by RestClient will not be parsed into {:status, :body, :headers}, but instead returned as {:raw_response}. `false` by default.
136
137
  * **rest_client_options**: Any additional options to be passed to `RestClient::Request.execute` unchanged. **Any option set here will completely overwrite all custom options**. For example, if you call `RestAPIBuilder::Request.execute(method: :post, rest_client_options: {method: :get})`, the resulting request will be sent as GET. Optional.
137
138
 
138
139
  ### RestAPIBuilder::Request.json_execute(options)
@@ -21,13 +21,18 @@ module RestAPIBuilder
21
21
  path: nil,
22
22
  logger: nil,
23
23
  parse_json: false,
24
+ raw_response: false,
24
25
  rest_client_options: {}
25
26
  )
26
27
  if method == :get && body
27
28
  raise ArgumentError, 'GET requests do not support body'
28
29
  end
29
30
 
30
- response_parser = RestAPIBuilder::RestClientResponseParser.new(logger: logger, parse_json: parse_json)
31
+ response_parser = RestAPIBuilder::RestClientResponseParser.new(
32
+ logger: logger,
33
+ parse_json: parse_json,
34
+ raw_response: raw_response
35
+ )
31
36
  headers = headers.merge(params: query) if query
32
37
 
33
38
  begin
@@ -2,13 +2,17 @@ require 'json'
2
2
 
3
3
  module RestAPIBuilder
4
4
  class RestClientResponseParser
5
- def initialize(logger:, parse_json:)
5
+ def initialize(logger:, parse_json:, raw_response:)
6
6
  @logger = logger
7
7
  @parse_json = parse_json
8
+ @raw_response = raw_response
8
9
  end
9
10
 
10
11
  def parse_response(response, success:)
12
+ return { success: success, raw_response: response } if @raw_response
13
+
11
14
  body = @parse_json ? parse_json(response.body) : response.body
15
+
12
16
  result = {
13
17
  success: success,
14
18
  status: response.code,
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'rest_api_builder'
3
- s.version = '0.0.3'
3
+ s.version = '0.0.4'
4
4
  s.summary = "A simple wrapper for rest-client"
5
5
  s.description = "A simple wrapper for rest-client aiming to make creation and testing of API clients easier."
6
6
  s.authors = ["Alexey D"]
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rest_api_builder
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alexey D
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-07-23 00:00:00.000000000 Z
11
+ date: 2020-07-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rubocop