bookingsync-api 0.0.8 → 0.0.9
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/.travis.yml +1 -1
- data/README.md +30 -0
- data/lib/bookingsync/api.rb +3 -3
- data/lib/bookingsync/api/client.rb +22 -2
- data/lib/bookingsync/api/client/bookings.rb +9 -7
- data/lib/bookingsync/api/client/inquiries.rb +6 -4
- data/lib/bookingsync/api/client/payments.rb +4 -4
- data/lib/bookingsync/api/client/periods.rb +14 -13
- data/lib/bookingsync/api/client/photos.rb +53 -0
- data/lib/bookingsync/api/client/rates_tables.rb +5 -5
- data/lib/bookingsync/api/client/rental_agreements.rb +22 -19
- data/lib/bookingsync/api/client/rentals.rb +7 -6
- data/lib/bookingsync/api/client/reviews.rb +6 -5
- data/lib/bookingsync/api/client/seasons.rb +15 -13
- data/lib/bookingsync/api/client/special_offers.rb +19 -18
- data/lib/bookingsync/api/error.rb +18 -0
- data/lib/bookingsync/api/middleware/logger.rb +50 -0
- data/lib/bookingsync/api/version.rb +1 -1
- data/spec/bookingsync/api/client/bookings_spec.rb +5 -4
- data/spec/bookingsync/api/client/inquiries_spec.rb +4 -3
- data/spec/bookingsync/api/client/periods_spec.rb +9 -14
- data/spec/bookingsync/api/client/photos_spec.rb +58 -0
- data/spec/bookingsync/api/client/rental_agreements_spec.rb +10 -10
- data/spec/bookingsync/api/client/rentals_spec.rb +3 -3
- data/spec/bookingsync/api/client/reviews_spec.rb +5 -4
- data/spec/bookingsync/api/client/seasons_spec.rb +5 -4
- data/spec/bookingsync/api/client/special_offers_spec.rb +5 -4
- data/spec/bookingsync/api/client_spec.rb +43 -3
- data/spec/{cassettes → fixtures/cassettes}/BookingSync_API_Client_Amenities/_amenities/returns_amenities.yml +1 -1
- data/spec/{cassettes → fixtures/cassettes}/BookingSync_API_Client_BillingAddresses/_billing_addresses/returns_billing_addresses.yml +1 -1
- data/spec/{cassettes → fixtures/cassettes}/BookingSync_API_Client_Bookings/_bookings/pagination/with_a_block/yields_block_with_batch_of_bookings.yml +0 -0
- data/spec/{cassettes → fixtures/cassettes}/BookingSync_API_Client_Bookings/_bookings/pagination/with_auto_paginate_true/returns_all_bookings_joined_from_many_requests.yml +0 -0
- data/spec/{cassettes → fixtures/cassettes}/BookingSync_API_Client_Bookings/_bookings/pagination/with_per_page_setting/returns_limited_number_of_bookings.yml +0 -0
- data/spec/{cassettes → fixtures/cassettes}/BookingSync_API_Client_Bookings/_bookings/returns_bookings.yml +0 -0
- data/spec/{cassettes → fixtures/cassettes}/BookingSync_API_Client_Bookings/_cancel_booking/cancels_given_booking.yml +0 -0
- data/spec/{cassettes → fixtures/cassettes}/BookingSync_API_Client_Bookings/_clients/returns_clients.yml +0 -0
- data/spec/{cassettes → fixtures/cassettes}/BookingSync_API_Client_Bookings/_create_booking/creates_a_booking.yml +1 -1
- data/spec/{cassettes → fixtures/cassettes}/BookingSync_API_Client_Bookings/_create_client/creates_a_new_client.yml +0 -0
- data/spec/{cassettes → fixtures/cassettes}/BookingSync_API_Client_Bookings/_edit_booking/updates_given_booking_by_ID.yml +0 -0
- data/spec/{cassettes → fixtures/cassettes}/BookingSync_API_Client_Bookings/_edit_client/updates_given_client_by_ID.yml +0 -0
- data/spec/{cassettes → fixtures/cassettes}/BookingSync_API_Client_BookingsPayments/_bookings_payments/returns_bookings_payments.yml +1 -1
- data/spec/{cassettes → fixtures/cassettes}/BookingSync_API_Client_Destinations/_destinations/returns_destinations.yml +1 -1
- data/spec/{cassettes → fixtures/cassettes}/BookingSync_API_Client_Inquiries/_create_inquiry/creates_a_new_inquiry.yml +1 -1
- data/spec/{cassettes → fixtures/cassettes}/BookingSync_API_Client_Inquiries/_inquiries/returns_inquiries.yml +0 -0
- data/spec/{cassettes → fixtures/cassettes}/BookingSync_API_Client_Payments/_cancel_payment/cancels_given_payment.yml +1 -1
- data/spec/{cassettes → fixtures/cassettes}/BookingSync_API_Client_Payments/_create_payment/creates_a_new_payment.yml +1 -1
- data/spec/{cassettes → fixtures/cassettes}/BookingSync_API_Client_Payments/_edit_payment/updates_given_payment_by_ID.yml +1 -1
- data/spec/{cassettes → fixtures/cassettes}/BookingSync_API_Client_Payments/_payments/returns_payments.yml +1 -1
- data/spec/{cassettes → fixtures/cassettes}/BookingSync_API_Client_Periods/_create_period/creates_a_new_period.yml +2 -2
- data/spec/fixtures/cassettes/BookingSync_API_Client_Periods/_delete_period/deletes_given_period.yml +57 -0
- data/spec/{cassettes → fixtures/cassettes}/BookingSync_API_Client_Periods/_edit_period/updates_given_period_by_ID.yml +1 -1
- data/spec/{cassettes → fixtures/cassettes}/BookingSync_API_Client_Periods/_periods/returns_periods.yml +1 -1
- data/spec/fixtures/cassettes/BookingSync_API_Client_Photos/_create_photo/creates_a_photo.yml +63 -0
- data/spec/fixtures/cassettes/BookingSync_API_Client_Photos/_create_photo/creates_a_photo_with_encoded_photo_file.yml +63 -0
- data/spec/fixtures/cassettes/BookingSync_API_Client_Photos/_create_photo/creates_a_photo_with_photo_path.yml +63 -0
- data/spec/fixtures/cassettes/BookingSync_API_Client_Photos/_create_photo/creates_a_photo_with_remote_URL.yml +63 -0
- data/spec/fixtures/cassettes/BookingSync_API_Client_Photos/_delete_photo/delete_given_photo.yml +57 -0
- data/spec/fixtures/cassettes/BookingSync_API_Client_Photos/_edit_photo/updates_photo_s_description.yml +61 -0
- data/spec/fixtures/cassettes/BookingSync_API_Client_Photos/_edit_photo/updates_photo_s_image_file.yml +61 -0
- data/spec/{cassettes → fixtures/cassettes}/BookingSync_API_Client_Photos/_photos/returns_photos.yml +1 -1
- data/spec/{cassettes → fixtures/cassettes}/BookingSync_API_Client_Rates/_rates/returns_rates.yml +0 -0
- data/spec/{cassettes → fixtures/cassettes}/BookingSync_API_Client_RatesRules/_rates_rules/returns_rates_rules.yml +0 -0
- data/spec/{cassettes → fixtures/cassettes}/BookingSync_API_Client_RatesTables/_create_rates_table/creates_a_new_rates_table.yml +1 -1
- data/spec/{cassettes → fixtures/cassettes}/BookingSync_API_Client_RatesTables/_delete_rates_table/deletes_given_rates_table.yml +1 -1
- data/spec/{cassettes → fixtures/cassettes}/BookingSync_API_Client_RatesTables/_edit_rates_table/updates_given_rates_table_by_ID.yml +1 -1
- data/spec/{cassettes → fixtures/cassettes}/BookingSync_API_Client_RatesTables/_rates_tables/returns_rates_tables.yml +1 -1
- data/spec/{cassettes → fixtures/cassettes}/BookingSync_API_Client_RentalAgreements/_create_rental_agreement/creates_a_new_rental_agreement.yml +1 -1
- data/spec/{cassettes → fixtures/cassettes}/BookingSync_API_Client_RentalAgreements/_create_rental_agreement_for_booking/creates_a_new_rental_agreement.yml +3 -3
- data/spec/{cassettes → fixtures/cassettes}/BookingSync_API_Client_RentalAgreements/_create_rental_agreement_for_rental/creates_a_new_rental_agreement.yml +3 -3
- data/spec/{cassettes → fixtures/cassettes}/BookingSync_API_Client_RentalAgreements/_rental_agreements/returns_rental_agreements.yml +1 -1
- data/spec/{cassettes → fixtures/cassettes}/BookingSync_API_Client_Rentals/_create_rental/creates_a_new_rental.yml +1 -1
- data/spec/{cassettes/BookingSync_API_Client_Rentals/_cancel_rental/cancels_given_rental.yml → fixtures/cassettes/BookingSync_API_Client_Rentals/_delete_rental/deletes_given_rental.yml} +1 -1
- data/spec/{cassettes → fixtures/cassettes}/BookingSync_API_Client_Rentals/_edit_rental/updates_given_rental_by_ID.yml +1 -1
- data/spec/{cassettes → fixtures/cassettes}/BookingSync_API_Client_Rentals/_rental/returns_a_single_rental.yml +0 -0
- data/spec/{cassettes → fixtures/cassettes}/BookingSync_API_Client_Rentals/_rentals/links/returns_associated_photos.yml +0 -0
- data/spec/{cassettes → fixtures/cassettes}/BookingSync_API_Client_Rentals/_rentals/links/returns_links_to_associated_resources.yml +0 -0
- data/spec/{cassettes → fixtures/cassettes}/BookingSync_API_Client_Rentals/_rentals/returns_rentals.yml +1 -1
- data/spec/{cassettes → fixtures/cassettes}/BookingSync_API_Client_Reviews/_create_review/creates_a_new_review.yml +3 -3
- data/spec/{cassettes → fixtures/cassettes}/BookingSync_API_Client_Reviews/_reviews/returns_reviews.yml +1 -1
- data/spec/{cassettes → fixtures/cassettes}/BookingSync_API_Client_Seasons/_create_season/creates_a_new_season.yml +3 -3
- data/spec/{cassettes → fixtures/cassettes}/BookingSync_API_Client_Seasons/_delete_season/deletes_given_season.yml +1 -1
- data/spec/{cassettes → fixtures/cassettes}/BookingSync_API_Client_Seasons/_edit_season/updates_given_season_by_ID.yml +1 -1
- data/spec/{cassettes → fixtures/cassettes}/BookingSync_API_Client_Seasons/_seasons/returns_seasons.yml +1 -1
- data/spec/{cassettes → fixtures/cassettes}/BookingSync_API_Client_SpecialOffers/_create_special_offer/creates_a_new_special_offer.yml +2 -2
- data/spec/{cassettes → fixtures/cassettes}/BookingSync_API_Client_SpecialOffers/_delete_special_offer/deletes_given_special_offer.yml +1 -1
- data/spec/{cassettes → fixtures/cassettes}/BookingSync_API_Client_SpecialOffers/_edit_special_offer/updates_given_special_offer_by_ID.yml +1 -1
- data/spec/{cassettes → fixtures/cassettes}/BookingSync_API_Client_SpecialOffers/_special_offers/returns_special_offers.yml +0 -0
- data/spec/{cassettes → fixtures/cassettes}/spec/cassettes/BookingSync_API_Client_Bookings/_create_booking/creates_a_booking_yml.yml +0 -0
- data/spec/fixtures/files/test.jpg +0 -0
- data/spec/spec_helper.rb +1 -1
- metadata +141 -124
- data/spec/cassettes/BookingSync_API_Client_Periods/_delete_period/deletes_given_period.yml +0 -70
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 15c752a5fbf7e0b1d4990d6b34afc96614ba55ea
|
4
|
+
data.tar.gz: 56a26b6f8d5ddec6b917f0201a0c9455f90df413
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 410fa026ba1cc55e7a9a01ef2a35747b143e4528f3e2d5ebf1a1990a334e3e3182f5d50240e090ccfd823504619c9ebb1e8ff11eaf68264c421781cf68a89c58
|
7
|
+
data.tar.gz: 16fbf28c39dccbacfb1f4199bf1770fc288ef40178520f688456a34d8a35113d453be8d37e66cf0bfddb307f60ebd3a8f525a9380e7b4282323e7cae72bcedae
|
data/.travis.yml
CHANGED
data/README.md
CHANGED
@@ -45,6 +45,26 @@ Fetch all resources (with multiple requests under the hood) and return one big a
|
|
45
45
|
|
46
46
|
api.bookings(auto_paginate: true) => [BookingSync::API::Resource, BookingSync::API::Resource, ...]
|
47
47
|
|
48
|
+
### Logging
|
49
|
+
|
50
|
+
Sometimes it's useful to see what data bookingsync-api gem sends and what it
|
51
|
+
receives from the API. By default, gem doesn't log anything.
|
52
|
+
There are two ways to enable logging:
|
53
|
+
|
54
|
+
1. Set `BOOKINGSYNC_API_DEBUG` environment variable to `true`, when running
|
55
|
+
gem or your app server in development. This will print all logs to `STDOUT`.
|
56
|
+
|
57
|
+
2. Pass your own logger to API client, it can be for example `Rails.logger`.
|
58
|
+
|
59
|
+
api = BookingSync::API.new("OAUTH_TOKEN", logger: Rails.logger)
|
60
|
+
|
61
|
+
#### Log levels
|
62
|
+
|
63
|
+
`INFO` - Logged are only request method and the URL.
|
64
|
+
`DEBUG` - Logged are request and response headers and bodies.
|
65
|
+
|
66
|
+
When using `BOOKINGSYNC_API_DEBUG` variable, log level is DEBUG.
|
67
|
+
|
48
68
|
## Gem documentation
|
49
69
|
|
50
70
|
See [gem documentation](http://rdoc.info/github/BookingSync/bookingsync-api/master/frames) for more info.
|
@@ -70,6 +90,16 @@ you need to run spec with below environment variables.
|
|
70
90
|
|
71
91
|
If you want to change a cassette, you need to delete it first.
|
72
92
|
|
93
|
+
### Environment variables
|
94
|
+
|
95
|
+
There are a few environment variables which comes handy while developing and
|
96
|
+
debugging bookingsync-api gem.
|
97
|
+
|
98
|
+
* `BOOKINGSYNC_URL` - The url of the website, should be. Default https://www.bookingsync.com
|
99
|
+
* `BOOKINGSYNC_VERIFY_SSL` - Verify SSL. Default to true.
|
100
|
+
* `BOOKINGSYNC_API_DEBUG` - If true, gem will log all request/responses to STDOUT. Default to false.
|
101
|
+
* `ACCESS_TOKEN` - OAuth token.
|
102
|
+
|
73
103
|
## Contributing
|
74
104
|
|
75
105
|
1. Fork it ( http://github.com/BookingSync/bookingsync-api/fork )
|
data/lib/bookingsync/api.rb
CHANGED
@@ -1,5 +1,4 @@
|
|
1
1
|
require "faraday"
|
2
|
-
|
3
2
|
require "bookingsync/api/version"
|
4
3
|
require "bookingsync/api/client"
|
5
4
|
|
@@ -8,9 +7,10 @@ module BookingSync
|
|
8
7
|
# Return new API Client
|
9
8
|
#
|
10
9
|
# @param token [String] OAuth token
|
10
|
+
# @param options [Hash] Options for the API Client
|
11
11
|
# @return [BookingSync::API::Client] New BookingSync API client
|
12
|
-
def self.new(token)
|
13
|
-
Client.new(token)
|
12
|
+
def self.new(token, options = {})
|
13
|
+
Client.new(token, options)
|
14
14
|
end
|
15
15
|
end
|
16
16
|
end
|
@@ -1,4 +1,5 @@
|
|
1
1
|
require "bookingsync/api/middleware/authentication"
|
2
|
+
require "bookingsync/api/middleware/logger"
|
2
3
|
require "bookingsync/api/client/amenities"
|
3
4
|
require "bookingsync/api/client/billing_addresses"
|
4
5
|
require "bookingsync/api/client/bookings"
|
@@ -22,6 +23,7 @@ require "bookingsync/api/relation"
|
|
22
23
|
require "bookingsync/api/response"
|
23
24
|
require "bookingsync/api/resource"
|
24
25
|
require "bookingsync/api/serializer"
|
26
|
+
require "logger"
|
25
27
|
|
26
28
|
module BookingSync::API
|
27
29
|
class Client
|
@@ -46,16 +48,19 @@ module BookingSync::API
|
|
46
48
|
|
47
49
|
MEDIA_TYPE = "application/vnd.api+json"
|
48
50
|
|
49
|
-
attr_reader :token
|
51
|
+
attr_reader :token, :logger
|
50
52
|
|
51
53
|
# Initialize new Client
|
52
54
|
#
|
53
55
|
# @param token [String] OAuth token
|
54
56
|
# @param options [Hash]
|
55
57
|
# @option options [String] base_url: Base URL to BookingSync site
|
58
|
+
# @option options [Logger] logger: Logger where headers and body of every
|
59
|
+
# request and response will be logged.
|
56
60
|
# @return [BookingSync::API::Client] New BookingSync API client
|
57
61
|
def initialize(token, options = {})
|
58
62
|
@token = token
|
63
|
+
@logger = options[:logger] || default_logger
|
59
64
|
@base_url = options[:base_url]
|
60
65
|
@serializer = Serializer.new
|
61
66
|
@conn = Faraday.new(faraday_options)
|
@@ -212,6 +217,7 @@ module BookingSync::API
|
|
212
217
|
def middleware
|
213
218
|
Faraday::RackBuilder.new do |builder|
|
214
219
|
builder.use :authentication, token
|
220
|
+
builder.use :logger, logger
|
215
221
|
builder.adapter Faraday.default_adapter
|
216
222
|
end
|
217
223
|
end
|
@@ -262,9 +268,23 @@ module BookingSync::API
|
|
262
268
|
when 204; nil # destroy/cancel
|
263
269
|
when 200..299; response
|
264
270
|
when 401; raise Unauthorized.new
|
271
|
+
when 404; raise NotFound.new
|
265
272
|
when 422; raise UnprocessableEntity.new
|
266
|
-
else
|
273
|
+
else raise UnsupportedResponse.new(response)
|
267
274
|
end
|
268
275
|
end
|
276
|
+
|
277
|
+
def debug?
|
278
|
+
ENV["BOOKINGSYNC_API_DEBUG"] == "true"
|
279
|
+
end
|
280
|
+
|
281
|
+
# Return default logger. By default we don't log anywhere.
|
282
|
+
# If we are in debug mode, we log everything to STDOUT.
|
283
|
+
#
|
284
|
+
# @return [Logger] Logger where faraday middleware will log requests and
|
285
|
+
# responses.
|
286
|
+
def default_logger
|
287
|
+
Logger.new(debug? ? STDOUT : nil)
|
288
|
+
end
|
269
289
|
end
|
270
290
|
end
|
@@ -32,10 +32,12 @@ module BookingSync::API
|
|
32
32
|
|
33
33
|
# Create a booking
|
34
34
|
#
|
35
|
-
# @param
|
36
|
-
#
|
37
|
-
|
38
|
-
|
35
|
+
# @param rental [BookingSync::API::Resource|Integer] Rental or ID of
|
36
|
+
# the rental for which booking will be created.
|
37
|
+
# @param options [Hash] Booking attributes.
|
38
|
+
# @return [BookingSync::API::Resource] Newly create booking.
|
39
|
+
def create_booking(rental, options = {})
|
40
|
+
post("rentals/#{rental}/bookings", bookings: [options]).pop
|
39
41
|
end
|
40
42
|
|
41
43
|
# Edit a booking
|
@@ -53,9 +55,9 @@ module BookingSync::API
|
|
53
55
|
|
54
56
|
# Cancel a booking
|
55
57
|
#
|
56
|
-
# @param booking [BookingSync::API::Resource|Integer] Booking or ID of
|
57
|
-
# to be canceled
|
58
|
-
# @return [
|
58
|
+
# @param booking [BookingSync::API::Resource|Integer] Booking or ID of
|
59
|
+
# the booking to be canceled.
|
60
|
+
# @return [NilClass] Returns nil on success.
|
59
61
|
def cancel_booking(booking, options = {})
|
60
62
|
delete "bookings/#{booking}"
|
61
63
|
end
|
@@ -13,10 +13,12 @@ module BookingSync::API
|
|
13
13
|
|
14
14
|
# Create a new inquiry
|
15
15
|
#
|
16
|
-
# @param
|
17
|
-
#
|
18
|
-
|
19
|
-
|
16
|
+
# @param rental [BookingSync::API::Resource] Rental or ID of the rental
|
17
|
+
# for which an inquiry will be created.
|
18
|
+
# @param options [Hash] Inquiry attributes.
|
19
|
+
# @return [BookingSync::API::Resource] Newly create inquiry.
|
20
|
+
def create_inquiry(rental, options = {})
|
21
|
+
post("rentals/#{rental}/inquiries", inquiries: [options]).pop
|
20
22
|
end
|
21
23
|
end
|
22
24
|
end
|
@@ -42,10 +42,10 @@ module BookingSync::API
|
|
42
42
|
|
43
43
|
# Cancel a payment
|
44
44
|
#
|
45
|
-
# @param payment [BookingSync::API::Resource|Integer]
|
46
|
-
# to be canceled
|
47
|
-
# @return [
|
48
|
-
def cancel_payment(payment
|
45
|
+
# @param payment [BookingSync::API::Resource|Integer] Payment or ID of
|
46
|
+
# the payment to be canceled.
|
47
|
+
# @return [NilClass] Returns nil on success.
|
48
|
+
def cancel_payment(payment)
|
49
49
|
delete "payments/#{payment}"
|
50
50
|
end
|
51
51
|
end
|
@@ -20,20 +20,21 @@ module BookingSync::API
|
|
20
20
|
|
21
21
|
# Create a new period
|
22
22
|
#
|
23
|
-
# @param
|
24
|
-
#
|
25
|
-
# @
|
26
|
-
|
27
|
-
|
23
|
+
# @param season [BookingSync::API::Resource|Integer] Season or ID of
|
24
|
+
# the season for which period will be created.
|
25
|
+
# @param options [Hash] Period's attributes.
|
26
|
+
# @return [BookingSync::API::Resource] Newly created period.
|
27
|
+
def create_period(season, options = {})
|
28
|
+
post("seasons/#{season}/periods", periods: [options]).pop
|
28
29
|
end
|
29
30
|
|
30
31
|
# Edit a period
|
31
32
|
#
|
32
|
-
# @param period [BookingSync::API::Resource|Integer]
|
33
|
-
# to be updated
|
34
|
-
# @param options [Hash] period attributes to be updated
|
33
|
+
# @param period [BookingSync::API::Resource|Integer] Period or ID of
|
34
|
+
# the period to be updated.
|
35
|
+
# @param options [Hash] period attributes to be updated.
|
35
36
|
# @return [BookingSync::API::Resource] Updated period on success,
|
36
|
-
#
|
37
|
+
# exception is raised otherwise.
|
37
38
|
# @example
|
38
39
|
# period = @api.periods.first
|
39
40
|
# @api.edit_period(period, { end_at: "2014-04-28" })
|
@@ -43,10 +44,10 @@ module BookingSync::API
|
|
43
44
|
|
44
45
|
# Delete a period
|
45
46
|
#
|
46
|
-
# @param period [BookingSync::API::Resource|Integer]
|
47
|
-
# to be deleted
|
48
|
-
# @return [
|
49
|
-
def delete_period(period
|
47
|
+
# @param period [BookingSync::API::Resource|Integer] Period or ID
|
48
|
+
# of the period to be deleted.
|
49
|
+
# @return [NilClass] Returns nil on success.
|
50
|
+
def delete_period(period)
|
50
51
|
delete "periods/#{period}"
|
51
52
|
end
|
52
53
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
require "base64"
|
2
|
+
|
1
3
|
module BookingSync::API
|
2
4
|
class Client
|
3
5
|
module Photos
|
@@ -17,6 +19,57 @@ module BookingSync::API
|
|
17
19
|
def photos(options = {}, &block)
|
18
20
|
paginate :photos, options, &block
|
19
21
|
end
|
22
|
+
|
23
|
+
# Create a photo
|
24
|
+
#
|
25
|
+
# @param rental [BookingSync::API::Resource|Integer] Rental object or ID
|
26
|
+
# for which the photo will be created. Image can be provided in three
|
27
|
+
# was, as a file path, encode string or as an URL.
|
28
|
+
# @param options [Hash] Photo's attributes.
|
29
|
+
# @option options [String] photo_path: Path to the image to be uploaded.
|
30
|
+
# @option options [String] photo: Photo encoded with Base64
|
31
|
+
# @option options [String] remote_photo_url: URL to a remote image which
|
32
|
+
# will be fetched and then saved
|
33
|
+
# @return [BookingSync::API::Resource] Newly created photo.
|
34
|
+
# @example Create a photo.
|
35
|
+
# @api.create_photo(10, photo_path: 'rentals/big_one.jpg')
|
36
|
+
# @see http://docs.api.bookingsync.com/reference/endpoints/photos/#create-a-new-photo
|
37
|
+
def create_photo(rental, options = {})
|
38
|
+
if photo_path = options.delete(:photo_path)
|
39
|
+
options[:photo] ||= encode(photo_path)
|
40
|
+
end
|
41
|
+
post("rentals/#{rental}/photos", photos: [options]).pop
|
42
|
+
end
|
43
|
+
|
44
|
+
# Edit a photo
|
45
|
+
#
|
46
|
+
# @param photo [BookingSync::API::Resource|Integer] Photo or ID of the
|
47
|
+
# photo to be updated.
|
48
|
+
# @param options [Hash] Photo's attributes.
|
49
|
+
# @return [BookingSync::API::Resource] Updated photo
|
50
|
+
# @see http://docs.api.bookingsync.com/reference/endpoints/photos/#update-a-photo
|
51
|
+
def edit_photo(photo, options = {})
|
52
|
+
if photo_path = options.delete(:photo_path)
|
53
|
+
options[:photo] ||= encode(photo_path)
|
54
|
+
end
|
55
|
+
put("photos/#{photo}", photos: [options]).pop
|
56
|
+
end
|
57
|
+
|
58
|
+
# Delete a photo
|
59
|
+
#
|
60
|
+
# @param photo [BookingSync::API::Resource|Integer] Photo or ID of the
|
61
|
+
# photo to be deleted.
|
62
|
+
# @return [NilClass] Returns nil on success.
|
63
|
+
# @see http://docs.api.bookingsync.com/reference/endpoints/photos/#destroy-a-photo
|
64
|
+
def delete_photo(photo)
|
65
|
+
delete "photos/#{photo}"
|
66
|
+
end
|
67
|
+
|
68
|
+
private
|
69
|
+
|
70
|
+
def encode(file_path)
|
71
|
+
Base64.encode64(File.read(file_path))
|
72
|
+
end
|
20
73
|
end
|
21
74
|
end
|
22
75
|
end
|
@@ -40,12 +40,12 @@ module BookingSync::API
|
|
40
40
|
put("rates_tables/#{rates_table}", rates_tables: [options]).pop
|
41
41
|
end
|
42
42
|
|
43
|
-
#
|
43
|
+
# Delete a rates_table
|
44
44
|
#
|
45
|
-
# @param rates_table [BookingSync::API::Resource|Integer]
|
46
|
-
#
|
47
|
-
# @return [
|
48
|
-
def delete_rates_table(rates_table
|
45
|
+
# @param rates_table [BookingSync::API::Resource|Integer] Rates table or
|
46
|
+
# ID of the rates table to be deleteed.
|
47
|
+
# @return [NilClass] Returns nil on success
|
48
|
+
def delete_rates_table(rates_table)
|
49
49
|
delete "rates_tables/#{rates_table}"
|
50
50
|
end
|
51
51
|
end
|
@@ -1,9 +1,10 @@
|
|
1
1
|
module BookingSync::API
|
2
2
|
class Client
|
3
3
|
module RentalAgreements
|
4
|
-
# List rental agreements
|
4
|
+
# List rental agreements.
|
5
5
|
#
|
6
|
-
# Returns rental agreements for the rentals of the account
|
6
|
+
# Returns rental agreements for the rentals of the account
|
7
|
+
# user is authenticated with.
|
7
8
|
# @param options [Hash] A customizable set of options.
|
8
9
|
# @option options [Array] fields: List of fields to be fetched.
|
9
10
|
# @return [Array<BookingSync::API::Resource>] Array of rental agreements.
|
@@ -18,30 +19,32 @@ module BookingSync::API
|
|
18
19
|
paginate :rental_agreements, options, &block
|
19
20
|
end
|
20
21
|
|
21
|
-
# Create a new rental agreement for a booking
|
22
|
+
# Create a new rental agreement for a booking.
|
22
23
|
#
|
23
|
-
# @param
|
24
|
-
#
|
25
|
-
# @
|
26
|
-
|
27
|
-
|
28
|
-
|
24
|
+
# @param booking [BookingSync::API::Resource|Integer] Booking or ID of
|
25
|
+
# the booking for which rental agreement will be created.
|
26
|
+
# @param options [Hash] Rental agreement's attributes.
|
27
|
+
# @return [BookingSync::API::Resource] Newly created rental agreement.
|
28
|
+
def create_rental_agreement_for_booking(booking, options = {})
|
29
|
+
post("bookings/#{booking}/rental_agreements",
|
30
|
+
rental_agreements: [options]).pop
|
29
31
|
end
|
30
32
|
|
31
|
-
# Create a new rental agreement for a rental
|
33
|
+
# Create a new rental agreement for a rental.
|
32
34
|
#
|
33
|
-
# @param
|
34
|
-
#
|
35
|
-
# @
|
36
|
-
|
37
|
-
|
38
|
-
|
35
|
+
# @param rental [BookingSync::API::Resource|Integer] Rental or ID of
|
36
|
+
# the rental for which rental agreement will be created.
|
37
|
+
# @param options [Hash] Rental agreement's attributes.
|
38
|
+
# @return [BookingSync::API::Resource] Newly created rental agreement
|
39
|
+
def create_rental_agreement_for_rental(rental, options = {})
|
40
|
+
post("rentals/#{rental}/rental_agreements",
|
41
|
+
rental_agreements: [options]).pop
|
39
42
|
end
|
40
43
|
|
41
|
-
# Create a new rental agreement for an account
|
44
|
+
# Create a new rental agreement for an account.
|
42
45
|
#
|
43
|
-
# @param options [Hash]
|
44
|
-
# @return [BookingSync::API::
|
46
|
+
# @param options [Hash] Rental agreement's attributes.
|
47
|
+
# @return [BookingSync::API::Resource] Newly created rental agreement.
|
45
48
|
def create_rental_agreement(options = {})
|
46
49
|
post(:rental_agreements, rental_agreements: [options]).pop
|
47
50
|
end
|
@@ -39,18 +39,19 @@ module BookingSync::API
|
|
39
39
|
put("rentals/#{rental}", rentals: [options]).pop
|
40
40
|
end
|
41
41
|
|
42
|
-
#
|
42
|
+
# Delete a rental
|
43
43
|
#
|
44
|
-
# @param rental [BookingSync::API::Resource|Integer]
|
45
|
-
# to be
|
46
|
-
# @return [
|
47
|
-
def
|
44
|
+
# @param rental [BookingSync::API::Resource|Integer] Rental or ID
|
45
|
+
# of the rental to be deleted.
|
46
|
+
# @return [NilClass] Returns nil on success.
|
47
|
+
def delete_rental(rental)
|
48
48
|
delete "rentals/#{rental}"
|
49
49
|
end
|
50
50
|
|
51
51
|
# Get a single rental
|
52
52
|
#
|
53
|
-
# @param rental [BookingSync::API::Resource|Integer] Rental or ID
|
53
|
+
# @param rental [BookingSync::API::Resource|Integer] Rental or ID
|
54
|
+
# of the rental.
|
54
55
|
# @return [BookingSync::API::Resource]
|
55
56
|
def rental(rental)
|
56
57
|
get("rentals/#{rental}").pop
|
@@ -20,11 +20,12 @@ module BookingSync::API
|
|
20
20
|
|
21
21
|
# Create a new review
|
22
22
|
#
|
23
|
-
# @param
|
24
|
-
#
|
25
|
-
# @
|
26
|
-
|
27
|
-
|
23
|
+
# @param booking [BookingSync::API::Resource|Integer] Booking or ID of
|
24
|
+
# the booking for which a review will be created.
|
25
|
+
# @param options [Hash] Review's attributes.
|
26
|
+
# @return [BookingSync::API::Resource] Newly created review.
|
27
|
+
def create_review(booking, options = {})
|
28
|
+
post("bookings/#{booking}/reviews", reviews: [options]).pop
|
28
29
|
end
|
29
30
|
end
|
30
31
|
end
|