guesty-client 0.2.1 → 0.2.3
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 +25 -1
- data/lib/guesty/access_tokens/upsert.rb +24 -3
- data/lib/guesty/reservations/resolutions/index.rb +55 -0
- data/lib/guesty/version.rb +1 -1
- data/lib/guesty.rb +1 -0
- data/sig/guesty.rbs +19 -0
- metadata +3 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 81b130a2500214e38bcdf321b7da4a9270e26885435bdca751578a8041f97c9c
|
|
4
|
+
data.tar.gz: a9beb0d022fd1915aaa09478a3371ee3d12d803c9072384d3e8bc653382b13db
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: e72fa07f7d987c3a375efb6b2c46d7f80b0aa27d97dc8fba3ea537f70041a898dc667f6b13a6a064ba85586fa1516ac13d572f805493a094e698eec08fe3296d
|
|
7
|
+
data.tar.gz: 02ac8280a331175279ca17eda6295acd4e4ad89a7516b7341451ea61a3cef03a34da0ec1364e00cc26c571cf563f70f40bb80ab76aec712ea30d94111daae26a
|
data/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,27 @@
|
|
|
2
2
|
|
|
3
3
|
## [Unreleased]
|
|
4
4
|
|
|
5
|
+
## [0.2.3] - 2026-11-22
|
|
6
|
+
|
|
7
|
+
### Fixed
|
|
8
|
+
|
|
9
|
+
- `AccessTokens::Upsert` can no longer take a priority offline when Guesty's token endpoint fails. Guesty counts every
|
|
10
|
+
token request, 502 answers included, against 5 per day per client id and answers 429 until 00:00 UTC. Minting is now
|
|
11
|
+
throttled per slot through `Guesty.config.rate_limiter` (`guesty_token_mint_<slot>`, once per 10 minutes, a throttled
|
|
12
|
+
caller raises `ThrottledError` without a request); a token expiring within 30 minutes is refreshed ahead and kept
|
|
13
|
+
when the mint fails; a slot with no valid token borrows another slot's valid token (never saved under the dead slot,
|
|
14
|
+
which keeps minting for itself) and raises the original error only when no slot has one.
|
|
15
|
+
|
|
16
|
+
## [0.2.2] - 2026-11-19
|
|
17
|
+
|
|
18
|
+
### Added
|
|
19
|
+
|
|
20
|
+
- `Reservations::Resolutions::Index` reads `GET /airbnb-resolutions-center/reservations/{id}/resolutions`, the
|
|
21
|
+
reservation's closed Airbnb Resolution Center requests created in the `created_at:` Range (both ends required).
|
|
22
|
+
Each comes back as `{ external_id:, state:, amount_paid:, currency:, closed_at: }`: `external_id` is Airbnb's
|
|
23
|
+
request id (as in `airbnb.com/resolutions/<id>`), `state` the lowercased status (`CLOSED_STATE`) and `closed_at`
|
|
24
|
+
Airbnb's last update.
|
|
25
|
+
|
|
5
26
|
## [0.2.1] - 2026-11-18
|
|
6
27
|
|
|
7
28
|
### Added
|
|
@@ -95,6 +116,9 @@ that integration's provider specs, ported with their recorded VCR cassettes.
|
|
|
95
116
|
- Webhooks: `Index`, `Create`, `Update`, `Sync`, `Signatures::Verify` for Svix signatures.
|
|
96
117
|
- Views: `Create`, `Update`.
|
|
97
118
|
|
|
98
|
-
[Unreleased]: https://github.com/guestitab/guesty-client/compare/v0.2.
|
|
119
|
+
[Unreleased]: https://github.com/guestitab/guesty-client/compare/v0.2.3...staging
|
|
120
|
+
[0.2.3]: https://github.com/guestitab/guesty-client/compare/v0.2.2...v0.2.3
|
|
121
|
+
[0.2.2]: https://github.com/guestitab/guesty-client/compare/v0.2.1...v0.2.2
|
|
122
|
+
[0.2.1]: https://github.com/guestitab/guesty-client/compare/v0.2.0...v0.2.1
|
|
99
123
|
[0.2.0]: https://github.com/guestitab/guesty-client/compare/v0.1.0...v0.2.0
|
|
100
124
|
[0.1.0]: https://github.com/guestitab/guesty-client/releases/tag/v0.1.0
|
|
@@ -1,17 +1,19 @@
|
|
|
1
1
|
module Guesty
|
|
2
2
|
module AccessTokens
|
|
3
|
-
# Guesty mints only 5 access tokens per client id within 24 hours and
|
|
4
|
-
# answers 429 to everything after, so a token must never be discarded.
|
|
5
3
|
class Upsert
|
|
6
4
|
include Guesty::Operation
|
|
7
5
|
|
|
8
6
|
OAUTH_ENDPOINT = 'https://open-api.guesty.com/oauth2/token'.freeze #: ::String
|
|
7
|
+
MINT_INTERVAL = 10.minutes #: untyped
|
|
8
|
+
REFRESH_WINDOW = 30.minutes #: untyped
|
|
9
9
|
|
|
10
10
|
# @rbs () -> Dry::Monads::Result[untyped]
|
|
11
11
|
def call
|
|
12
12
|
slot = Guesty.current_slot
|
|
13
|
+
token = store.read(slot[:key])
|
|
14
|
+
return Success(token) if token && token.expires_at > REFRESH_WINDOW.from_now
|
|
13
15
|
|
|
14
|
-
Success(
|
|
16
|
+
Success(mint_or_fallback(slot, token))
|
|
15
17
|
end
|
|
16
18
|
|
|
17
19
|
private
|
|
@@ -20,8 +22,27 @@ module Guesty
|
|
|
20
22
|
Guesty.config.token_store
|
|
21
23
|
end
|
|
22
24
|
|
|
25
|
+
# A token must never be discarded: Guesty mints only 5 access tokens per client id per day, counts every
|
|
26
|
+
# token request (502 answers included) and answers 429 to everything after, until 00:00 UTC. A failed or
|
|
27
|
+
# throttled mint keeps the stored token, or borrows another slot's, and never saves the borrowed one here.
|
|
28
|
+
# @rbs (Guesty::slot slot, untyped token) -> untyped
|
|
29
|
+
def mint_or_fallback(slot, token)
|
|
30
|
+
mint(slot)
|
|
31
|
+
rescue Guesty::Error, Faraday::Error => e
|
|
32
|
+
token || borrowed_token || raise(e)
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
# @rbs () -> untyped
|
|
36
|
+
def borrowed_token
|
|
37
|
+
slots = (Guesty.config.credentials.keys - [:webhook_key]).flat_map { |priority| Guesty.token_slots(priority) }
|
|
38
|
+
|
|
39
|
+
slots.lazy.filter_map { |slot| store.read(slot[:key]) }.first
|
|
40
|
+
end
|
|
41
|
+
|
|
23
42
|
# @rbs (Guesty::slot slot) -> untyped
|
|
24
43
|
def mint(slot)
|
|
44
|
+
Guesty.config.rate_limiter.throttle!(key: :"guesty_token_mint_#{slot[:key]}", threshold: 1, interval: MINT_INTERVAL)
|
|
45
|
+
|
|
25
46
|
response = Guesty.connection(url: OAUTH_ENDPOINT, skip_auth: true).post do |req|
|
|
26
47
|
req.headers['Content-Type'] = 'application/x-www-form-urlencoded'
|
|
27
48
|
req.body = { grant_type: 'client_credentials', scope: 'open-api', client_secret: slot[:secret], client_id: slot[:client_id] }
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
module Guesty
|
|
2
|
+
module Reservations
|
|
3
|
+
module Resolutions
|
|
4
|
+
# Airbnb Resolution Center: Guesty lists only closed resolutions, about a day after Airbnb closes them,
|
|
5
|
+
# and filters them by their creation time.
|
|
6
|
+
class Index
|
|
7
|
+
include Guesty::Operation
|
|
8
|
+
|
|
9
|
+
CLOSED_STATE = 'closed'.freeze #: ::String
|
|
10
|
+
INVALID_RESPONSE = 'Guesty resolutions response has an unexpected shape.'.freeze #: ::String
|
|
11
|
+
|
|
12
|
+
# @rbs (reservation_id: ::String, created_at: ::Range[::Time | ::ActiveSupport::TimeWithZone]) -> Dry::Monads::Result[::Array[untyped]]
|
|
13
|
+
def call(reservation_id:, created_at:)
|
|
14
|
+
argument! reservation_id: :required if reservation_id.blank?
|
|
15
|
+
argument! created_at: :invalid unless created_at.is_a?(Range) && created_at.begin && created_at.end
|
|
16
|
+
|
|
17
|
+
body = request(:get, "airbnb-resolutions-center/reservations/#{reservation_id}/resolutions", query(created_at))
|
|
18
|
+
|
|
19
|
+
Success(normalize_response(body))
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
private
|
|
23
|
+
|
|
24
|
+
# @rbs (::Range[::Time | ::ActiveSupport::TimeWithZone] created_at) -> ::Hash[::Symbol, ::String]
|
|
25
|
+
def query(created_at)
|
|
26
|
+
{
|
|
27
|
+
from: created_at.begin.utc.iso8601,
|
|
28
|
+
to: created_at.end.utc.iso8601
|
|
29
|
+
}
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
# @rbs (untyped body) -> ::Array[untyped]
|
|
33
|
+
def normalize_response(body)
|
|
34
|
+
resolutions = body[:resolutions] if body.is_a?(Hash)
|
|
35
|
+
error! INVALID_RESPONSE unless resolutions.is_a?(Array)
|
|
36
|
+
|
|
37
|
+
resolutions.map { |resolution| normalize_resolution(resolution) }
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
# @rbs (untyped resolution) -> untyped
|
|
41
|
+
def normalize_resolution(resolution)
|
|
42
|
+
updated_at = resolution[:airbnbUpdatedAt]
|
|
43
|
+
|
|
44
|
+
{
|
|
45
|
+
external_id: resolution.fetch(:resolutionId),
|
|
46
|
+
state: resolution[:statusName]&.downcase,
|
|
47
|
+
amount_paid: resolution[:totalAmountPaid]&.to_d,
|
|
48
|
+
currency: resolution[:currency],
|
|
49
|
+
closed_at: (Time.iso8601(updated_at) if updated_at.present?)
|
|
50
|
+
}
|
|
51
|
+
end
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
end
|
data/lib/guesty/version.rb
CHANGED
data/lib/guesty.rb
CHANGED
|
@@ -48,6 +48,7 @@ require_relative 'guesty/reservations/index'
|
|
|
48
48
|
require_relative 'guesty/reservations/pre_approve'
|
|
49
49
|
require_relative 'guesty/reservations/recover'
|
|
50
50
|
require_relative 'guesty/reservations/relocate'
|
|
51
|
+
require_relative 'guesty/reservations/resolutions/index'
|
|
51
52
|
require_relative 'guesty/reservations/reviews/extractors/base'
|
|
52
53
|
require_relative 'guesty/reservations/reviews/extractors/airbnb'
|
|
53
54
|
require_relative 'guesty/reservations/reviews/extractors/booking_com'
|
data/sig/guesty.rbs
CHANGED
|
@@ -106,6 +106,8 @@ module Guesty
|
|
|
106
106
|
module AccessTokens
|
|
107
107
|
class Upsert
|
|
108
108
|
OAUTH_ENDPOINT: ::String
|
|
109
|
+
MINT_INTERVAL: untyped
|
|
110
|
+
REFRESH_WINDOW: untyped
|
|
109
111
|
|
|
110
112
|
def call: () -> ::Dry::Monads::Result[untyped]
|
|
111
113
|
alias call! call
|
|
@@ -238,6 +240,23 @@ module Guesty
|
|
|
238
240
|
end
|
|
239
241
|
end
|
|
240
242
|
|
|
243
|
+
module Resolutions
|
|
244
|
+
class Index
|
|
245
|
+
CLOSED_STATE: ::String
|
|
246
|
+
|
|
247
|
+
type resolution = {
|
|
248
|
+
external_id: ::String,
|
|
249
|
+
state: ::String?,
|
|
250
|
+
amount_paid: ::BigDecimal?,
|
|
251
|
+
currency: ::String?,
|
|
252
|
+
closed_at: ::Time?
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
def call: (reservation_id: ::String, created_at: ::Range[::Time | ::ActiveSupport::TimeWithZone]) -> ::Dry::Monads::Result[::Array[resolution]]
|
|
256
|
+
alias call! call
|
|
257
|
+
end
|
|
258
|
+
end
|
|
259
|
+
|
|
241
260
|
module Reviews
|
|
242
261
|
class Index
|
|
243
262
|
def call: (since: ::Time, ?skip: ::Integer, ?take: ::Integer) -> ::Dry::Monads::Result[::Array[::Hash[::Symbol, untyped]]]
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: guesty-client
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.2.
|
|
4
|
+
version: 0.2.3
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Guestit
|
|
@@ -146,6 +146,7 @@ files:
|
|
|
146
146
|
- lib/guesty/reservations/pre_approve.rb
|
|
147
147
|
- lib/guesty/reservations/recover.rb
|
|
148
148
|
- lib/guesty/reservations/relocate.rb
|
|
149
|
+
- lib/guesty/reservations/resolutions/index.rb
|
|
149
150
|
- lib/guesty/reservations/reviews/extractors/airbnb.rb
|
|
150
151
|
- lib/guesty/reservations/reviews/extractors/base.rb
|
|
151
152
|
- lib/guesty/reservations/reviews/extractors/booking_com.rb
|
|
@@ -189,7 +190,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
189
190
|
- !ruby/object:Gem::Version
|
|
190
191
|
version: '0'
|
|
191
192
|
requirements: []
|
|
192
|
-
rubygems_version: 4.0.
|
|
193
|
+
rubygems_version: 4.0.20
|
|
193
194
|
specification_version: 4
|
|
194
195
|
summary: Ruby client for the Guesty Open API
|
|
195
196
|
test_files: []
|