Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

# master

## 0.1.14 - 2019-10-09
- Add supports for `rental_contacts` endpoint.

## 0.1.13 - 2019-10-08
- Add supports for `contacts` endpoint.

Expand Down
2 changes: 2 additions & 0 deletions lib/bookingsync/api/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
require "bookingsync/api/client/rental_agreements"
require "bookingsync/api/client/rental_cancelation_policies"
require "bookingsync/api/client/rental_cancelation_policy_items"
require "bookingsync/api/client/rental_contacts"
require "bookingsync/api/client/rentals_contents_overrides"
require "bookingsync/api/client/reviews"
require "bookingsync/api/client/seasons"
Expand Down Expand Up @@ -92,6 +93,7 @@ class Client
include BookingSync::API::Client::Rates
include BookingSync::API::Client::RatesRules
include BookingSync::API::Client::RatesTables
include BookingSync::API::Client::RentalContacts
include BookingSync::API::Client::Rentals
include BookingSync::API::Client::RentalsFees
include BookingSync::API::Client::RentalsAmenities
Expand Down
65 changes: 65 additions & 0 deletions lib/bookingsync/api/client/rental_contacts.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
module BookingSync::API
class Client
module RentalContacts
# List rental_contacts
#
# Returns all rantal_contacts related to rentals for the current account.
# @param options [Hash] A customizable set of options.
# @option options [Array] fields: List of fields to be fetched.
# @return [Array<BookingSync::API::Resource>] Array of rental_contacts.
#
# @example Get the list of rental_contacts for the current account
# rental_contacts = @api.rental_contacts
# rental_contacts.first.contact.title # => "Internet"
# @see http://developers.bookingsync.com/reference/endpoints/rental_contacts/#list-rentals-contacts
def rental_contacts(options = {}, &block)
paginate :rental_contacts, options, &block
end

# Get a single rental_contact
#
# @param rental_contact [BookingSync::API::Resource|Integer]
# rental_contact or ID of the rental_contact.
# @return [BookingSync::API::Resource]
def rental_contact(rental_contact)
get("rental_contacts/#{rental_contact}").pop
end

# Create a rental's contact
#
# @param rental [BookingSync::API::Resource|Integer] Rental object or ID
# for which the rental contact will be created.
# @param options [Hash] Rental Amenity' s attributes.
# @return [BookingSync::API::Resource] Newly created rental's contact.
# @example Create a rental's contact.
# @api.create_rental_contact(10, { contact_id: 50 }) # Add the Internet contact to the rental with ID 10
# @see http://developers.bookingsync.com/reference/endpoints/rental_contacts/#create-a-new-rentals-contact
def create_rental_contact(rental, options = {})
post("rentals/#{rental}/rental_contacts", rental_contacts: [options]).pop
end

# Edit a rental_contact
#
# @param rental_contact [BookingSync::API::Resource|Integer] RentalsAmenity or ID of
# the rental_contact to be updated.
# @param options [Hash] rental_contact attributes to be updated.
# @return [BookingSync::API::Resource] Updated rental_contact on success,
# exception is raised otherwise.
# @example
# rental_contact = @api.rental_contacts.first
# @api.edit_rental_contact(rental_contact, { details_en: "Details" })
def edit_rental_contact(rental_contact, options = {})
put("rental_contacts/#{rental_contact}", rental_contacts: [options]).pop
end

# Delete a rental_contact
#
# @param rental_contact [BookingSync::API::Resource|Integer] RentalsAmenity or ID
# of the rental_contact to be deleted.
# @return [NilClass] Returns nil on success.
def delete_rental_contact(rental_contact)
delete "rental_contacts/#{rental_contact}"
end
end
end
end
2 changes: 1 addition & 1 deletion lib/bookingsync/api/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module BookingSync
module API
VERSION = "0.1.13"
VERSION = "0.1.14"
end
end
78 changes: 78 additions & 0 deletions spec/bookingsync/api/client/rental_contacts_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
require "spec_helper"

describe BookingSync::API::Client::RentalContacts do
let(:client) { BookingSync::API::Client.new(test_access_token) }

before { |ex| @casette_base_path = casette_path(casette_dir, ex.metadata) }

describe ".rental_contacts", :vcr do
it "returns rental contacts" do
expect(client.rental_contacts).not_to be_empty
assert_requested :get, bs_url("rental_contacts")
end

describe "links" do
it "returns associated rental" do
rental_contacts = client.rental_contacts.first
expect(rental_contacts.rental).not_to be_empty
end

it "returns associated contacts" do
Comment thread
JulienItard marked this conversation as resolved.
rental_contacts = client.rental_contacts.first
expect(rental_contacts.dig(:links, :contact)).to eq 1
expect(rental_contacts.dig(:links, :rental)).to eq 1
end
end
end

describe ".create_rental_contact", :vcr do
let(:attributes) { { contact_id: 1, kind: "owner", roles: ["invoices"] } }
let(:rental) { BookingSync::API::Resource.new(client, id: 1) }

it "creates a new rental_contact" do
client.create_rental_contact(rental, attributes)
assert_requested :post, bs_url("rentals/#{rental}/rental_contacts"),
body: { rental_contacts: [attributes] }.to_json
end

it "returns newly created rental_contact" do
VCR.use_cassette("BookingSync_API_Client_RentalContacts/_create_rental_contact/creates_a_new_rental_contact") do
rental_contacts = client.create_rental_contact(rental, attributes)
Comment thread
JulienItard marked this conversation as resolved.
expect(rental_contacts.dig(:links, :contact)).to eq(1)
expect(rental_contacts.dig(:links, :rental)).to eq(1)
end
end
end

describe ".edit_rental_contact", :vcr do
let(:attributes) { { kind: "manager" } }
let(:created_rental_contacts_id) {
find_resource("#{@casette_base_path}_create_rental_contact/creates_a_new_rental_contact.yml", "rental_contacts")[:id]
}

it "updates given rental_contact by ID" do
client.edit_rental_contact(created_rental_contacts_id, attributes)
assert_requested :put, bs_url("rental_contacts/#{created_rental_contacts_id}"),
body: { rental_contacts: [attributes] }.to_json
end

it "returns updated rental_contact" do
VCR.use_cassette("BookingSync_API_Client_RentalContacts/_edit_rental_contact/updates_given_rental_contact_by_ID") do
rental_contacts = client.edit_rental_contact(created_rental_contacts_id, attributes)
expect(rental_contacts).to be_kind_of(BookingSync::API::Resource)
expect(rental_contacts.fetch(:kind)).to eq("manager")
end
end
end

describe ".delete_rental_contact", :vcr do
let(:created_rental_contacts_id) {
find_resource("#{@casette_base_path}_create_rental_contact/creates_a_new_rental_contact.yml", "rental_contacts")[:id]
}

it "deletes given rental_contact" do
client.delete_rental_contact(created_rental_contacts_id)
assert_requested :delete, bs_url("rental_contacts/#{created_rental_contacts_id}")
end
end
end

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading