-
Notifications
You must be signed in to change notification settings - Fork 6
add support for rental_contacts endpoint #134
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
adrian-fernandez
wants to merge
3
commits into
master
Choose a base branch
from
add-rental-contacts
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 | ||
| 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) | ||
|
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 | ||
71 changes: 71 additions & 0 deletions
71
...ingSync_API_Client_RentalContacts/_create_rental_contact/creates_a_new_rental_contact.yml
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
63 changes: 63 additions & 0 deletions
63
...ingSync_API_Client_RentalContacts/_delete_rental_contact/deletes_given_rental_contact.yml
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
69 changes: 69 additions & 0 deletions
69
...ync_API_Client_RentalContacts/_edit_rental_contact/updates_given_rental_contact_by_ID.yml
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.