svelte 0.2.0 → 0.3.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: a8aabcb7e5bafe83a0ad58ec737e2714afc5b2a6cb11264755dda73d2fd23a41
4
- data.tar.gz: 96215b0581084eb9d196838ab9ef329030ec6e1cb80103a6b6e9ae0c15627ffd
3
+ metadata.gz: d515f944eb4733ad04a53f899efcb9d92d42e9186e4b182d209593f5486b9a10
4
+ data.tar.gz: d2a523d6ba449aa86b0b67262a91ff21b398fc04a7205d91c15e836124ae95b7
5
5
  SHA512:
6
- metadata.gz: 2324bc8a06b283b780e6cff3f711609de82c0e1f06e504baaad12cf0200ef2a31ccf05c0027e785f1a00f9b542d5a8dfa2f868385cd6758928463a96eae4aca3
7
- data.tar.gz: 92d72d2a0538d3aee9eb6e27826812dc489e0fb6ff3c200a2cb543e817d146a7756d833131c50c2df678ce42505d59c795b897e3e27b89c6269b4e951f9d8af7
6
+ metadata.gz: 20e46f345e5554de3954a6937aaf08cc810a558f14f2cd8795f70d65ffd4bcf2ff5c80c955d11a3f6521d6f48dc098617e5e56ba5d030cc4fea8ac45abd09585
7
+ data.tar.gz: 2694aa185dd3b8aef3c2f5bf6d19b0c63f75ae5d9767c6bc66d987b057e649f8690b2b765cf2bd95732a4c09f013981fe3fa5719619b1d6999cf9b8a10d29f60
@@ -0,0 +1,6 @@
1
+ # Changelog
2
+
3
+ ## [0.3.0] - 2019-08-14
4
+
5
+ - Added support for headers ([#20](https://github.com/notonthehighstreet/svelte/pull/20))
6
+
@@ -13,18 +13,21 @@ module Svelte
13
13
  # @param configuration [Configuration] Swagger API configuration
14
14
  # @param parameters [Hash] payload of the request, i.e. `{ petId: 1}`
15
15
  # @param options [Hash] request options, i.e. `{ timeout: 10 }`
16
- def call(verb:, path:, configuration:, parameters:, options:)
16
+ # @param headers [Hash] headers to be included in the request
17
+ def call(verb:, path:, configuration:, parameters:, options:, headers: nil)
17
18
  url = url_for(configuration: configuration,
18
19
  path: path,
19
20
  parameters: parameters)
20
21
  request_parameters = clean_parameters(path: path,
21
22
  parameters: parameters)
22
- request_options = build_request_options(configuration: configuration,
23
- options: options)
23
+ request_headers = build_request_headers(configuration: configuration,
24
+ options: options,
25
+ headers: headers)
24
26
  RestClient.call(verb: verb,
25
27
  url: url,
26
28
  params: request_parameters,
27
- options: request_options)
29
+ headers: request_headers,
30
+ options: options)
28
31
  end
29
32
 
30
33
  private
@@ -58,12 +61,12 @@ module Svelte
58
61
  clean_parameters
59
62
  end
60
63
 
61
- def build_request_options(configuration:, options:)
62
- if configuration.headers&.any?
63
- return (options || {}).merge(headers: configuration.headers)
64
- end
64
+ def build_request_headers(configuration:, options:, headers:)
65
+ configuration_headers = configuration.headers || {}
66
+ options_headers = options[:headers] || {}
67
+ request_headers = headers || {}
65
68
 
66
- options
69
+ configuration_headers.merge(options_headers).merge(request_headers)
67
70
  end
68
71
  end
69
72
  end
@@ -12,11 +12,17 @@ module Svelte
12
12
  builder = self
13
13
  method_name = StringManipulator.method_name_for(operation.id)
14
14
  module_constant.define_singleton_method(method_name) do |*parameters|
15
+ request_parameters = builder.request_parameters(full_parameters: parameters)
16
+ headers = builder.strip_headers!(
17
+ operation_parameters: operation.properties["parameters"],
18
+ request_parameters: request_parameters)
19
+
15
20
  GenericOperation.call(
16
21
  verb: operation.verb,
17
22
  path: operation.path,
18
23
  configuration: configuration,
19
- parameters: builder.request_parameters(full_parameters: parameters),
24
+ headers: headers,
25
+ parameters: request_parameters,
20
26
  options: builder.options(full_parameters: parameters)
21
27
  )
22
28
  end
@@ -46,6 +52,21 @@ module Svelte
46
52
  def options(full_parameters:)
47
53
  full_parameters[1] || {}
48
54
  end
55
+
56
+ # Strips headers from parameters and returns them.
57
+ # @param operation_parameters [Array] The parameters defined by the operation
58
+ # @param request_parameters [Hash] The parameters given by the caller
59
+ # @return [Hash] The headers for GenericOperation to build the request
60
+ def strip_headers!(operation_parameters:, request_parameters:)
61
+ header_names = operation_parameters.reduce([]) do |memo, param|
62
+ memo.push(param["name"].downcase) if param["in"] == 'header'
63
+ memo
64
+ end
65
+
66
+ headers = request_parameters.select { |key, val| header_names.include?(key)}
67
+ request_parameters.reject! { |key, val| header_names.include?(key) }
68
+ headers.empty? ? nil : headers
69
+ end
49
70
  end
50
71
  end
51
72
  end
@@ -17,12 +17,12 @@ module Svelte
17
17
  # @param options [Hash] options
18
18
  # @raise [HTTPError] if an HTTP layer error occurs,
19
19
  # an exception will be raised
20
+ # @param headers [Hash] headers to be sent along with the request
20
21
  #
21
22
  # @return [Faraday::Response] http response from the service
22
- def call(verb:, url:, params: {}, options: {})
23
- connection.send verb, url, params do |request|
23
+ def call(verb:, url:, params: {}, options: {}, headers: {})
24
+ connection.send verb, url, params, headers do |request|
24
25
  request.options.timeout = options[:timeout] if options[:timeout]
25
- options[:headers]&.each { |key, value| request.headers[key] = value }
26
26
  end
27
27
  rescue Faraday::TimeoutError => e
28
28
  raise HTTPError.new(parent: e)
@@ -2,5 +2,5 @@
2
2
 
3
3
  module Svelte
4
4
  # Version
5
- VERSION = '0.2.0'
5
+ VERSION = '0.3.0'
6
6
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: svelte
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - notonthehighstreet.com
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-07-10 00:00:00.000000000 Z
11
+ date: 2019-08-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -178,6 +178,7 @@ files:
178
178
  - ".ruby-version"
179
179
  - ".travis.yml"
180
180
  - ".yardopts"
181
+ - CHANGELOG.md
181
182
  - CODE_OF_CONDUCT.md
182
183
  - Gemfile
183
184
  - LICENSE.txt