guesty-client 0.1.0 → 0.2.1

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.
Files changed (63) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +67 -1
  3. data/README.md +2 -3
  4. data/lib/guesty/access_tokens/upsert.rb +8 -34
  5. data/lib/guesty/api_error.rb +8 -16
  6. data/lib/guesty/client.rb +6 -12
  7. data/lib/guesty/config.rb +1 -16
  8. data/lib/guesty/conversations/attachments/index.rb +2 -6
  9. data/lib/guesty/conversations/index.rb +14 -32
  10. data/lib/guesty/conversations/messages/reply.rb +2 -24
  11. data/lib/guesty/conversations/posts/index.rb +18 -25
  12. data/lib/guesty/conversations/posts/since.rb +0 -1
  13. data/lib/guesty/conversations/search.rb +2 -5
  14. data/lib/guesty/conversations/show.rb +1 -10
  15. data/lib/guesty/conversations.rb +5 -1
  16. data/lib/guesty/error.rb +0 -4
  17. data/lib/guesty/guest_folio/invoice_items/index.rb +2 -6
  18. data/lib/guesty/guests/profiles/create.rb +1 -5
  19. data/lib/guesty/guests/profiles/show.rb +1 -8
  20. data/lib/guesty/guests/profiles/update.rb +2 -7
  21. data/lib/guesty/homes/calendars/show.rb +29 -68
  22. data/lib/guesty/homes/search.rb +4 -23
  23. data/lib/guesty/memory_rate_limiter.rb +0 -3
  24. data/lib/guesty/memory_token_store.rb +0 -8
  25. data/lib/guesty/operation.rb +5 -3
  26. data/lib/guesty/payments/index.rb +14 -0
  27. data/lib/guesty/payments/record.rb +59 -0
  28. data/lib/guesty/rate_limiter_middleware.rb +2 -15
  29. data/lib/guesty/reservations/accommodation_fare/update.rb +4 -5
  30. data/lib/guesty/reservations/approve.rb +2 -8
  31. data/lib/guesty/reservations/booking_date/update.rb +19 -0
  32. data/lib/guesty/reservations/confirmation_code/update.rb +22 -0
  33. data/lib/guesty/reservations/create.rb +1 -8
  34. data/lib/guesty/reservations/custom_fields/update.rb +2 -11
  35. data/lib/guesty/reservations/dates/update.rb +2 -8
  36. data/lib/guesty/reservations/decline.rb +1 -11
  37. data/lib/guesty/reservations/guests/update.rb +43 -0
  38. data/lib/guesty/reservations/index.rb +18 -0
  39. data/lib/guesty/reservations/pre_approve.rb +2 -8
  40. data/lib/guesty/reservations/recover.rb +3 -11
  41. data/lib/guesty/reservations/relocate.rb +18 -0
  42. data/lib/guesty/reservations/reviews/extractors/airbnb.rb +0 -1
  43. data/lib/guesty/reservations/reviews/index.rb +17 -42
  44. data/lib/guesty/reservations/search.rb +58 -35
  45. data/lib/guesty/reservations/show.rb +7 -16
  46. data/lib/guesty/reservations/source/update.rb +19 -0
  47. data/lib/guesty/reservations/status/update.rb +1 -3
  48. data/lib/guesty/reviews/respond.rb +1 -3
  49. data/lib/guesty/version.rb +1 -1
  50. data/lib/guesty/views/create.rb +1 -5
  51. data/lib/guesty/views/update.rb +1 -19
  52. data/lib/guesty/webhooks/create.rb +1 -7
  53. data/lib/guesty/webhooks/index.rb +1 -7
  54. data/lib/guesty/webhooks/signatures/verify.rb +3 -6
  55. data/lib/guesty/webhooks/sync.rb +0 -3
  56. data/lib/guesty/webhooks/update.rb +1 -7
  57. data/lib/guesty.rb +8 -4
  58. data/sig/guesty.rbs +53 -30
  59. metadata +9 -5
  60. data/lib/guesty/reservations/flags/update.rb +0 -33
  61. data/lib/guesty/reservations/payments/create.rb +0 -72
  62. data/lib/guesty/reservations/stays/update.rb +0 -42
  63. data/lib/guesty/reservations/update.rb +0 -19
data/sig/guesty.rbs CHANGED
@@ -24,7 +24,6 @@ module Guesty
24
24
  def self.rate_limit_key: (::Symbol window) -> ::Symbol
25
25
  def self.token_slots: (?::Symbol priority) -> ::Array[slot]
26
26
  def self.webhook_key: () -> ::String?
27
- def self.sync_guest_and_reservation_changes?: () -> bool
28
27
  def self.pick_slot: (::Symbol priority) -> slot
29
28
  def self.successful_response?: (untyped response) -> bool
30
29
  def self.retryable_read?: (::StandardError error) -> bool
@@ -74,8 +73,6 @@ module Guesty
74
73
  attr_accessor rate_limiter: untyped
75
74
  attr_accessor slot_picker: untyped
76
75
  attr_accessor base_url: ::String
77
- attr_accessor sync_guest_and_reservation_changes: bool
78
- attr_accessor custom_fields: ::Hash[::Symbol, ::String]
79
76
  attr_accessor default_currency: ::String?
80
77
  end
81
78
 
@@ -90,7 +87,6 @@ module Guesty
90
87
 
91
88
  def read: (::String slot_key) -> Token?
92
89
  def save: (slot_key: ::String, access_token: ::String, expires_at: ::Time) -> Token
93
- def clear: () -> ::Hash[untyped, untyped]
94
90
  end
95
91
 
96
92
  class MemoryRateLimiter
@@ -98,7 +94,6 @@ module Guesty
98
94
  end
99
95
 
100
96
  class RateLimiterMiddleware
101
- def initialize: (untyped app, ?::Hash[::Symbol, untyped] options) -> void
102
97
  def on_request: (untyped env) -> void
103
98
  end
104
99
 
@@ -124,15 +119,24 @@ module Guesty
124
119
  def self.from_conversation: (untyped conversation) -> ::Array[::Hash[::Symbol, untyped]]
125
120
 
126
121
  class Search
127
- FILTER_MAPPINGS: ::Hash[::Symbol, ::Hash[::Symbol, ::String]]
122
+ FILTER_MAPPINGS: ::Hash[::Symbol, ::Hash[::Symbol, untyped]]
123
+ SORTS: ::Array[::String]
124
+ TAKE: ::Integer
128
125
 
129
- def self.filters: (::Hash[::Symbol, untyped] attributes) -> ::Array[::Hash[::Symbol, untyped]]
130
- def call: (fields: ::Array[::String], attributes: ::Hash[::Symbol, untyped], ?skip: ::Integer, ?take: ::Integer) -> ::Dry::Monads::Result[::Hash[::Symbol, untyped]]
126
+ def self.filters: (::Hash[::Symbol, untyped] attributes) -> ::Array[::Hash[::Symbol, ::String]]
127
+ def call: (attributes: ::Hash[::Symbol, untyped], ?skip: ::Integer, ?take: ::Integer, ?sort: ::String) -> ::Dry::Monads::Result[::Hash[::Symbol, untyped]]
131
128
  alias call! call
132
129
  end
133
130
 
134
131
  class Show
135
- def call: (reservation_id: ::String, fields: ::Array[::String]) -> ::Dry::Monads::Result[::Hash[::Symbol, untyped]]
132
+ def call: (reservation_id: ::String) -> ::Dry::Monads::Result[::Hash[::Symbol, untyped]]
133
+ alias call! call
134
+ end
135
+
136
+ class Index
137
+ TAKE: ::Integer
138
+
139
+ def call: (reservation_ids: ::Array[::String]) -> ::Dry::Monads::Result[::Array[::Hash[::Symbol, untyped]]]
136
140
  alias call! call
137
141
  end
138
142
 
@@ -141,8 +145,8 @@ module Guesty
141
145
  alias call! call
142
146
  end
143
147
 
144
- class Update
145
- def call: (reservation_id: ::String, attributes: ::Hash[::Symbol, untyped]) -> ::Dry::Monads::Result[bool]
148
+ class Relocate
149
+ def call: (reservation_id: ::String, listing_id: ::String, ?ignore_calendar: bool?, ?ignore_terms: bool?, ?ignore_blocks: bool?) -> ::Dry::Monads::Result[bool]
146
150
  alias call! call
147
151
  end
148
152
 
@@ -187,16 +191,32 @@ module Guesty
187
191
  end
188
192
  end
189
193
 
190
- module Stays
194
+ module Guests
195
+ class Update
196
+ def call: (reservation_id: ::String, attributes: ::Hash[::Symbol, untyped]) -> ::Dry::Monads::Result[bool]
197
+ alias call! call
198
+ end
199
+ end
200
+
201
+ module ConfirmationCode
202
+ class Update
203
+ LENGTH: ::Range
204
+
205
+ def call: (reservation_id: ::String, confirmation_code: ::String) -> ::Dry::Monads::Result[bool]
206
+ alias call! call
207
+ end
208
+ end
209
+
210
+ module Source
191
211
  class Update
192
- def call: (reservation_id: ::String, stay: ::Hash[::Symbol, untyped]) -> ::Dry::Monads::Result[bool]
212
+ def call: (reservation_id: ::String, source: ::String, ?point_of_sale: ::String?, ?apply_recalculation: bool?) -> ::Dry::Monads::Result[bool]
193
213
  alias call! call
194
214
  end
195
215
  end
196
216
 
197
- module Flags
217
+ module BookingDate
198
218
  class Update
199
- def call: (reservation_id: ::String, flags: ::Hash[::Symbol, bool]) -> ::Dry::Monads::Result[bool]
219
+ def call: (reservation_id: ::String, booking_date: ::Time) -> ::Dry::Monads::Result[bool]
200
220
  alias call! call
201
221
  end
202
222
  end
@@ -213,17 +233,7 @@ module Guesty
213
233
 
214
234
  module CustomFields
215
235
  class Update
216
- def call: (reservation_id: ::String, custom_fields: ::Array[::Hash[::Symbol, untyped]]) -> ::Dry::Monads::Result[::Hash[::Symbol, untyped]]
217
- alias call! call
218
- end
219
- end
220
-
221
- module Payments
222
- class Create
223
- PAYMENT_METHOD_NAME: ::String
224
- HISTORY_UNAVAILABLE: ::String
225
-
226
- def call: (reservation_id: ::String, attributes: ::Hash[::Symbol, untyped]) -> ::Dry::Monads::Result[::Hash[::Symbol, untyped]]
236
+ def call: (reservation_id: ::String, custom_fields: ::Array[::Hash[::Symbol, untyped]]) -> ::Dry::Monads::Result[untyped]
227
237
  alias call! call
228
238
  end
229
239
  end
@@ -256,6 +266,7 @@ module Guesty
256
266
  CHANNELS: ::Hash[::String, ::String]
257
267
 
258
268
  def self.channel: (::String module_type) -> ::String
269
+ def self.summary: (untyped conversation) -> ::Hash[::Symbol, untyped]
259
270
 
260
271
  class Index
261
272
  FIELDS: ::String
@@ -283,6 +294,7 @@ module Guesty
283
294
  module Posts
284
295
  class Index
285
296
  LIMIT: ::Integer
297
+ CHANNEL_SENDER: ::String
286
298
 
287
299
  def call: (conversation_id: ::String, ?cursor: ::String?) -> ::Dry::Monads::Result[::Hash[::Symbol, untyped]]
288
300
  alias call! call
@@ -298,10 +310,6 @@ module Guesty
298
310
 
299
311
  module Messages
300
312
  class Reply
301
- BOOKING_MODULE_TYPES: ::Hash[::String, ::String]
302
-
303
- def self.module_type_for: (::String? channel_name) -> ::String?
304
-
305
313
  def call: (conversation_id: ::String, body: ::String, ?module_type: ::String?) -> ::Dry::Monads::Result[::Hash[::Symbol, untyped]]
306
314
  alias call! call
307
315
  end
@@ -317,6 +325,21 @@ module Guesty
317
325
  end
318
326
  end
319
327
 
328
+ module Payments
329
+ class Index
330
+ def call: (reservation_id: ::String) -> ::Dry::Monads::Result[::Hash[::Symbol, untyped]]
331
+ alias call! call
332
+ end
333
+
334
+ class Record
335
+ METHODS: ::Array[::String]
336
+ NOTE_MAX_LENGTH: ::Integer
337
+
338
+ def call: (reservation_id: ::String, attributes: ::Hash[::Symbol, untyped]) -> ::Dry::Monads::Result[::Hash[::Symbol, untyped]]
339
+ alias call! call
340
+ end
341
+ end
342
+
320
343
  module Guests
321
344
  OTA_LINK_TYPES: ::Hash[::Symbol, ::String]
322
345
 
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.1.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Guestit
@@ -129,18 +129,23 @@ files:
129
129
  - lib/guesty/memory_rate_limiter.rb
130
130
  - lib/guesty/memory_token_store.rb
131
131
  - lib/guesty/operation.rb
132
+ - lib/guesty/payments/index.rb
133
+ - lib/guesty/payments/record.rb
132
134
  - lib/guesty/rate_limiter_middleware.rb
133
135
  - lib/guesty/reservations.rb
134
136
  - lib/guesty/reservations/accommodation_fare/update.rb
135
137
  - lib/guesty/reservations/approve.rb
138
+ - lib/guesty/reservations/booking_date/update.rb
139
+ - lib/guesty/reservations/confirmation_code/update.rb
136
140
  - lib/guesty/reservations/create.rb
137
141
  - lib/guesty/reservations/custom_fields/update.rb
138
142
  - lib/guesty/reservations/dates/update.rb
139
143
  - lib/guesty/reservations/decline.rb
140
- - lib/guesty/reservations/flags/update.rb
141
- - lib/guesty/reservations/payments/create.rb
144
+ - lib/guesty/reservations/guests/update.rb
145
+ - lib/guesty/reservations/index.rb
142
146
  - lib/guesty/reservations/pre_approve.rb
143
147
  - lib/guesty/reservations/recover.rb
148
+ - lib/guesty/reservations/relocate.rb
144
149
  - lib/guesty/reservations/reviews/extractors/airbnb.rb
145
150
  - lib/guesty/reservations/reviews/extractors/base.rb
146
151
  - lib/guesty/reservations/reviews/extractors/booking_com.rb
@@ -148,10 +153,9 @@ files:
148
153
  - lib/guesty/reservations/reviews/index.rb
149
154
  - lib/guesty/reservations/search.rb
150
155
  - lib/guesty/reservations/show.rb
156
+ - lib/guesty/reservations/source/update.rb
151
157
  - lib/guesty/reservations/status/cancel.rb
152
158
  - lib/guesty/reservations/status/update.rb
153
- - lib/guesty/reservations/stays/update.rb
154
- - lib/guesty/reservations/update.rb
155
159
  - lib/guesty/reviews/respond.rb
156
160
  - lib/guesty/version.rb
157
161
  - lib/guesty/views/create.rb
@@ -1,33 +0,0 @@
1
- module Guesty
2
- module Reservations
3
- module Flags
4
- # Sets account custom fields on a reservation. The field ids are
5
- # account-specific, so the host injects them (Guesty.config.custom_fields,
6
- # keyed by flag name: blacklisted, grants_created, grants_partial).
7
- class Update
8
- include Guesty::Operation
9
-
10
- # @rbs (reservation_id: ::String, flags: ::Hash[::Symbol, bool]) -> Dry::Monads::Result[bool]
11
- def call(reservation_id:, flags:)
12
- custom_fields = flags.map { |name, value| { fieldId: field_ids.fetch(name), value: value.to_s } }
13
- body = { customFields: custom_fields }
14
- response = Guesty.do_request(
15
- :put,
16
- "reservations-v3/#{reservation_id}/custom-fields",
17
- body
18
- )
19
-
20
- raise response.failure if response.failure?
21
-
22
- Success(true)
23
- end
24
-
25
- private
26
-
27
- def field_ids
28
- Guesty.config.custom_fields
29
- end
30
- end
31
- end
32
- end
33
- end
@@ -1,72 +0,0 @@
1
- module Guesty
2
- module Reservations
3
- module Payments
4
- # Records a payment taken outside Guesty. Idempotent per payment intent:
5
- # a reservation already fully paid, or with a payment noting the intent,
6
- # is returned without a post.
7
- class Create
8
- include Guesty::Operation
9
-
10
- PAYMENT_METHOD_NAME = 'RECORDED_CASH'.freeze #: ::String
11
- HISTORY_UNAVAILABLE = 'Guesty has not returned the payment history yet. Try again later.'.freeze #: ::String
12
-
13
- # @rbs (reservation_id: ::String, attributes: ::Hash[::Symbol, untyped]) -> Dry::Monads::Result[::Hash[::Symbol, untyped]]
14
- def call(reservation_id:, attributes:)
15
- validate_arguments!(reservation_id:, attributes:)
16
-
17
- @reservation_id = reservation_id
18
-
19
- return Success(reservation) if fully_paid? || recorded?(attributes)
20
-
21
- response = Guesty.do_request :post, "reservations/#{reservation_id}/payments", payload(attributes), retries: 0
22
- return response unless response.success?
23
-
24
- Success(response.value!.body)
25
- end
26
-
27
- private
28
-
29
- def validate_arguments!(reservation_id:, attributes:)
30
- argument! reservation_id: :required if reservation_id.blank?
31
- argument! attributes: :required if attributes.blank?
32
- argument! amount: :required if attributes[:amount].blank?
33
- argument! amount: :must_be_positive if attributes[:amount].present? && attributes[:amount] <= 0
34
- argument! paid_at: :required if attributes[:paid_at].blank?
35
- argument! payment_intent_id: :required if attributes[:payment_intent_id].blank?
36
- end
37
-
38
- # @rbs () -> ::Hash[::Symbol, untyped]
39
- def reservation
40
- @reservation ||= Show.new.call!(reservation_id: @reservation_id, fields: %w[money.isFullyPaid money.payments money.totalPaid]).value!
41
- end
42
-
43
- # @rbs () -> bool
44
- def fully_paid?
45
- reservation[:money][:isFullyPaid]
46
- end
47
-
48
- # @rbs (::Hash[::Symbol, untyped] attributes) -> bool
49
- def recorded?(attributes)
50
- payments = reservation[:money][:payments]
51
-
52
- return payments.any? { |payment| payment[:note]&.include?(attributes[:payment_intent_id]) } if payments
53
- return false if reservation[:money][:totalPaid]&.zero?
54
-
55
- error! HISTORY_UNAVAILABLE
56
- end
57
-
58
- # @rbs (::Hash[::Symbol, untyped] attributes) -> ::Hash[::Symbol, untyped]
59
- def payload(attributes)
60
- {
61
- paymentMethod: {
62
- method: PAYMENT_METHOD_NAME
63
- },
64
- amount: attributes[:amount],
65
- paidAt: attributes[:paid_at].strftime('%Y-%m-%d'),
66
- note: "Payment recorded in Guestit.se / Stripe #{attributes[:payment_intent_id]}"
67
- }
68
- end
69
- end
70
- end
71
- end
72
- end
@@ -1,42 +0,0 @@
1
- module Guesty
2
- module Reservations
3
- module Stays
4
- class Update
5
- include Guesty::Operation
6
-
7
- # @rbs (reservation_id: ::String, stay: ::Hash[::Symbol, untyped]) -> Dry::Monads::Result[bool]
8
- def call(reservation_id:, stay:)
9
- response = Guesty.do_request(
10
- :put,
11
- "reservations/#{reservation_id}",
12
- stay_attributes(stay)
13
- )
14
-
15
- raise response.failure if response.failure?
16
-
17
- Success(true)
18
- end
19
-
20
- private
21
-
22
- # @rbs (::Hash[::Symbol, untyped] stay) -> ::Hash[::Symbol, untyped]
23
- def stay_attributes(stay)
24
- {
25
- checkInDateLocalized: stay.fetch(:start_date).iso8601,
26
- checkOutDateLocalized: stay.fetch(:end_date).iso8601,
27
- plannedArrival: stay.fetch(:check_in).strftime('%H:%M'),
28
- plannedDeparture: stay.fetch(:check_out).strftime('%H:%M'),
29
- guestsCount: stay.fetch(:num_guests),
30
- numberOfGuests: {
31
- numberOfAdults: stay.fetch(:adults),
32
- numberOfChildren: stay.fetch(:children)
33
- },
34
- ignoreCalendar: stay.fetch(:ignore_calendar),
35
- ignoreTerms: true,
36
- listingId: stay.fetch(:listing_external_id)
37
- }
38
- end
39
- end
40
- end
41
- end
42
- end
@@ -1,19 +0,0 @@
1
- module Guesty
2
- module Reservations
3
- class Update
4
- include Guesty::Operation
5
-
6
- # @rbs (reservation_id: ::String, attributes: ::Hash[::Symbol, untyped]) -> Dry::Monads::Result[bool]
7
- def call(reservation_id:, attributes:)
8
- argument! reservation_id: :required if reservation_id.blank?
9
- argument! attributes: :required if attributes.blank?
10
-
11
- response = Guesty.do_request :put, "reservations/#{reservation_id}", attributes
12
-
13
- raise response.failure unless response.success?
14
-
15
- Success(true)
16
- end
17
- end
18
- end
19
- end