Skip to content

Commit

Permalink
Wrap host reviews, review dismissal and review replies (#144)
Browse files Browse the repository at this point in the history
* 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
StoneFrog authored Aug 1, 2023
1 parent 5b4d76b commit 9aaa477
Show file tree
Hide file tree
Showing 29 changed files with 1,477 additions and 75 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

# master

- Add support for `host_reviews` endpoint.
- Add support for `review_replies` endpoint.
- Add support for `dismiss_review` action.

## 1.0.0

- Drop support for ruby prior to 2.7
Expand Down
4 changes: 4 additions & 0 deletions lib/bookingsync/api/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
require "bookingsync/api/client/contacts"
require "bookingsync/api/client/destinations"
require "bookingsync/api/client/fees"
require "bookingsync/api/client/host_reviews"
require "bookingsync/api/client/hosts"
require "bookingsync/api/client/inquiries"
require "bookingsync/api/client/living_rooms"
Expand All @@ -39,6 +40,7 @@
require "bookingsync/api/client/rental_cancelation_policy_items"
require "bookingsync/api/client/rentals_contents_overrides"
require "bookingsync/api/client/rental_urls"
require "bookingsync/api/client/review_replies"
require "bookingsync/api/client/reviews"
require "bookingsync/api/client/seasons"
require "bookingsync/api/client/special_offers"
Expand Down Expand Up @@ -79,6 +81,7 @@ class Client
include BookingSync::API::Client::Destinations
include BookingSync::API::Client::Fees
include BookingSync::API::Client::Hosts
include BookingSync::API::Client::HostReviews
include BookingSync::API::Client::Inquiries
include BookingSync::API::Client::LivingRooms
include BookingSync::API::Client::Messages
Expand All @@ -101,6 +104,7 @@ class Client
include BookingSync::API::Client::RentalCancelationPolicyItems
include BookingSync::API::Client::RentalsContentsOverrides
include BookingSync::API::Client::RentalUrls
include BookingSync::API::Client::ReviewReplies
include BookingSync::API::Client::Reviews
include BookingSync::API::Client::Seasons
include BookingSync::API::Client::SpecialOffers
Expand Down
95 changes: 95 additions & 0 deletions lib/bookingsync/api/client/host_reviews.rb
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
53 changes: 53 additions & 0 deletions lib/bookingsync/api/client/review_replies.rb
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
10 changes: 10 additions & 0 deletions lib/bookingsync/api/client/reviews.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,16 @@ def review(review, options = {})
def create_review(booking, options = {})
post("bookings/#{booking}/reviews", reviews: [options]).pop
end

# Dismiss a review
#
# @param booking [BookingSync::API::Resource|Integer] Review or ID of
# the review which you want to dismiss.
# @param options [Hash] Review's dismissal attributes.
# @return [BookingSync::API::Resource] Dismissed review.
def dismiss_review(review, options = {})
put("reviews/#{review}/dismiss", reviews: [options]).pop
end
end
end
end
150 changes: 150 additions & 0 deletions spec/bookingsync/api/client/host_reviews_spec.rb
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
Loading

0 comments on commit 9aaa477

Please sign in to comment.