onebusaway-sdk 0.1.0.pre.alpha.206 → 0.1.0.pre.alpha.207
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/README.md +32 -20
- data/lib/onebusaway-sdk/base_client.rb +41 -49
- data/lib/onebusaway-sdk/base_model.rb +489 -514
- data/lib/onebusaway-sdk/base_page.rb +35 -15
- data/lib/onebusaway-sdk/client.rb +1 -3
- data/lib/onebusaway-sdk/errors.rb +12 -17
- data/lib/onebusaway-sdk/extern.rb +1 -4
- data/lib/onebusaway-sdk/models/references.rb +0 -21
- data/lib/onebusaway-sdk/models/report_problem_with_stop_retrieve_params.rb +0 -21
- data/lib/onebusaway-sdk/models/report_problem_with_trip_retrieve_params.rb +0 -23
- data/lib/onebusaway-sdk/pooled_net_requester.rb +40 -46
- data/lib/onebusaway-sdk/request_options.rb +4 -11
- data/lib/onebusaway-sdk/resources/agencies_with_coverage.rb +0 -2
- data/lib/onebusaway-sdk/resources/agency.rb +0 -2
- data/lib/onebusaway-sdk/resources/arrival_and_departure.rb +0 -3
- data/lib/onebusaway-sdk/resources/block.rb +0 -2
- data/lib/onebusaway-sdk/resources/config.rb +0 -2
- data/lib/onebusaway-sdk/resources/current_time.rb +0 -2
- data/lib/onebusaway-sdk/resources/report_problem_with_stop.rb +0 -2
- data/lib/onebusaway-sdk/resources/report_problem_with_trip.rb +0 -2
- data/lib/onebusaway-sdk/resources/route.rb +0 -2
- data/lib/onebusaway-sdk/resources/route_ids_for_agency.rb +0 -2
- data/lib/onebusaway-sdk/resources/routes_for_agency.rb +0 -2
- data/lib/onebusaway-sdk/resources/routes_for_location.rb +0 -2
- data/lib/onebusaway-sdk/resources/schedule_for_route.rb +0 -2
- data/lib/onebusaway-sdk/resources/schedule_for_stop.rb +0 -2
- data/lib/onebusaway-sdk/resources/search_for_route.rb +0 -2
- data/lib/onebusaway-sdk/resources/search_for_stop.rb +0 -2
- data/lib/onebusaway-sdk/resources/shape.rb +0 -2
- data/lib/onebusaway-sdk/resources/stop.rb +0 -2
- data/lib/onebusaway-sdk/resources/stop_ids_for_agency.rb +0 -2
- data/lib/onebusaway-sdk/resources/stops_for_agency.rb +0 -2
- data/lib/onebusaway-sdk/resources/stops_for_location.rb +0 -2
- data/lib/onebusaway-sdk/resources/stops_for_route.rb +0 -2
- data/lib/onebusaway-sdk/resources/trip.rb +0 -2
- data/lib/onebusaway-sdk/resources/trip_details.rb +0 -2
- data/lib/onebusaway-sdk/resources/trip_for_vehicle.rb +0 -2
- data/lib/onebusaway-sdk/resources/trips_for_location.rb +0 -2
- data/lib/onebusaway-sdk/resources/trips_for_route.rb +0 -2
- data/lib/onebusaway-sdk/resources/vehicles_for_agency.rb +0 -2
- data/lib/onebusaway-sdk/util.rb +201 -118
- data/lib/onebusaway-sdk/version.rb +1 -1
- data/lib/onebusaway-sdk.rb +1 -0
- data/manifest.yaml +1 -0
- data/rbi/lib/onebusaway-sdk/base_client.rbi +46 -21
- data/rbi/lib/onebusaway-sdk/base_model.rbi +400 -256
- data/rbi/lib/onebusaway-sdk/base_page.rbi +3 -4
- data/rbi/lib/onebusaway-sdk/client.rbi +7 -2
- data/rbi/lib/onebusaway-sdk/errors.rbi +41 -8
- data/rbi/lib/onebusaway-sdk/extern.rbi +1 -1
- data/rbi/lib/onebusaway-sdk/models/agencies_with_coverage_list_params.rbi +5 -2
- data/rbi/lib/onebusaway-sdk/models/agencies_with_coverage_list_response.rbi +9 -6
- data/rbi/lib/onebusaway-sdk/models/agency_retrieve_params.rbi +5 -2
- data/rbi/lib/onebusaway-sdk/models/agency_retrieve_response.rbi +6 -6
- data/rbi/lib/onebusaway-sdk/models/arrival_and_departure_list_params.rbi +5 -2
- data/rbi/lib/onebusaway-sdk/models/arrival_and_departure_list_response.rbi +95 -14
- data/rbi/lib/onebusaway-sdk/models/arrival_and_departure_retrieve_params.rbi +2 -9
- data/rbi/lib/onebusaway-sdk/models/arrival_and_departure_retrieve_response.rbi +93 -12
- data/rbi/lib/onebusaway-sdk/models/block_retrieve_params.rbi +5 -2
- data/rbi/lib/onebusaway-sdk/models/block_retrieve_response.rbi +14 -20
- data/rbi/lib/onebusaway-sdk/models/config_retrieve_params.rbi +5 -2
- data/rbi/lib/onebusaway-sdk/models/config_retrieve_response.rbi +8 -14
- data/rbi/lib/onebusaway-sdk/models/current_time_retrieve_params.rbi +5 -2
- data/rbi/lib/onebusaway-sdk/models/current_time_retrieve_response.rbi +6 -6
- data/rbi/lib/onebusaway-sdk/models/references.rbi +60 -43
- data/rbi/lib/onebusaway-sdk/models/report_problem_with_stop_retrieve_params.rbi +10 -6
- data/rbi/lib/onebusaway-sdk/models/report_problem_with_trip_retrieve_params.rbi +15 -6
- data/rbi/lib/onebusaway-sdk/models/response_wrapper.rbi +4 -2
- data/rbi/lib/onebusaway-sdk/models/route_ids_for_agency_list_params.rbi +5 -2
- data/rbi/lib/onebusaway-sdk/models/route_ids_for_agency_list_response.rbi +4 -4
- data/rbi/lib/onebusaway-sdk/models/route_retrieve_params.rbi +5 -2
- data/rbi/lib/onebusaway-sdk/models/route_retrieve_response.rbi +6 -6
- data/rbi/lib/onebusaway-sdk/models/routes_for_agency_list_params.rbi +5 -2
- data/rbi/lib/onebusaway-sdk/models/routes_for_agency_list_response.rbi +6 -6
- data/rbi/lib/onebusaway-sdk/models/routes_for_location_list_params.rbi +2 -2
- data/rbi/lib/onebusaway-sdk/models/routes_for_location_list_response.rbi +6 -6
- data/rbi/lib/onebusaway-sdk/models/schedule_for_route_retrieve_params.rbi +5 -8
- data/rbi/lib/onebusaway-sdk/models/schedule_for_route_retrieve_response.rbi +19 -16
- data/rbi/lib/onebusaway-sdk/models/schedule_for_stop_retrieve_params.rbi +5 -8
- data/rbi/lib/onebusaway-sdk/models/schedule_for_stop_retrieve_response.rbi +14 -14
- data/rbi/lib/onebusaway-sdk/models/search_for_route_list_params.rbi +4 -2
- data/rbi/lib/onebusaway-sdk/models/search_for_route_list_response.rbi +6 -6
- data/rbi/lib/onebusaway-sdk/models/search_for_stop_list_params.rbi +4 -2
- data/rbi/lib/onebusaway-sdk/models/search_for_stop_list_response.rbi +6 -6
- data/rbi/lib/onebusaway-sdk/models/shape_retrieve_params.rbi +5 -2
- data/rbi/lib/onebusaway-sdk/models/shape_retrieve_response.rbi +7 -6
- data/rbi/lib/onebusaway-sdk/models/stop_ids_for_agency_list_params.rbi +5 -2
- data/rbi/lib/onebusaway-sdk/models/stop_ids_for_agency_list_response.rbi +4 -4
- data/rbi/lib/onebusaway-sdk/models/stop_retrieve_params.rbi +5 -2
- data/rbi/lib/onebusaway-sdk/models/stop_retrieve_response.rbi +6 -6
- data/rbi/lib/onebusaway-sdk/models/stops_for_agency_list_params.rbi +5 -2
- data/rbi/lib/onebusaway-sdk/models/stops_for_agency_list_response.rbi +4 -4
- data/rbi/lib/onebusaway-sdk/models/stops_for_location_list_params.rbi +6 -2
- data/rbi/lib/onebusaway-sdk/models/stops_for_location_list_response.rbi +6 -6
- data/rbi/lib/onebusaway-sdk/models/stops_for_route_list_params.rbi +4 -2
- data/rbi/lib/onebusaway-sdk/models/stops_for_route_list_response.rbi +14 -14
- data/rbi/lib/onebusaway-sdk/models/trip_detail_retrieve_params.rbi +10 -2
- data/rbi/lib/onebusaway-sdk/models/trip_detail_retrieve_response.rbi +54 -23
- data/rbi/lib/onebusaway-sdk/models/trip_for_vehicle_retrieve_params.rbi +9 -8
- data/rbi/lib/onebusaway-sdk/models/trip_for_vehicle_retrieve_response.rbi +54 -23
- data/rbi/lib/onebusaway-sdk/models/trip_retrieve_params.rbi +5 -2
- data/rbi/lib/onebusaway-sdk/models/trip_retrieve_response.rbi +6 -6
- data/rbi/lib/onebusaway-sdk/models/trips_for_location_list_params.rbi +12 -12
- data/rbi/lib/onebusaway-sdk/models/trips_for_location_list_response.rbi +56 -16
- data/rbi/lib/onebusaway-sdk/models/trips_for_route_list_params.rbi +6 -2
- data/rbi/lib/onebusaway-sdk/models/trips_for_route_list_response.rbi +54 -16
- data/rbi/lib/onebusaway-sdk/models/vehicles_for_agency_list_params.rbi +3 -2
- data/rbi/lib/onebusaway-sdk/models/vehicles_for_agency_list_response.rbi +52 -14
- data/rbi/lib/onebusaway-sdk/pooled_net_requester.rbi +28 -13
- data/rbi/lib/onebusaway-sdk/request_options.rbi +25 -2
- data/rbi/lib/onebusaway-sdk/resources/agencies_with_coverage.rbi +4 -2
- data/rbi/lib/onebusaway-sdk/resources/agency.rbi +8 -3
- data/rbi/lib/onebusaway-sdk/resources/arrival_and_departure.rbi +14 -3
- data/rbi/lib/onebusaway-sdk/resources/block.rbi +8 -3
- data/rbi/lib/onebusaway-sdk/resources/config.rbi +3 -2
- data/rbi/lib/onebusaway-sdk/resources/current_time.rbi +3 -2
- data/rbi/lib/onebusaway-sdk/resources/report_problem_with_stop.rbi +9 -2
- data/rbi/lib/onebusaway-sdk/resources/report_problem_with_trip.rbi +14 -2
- data/rbi/lib/onebusaway-sdk/resources/route.rbi +8 -3
- data/rbi/lib/onebusaway-sdk/resources/route_ids_for_agency.rbi +8 -3
- data/rbi/lib/onebusaway-sdk/resources/routes_for_agency.rbi +8 -3
- data/rbi/lib/onebusaway-sdk/resources/routes_for_location.rbi +3 -2
- data/rbi/lib/onebusaway-sdk/resources/schedule_for_route.rbi +11 -3
- data/rbi/lib/onebusaway-sdk/resources/schedule_for_stop.rbi +11 -3
- data/rbi/lib/onebusaway-sdk/resources/search_for_route.rbi +10 -3
- data/rbi/lib/onebusaway-sdk/resources/search_for_stop.rbi +10 -3
- data/rbi/lib/onebusaway-sdk/resources/shape.rbi +8 -3
- data/rbi/lib/onebusaway-sdk/resources/stop.rbi +8 -3
- data/rbi/lib/onebusaway-sdk/resources/stop_ids_for_agency.rbi +8 -3
- data/rbi/lib/onebusaway-sdk/resources/stops_for_agency.rbi +8 -3
- data/rbi/lib/onebusaway-sdk/resources/stops_for_location.rbi +16 -3
- data/rbi/lib/onebusaway-sdk/resources/stops_for_route.rbi +12 -3
- data/rbi/lib/onebusaway-sdk/resources/trip.rbi +8 -3
- data/rbi/lib/onebusaway-sdk/resources/trip_details.rbi +12 -2
- data/rbi/lib/onebusaway-sdk/resources/trip_for_vehicle.rbi +11 -2
- data/rbi/lib/onebusaway-sdk/resources/trips_for_location.rbi +12 -2
- data/rbi/lib/onebusaway-sdk/resources/trips_for_route.rbi +15 -3
- data/rbi/lib/onebusaway-sdk/resources/vehicles_for_agency.rbi +10 -3
- data/rbi/lib/onebusaway-sdk/util.rbi +207 -105
- data/rbi/lib/onebusaway-sdk/version.rbi +1 -1
- data/sig/onebusaway-sdk/base_client.rbs +6 -1
- data/sig/onebusaway-sdk/base_model.rbs +8 -6
- data/sig/onebusaway-sdk/base_page.rbs +1 -1
- data/sig/onebusaway-sdk/errors.rbs +4 -4
- data/sig/onebusaway-sdk/pooled_net_requester.rbs +11 -4
- data/sig/onebusaway-sdk/request_options.rbs +4 -0
- data/sig/onebusaway-sdk/util.rbs +33 -8
- data/sig/onebusaway-sdk/version.rbs +1 -1
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4afa1a6c65b03950bbef375b58bd9c893852b92f1b6a8e5d6316d41a2aede517
|
4
|
+
data.tar.gz: 655727298bb0188df296939c458ee293bead7cb75aef8bf662344606ca4104d2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 33a1c96f96d85f03dbc5d7100dbb859128b27108502b2ae2577a6e5ffb31ec89a1fc22cbdbdd0d6655e0bc441f85244a1684fb31f7341e812d004d23a34a233b
|
7
|
+
data.tar.gz: 044ddde2208e8ee77177a94af1003e931106a47e19e7cb51c9d7cf56e5847236d76d8e382b3285f2d3a5700e14da4d5d53d29e46c85765e687fb6e69a29a823a
|
data/README.md
CHANGED
@@ -1,20 +1,18 @@
|
|
1
1
|
# Onebusaway SDK Ruby API library
|
2
2
|
|
3
|
-
The Onebusaway SDK Ruby library provides convenient access to the Onebusaway SDK REST API from any Ruby 3.0.0+
|
4
|
-
application.
|
3
|
+
The Onebusaway SDK Ruby library provides convenient access to the Onebusaway SDK REST API from any Ruby 3.0.0+ application.
|
5
4
|
|
6
5
|
It is generated with [Stainless](https://www.stainless.com/).
|
7
6
|
|
8
7
|
## Documentation
|
9
8
|
|
10
|
-
Documentation for
|
9
|
+
Documentation for released of this gem can be found [on RubyDoc](https://gemdocs.org/gems/onebusaway-sdk).
|
11
10
|
|
12
11
|
The underlying REST API documentation can be found on [developer.onebusaway.org](https://developer.onebusaway.org).
|
13
12
|
|
14
13
|
## Installation
|
15
14
|
|
16
|
-
To use this gem during the beta, install directly from GitHub with Bundler by
|
17
|
-
adding the following to your application's `Gemfile`:
|
15
|
+
To use this gem during the beta, install directly from GitHub with Bundler by adding the following to your application's `Gemfile`:
|
18
16
|
|
19
17
|
```ruby
|
20
18
|
gem "onebusaway-sdk", git: "https://github.com/OneBusAway/ruby-sdk", branch: "main"
|
@@ -26,8 +24,7 @@ To fetch an initial copy of the gem:
|
|
26
24
|
bundle install
|
27
25
|
```
|
28
26
|
|
29
|
-
To update the version used by your application when updates are pushed to
|
30
|
-
GitHub:
|
27
|
+
To update the version used by your application when updates are pushed to GitHub:
|
31
28
|
|
32
29
|
```sh
|
33
30
|
bundle update onebusaway-sdk
|
@@ -44,13 +41,13 @@ onebusaway_sdk = OnebusawaySDK::Client.new(
|
|
44
41
|
)
|
45
42
|
|
46
43
|
current_time = onebusaway_sdk.current_time.retrieve
|
44
|
+
|
45
|
+
puts(current_time)
|
47
46
|
```
|
48
47
|
|
49
48
|
### Errors
|
50
49
|
|
51
|
-
When the library is unable to connect to the API, or if the API returns a
|
52
|
-
non-success status code (i.e., 4xx or 5xx response), a subclass of
|
53
|
-
`OnebusawaySDK::Error` will be thrown:
|
50
|
+
When the library is unable to connect to the API, or if the API returns a non-success status code (i.e., 4xx or 5xx response), a subclass of `OnebusawaySDK::Error` will be thrown:
|
54
51
|
|
55
52
|
```ruby
|
56
53
|
begin
|
@@ -78,10 +75,9 @@ Error codes are as followed:
|
|
78
75
|
|
79
76
|
### Retries
|
80
77
|
|
81
|
-
Certain errors will be automatically retried 2 times by default, with a short
|
82
|
-
|
83
|
-
connectivity problem), 408 Request Timeout, 409 Conflict, 429 Rate Limit, >=500 Internal errors,
|
84
|
-
and timeouts will all be retried by default.
|
78
|
+
Certain errors will be automatically retried 2 times by default, with a short exponential backoff.
|
79
|
+
|
80
|
+
Connection errors (for example, due to a network connectivity problem), 408 Request Timeout, 409 Conflict, 429 Rate Limit, >=500 Internal errors, and timeouts will all be retried by default.
|
85
81
|
|
86
82
|
You can use the `max_retries` option to configure or disable this:
|
87
83
|
|
@@ -98,8 +94,8 @@ onebusaway_sdk.current_time.retrieve(request_options: {max_retries: 5})
|
|
98
94
|
### Timeouts
|
99
95
|
|
100
96
|
By default, requests will time out after 60 seconds.
|
101
|
-
|
102
|
-
so in some cases a request could wait 2\*timeout seconds before it fails.
|
97
|
+
|
98
|
+
Timeouts are applied separately to the initial connection and the overall request time, so in some cases a request could wait 2\*timeout seconds before it fails.
|
103
99
|
|
104
100
|
You can use the `timeout` option to configure or disable this:
|
105
101
|
|
@@ -113,12 +109,28 @@ onebusaway_sdk = OnebusawaySDK::Client.new(
|
|
113
109
|
onebusaway_sdk.current_time.retrieve(request_options: {timeout: 5})
|
114
110
|
```
|
115
111
|
|
112
|
+
## Sorbet Support
|
113
|
+
|
114
|
+
This library is written with [Sorbet type definitions](https://sorbet.org/docs/rbi). However, there is no runtime dependency on the `sorbet-runtime`.
|
115
|
+
|
116
|
+
What this means is that while you can use Sorbet to type check your code statically, and benefit from the [Sorbet Language Server](https://sorbet.org/docs/lsp) in your editor, there is no runtime type checking and execution overhead from Sorbet itself.
|
117
|
+
|
118
|
+
Due to limitations with the Sorbet type system, where a method otherwise can take an instance of `OnebusawaySDK::BaseModel` class, you will need to use the `**` splat operator to pass the arguments:
|
119
|
+
|
120
|
+
Please follow Sorbet's [setup guides](https://sorbet.org/docs/adopting) for best experience.
|
121
|
+
|
122
|
+
```ruby
|
123
|
+
model = CurrentTimeRetrieveParams.new
|
124
|
+
|
125
|
+
onebusaway_sdk.current_time.retrieve(**model)
|
126
|
+
```
|
127
|
+
|
116
128
|
## Versioning
|
117
129
|
|
118
|
-
This package follows [SemVer](https://semver.org/spec/v2.0.0.html) conventions. As the
|
119
|
-
|
120
|
-
|
130
|
+
This package follows [SemVer](https://semver.org/spec/v2.0.0.html) conventions. As the library is in initial development and has a major version of `0`, APIs may change at any time.
|
131
|
+
|
132
|
+
This package considers improvements to the (non-runtime) `*.rbi` and `*.rbs` type definitions to be non-breaking changes.
|
121
133
|
|
122
134
|
## Requirements
|
123
135
|
|
124
|
-
Ruby 3.0 or higher.
|
136
|
+
Ruby 3.0.0 or higher.
|
@@ -1,10 +1,9 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module OnebusawaySDK
|
4
|
-
# @private
|
4
|
+
# @api private
|
5
5
|
#
|
6
6
|
# @abstract
|
7
|
-
#
|
8
7
|
class BaseClient
|
9
8
|
# from whatwg fetch spec
|
10
9
|
MAX_REDIRECTS = 20
|
@@ -21,12 +20,11 @@ module OnebusawaySDK
|
|
21
20
|
# rubocop:enable Style/MutableConstant
|
22
21
|
|
23
22
|
class << self
|
24
|
-
# @private
|
23
|
+
# @api private
|
25
24
|
#
|
26
25
|
# @param req [Hash{Symbol=>Object}]
|
27
26
|
#
|
28
27
|
# @raise [ArgumentError]
|
29
|
-
#
|
30
28
|
def validate!(req)
|
31
29
|
keys = [:method, :path, :query, :headers, :body, :unwrap, :page, :stream, :model, :options]
|
32
30
|
case req
|
@@ -41,13 +39,12 @@ module OnebusawaySDK
|
|
41
39
|
end
|
42
40
|
end
|
43
41
|
|
44
|
-
# @private
|
42
|
+
# @api private
|
45
43
|
#
|
46
44
|
# @param status [Integer]
|
47
45
|
# @param headers [Hash{String=>String}, Net::HTTPHeader]
|
48
46
|
#
|
49
47
|
# @return [Boolean]
|
50
|
-
#
|
51
48
|
def should_retry?(status, headers:)
|
52
49
|
coerced = OnebusawaySDK::Util.coerce_boolean(headers["x-should-retry"])
|
53
50
|
case [coerced, status]
|
@@ -65,7 +62,7 @@ module OnebusawaySDK
|
|
65
62
|
end
|
66
63
|
end
|
67
64
|
|
68
|
-
# @private
|
65
|
+
# @api private
|
69
66
|
#
|
70
67
|
# @param request [Hash{Symbol=>Object}] .
|
71
68
|
#
|
@@ -86,7 +83,6 @@ module OnebusawaySDK
|
|
86
83
|
# @param response_headers [Hash{String=>String}, Net::HTTPHeader]
|
87
84
|
#
|
88
85
|
# @return [Hash{Symbol=>Object}]
|
89
|
-
#
|
90
86
|
def follow_redirect(request, status:, response_headers:)
|
91
87
|
method, url, headers = request.fetch_values(:method, :url, :headers)
|
92
88
|
location =
|
@@ -128,14 +124,27 @@ module OnebusawaySDK
|
|
128
124
|
|
129
125
|
request
|
130
126
|
end
|
127
|
+
|
128
|
+
# @api private
|
129
|
+
#
|
130
|
+
# @param status [Integer, OnebusawaySDK::APIConnectionError]
|
131
|
+
# @param stream [Enumerable, nil]
|
132
|
+
def reap_connection!(status, stream:)
|
133
|
+
case status
|
134
|
+
in (..199) | (300..499)
|
135
|
+
stream&.each { next }
|
136
|
+
in OnebusawaySDK::APIConnectionError | (500..)
|
137
|
+
OnebusawaySDK::Util.close_fused!(stream)
|
138
|
+
else
|
139
|
+
end
|
140
|
+
end
|
131
141
|
end
|
132
142
|
|
133
|
-
# @private
|
134
|
-
#
|
143
|
+
# @api private
|
135
144
|
# @return [OnebusawaySDK::PooledNetRequester]
|
136
145
|
attr_accessor :requester
|
137
146
|
|
138
|
-
# @private
|
147
|
+
# @api private
|
139
148
|
#
|
140
149
|
# @param base_url [String]
|
141
150
|
# @param timeout [Float]
|
@@ -144,7 +153,6 @@ module OnebusawaySDK
|
|
144
153
|
# @param max_retry_delay [Float]
|
145
154
|
# @param headers [Hash{String=>String, Integer, Array<String, Integer, nil>, nil}]
|
146
155
|
# @param idempotency_header [String, nil]
|
147
|
-
#
|
148
156
|
def initialize(
|
149
157
|
base_url:,
|
150
158
|
timeout: 0.0,
|
@@ -171,19 +179,17 @@ module OnebusawaySDK
|
|
171
179
|
@max_retry_delay = max_retry_delay
|
172
180
|
end
|
173
181
|
|
174
|
-
# @private
|
182
|
+
# @api private
|
175
183
|
#
|
176
184
|
# @return [Hash{String=>String}]
|
177
|
-
#
|
178
185
|
private def auth_query = {}
|
179
186
|
|
180
|
-
# @private
|
187
|
+
# @api private
|
181
188
|
#
|
182
189
|
# @return [String]
|
183
|
-
#
|
184
190
|
private def generate_idempotency_key = "stainless-ruby-retry-#{SecureRandom.uuid}"
|
185
191
|
|
186
|
-
# @private
|
192
|
+
# @api private
|
187
193
|
#
|
188
194
|
# @param req [Hash{Symbol=>Object}] .
|
189
195
|
#
|
@@ -220,7 +226,6 @@ module OnebusawaySDK
|
|
220
226
|
# @option opts [Float, nil] :timeout
|
221
227
|
#
|
222
228
|
# @return [Hash{Symbol=>Object}]
|
223
|
-
#
|
224
229
|
private def build_request(req, opts)
|
225
230
|
method, uninterpolated_path = req.fetch_values(:method, :path)
|
226
231
|
|
@@ -245,8 +250,8 @@ module OnebusawaySDK
|
|
245
250
|
end
|
246
251
|
|
247
252
|
timeout = opts.fetch(:timeout, @timeout).to_f.clamp((0..))
|
248
|
-
unless headers.key?("x-stainless-
|
249
|
-
headers["x-stainless-
|
253
|
+
unless headers.key?("x-stainless-timeout") || timeout.zero?
|
254
|
+
headers["x-stainless-timeout"] = timeout.to_s
|
250
255
|
end
|
251
256
|
|
252
257
|
headers.reject! { |_, v| v.to_s.empty? }
|
@@ -270,13 +275,12 @@ module OnebusawaySDK
|
|
270
275
|
}
|
271
276
|
end
|
272
277
|
|
273
|
-
# @private
|
278
|
+
# @api private
|
274
279
|
#
|
275
280
|
# @param headers [Hash{String=>String}]
|
276
281
|
# @param retry_count [Integer]
|
277
282
|
#
|
278
283
|
# @return [Float]
|
279
|
-
#
|
280
284
|
private def retry_delay(headers, retry_count:)
|
281
285
|
# Non-standard extension
|
282
286
|
span = Float(headers["retry-after-ms"], exception: false)&.then { _1 / 1000 }
|
@@ -297,7 +301,7 @@ module OnebusawaySDK
|
|
297
301
|
(@initial_retry_delay * scale * jitter).clamp(0, @max_retry_delay)
|
298
302
|
end
|
299
303
|
|
300
|
-
# @private
|
304
|
+
# @api private
|
301
305
|
#
|
302
306
|
# @param request [Hash{Symbol=>Object}] .
|
303
307
|
#
|
@@ -321,7 +325,6 @@ module OnebusawaySDK
|
|
321
325
|
#
|
322
326
|
# @raise [OnebusawaySDK::APIError]
|
323
327
|
# @return [Array(Integer, Net::HTTPResponse, Enumerable)]
|
324
|
-
#
|
325
328
|
private def send_request(request, redirect_count:, retry_count:, send_retry_header:)
|
326
329
|
url, headers, max_retries, timeout = request.fetch_values(:url, :headers, :max_retries, :timeout)
|
327
330
|
input = {**request.except(:timeout), deadline: OnebusawaySDK::Util.monotonic_secs + timeout}
|
@@ -331,28 +334,23 @@ module OnebusawaySDK
|
|
331
334
|
end
|
332
335
|
|
333
336
|
begin
|
334
|
-
response, stream = @requester.execute(input)
|
335
|
-
status = Integer(response.code)
|
337
|
+
status, response, stream = @requester.execute(input)
|
336
338
|
rescue OnebusawaySDK::APIConnectionError => e
|
337
339
|
status = e
|
338
340
|
end
|
339
341
|
|
340
|
-
# normally we want to drain the response body and reuse the HTTP session by clearing the socket buffers
|
341
|
-
# unless we hit a server error
|
342
|
-
srv_fault = (500...).include?(status)
|
343
|
-
|
344
342
|
case status
|
345
343
|
in ..299
|
346
344
|
[status, response, stream]
|
347
345
|
in 300..399 if redirect_count >= self.class::MAX_REDIRECTS
|
348
|
-
|
346
|
+
self.class.reap_connection!(status, stream: stream)
|
349
347
|
|
350
|
-
|
348
|
+
message = "Failed to complete the request within #{self.class::MAX_REDIRECTS} redirects."
|
351
349
|
raise OnebusawaySDK::APIConnectionError.new(url: url, message: message)
|
352
350
|
in 300..399
|
353
|
-
|
351
|
+
self.class.reap_connection!(status, stream: stream)
|
354
352
|
|
355
|
-
|
353
|
+
request = self.class.follow_redirect(request, status: status, response_headers: response)
|
356
354
|
send_request(
|
357
355
|
request,
|
358
356
|
redirect_count: redirect_count + 1,
|
@@ -362,12 +360,10 @@ module OnebusawaySDK
|
|
362
360
|
in OnebusawaySDK::APIConnectionError if retry_count >= max_retries
|
363
361
|
raise status
|
364
362
|
in (400..) if retry_count >= max_retries || !self.class.should_retry?(status, headers: response)
|
365
|
-
decoded =
|
366
|
-
|
367
|
-
|
368
|
-
|
369
|
-
else
|
370
|
-
stream.each { next }
|
363
|
+
decoded = Kernel.then do
|
364
|
+
OnebusawaySDK::Util.decode_content(response, stream: stream, suppress_error: true)
|
365
|
+
ensure
|
366
|
+
self.class.reap_connection!(status, stream: stream)
|
371
367
|
end
|
372
368
|
|
373
369
|
raise OnebusawaySDK::APIStatusError.for(
|
@@ -378,13 +374,9 @@ module OnebusawaySDK
|
|
378
374
|
response: response
|
379
375
|
)
|
380
376
|
in (400..) | OnebusawaySDK::APIConnectionError
|
381
|
-
|
377
|
+
self.class.reap_connection!(status, stream: stream)
|
382
378
|
|
383
|
-
|
384
|
-
OnebusawaySDK::Util.close_fused!(stream)
|
385
|
-
else
|
386
|
-
stream&.each { next }
|
387
|
-
end
|
379
|
+
delay = retry_delay(response, retry_count: retry_count)
|
388
380
|
sleep(delay)
|
389
381
|
|
390
382
|
send_request(
|
@@ -423,7 +415,6 @@ module OnebusawaySDK
|
|
423
415
|
#
|
424
416
|
# @raise [OnebusawaySDK::APIError]
|
425
417
|
# @return [Object]
|
426
|
-
#
|
427
418
|
def request(req)
|
428
419
|
self.class.validate!(req)
|
429
420
|
model = req.fetch(:model) { OnebusawaySDK::Unknown }
|
@@ -446,7 +437,7 @@ module OnebusawaySDK
|
|
446
437
|
in { stream: Class => st }
|
447
438
|
st.new(model: model, url: url, status: status, response: response, messages: decoded)
|
448
439
|
in { page: Class => page }
|
449
|
-
page.new(client: self, req: req, headers: response,
|
440
|
+
page.new(client: self, req: req, headers: response, page_data: decoded)
|
450
441
|
else
|
451
442
|
unwrapped = OnebusawaySDK::Util.dig(decoded, req[:unwrap])
|
452
443
|
OnebusawaySDK::Converter.coerce(model, unwrapped)
|
@@ -454,10 +445,11 @@ module OnebusawaySDK
|
|
454
445
|
end
|
455
446
|
|
456
447
|
# @return [String]
|
457
|
-
#
|
458
448
|
def inspect
|
449
|
+
# rubocop:disable Layout/LineLength
|
459
450
|
base_url = OnebusawaySDK::Util.unparse_uri(@base_url)
|
460
451
|
"#<#{self.class.name}:0x#{object_id.to_s(16)} base_url=#{base_url} max_retries=#{@max_retries} timeout=#{@timeout}>"
|
452
|
+
# rubocop:enable Layout/LineLength
|
461
453
|
end
|
462
454
|
end
|
463
455
|
end
|