kobana 0.3.1 → 0.3.2

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: 3bc6a9da2db1bd8cb2aa863f729e4ee3ef9cd4c143e9c38e5ce5e64c633e1f98
4
- data.tar.gz: 2841dae640966617c6c9a897681cc26ae0ace4c933613ae0147d91ab0ffda53e
3
+ metadata.gz: fb9688ae8ad7106ca655b5db3b61f0a901c740ed818a60339c9f506833cbae32
4
+ data.tar.gz: 4d9d89c6a37ef389ea0c30ff33d8e6e29cf29e94c1e7cb6760a73b3a99750e5f
5
5
  SHA512:
6
- metadata.gz: 1740ebb8d3b894fd4b0b215450ea4563da1ece74da1002d046f874b8661007716989e9ed8c52279ed95983714e42cca1b3bc3a4c05e369910ca2aec6b68b67f8
7
- data.tar.gz: 75ec69765d55582b1363d014ba78ebc4e93d5407e6aef4b18020bd1c3c78d1d4c59b8207d0d40bf9522e81a08364e03779d7743ebcd9a8b5894f15d58d91f4bf
6
+ metadata.gz: 5d3246c4cbb7357282c1bef55d9dbb0dbd00e092e96e1c4c95acc354183589eedbd47baa9c27cae48732f29e8b7e2b20579bb31577cc5fa5237c48a79ee2b17a
7
+ data.tar.gz: 9e4cf09cc138db4cee8cfd52fcb1312043c9833d38e2676eb8e808a39b183722e1bd2c5f63cfa594881be428f4a95d515f10f67aa893b9be0e36e284dc2a0c7c
data/CHANGELOG.md CHANGED
@@ -1,5 +1,6 @@
1
1
  ## [Unreleased]
2
2
 
3
+ - Add configurable HTTP timeouts (`config.open_timeout` / `config.timeout`, in seconds, passed to Faraday). Default `nil` (no timeout) keeps existing behavior; set them to fail fast instead of blocking when the API is slow.
3
4
  - Add debug option
4
5
 
5
6
  ## [0.1.0] - 2023-10-27
data/README.md CHANGED
@@ -88,6 +88,24 @@ client.configure do |config|
88
88
  end
89
89
  ```
90
90
 
91
+ #### HTTP timeouts
92
+
93
+ By default the client has **no** HTTP timeout, so a slow or hanging API call
94
+ blocks the caller until the underlying socket gives up. Set `open_timeout`
95
+ (connection establishment) and/or `timeout` (response read), in seconds, to fail
96
+ fast instead — both are passed straight to Faraday:
97
+
98
+ ```ruby
99
+ Kobana.configure do |config|
100
+ config.api_token = 'YOUR_API_TOKEN'
101
+ config.open_timeout = 2 # seconds to establish the TCP connection
102
+ config.timeout = 8 # seconds to read the response
103
+ end
104
+ ```
105
+
106
+ When unset (`nil`), behavior is unchanged. Tune `timeout` above the longest
107
+ expected operation (e.g. large multipart uploads / batch exports).
108
+
91
109
  ### Usage
92
110
 
93
111
  The gem supports both global configuration (backward compatible) and multi-client usage patterns.
@@ -2,12 +2,18 @@
2
2
 
3
3
  module Kobana
4
4
  class Configuration
5
- attr_accessor :api_token, :environment, :custom_headers, :debug, :api_version
5
+ # `open_timeout` and `timeout` are passed straight to Faraday (in seconds).
6
+ # Both default to nil (no timeout) to preserve historical behavior; set them
7
+ # to fail fast instead of blocking the caller when the API is slow/hanging.
8
+ attr_accessor :api_token, :environment, :custom_headers, :debug, :api_version,
9
+ :open_timeout, :timeout
6
10
 
7
11
  def initialize
8
12
  @custom_headers = {}
9
13
  @environment = :sandbox
10
- @api_version = :v2
14
+ # nil means "no global override" — each resource uses its own declared
15
+ # api_version (see Resources::Base). Set this to force a version globally.
16
+ @api_version = nil
11
17
  end
12
18
 
13
19
  def inspect
@@ -45,10 +45,18 @@ module Kobana
45
45
  faraday.request :json
46
46
  faraday.adapter Faraday.default_adapter
47
47
  faraday.headers = headers
48
+ apply_timeouts(faraday, config)
48
49
  faraday.response :logger, logger if config.debug
49
50
  end
50
51
  end
51
52
 
53
+ # Applies Faraday connect/read timeouts from the configuration when set.
54
+ # No-op when unset, so the default behavior (no timeout) is preserved.
55
+ def apply_timeouts(faraday, config)
56
+ faraday.options.open_timeout = config.open_timeout if config.open_timeout
57
+ faraday.options.timeout = config.timeout if config.timeout
58
+ end
59
+
52
60
  public
53
61
 
54
62
  def multipart_connection
@@ -67,6 +75,7 @@ module Kobana
67
75
  faraday.headers = headers.merge(
68
76
  "Content-Type" => "multipart/form-data"
69
77
  )
78
+ apply_timeouts(faraday, config)
70
79
  faraday.response :logger, logger if config.debug
71
80
  end
72
81
  end
@@ -68,7 +68,7 @@ module Kobana
68
68
  return unless response[:data].is_a?(Hash)
69
69
 
70
70
  @errors = response[:data][:errors] if response[:data].key?(:errors)
71
- @errors = [title: response[:data][:error]] if response[:data].key?(:error)
71
+ @errors = [{ title: response[:data][:error] }] if response[:data].key?(:error)
72
72
  end
73
73
  end
74
74
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Kobana
4
- VERSION = "0.3.1"
4
+ VERSION = "0.3.2"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kobana
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 0.3.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kivanio Barbosa
@@ -104,14 +104,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
104
104
  requirements:
105
105
  - - ">="
106
106
  - !ruby/object:Gem::Version
107
- version: 3.2.6
107
+ version: '3.3'
108
108
  required_rubygems_version: !ruby/object:Gem::Requirement
109
109
  requirements:
110
110
  - - ">="
111
111
  - !ruby/object:Gem::Version
112
112
  version: '0'
113
113
  requirements: []
114
- rubygems_version: 3.7.1
114
+ rubygems_version: 4.0.13
115
115
  specification_version: 4
116
116
  summary: Kobana API Client
117
117
  test_files: []