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
@@ -20,19 +20,21 @@ module BookingSync::API
|
|
20
20
|
|
21
21
|
# Create a new season
|
22
22
|
#
|
23
|
-
# @param rates_table_id [Integer]
|
24
|
-
#
|
25
|
-
# @
|
26
|
-
|
27
|
-
|
23
|
+
# @param rates_table_id [BookingSync::API::Resource|Integer] Rates table
|
24
|
+
# or ID of the rates table for which a season will be created.
|
25
|
+
# @param options [Hash] Season's attributes.
|
26
|
+
# @return [BookingSync::API::Resource] Newly created season.
|
27
|
+
def create_season(rates_table, options = {})
|
28
|
+
post("rates_tables/#{rates_table}/seasons", seasons: [options]).pop
|
28
29
|
end
|
29
30
|
|
30
31
|
# Edit a season
|
31
32
|
#
|
32
|
-
# @param season [BookingSync::API::Resource|Integer]
|
33
|
-
# to be updated
|
34
|
-
# @param options [Hash]
|
35
|
-
# @return [BookingSync::API::Resource] Updated season on success,
|
33
|
+
# @param season [BookingSync::API::Resource|Integer] Season or ID of
|
34
|
+
# the season to be updated.
|
35
|
+
# @param options [Hash] Season attributes to be updated.
|
36
|
+
# @return [BookingSync::API::Resource] Updated season on success,
|
37
|
+
# exception is raised otherwise.
|
36
38
|
# @example
|
37
39
|
# season = @api.seasons.first
|
38
40
|
# @api.edit_season(season, { name: "Some season" })
|
@@ -42,10 +44,10 @@ module BookingSync::API
|
|
42
44
|
|
43
45
|
# Delete a season
|
44
46
|
#
|
45
|
-
# @param season [BookingSync::API::Resource|Integer]
|
46
|
-
# to be deleted
|
47
|
-
# @return [
|
48
|
-
def delete_season(season
|
47
|
+
# @param season [BookingSync::API::Resource|Integer] Season or ID
|
48
|
+
# of the season to be deleted.
|
49
|
+
# @return [NilClass] Returns nil on success.
|
50
|
+
def delete_season(season)
|
49
51
|
delete "seasons/#{season}"
|
50
52
|
end
|
51
53
|
end
|
@@ -3,7 +3,7 @@ module BookingSync::API
|
|
3
3
|
module SpecialOffers
|
4
4
|
# List special_offers
|
5
5
|
#
|
6
|
-
# Returns
|
6
|
+
# Returns special offers for the account user is authenticated with.
|
7
7
|
# @param options [Hash] A customizable set of options.
|
8
8
|
# @option options [Array] fields: List of fields to be fetched.
|
9
9
|
# @return [Array<BookingSync::API::Resource>] Array of special_offers.
|
@@ -18,35 +18,36 @@ module BookingSync::API
|
|
18
18
|
paginate :special_offers, options, &block
|
19
19
|
end
|
20
20
|
|
21
|
-
# Create a new
|
21
|
+
# Create a new special offer for a rental
|
22
22
|
#
|
23
|
-
# @param
|
24
|
-
#
|
25
|
-
# @
|
26
|
-
|
27
|
-
|
23
|
+
# @param rental [BookingSync::API::Resource|Integer] Rental or ID of the
|
24
|
+
# rental for which special offer will be created.
|
25
|
+
# @param options [Hash] Special offer's attributes.
|
26
|
+
# @return [BookingSync::API::Resource] Newly created special offer.
|
27
|
+
def create_special_offer(rental, options = {})
|
28
|
+
post("rentals/#{rental}/special_offers", special_offers: [options]).pop
|
28
29
|
end
|
29
30
|
|
30
|
-
# Edit a
|
31
|
+
# Edit a special offer
|
31
32
|
#
|
32
|
-
# @param special_offer [BookingSync::API::Resource|Integer]
|
33
|
-
# ID of the special offer to be updated
|
34
|
-
# @param options [Hash] special offer attributes to be updated
|
33
|
+
# @param special_offer [BookingSync::API::Resource|Integer] Special offer
|
34
|
+
# or ID of the special offer to be updated.
|
35
|
+
# @param options [Hash] special offer attributes to be updated.
|
35
36
|
# @return [BookingSync::API::Resource] Updated special offer on success,
|
36
|
-
#
|
37
|
+
# exception is raised otherwise.
|
37
38
|
# @example
|
38
39
|
# special_offer = @api.special_offers.first
|
39
|
-
# @api.edit_special_offer(special_offer, {
|
40
|
+
# @api.edit_special_offer(special_offer, {name: "New offer"})
|
40
41
|
def edit_special_offer(special_offer, options = {})
|
41
42
|
put("special_offers/#{special_offer}", special_offers: [options]).pop
|
42
43
|
end
|
43
44
|
|
44
|
-
# Delete a
|
45
|
+
# Delete a special offer
|
45
46
|
#
|
46
|
-
# @param special_offer [BookingSync::API::Resource|Integer]
|
47
|
-
# ID of the special offer to be deleted
|
48
|
-
# @return [
|
49
|
-
def delete_special_offer(special_offer
|
47
|
+
# @param special_offer [BookingSync::API::Resource|Integer] Special offer
|
48
|
+
# or ID of the special offer to be deleted.
|
49
|
+
# @return [NilClass] Returns nil on success.
|
50
|
+
def delete_special_offer(special_offer)
|
50
51
|
delete "special_offers/#{special_offer}"
|
51
52
|
end
|
52
53
|
end
|
@@ -3,4 +3,22 @@ module BookingSync::API
|
|
3
3
|
class Error < StandardError; end
|
4
4
|
class Unauthorized < Error; end
|
5
5
|
class UnprocessableEntity < Error; end
|
6
|
+
class NotFound < Error; end
|
7
|
+
|
8
|
+
class UnsupportedResponse < Error
|
9
|
+
attr_reader :status, :headers, :body
|
10
|
+
|
11
|
+
def initialize(response)
|
12
|
+
@status = response.status
|
13
|
+
@headers = response.headers
|
14
|
+
@body = response.body
|
15
|
+
end
|
16
|
+
|
17
|
+
def message
|
18
|
+
%Q{Received unsupported response from BookingSync API
|
19
|
+
HTTP status code : #{status}
|
20
|
+
Headers : #{headers}
|
21
|
+
Body : #{body}}
|
22
|
+
end
|
23
|
+
end
|
6
24
|
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
require 'forwardable'
|
2
|
+
|
3
|
+
module BookingSync::API::Middleware
|
4
|
+
# Provides logger for request and responses made by API Client.
|
5
|
+
# JSON data is displayed in an eye-friendly format.
|
6
|
+
# User can provide his own logger in BookingSync::API::Client.new
|
7
|
+
#
|
8
|
+
# Log Levels
|
9
|
+
# INFO - logged are only request method and URL.
|
10
|
+
# DEBUG - logged are headers and bodies of requests and responses.
|
11
|
+
class Logger < Faraday::Middleware
|
12
|
+
extend Forwardable
|
13
|
+
|
14
|
+
def initialize(app, logger)
|
15
|
+
super(app)
|
16
|
+
@logger = logger
|
17
|
+
end
|
18
|
+
|
19
|
+
def_delegators :@logger, :debug, :info, :warn, :error, :fatal
|
20
|
+
|
21
|
+
def call(env)
|
22
|
+
info "#{env.method.upcase} #{env.url.to_s}"
|
23
|
+
debug('Request headers') { dump_headers env.request_headers }
|
24
|
+
debug('Request body') { dump_body env.body }
|
25
|
+
@app.call(env).tap do |response|
|
26
|
+
debug('Response headers') { dump_headers response.env.response_headers }
|
27
|
+
debug('Response status') { response.env.status }
|
28
|
+
debug('Response body') { dump_body response.env.body }
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
private
|
33
|
+
|
34
|
+
def dump_body(body)
|
35
|
+
if body && body != ""
|
36
|
+
JSON.pretty_generate(JSON.parse(body))
|
37
|
+
else
|
38
|
+
"No body"
|
39
|
+
end
|
40
|
+
rescue JSON::ParserError
|
41
|
+
"Invalid JSON"
|
42
|
+
end
|
43
|
+
|
44
|
+
def dump_headers(headers)
|
45
|
+
headers.map { |k, v| "#{k}: #{v.inspect}" }.join("\n")
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
Faraday::Middleware.register_middleware logger: Logger
|
50
|
+
end
|
@@ -39,19 +39,20 @@ describe BookingSync::API::Client::Bookings do
|
|
39
39
|
|
40
40
|
describe ".create_booking", :vcr do
|
41
41
|
let(:attributes) {
|
42
|
-
{start_at: '2014-01-03', end_at: '2014-01-04',
|
42
|
+
{start_at: '2014-01-03', end_at: '2014-01-04',
|
43
43
|
booked: true}
|
44
44
|
}
|
45
|
+
let(:rental) { BookingSync::API::Resource.new(client, id: 20) }
|
45
46
|
|
46
47
|
it "creates a booking" do
|
47
|
-
client.create_booking(attributes)
|
48
|
-
assert_requested :post, bs_url("bookings"),
|
48
|
+
client.create_booking(rental, attributes)
|
49
|
+
assert_requested :post, bs_url("rentals/20/bookings"),
|
49
50
|
body: {bookings: [attributes]}.to_json
|
50
51
|
end
|
51
52
|
|
52
53
|
it "returns newly created booking" do
|
53
54
|
VCR.use_cassette('BookingSync_API_Client_Bookings/_create_booking/creates_a_booking') do
|
54
|
-
booking = client.create_booking(attributes)
|
55
|
+
booking = client.create_booking(rental, attributes)
|
55
56
|
expect(booking.account_id).to eql(1)
|
56
57
|
expect(booking.rental_id).to eql(20)
|
57
58
|
end
|
@@ -19,16 +19,17 @@ describe BookingSync::API::Client::Inquiries do
|
|
19
19
|
lastname: "Smith",
|
20
20
|
email: "john@example.com"
|
21
21
|
} }
|
22
|
+
let(:rental) { BookingSync::API::Resource.new(client, id: 7) }
|
22
23
|
|
23
24
|
it "creates a new inquiry" do
|
24
|
-
client.create_inquiry(attributes)
|
25
|
-
assert_requested :post, bs_url("inquiries"),
|
25
|
+
client.create_inquiry(rental, attributes)
|
26
|
+
assert_requested :post, bs_url("rentals/7/inquiries"),
|
26
27
|
body: {inquiries: [attributes]}.to_json
|
27
28
|
end
|
28
29
|
|
29
30
|
it "returns newly created inquiry" do
|
30
31
|
VCR.use_cassette('BookingSync_API_Client_Inquiries/_create_inquiry/creates_a_new_inquiry') do
|
31
|
-
inquiry = client.create_inquiry(attributes)
|
32
|
+
inquiry = client.create_inquiry(rental, attributes)
|
32
33
|
expect(inquiry.rental_id).to eql(7)
|
33
34
|
expect(inquiry.firstname).to eql("John")
|
34
35
|
end
|
@@ -1,7 +1,6 @@
|
|
1
1
|
require "spec_helper"
|
2
2
|
|
3
3
|
describe BookingSync::API::Client::Periods do
|
4
|
-
|
5
4
|
let(:client) { BookingSync::API::Client.new(test_access_token) }
|
6
5
|
|
7
6
|
describe ".periods", :vcr do
|
@@ -12,20 +11,18 @@ describe BookingSync::API::Client::Periods do
|
|
12
11
|
end
|
13
12
|
|
14
13
|
describe ".create_period", :vcr do
|
15
|
-
let(:attributes) { {
|
16
|
-
|
17
|
-
end_at: "2013-04-22"
|
18
|
-
} }
|
14
|
+
let(:attributes) { {start_at: "2013-04-10", end_at: "2013-04-22"} }
|
15
|
+
let(:season) { BookingSync::API::Resource.new(client, id: 9) }
|
19
16
|
|
20
17
|
it "creates a new period" do
|
21
|
-
client.create_period(
|
22
|
-
assert_requested :post, bs_url("periods"),
|
23
|
-
body: {
|
18
|
+
client.create_period(season, attributes)
|
19
|
+
assert_requested :post, bs_url("seasons/9/periods"),
|
20
|
+
body: {periods: [attributes]}.to_json
|
24
21
|
end
|
25
22
|
|
26
23
|
it "returns newly created period" do
|
27
24
|
VCR.use_cassette('BookingSync_API_Client_Periods/_create_period/creates_a_new_period') do
|
28
|
-
period = client.create_period(
|
25
|
+
period = client.create_period(season, attributes)
|
29
26
|
expect(period.start_at).to eql(Time.parse(attributes[:start_at]))
|
30
27
|
expect(period.end_at).to eql(Time.parse(attributes[:end_at]))
|
31
28
|
end
|
@@ -33,9 +30,7 @@ describe BookingSync::API::Client::Periods do
|
|
33
30
|
end
|
34
31
|
|
35
32
|
describe ".edit_period", :vcr do
|
36
|
-
let(:attributes) {
|
37
|
-
{ end_at: '2014-07-15' }
|
38
|
-
}
|
33
|
+
let(:attributes) { {end_at: '2014-07-15'} }
|
39
34
|
|
40
35
|
it "updates given period by ID" do
|
41
36
|
client.edit_period(6, attributes)
|
@@ -54,8 +49,8 @@ describe BookingSync::API::Client::Periods do
|
|
54
49
|
|
55
50
|
describe ".delete_period", :vcr do
|
56
51
|
it "deletes given period" do
|
57
|
-
client.delete_period(
|
58
|
-
assert_requested :delete, bs_url("periods/
|
52
|
+
client.delete_period(3)
|
53
|
+
assert_requested :delete, bs_url("periods/3")
|
59
54
|
end
|
60
55
|
end
|
61
56
|
end
|
@@ -2,6 +2,7 @@ require "spec_helper"
|
|
2
2
|
|
3
3
|
describe BookingSync::API::Client::Photos do
|
4
4
|
let(:client) { BookingSync::API::Client.new(test_access_token) }
|
5
|
+
let(:rental) { BookingSync::API::Resource.new(client, id: 2) }
|
5
6
|
|
6
7
|
describe ".photos", :vcr do
|
7
8
|
it "returns photos" do
|
@@ -9,4 +10,61 @@ describe BookingSync::API::Client::Photos do
|
|
9
10
|
assert_requested :get, bs_url("photos")
|
10
11
|
end
|
11
12
|
end
|
13
|
+
|
14
|
+
describe ".create_photo", :vcr do
|
15
|
+
let(:attributes) do
|
16
|
+
{photo_path: "spec/fixtures/files/test.jpg",
|
17
|
+
description_en: "Funny", kind: "livingroom"}
|
18
|
+
end
|
19
|
+
|
20
|
+
it "creates a photo with photo path" do
|
21
|
+
photo = client.create_photo(rental, attributes)
|
22
|
+
assert_requested :post, bs_url("rentals/2/photos"),
|
23
|
+
body: {photos: [attributes]}.to_json
|
24
|
+
expect(photo.kind).to eq("livingroom")
|
25
|
+
end
|
26
|
+
|
27
|
+
it "creates a photo with encoded photo file" do
|
28
|
+
encoded = Base64.encode64(File.read("spec/fixtures/files/test.jpg"))
|
29
|
+
photo = client.create_photo(rental, photo: encoded, kind: "livingroom")
|
30
|
+
assert_requested :post, bs_url("rentals/2/photos"),
|
31
|
+
body: {photos: [photo: encoded, kind: "livingroom"]}.to_json
|
32
|
+
expect(photo.kind).to eq("livingroom")
|
33
|
+
end
|
34
|
+
|
35
|
+
it "creates a photo with remote URL" do
|
36
|
+
remote_url = "https://www.ruby-lang.org/images/header-ruby-logo.png"
|
37
|
+
photo = client.create_photo(rental, remote_photo_url: remote_url,
|
38
|
+
kind: "livingroom")
|
39
|
+
assert_requested :post, bs_url("rentals/2/photos"),
|
40
|
+
body: {photos: [remote_photo_url: remote_url, kind: "livingroom"]}.to_json
|
41
|
+
expect(photo.kind).to eq("livingroom")
|
42
|
+
end
|
43
|
+
|
44
|
+
it "returns newly created photo" do
|
45
|
+
VCR.use_cassette('BookingSync_API_Client_Photos/_create_photo/creates_a_photo') do
|
46
|
+
photo = client.create_photo(rental, attributes)
|
47
|
+
expect(photo.kind).to eq("livingroom")
|
48
|
+
expect(photo.description.en).to eq("Funny")
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
describe ".edit_photo", :vcr do
|
54
|
+
it "updates photo's description" do
|
55
|
+
photo = client.edit_photo(37, description_en: "Not funny anymore")
|
56
|
+
expect(photo.description.en).to eq("Not funny anymore")
|
57
|
+
end
|
58
|
+
|
59
|
+
it "updates photo's image file" do
|
60
|
+
photo = client.edit_photo(37, file_path: "spec/fixtures/files/test.jpg")
|
61
|
+
expect(photo.description.en).to eq("Not funny anymore")
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
describe ".delete_photo", :vcr do
|
66
|
+
it "delete given photo" do
|
67
|
+
expect(client.delete_photo(37)).to be_nil
|
68
|
+
end
|
69
|
+
end
|
12
70
|
end
|
@@ -29,34 +29,34 @@ describe BookingSync::API::Client::RentalAgreements do
|
|
29
29
|
end
|
30
30
|
|
31
31
|
describe ".create_rental_agreement_for_booking", :vcr do
|
32
|
-
let(:
|
32
|
+
let(:booking) { BookingSync::API::Resource.new(client, id: 2) }
|
33
33
|
|
34
34
|
it "creates a new rental agreement" do
|
35
|
-
client.create_rental_agreement_for_booking(
|
36
|
-
assert_requested :post, bs_url("rental_agreements"),
|
37
|
-
body: {
|
35
|
+
client.create_rental_agreement_for_booking(booking, attributes)
|
36
|
+
assert_requested :post, bs_url("bookings/#{booking}/rental_agreements"),
|
37
|
+
body: {rental_agreements: [attributes]}.to_json
|
38
38
|
end
|
39
39
|
|
40
40
|
it "returns newly created rental agreement" do
|
41
41
|
VCR.use_cassette('BookingSync_API_Client_RentalAgreements/_create_rental_agreement_for_booking/creates_a_new_rental_agreement') do
|
42
|
-
rental_agreement = client.create_rental_agreement_for_booking(
|
42
|
+
rental_agreement = client.create_rental_agreement_for_booking(booking, attributes)
|
43
43
|
expect(rental_agreement.body).to eql(attributes[:body])
|
44
44
|
end
|
45
45
|
end
|
46
46
|
end
|
47
47
|
|
48
48
|
describe ".create_rental_agreement_for_rental", :vcr do
|
49
|
-
let(:
|
49
|
+
let(:rental) { BookingSync::API::Resource.new(client, id: 20) }
|
50
50
|
|
51
51
|
it "creates a new rental agreement" do
|
52
|
-
client.create_rental_agreement_for_rental(
|
53
|
-
assert_requested :post, bs_url("rental_agreements"),
|
54
|
-
body: {
|
52
|
+
client.create_rental_agreement_for_rental(rental, attributes)
|
53
|
+
assert_requested :post, bs_url("rentals/20/rental_agreements"),
|
54
|
+
body: {rental_agreements: [attributes]}.to_json
|
55
55
|
end
|
56
56
|
|
57
57
|
it "returns newly created rental agreement" do
|
58
58
|
VCR.use_cassette('BookingSync_API_Client_RentalAgreements/_create_rental_agreement_for_rental/creates_a_new_rental_agreement') do
|
59
|
-
rental_agreement = client.create_rental_agreement_for_rental(
|
59
|
+
rental_agreement = client.create_rental_agreement_for_rental(rental, attributes)
|
60
60
|
expect(rental_agreement.body).to eql(attributes[:body])
|
61
61
|
end
|
62
62
|
end
|
@@ -61,9 +61,9 @@ describe BookingSync::API::Client::Rentals do
|
|
61
61
|
end
|
62
62
|
end
|
63
63
|
|
64
|
-
describe ".
|
65
|
-
it "
|
66
|
-
client.
|
64
|
+
describe ".delete_rental", :vcr do
|
65
|
+
it "deletes given rental" do
|
66
|
+
client.delete_rental(4)
|
67
67
|
assert_requested :delete, bs_url("rentals/4")
|
68
68
|
end
|
69
69
|
end
|
@@ -15,16 +15,17 @@ describe BookingSync::API::Client::Reviews do
|
|
15
15
|
comment: "Awesome place",
|
16
16
|
rating: 5
|
17
17
|
}}
|
18
|
+
let(:booking) { BookingSync::API::Resource.new(client, id: 1) }
|
18
19
|
|
19
20
|
it "creates a new review" do
|
20
|
-
client.create_review(
|
21
|
-
assert_requested :post, bs_url("reviews"),
|
22
|
-
body: {
|
21
|
+
client.create_review(booking, attributes)
|
22
|
+
assert_requested :post, bs_url("bookings/1/reviews"),
|
23
|
+
body: {reviews: [attributes]}.to_json
|
23
24
|
end
|
24
25
|
|
25
26
|
it "returns newly created review" do
|
26
27
|
VCR.use_cassette('BookingSync_API_Client_Reviews/_create_review/creates_a_new_review') do
|
27
|
-
review = client.create_review(
|
28
|
+
review = client.create_review(booking, attributes)
|
28
29
|
expect(review.comment).to eql(attributes[:comment])
|
29
30
|
expect(review.rating).to eql(attributes[:rating])
|
30
31
|
end
|