kobana 0.3.0 → 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 +4 -4
- data/CHANGELOG.md +1 -0
- data/README.md +18 -0
- data/lib/kobana/configuration.rb +8 -1
- data/lib/kobana/resources/base.rb +3 -1
- data/lib/kobana/resources/connection.rb +12 -1
- data/lib/kobana/resources/operations.rb +1 -1
- data/lib/kobana/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: fb9688ae8ad7106ca655b5db3b61f0a901c740ed818a60339c9f506833cbae32
|
|
4
|
+
data.tar.gz: 4d9d89c6a37ef389ea0c30ff33d8e6e29cf29e94c1e7cb6760a73b3a99750e5f
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
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.
|
data/lib/kobana/configuration.rb
CHANGED
|
@@ -2,11 +2,18 @@
|
|
|
2
2
|
|
|
3
3
|
module Kobana
|
|
4
4
|
class Configuration
|
|
5
|
-
|
|
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
|
|
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
|
|
10
17
|
end
|
|
11
18
|
|
|
12
19
|
def inspect
|
|
@@ -23,9 +23,11 @@ module Kobana
|
|
|
23
23
|
|
|
24
24
|
def inherited(subclass)
|
|
25
25
|
super
|
|
26
|
+
# Set defaults only if not already set by parent classes
|
|
26
27
|
subclass.resource_endpoint ||= infer_resource_endpoint(subclass)
|
|
27
28
|
subclass.primary_key ||= :uid
|
|
28
|
-
|
|
29
|
+
# Don't override api_version if it's already been set
|
|
30
|
+
subclass.api_version = :v2 unless subclass.instance_variable_defined?(:@api_version)
|
|
29
31
|
subclass.errors ||= []
|
|
30
32
|
subclass.default_attributes ||= {}
|
|
31
33
|
end
|
|
@@ -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
|
|
@@ -106,7 +115,9 @@ module Kobana
|
|
|
106
115
|
|
|
107
116
|
def base_url
|
|
108
117
|
config = client&.configuration || Kobana.configuration
|
|
109
|
-
|
|
118
|
+
# Prioritize client configuration api_version over class api_version
|
|
119
|
+
version = config.api_version&.to_sym || api_version&.to_sym
|
|
120
|
+
BASE_URI[version][config.environment&.to_sym]
|
|
110
121
|
end
|
|
111
122
|
end
|
|
112
123
|
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
|
|
data/lib/kobana/version.rb
CHANGED
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.
|
|
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.
|
|
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:
|
|
114
|
+
rubygems_version: 4.0.13
|
|
115
115
|
specification_version: 4
|
|
116
116
|
summary: Kobana API Client
|
|
117
117
|
test_files: []
|