-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Wrap host reviews, review dismissal and review replies (#144)
* add suppoort for host reviews and reviews replies * rubo * add new host reviews endpoints rerecord specs * rework specs for older rubies * rubo * adjust command for rubocop following new gem release * dismissal * migrate faraday to 2+ * revert settigns * changelog
- Loading branch information
Showing
29 changed files
with
1,477 additions
and
75 deletions.
There are no files selected for viewing
This file contains 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 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 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,95 @@ | ||
module BookingSync::API | ||
class Client | ||
module HostReviews | ||
# List host reviews | ||
# | ||
# Returns host reviews for the account user is authenticated with. | ||
# @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 reviews. | ||
# | ||
# @example Get the list of host reviews for the current account | ||
# host_reviews = @api.host_reviews | ||
# host_reviews.first.is_guest_recommended # => true | ||
# @example Get the list of host reviews only with submitted_at and comment for smaller response | ||
# @api.host_reviews(fields: [:submitted_at, :comment]) | ||
# @see http://developers.bookingsync.com/reference/endpoints/host_reviews/#list-host-reviews | ||
def host_reviews(options = {}, &block) | ||
paginate :host_reviews, options, &block | ||
end | ||
|
||
# Get a single host review | ||
# | ||
# @param host review [BookingSync::API::Resource|String] HostReview or ID | ||
# of the host review. | ||
# @param options [Hash] A customizable set of query options. | ||
# @option options [Array] fields: List of fields to be fetched. | ||
# @return [BookingSync::API::Resource] | ||
def host_review(host_review, options = {}) | ||
get("host_reviews/#{host_review}", options).pop | ||
end | ||
|
||
# Create a new non-submitted host review | ||
# | ||
# @param booking [BookingSync::API::Resource|Integer] Booking or ID of | ||
# the booking for which a host review will be created. | ||
# @param options [Hash] Host Review's attributes. | ||
# @return [BookingSync::API::Resource] Newly created host review. | ||
def create_draft_host_review(booking, options = {}) | ||
post("bookings/#{booking}/host_reviews/draft", host_reviews: [options]).pop | ||
end | ||
|
||
# Create a new submitted host review | ||
# | ||
# @param booking [BookingSync::API::Resource|Integer] Booking or ID of | ||
# the booking for which a host review will be created. | ||
# @param options [Hash] Host Review's attributes. | ||
# @return [BookingSync::API::Resource] Newly created host review. | ||
def create_submitted_host_review(booking, options = {}) | ||
post("bookings/#{booking}/host_reviews", host_reviews: [options]).pop | ||
end | ||
|
||
# Edit a draft host review | ||
# | ||
# @param host review [BookingSync::API::Resource|String] Host Review or ID of | ||
# the host review to be updated. | ||
# @param options [Hash] Host review attributes to be updated. | ||
# @return [BookingSync::API::Resource] Updated host review on success, | ||
# exception is raised otherwise. | ||
# @example | ||
# host_review = @api.host_reviews.first | ||
# @api.edit_host_review(host_review, { comment: "Thanks for being such a great guest!", submitted_at: "20201-03-22T12:00:00Z" }) | ||
def edit_draft_host_review(host_review, options = {}) | ||
put("host_reviews/draft/#{host_review}", host_reviews: [options]).pop | ||
end | ||
|
||
# Submit a draft host review | ||
# | ||
# @param host review [BookingSync::API::Resource|String] Host Review or ID of | ||
# the host review to be updated. | ||
# @param options [Hash] Host review attributes to be updated. | ||
# @return [BookingSync::API::Resource] Updated host review on success, | ||
# exception is raised otherwise. | ||
# @example | ||
# host_review = @api.host_reviews.first | ||
# @api.edit_host_review(host_review, { comment: "Thanks for being such a great guest!", submitted_at: "20201-03-22T12:00:00Z" }) | ||
def submit_draft_host_review(host_review, options = {}) | ||
put("host_reviews/draft/#{host_review}/submit", host_reviews: [options]).pop | ||
end | ||
|
||
# Dismiss a host review | ||
# | ||
# @param host review [BookingSync::API::Resource|String] Host Review or ID of | ||
# the host review to be dismissed. | ||
# @param options [Hash] Host review dismissal attributes. | ||
# @return [BookingSync::API::Resource] Dismissed host review on success, | ||
# exception is raised otherwise. | ||
# @example | ||
# host_review = @api.host_reviews.first | ||
# @api.dismiss_host_review(host_review, { dismissed_at: "20201-03-22T12:00:00Z" }) | ||
def dismiss_host_review(host_review, options = {}) | ||
put("host_reviews/#{host_review}/dismiss", host_reviews: [options]).pop | ||
end | ||
end | ||
end | ||
end |
This file contains 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,53 @@ | ||
module BookingSync::API | ||
class Client | ||
module ReviewReplies | ||
# List review replies | ||
# | ||
# Returns review replies for the account user is authenticated with. | ||
# @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 review replies. | ||
# | ||
# @example Get the list of review replies for the current account | ||
# review_replies = @api.review_replies | ||
# review_replies.first.message # => "Thanks for the feedback!" | ||
# @example Get the list of review_replies only with message and submitted_at for smaller response | ||
# @api.review_replies(fields: [:message, :submitted_at]) | ||
# @see http://developers.bookingsync.com/reference/endpoints/review_replies/#list-review-replies | ||
def review_replies(options = {}, &block) | ||
paginate :review_replies, options, &block | ||
end | ||
|
||
# Get a single review reply | ||
# | ||
# @param review reply [BookingSync::API::Resource|String] Review Reply or ID | ||
# of the review reply. | ||
# @param options [Hash] A customizable set of query options. | ||
# @option options [Array] fields: List of fields to be fetched. | ||
# @return [BookingSync::API::Resource] | ||
def review_reply(review_reply, options = {}) | ||
get("review_replies/#{review_reply}", options).pop | ||
end | ||
|
||
# Create a new review reply | ||
# | ||
# @param review [BookingSync::API::Resource|Integer] Review or ID of | ||
# the review for which a reply will be created. | ||
# @param options [Hash] Review's attributes. | ||
# @return [BookingSync::API::Resource] Newly created review. | ||
def create_guest_review_reply(review, options = {}) | ||
post("reviews/#{review}/reply", review_replies: [options]).pop | ||
end | ||
|
||
# Create a new host review reply | ||
# | ||
# @param host review [BookingSync::API::Resource|Integer] HostReview or ID of | ||
# the host review for which a reply will be created. | ||
# @param options [Hash] Review's attributes. | ||
# @return [BookingSync::API::Resource] Newly created review. | ||
def create_host_review_reply(host_review, options = {}) | ||
post("host_reviews/#{host_review}/reply", review_replies: [options]).pop | ||
end | ||
end | ||
end | ||
end |
This file contains 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 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,150 @@ | ||
require "spec_helper" | ||
|
||
describe BookingSync::API::Client::HostReviews do | ||
let(:client) { BookingSync::API::Client.new(test_access_token) } | ||
|
||
before { |ex| @casette_base_path = casette_path(casette_dir, ex.metadata) } | ||
|
||
describe ".host_reviews", :vcr do | ||
it "returns host_reviews" do | ||
expect(client.host_reviews).not_to be_empty | ||
assert_requested :get, bs_url("host_reviews") | ||
end | ||
end | ||
|
||
describe ".host_review", :vcr do | ||
let(:prefetched_host_review_id) do | ||
find_resource("#{@casette_base_path}_host_reviews/returns_host_reviews.yml", "host_reviews")[:id] | ||
end | ||
|
||
it "returns a single host_review" do | ||
host_review = client.host_review(prefetched_host_review_id) | ||
expect(host_review.id).to eq prefetched_host_review_id | ||
end | ||
end | ||
|
||
describe ".create_draft_host_review", :vcr do | ||
let(:attributes) { { comment: "Awesome guest", expires_at: "2045-06-07T12:00:00Z", shareable: false } } | ||
let(:booking) { BookingSync::API::Resource.new(client, id: 228) } | ||
|
||
it "creates a new draft review" do | ||
client.create_draft_host_review(booking, attributes) | ||
assert_requested :post, bs_url("bookings/#{booking}/host_reviews/draft"), | ||
body: { host_reviews: [attributes] }.to_json | ||
end | ||
|
||
it "returns newly created review" do | ||
VCR.use_cassette("BookingSync_API_Client_HostReviews/_create_draft_host_review/creates_a_new_draft_review") do | ||
host_review = client.create_draft_host_review(booking, attributes) | ||
expect(host_review.comment).to eq(attributes[:comment]) | ||
end | ||
end | ||
end | ||
|
||
describe ".create_submitted_host_review", :vcr do | ||
let(:attributes) do | ||
{ | ||
comment: "Awesome guest", | ||
submitted_at: "2020-06-06T12:00:00Z", | ||
expires_at: "2020-06-07T12:00:00Z", | ||
is_guest_recommended: true, | ||
shareable: false, | ||
source_id: source_id, | ||
criteria: { | ||
cleanliness: { rating: 5 }, | ||
respect_house_rules: { rating: 4 }, | ||
communication: { rating: 5 } | ||
} | ||
} | ||
end | ||
let(:booking) { BookingSync::API::Resource.new(client, id: 3) } | ||
let(:source_id) { 2 } | ||
|
||
it "creates a new submitted review" do | ||
client.create_submitted_host_review(booking, attributes) | ||
assert_requested :post, bs_url("bookings/#{booking}/host_reviews"), | ||
body: { host_reviews: [attributes] }.to_json | ||
end | ||
|
||
it "returns newly created review" do | ||
VCR.use_cassette("BookingSync_API_Client_HostReviews/_create_submitted_host_review/creates_a_new_submitted_review") do | ||
host_review = client.create_submitted_host_review(booking, attributes) | ||
expect(host_review.comment).to eq(attributes[:comment]) | ||
end | ||
end | ||
end | ||
|
||
describe ".edit_draft_host_review", :vcr do | ||
let(:attributes) { { comment: "Woops, not great after all, he emptied the fridge" } } | ||
let(:created_host_review_id) do | ||
find_resource("#{@casette_base_path}_create_draft_host_review/creates_a_new_draft_review.yml", "host_reviews")[:id] | ||
end | ||
|
||
it "updates given host review by ID" do | ||
client.edit_draft_host_review(created_host_review_id, attributes) | ||
assert_requested :put, bs_url("host_reviews/draft/#{created_host_review_id}"), | ||
body: { host_reviews: [attributes] }.to_json | ||
end | ||
|
||
it "returns updated host review" do | ||
VCR.use_cassette("BookingSync_API_Client_HostReviews/_edit_draft_host_review/updates_given_host_review_by_ID") do | ||
host_review = client.edit_draft_host_review(created_host_review_id, attributes) | ||
expect(host_review).to be_kind_of(BookingSync::API::Resource) | ||
expect(host_review.comment).to eq("Woops, not great after all, he emptied the fridge") | ||
end | ||
end | ||
end | ||
|
||
describe ".submit_draft_host_review", :vcr do | ||
let(:attributes) do | ||
{ | ||
comment: "Woops, not great after all, he emptied the fridge", | ||
submitted_at: "2021-06-06T12:00:00Z", | ||
is_guest_recommended: false | ||
} | ||
end | ||
let(:created_host_review_id) do | ||
find_resource("#{@casette_base_path}_create_draft_host_review/creates_a_new_draft_review.yml", "host_reviews")[:id] | ||
end | ||
|
||
it "submits given host review by ID" do | ||
client.submit_draft_host_review(created_host_review_id, attributes) | ||
assert_requested :put, bs_url("host_reviews/draft/#{created_host_review_id}/submit"), | ||
body: { host_reviews: [attributes] }.to_json | ||
end | ||
|
||
it "returns updated host review" do | ||
VCR.use_cassette("BookingSync_API_Client_HostReviews/_submit_draft_host_review/submits_given_host_review_by_ID") do | ||
host_review = client.submit_draft_host_review(created_host_review_id, attributes) | ||
expect(host_review).to be_kind_of(BookingSync::API::Resource) | ||
expect( | ||
host_review.values_at(:comment, :submitted_at, :is_guest_recommended) | ||
).to eq([ | ||
"Woops, not great after all, he emptied the fridge", | ||
Time.parse("2021-06-06T12:00:00Z"), | ||
false | ||
]) | ||
end | ||
end | ||
end | ||
|
||
describe ".dismiss_host_review", :vcr do | ||
let(:attributes) { { dismissed_at: "2021-12-01T16:00:00Z" } } | ||
let(:created_host_review_id) do | ||
find_resource("#{@casette_base_path}_create_submitted_host_review/creates_a_new_submitted_review.yml", "host_reviews")[:id] | ||
end | ||
|
||
it "dismisses host review" do | ||
client.dismiss_host_review(created_host_review_id, attributes) | ||
assert_requested :put, bs_url("host_reviews/#{created_host_review_id}/dismiss"), | ||
body: { host_reviews: [attributes] }.to_json | ||
end | ||
|
||
it "returns dismissed review" do | ||
VCR.use_cassette("BookingSync_API_Client_HostReviews/_dismiss_host_review/dismisses_host_review") do | ||
host_review = client.dismiss_host_review(created_host_review_id, attributes) | ||
expect(host_review.dismissed_at).to eq(Time.parse(attributes[:dismissed_at])) | ||
end | ||
end | ||
end | ||
end |
Oops, something went wrong.