bookingsync-api 0.0.8 → 0.0.9

Sign up to get free protection for your applications and to get access to all the features.
Files changed (93) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +1 -1
  3. data/README.md +30 -0
  4. data/lib/bookingsync/api.rb +3 -3
  5. data/lib/bookingsync/api/client.rb +22 -2
  6. data/lib/bookingsync/api/client/bookings.rb +9 -7
  7. data/lib/bookingsync/api/client/inquiries.rb +6 -4
  8. data/lib/bookingsync/api/client/payments.rb +4 -4
  9. data/lib/bookingsync/api/client/periods.rb +14 -13
  10. data/lib/bookingsync/api/client/photos.rb +53 -0
  11. data/lib/bookingsync/api/client/rates_tables.rb +5 -5
  12. data/lib/bookingsync/api/client/rental_agreements.rb +22 -19
  13. data/lib/bookingsync/api/client/rentals.rb +7 -6
  14. data/lib/bookingsync/api/client/reviews.rb +6 -5
  15. data/lib/bookingsync/api/client/seasons.rb +15 -13
  16. data/lib/bookingsync/api/client/special_offers.rb +19 -18
  17. data/lib/bookingsync/api/error.rb +18 -0
  18. data/lib/bookingsync/api/middleware/logger.rb +50 -0
  19. data/lib/bookingsync/api/version.rb +1 -1
  20. data/spec/bookingsync/api/client/bookings_spec.rb +5 -4
  21. data/spec/bookingsync/api/client/inquiries_spec.rb +4 -3
  22. data/spec/bookingsync/api/client/periods_spec.rb +9 -14
  23. data/spec/bookingsync/api/client/photos_spec.rb +58 -0
  24. data/spec/bookingsync/api/client/rental_agreements_spec.rb +10 -10
  25. data/spec/bookingsync/api/client/rentals_spec.rb +3 -3
  26. data/spec/bookingsync/api/client/reviews_spec.rb +5 -4
  27. data/spec/bookingsync/api/client/seasons_spec.rb +5 -4
  28. data/spec/bookingsync/api/client/special_offers_spec.rb +5 -4
  29. data/spec/bookingsync/api/client_spec.rb +43 -3
  30. data/spec/{cassettes → fixtures/cassettes}/BookingSync_API_Client_Amenities/_amenities/returns_amenities.yml +1 -1
  31. data/spec/{cassettes → fixtures/cassettes}/BookingSync_API_Client_BillingAddresses/_billing_addresses/returns_billing_addresses.yml +1 -1
  32. data/spec/{cassettes → fixtures/cassettes}/BookingSync_API_Client_Bookings/_bookings/pagination/with_a_block/yields_block_with_batch_of_bookings.yml +0 -0
  33. 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
  34. data/spec/{cassettes → fixtures/cassettes}/BookingSync_API_Client_Bookings/_bookings/pagination/with_per_page_setting/returns_limited_number_of_bookings.yml +0 -0
  35. data/spec/{cassettes → fixtures/cassettes}/BookingSync_API_Client_Bookings/_bookings/returns_bookings.yml +0 -0
  36. data/spec/{cassettes → fixtures/cassettes}/BookingSync_API_Client_Bookings/_cancel_booking/cancels_given_booking.yml +0 -0
  37. data/spec/{cassettes → fixtures/cassettes}/BookingSync_API_Client_Bookings/_clients/returns_clients.yml +0 -0
  38. data/spec/{cassettes → fixtures/cassettes}/BookingSync_API_Client_Bookings/_create_booking/creates_a_booking.yml +1 -1
  39. data/spec/{cassettes → fixtures/cassettes}/BookingSync_API_Client_Bookings/_create_client/creates_a_new_client.yml +0 -0
  40. data/spec/{cassettes → fixtures/cassettes}/BookingSync_API_Client_Bookings/_edit_booking/updates_given_booking_by_ID.yml +0 -0
  41. data/spec/{cassettes → fixtures/cassettes}/BookingSync_API_Client_Bookings/_edit_client/updates_given_client_by_ID.yml +0 -0
  42. data/spec/{cassettes → fixtures/cassettes}/BookingSync_API_Client_BookingsPayments/_bookings_payments/returns_bookings_payments.yml +1 -1
  43. data/spec/{cassettes → fixtures/cassettes}/BookingSync_API_Client_Destinations/_destinations/returns_destinations.yml +1 -1
  44. data/spec/{cassettes → fixtures/cassettes}/BookingSync_API_Client_Inquiries/_create_inquiry/creates_a_new_inquiry.yml +1 -1
  45. data/spec/{cassettes → fixtures/cassettes}/BookingSync_API_Client_Inquiries/_inquiries/returns_inquiries.yml +0 -0
  46. data/spec/{cassettes → fixtures/cassettes}/BookingSync_API_Client_Payments/_cancel_payment/cancels_given_payment.yml +1 -1
  47. data/spec/{cassettes → fixtures/cassettes}/BookingSync_API_Client_Payments/_create_payment/creates_a_new_payment.yml +1 -1
  48. data/spec/{cassettes → fixtures/cassettes}/BookingSync_API_Client_Payments/_edit_payment/updates_given_payment_by_ID.yml +1 -1
  49. data/spec/{cassettes → fixtures/cassettes}/BookingSync_API_Client_Payments/_payments/returns_payments.yml +1 -1
  50. data/spec/{cassettes → fixtures/cassettes}/BookingSync_API_Client_Periods/_create_period/creates_a_new_period.yml +2 -2
  51. data/spec/fixtures/cassettes/BookingSync_API_Client_Periods/_delete_period/deletes_given_period.yml +57 -0
  52. data/spec/{cassettes → fixtures/cassettes}/BookingSync_API_Client_Periods/_edit_period/updates_given_period_by_ID.yml +1 -1
  53. data/spec/{cassettes → fixtures/cassettes}/BookingSync_API_Client_Periods/_periods/returns_periods.yml +1 -1
  54. data/spec/fixtures/cassettes/BookingSync_API_Client_Photos/_create_photo/creates_a_photo.yml +63 -0
  55. data/spec/fixtures/cassettes/BookingSync_API_Client_Photos/_create_photo/creates_a_photo_with_encoded_photo_file.yml +63 -0
  56. data/spec/fixtures/cassettes/BookingSync_API_Client_Photos/_create_photo/creates_a_photo_with_photo_path.yml +63 -0
  57. data/spec/fixtures/cassettes/BookingSync_API_Client_Photos/_create_photo/creates_a_photo_with_remote_URL.yml +63 -0
  58. data/spec/fixtures/cassettes/BookingSync_API_Client_Photos/_delete_photo/delete_given_photo.yml +57 -0
  59. data/spec/fixtures/cassettes/BookingSync_API_Client_Photos/_edit_photo/updates_photo_s_description.yml +61 -0
  60. data/spec/fixtures/cassettes/BookingSync_API_Client_Photos/_edit_photo/updates_photo_s_image_file.yml +61 -0
  61. data/spec/{cassettes → fixtures/cassettes}/BookingSync_API_Client_Photos/_photos/returns_photos.yml +1 -1
  62. data/spec/{cassettes → fixtures/cassettes}/BookingSync_API_Client_Rates/_rates/returns_rates.yml +0 -0
  63. data/spec/{cassettes → fixtures/cassettes}/BookingSync_API_Client_RatesRules/_rates_rules/returns_rates_rules.yml +0 -0
  64. data/spec/{cassettes → fixtures/cassettes}/BookingSync_API_Client_RatesTables/_create_rates_table/creates_a_new_rates_table.yml +1 -1
  65. data/spec/{cassettes → fixtures/cassettes}/BookingSync_API_Client_RatesTables/_delete_rates_table/deletes_given_rates_table.yml +1 -1
  66. data/spec/{cassettes → fixtures/cassettes}/BookingSync_API_Client_RatesTables/_edit_rates_table/updates_given_rates_table_by_ID.yml +1 -1
  67. data/spec/{cassettes → fixtures/cassettes}/BookingSync_API_Client_RatesTables/_rates_tables/returns_rates_tables.yml +1 -1
  68. data/spec/{cassettes → fixtures/cassettes}/BookingSync_API_Client_RentalAgreements/_create_rental_agreement/creates_a_new_rental_agreement.yml +1 -1
  69. data/spec/{cassettes → fixtures/cassettes}/BookingSync_API_Client_RentalAgreements/_create_rental_agreement_for_booking/creates_a_new_rental_agreement.yml +3 -3
  70. data/spec/{cassettes → fixtures/cassettes}/BookingSync_API_Client_RentalAgreements/_create_rental_agreement_for_rental/creates_a_new_rental_agreement.yml +3 -3
  71. data/spec/{cassettes → fixtures/cassettes}/BookingSync_API_Client_RentalAgreements/_rental_agreements/returns_rental_agreements.yml +1 -1
  72. data/spec/{cassettes → fixtures/cassettes}/BookingSync_API_Client_Rentals/_create_rental/creates_a_new_rental.yml +1 -1
  73. 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
  74. data/spec/{cassettes → fixtures/cassettes}/BookingSync_API_Client_Rentals/_edit_rental/updates_given_rental_by_ID.yml +1 -1
  75. data/spec/{cassettes → fixtures/cassettes}/BookingSync_API_Client_Rentals/_rental/returns_a_single_rental.yml +0 -0
  76. data/spec/{cassettes → fixtures/cassettes}/BookingSync_API_Client_Rentals/_rentals/links/returns_associated_photos.yml +0 -0
  77. data/spec/{cassettes → fixtures/cassettes}/BookingSync_API_Client_Rentals/_rentals/links/returns_links_to_associated_resources.yml +0 -0
  78. data/spec/{cassettes → fixtures/cassettes}/BookingSync_API_Client_Rentals/_rentals/returns_rentals.yml +1 -1
  79. data/spec/{cassettes → fixtures/cassettes}/BookingSync_API_Client_Reviews/_create_review/creates_a_new_review.yml +3 -3
  80. data/spec/{cassettes → fixtures/cassettes}/BookingSync_API_Client_Reviews/_reviews/returns_reviews.yml +1 -1
  81. data/spec/{cassettes → fixtures/cassettes}/BookingSync_API_Client_Seasons/_create_season/creates_a_new_season.yml +3 -3
  82. data/spec/{cassettes → fixtures/cassettes}/BookingSync_API_Client_Seasons/_delete_season/deletes_given_season.yml +1 -1
  83. data/spec/{cassettes → fixtures/cassettes}/BookingSync_API_Client_Seasons/_edit_season/updates_given_season_by_ID.yml +1 -1
  84. data/spec/{cassettes → fixtures/cassettes}/BookingSync_API_Client_Seasons/_seasons/returns_seasons.yml +1 -1
  85. data/spec/{cassettes → fixtures/cassettes}/BookingSync_API_Client_SpecialOffers/_create_special_offer/creates_a_new_special_offer.yml +2 -2
  86. data/spec/{cassettes → fixtures/cassettes}/BookingSync_API_Client_SpecialOffers/_delete_special_offer/deletes_given_special_offer.yml +1 -1
  87. data/spec/{cassettes → fixtures/cassettes}/BookingSync_API_Client_SpecialOffers/_edit_special_offer/updates_given_special_offer_by_ID.yml +1 -1
  88. data/spec/{cassettes → fixtures/cassettes}/BookingSync_API_Client_SpecialOffers/_special_offers/returns_special_offers.yml +0 -0
  89. data/spec/{cassettes → fixtures/cassettes}/spec/cassettes/BookingSync_API_Client_Bookings/_create_booking/creates_a_booking_yml.yml +0 -0
  90. data/spec/fixtures/files/test.jpg +0 -0
  91. data/spec/spec_helper.rb +1 -1
  92. metadata +141 -124
  93. 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] ID of the rates table
24
- # @param options [Hash] season attributes
25
- # @return [BookingSync::API::Resource] Newly created season
26
- def create_season(rates_table_id, options = {})
27
- post(:seasons, rates_table_id: rates_table_id, seasons: [options]).pop
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] season or ID of the season
33
- # to be updated
34
- # @param options [Hash] season attributes to be updated
35
- # @return [BookingSync::API::Resource] Updated season on success, exception is raised otherwise
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] season or ID of the season
46
- # to be deleted
47
- # @return [Array] An empty Array on success, exception is raised otherwise
48
- def delete_season(season, options = {})
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 special_offers for the account user is authenticated with.
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 special_offer
21
+ # Create a new special offer for a rental
22
22
  #
23
- # @param rental_id [Integer] ID of the rental
24
- # @param options [Hash] special_offer attributes
25
- # @return [BookingSync::API::Resource] Newly created special offer
26
- def create_special_offer(rental_id, options = {})
27
- post(:special_offers, rental_id: rental_id, special_offers: [options]).pop
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 special_offer
31
+ # Edit a special offer
31
32
  #
32
- # @param special_offer [BookingSync::API::Resource|Integer] special offer or
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
- # exception is raised otherwise
37
+ # exception is raised otherwise.
37
38
  # @example
38
39
  # special_offer = @api.special_offers.first
39
- # @api.edit_special_offer(special_offer, { name: "New 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 special_offer
45
+ # Delete a special offer
45
46
  #
46
- # @param special_offer [BookingSync::API::Resource|Integer] special offer or
47
- # ID of the special offer to be deleted
48
- # @return [Array] An empty Array on success, exception is raised otherwise
49
- def delete_special_offer(special_offer, options = {})
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
@@ -1,5 +1,5 @@
1
1
  module BookingSync
2
2
  module API
3
- VERSION = "0.0.8"
3
+ VERSION = "0.0.9"
4
4
  end
5
5
  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', rental_id: 20,
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
- start_at: "2013-04-10",
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(9, attributes)
22
- assert_requested :post, bs_url("periods"),
23
- body: { season_id: 9, periods: [attributes] }.to_json
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(9, attributes)
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(10)
58
- assert_requested :delete, bs_url("periods/10")
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(:booking_id) { 2 }
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(booking_id, attributes)
36
- assert_requested :post, bs_url("rental_agreements"),
37
- body: { booking_id: booking_id, rental_agreements: [attributes] }.to_json
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(booking_id, attributes)
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(:rental_id) { 20 }
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(rental_id, attributes)
53
- assert_requested :post, bs_url("rental_agreements"),
54
- body: { rental_id: rental_id, rental_agreements: [attributes] }.to_json
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(rental_id, attributes)
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 ".cancel_rental", :vcr do
65
- it "cancels given rental" do
66
- client.cancel_rental(4)
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(1, attributes)
21
- assert_requested :post, bs_url("reviews"),
22
- body: { booking_id: 1, reviews: [attributes] }.to_json
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(1, attributes)
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