almodovar 1.7.6 → 1.7.8

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5bf8daf20a34b735694f237e74c7d6a3dbd2d3aeb383ed8a9fb4b9fee48d14b3
4
- data.tar.gz: 946f4449c0931dc085259a6238eae7b42306264b90bba73d9ba2291b24e72918
3
+ metadata.gz: b5e3ab978aae76e66bdf9720e0b0138ae3be35c51ee8406d6771bfa06e726df9
4
+ data.tar.gz: b51554cee84fc6bf7ed9875ea1b0be779d154af92da9a2468c00313f06d799f2
5
5
  SHA512:
6
- metadata.gz: 2c815dad7020c2e24db4fdd5f8633522638cba2e9eae3c2a9d7e682902653e5c83dc2f1ee618ba6c541054af14ad3ceedc1edcf1151256415c976d05b3e5f347
7
- data.tar.gz: 5595081a995e00af88b03720c555ab573048b1b5359f461cd818e41d6e0885cf658df79bbf865c024525b415c0f81013bcbb1dfca6b1dec168b2c118f974921b
6
+ metadata.gz: ac0df4ec63782ae8409e3d094bf747035a5721ab2d8074d754fd6e053f0f8478159e56bf1cd66e6e22ca95a92f4969cd136e520f7cf6335a0e32929188c5af8e
7
+ data.tar.gz: 21f7223520a6eb116ea50400b9f788c20a52ff2c173aac9088b1a9dbbb34a99998498e2f2a1795dac380876b77f76ac59a1c9ec103d7335909bfe03298613370
data/README.rdoc CHANGED
@@ -1,4 +1,4 @@
1
- =Almodovar {<img src="http://travis-ci.org/bebanjo/almodovar.png" />}[http://travis-ci.org/bebanjo/almodovar]
1
+ =Almodovar {<img src="https://github.com/bebanjo/almodovar/workflows/CI/badge.svg" />}[http://travis-ci.org/bebanjo/almodovar]
2
2
 
3
3
  Almodovar is a client for BeBanjo's Sequence & Movida API written in Ruby (it's actually a generic client which plays nice with any RESTful API following some conventions).
4
4
 
@@ -38,8 +38,15 @@ module Almodovar
38
38
 
39
39
  private
40
40
 
41
- def merge_headers(headers)
42
- (self.headers ||= {}).merge(headers)
41
+ def merge_headers(req_headers)
42
+ (default_headers || {}).
43
+ merge(self.headers ||= {}).
44
+ merge(req_headers)
45
+ end
46
+
47
+ def default_headers
48
+ defaults = Almodovar::default_options[:headers] || {}
49
+ defaults = defaults.is_a?(Proc) ? defaults.call() : defaults
43
50
  end
44
51
 
45
52
  def requires_auth?
@@ -17,7 +17,12 @@ module Almodovar
17
17
  def create(attrs = {})
18
18
  raise ArgumentError.new("You must specify one only root element which is the type of resource (e.g. `:project => { :name => 'Wadus' }` instead of just `:name => 'Wadus'`)") if attrs.size > 1
19
19
  root, body = attrs.first
20
- response = http.post(@url, body.to_xml(root: root, convert_links: true, skip_links_one_level: true), query_params, { "Content-Type" => "application/xml" })
20
+ if body.is_a?(Array)
21
+ body = body.to_xml(root: root)
22
+ else
23
+ body = body.to_xml(root: root, convert_links: true, skip_links_one_level: true)
24
+ end
25
+ response = http.post(@url, body, query_params, { "Content-Type" => "application/xml" })
21
26
  check_errors(response, @url, query_params)
22
27
  Resource.new(nil, @auth, Nokogiri::XML.parse(response.body).root)
23
28
  end
@@ -1,3 +1,3 @@
1
1
  module Almodovar
2
- VERSION = '1.7.6'
2
+ VERSION = '1.7.8'
3
3
  end
data/lib/almodovar.rb CHANGED
@@ -21,24 +21,41 @@ module Almodovar
21
21
  DEFAULT_RECEIVE_TIMEOUT = 120
22
22
 
23
23
  class << self
24
+
25
+ # default_options allows to configure some settings on the underlying HTTP client used by Almodovar:
26
+ # - send_timeout: Request sending timeout in sec. Defaults to 120
27
+ # - connect_timeout: Connect timeout in sec. Defaults to 30
28
+ # - receive_timeout: Response receiving timeout in sec. Defaults to 120
29
+ # - user_agent: User-Agent header in HTTP request. defaults to Almodovar/#{Almodovar::VERSION}
30
+ # - force_basic_auth: flag for sending Authorization header w/o getting 401 first. Useful during tests
31
+ # - headers: is for providing default headers Hash that all HTTP
32
+ # requests should have, such as custom 'X-Request-Id' header in tracing.
33
+ # As Almodovar does not expose http API, this accept a proc which will be
34
+ # evaluated per request. You can override :headers with Almodovar::HTTPClient headers method
35
+ # or using Hash parameter in HTTP request methods but this is not accessible on default Almodovar usage.
24
36
  def default_options
25
37
  default = {
26
38
  send_timeout: DEFAULT_SEND_TIMEOUT,
27
39
  connect_timeout: DEFAULT_CONNECT_TIMEOUT,
28
40
  receive_timeout: DEFAULT_RECEIVE_TIMEOUT,
29
41
  user_agent: "Almodovar/#{Almodovar::VERSION}",
30
- force_basic_auth: false
42
+ force_basic_auth: false,
43
+ headers: nil,
31
44
  }
32
45
  default.merge(@default_options || {})
33
46
  end
34
47
 
35
48
  def default_options=(options = {})
36
- @default_options = {
37
- send_timeout: options[:send_timeout],
38
- connect_timeout: options[:connect_timeout],
39
- receive_timeout: options[:receive_timeout],
40
- force_basic_auth: options[:force_basic_auth]
41
- }
49
+ @default_options ||= {}
50
+ # Only assign provided keys too keep defaults when merging
51
+ %i(send_timeout connect_timeout receive_timeout force_basic_auth headers).each do |key|
52
+ @default_options[key] = options[key] if options.has_key?(key)
53
+ end
54
+ @default_options
55
+ end
56
+
57
+ def reset_options
58
+ @default_options = nil
42
59
  end
43
60
  end
44
61
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: almodovar
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.7.6
4
+ version: 1.7.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - BeBanjo S.L.
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-03-10 00:00:00.000000000 Z
11
+ date: 2022-12-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: builder