-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #374 from roomorama/release/0.11.0
Release/0.11.0
- Loading branch information
Showing
46 changed files
with
1,020 additions
and
350 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
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 |
---|---|---|
|
@@ -6,3 +6,4 @@ | |
- ROOMORAMA_SECRET_WAYTOSTAY | ||
- ROOMORAMA_SECRET_CIIRUS | ||
- ROOMORAMA_SECRET_SAW | ||
- ZENDESK_NOTIFY_URL |
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,18 @@ | ||
require_relative "../cancel" | ||
require_relative "../zendesk_notify_cancellation" | ||
|
||
module API::Controllers::AtLeisure | ||
|
||
# API::Controllers::AtLeisure::Cancel | ||
# | ||
# AtLeisure does not have a cancellation API. Therefore, when a booking is | ||
# cancelled, we notify Customer Support through Zendesk. | ||
class Cancel | ||
include API::Controllers::Cancel | ||
include API::Controllers::ZendeskNotifyCancellation | ||
|
||
def supplier_name | ||
AtLeisure::Client::SUPPLIER_NAME | ||
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,18 @@ | ||
require_relative "../cancel" | ||
require_relative "../zendesk_notify_cancellation" | ||
|
||
module API::Controllers::Poplidays | ||
|
||
# API::Controllers::Poplidays::Cancel | ||
# | ||
# Poplidays does not have a cancellation API. Therefore, when a booking is | ||
# cancelled, we notify Customer Support through Zendesk. | ||
class Cancel | ||
include API::Controllers::Cancel | ||
include API::Controllers::ZendeskNotifyCancellation | ||
|
||
def supplier_name | ||
Poplidays::Client::SUPPLIER_NAME | ||
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,32 @@ | ||
module API::Controllers | ||
|
||
# +API::Controllers::ZendeskNotifyCancellation+ | ||
# | ||
# This module implements the +cancel_reservation+ method expected to be present | ||
# on cancellation controllers that include the helper +API::Controllers::Cancel+ | ||
# module. | ||
# | ||
# The +cancel_reservation+ expects a +supplier_name+ method to be implemented | ||
# (a requirement already enforced by +API::Controllers::Cancel+), and sends a request | ||
# to the +ZendeskNotify+ service to notify Customer Support about a supplier cancellation. | ||
# | ||
# To be used by suppliers which do not provide a cancellation API. | ||
module ZendeskNotifyCancellation | ||
|
||
def cancel_reservation(params) | ||
zendesk_notify = API::Support::ZendeskNotify.new.notify("cancellation", { | ||
supplier: supplier_name, | ||
supplier_id: params[:reference_number], | ||
bridge_id: params[:inquiry_id] | ||
}) | ||
|
||
if zendesk_notify.success? | ||
Result.new(params[:reference_number]) | ||
else | ||
zendesk_notify | ||
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,91 @@ | ||
module API::Support | ||
|
||
# +API::Support::ZendeskNotify+ | ||
# | ||
# This is a client class to the +ZendeskNotify+ service, a simple API to | ||
# send tickets on Roomorama/BridgeRentals Zendesk account. | ||
# | ||
# Usage | ||
# | ||
# client = API::Support::ZendeskNotify.new | ||
# ticket_id = "cancellation" | ||
# attributes = { | ||
# supplier: "Supplier X", | ||
# supplier_id: "212", | ||
# bridge_id: "291" | ||
# } | ||
# | ||
# client.notify # => <#Result value=true> | ||
# | ||
# The +attributes+ passed when calling the +notify+ method are dependent on the | ||
# type of ticket being sent. | ||
class ZendeskNotify | ||
include Concierge::JSON | ||
|
||
SUPPORTED_TICKETS = %w(cancellation) | ||
|
||
# Zendesk's API is very slow when sending tickets. Especially on the sandbox | ||
# environment. As the cancellation webhook is sent on the background, without | ||
# blocking the user interface, we can afford a higher timeout. | ||
CONNECTION_TIMEOUT = 20 | ||
|
||
attr_reader :http, :endpoint | ||
|
||
# initializes internal state. The +ZendeskNotify+ service URL must be properly | ||
# configured on the +ZENDESK_NOTIFY_URL+ environment variable. | ||
def initialize | ||
uri = URI.parse(zendesk_notify_url) | ||
host = [uri.scheme, "://", uri.host].join | ||
|
||
@http = Concierge::HTTPClient.new(host, timeout: CONNECTION_TIMEOUT) | ||
@endpoint = uri.request_uri | ||
end | ||
|
||
def notify(ticket_id, attributes) | ||
return invalid_ticket unless SUPPORTED_TICKETS.include?(ticket_id.to_s) | ||
|
||
params = { | ||
ticketId: ticket_id, | ||
attributes: attributes | ||
} | ||
|
||
result = http.post(endpoint, json_encode(params), { "Content-Type" => "application/json" }) | ||
return result unless result.success? | ||
|
||
parse_response(result.value.body) | ||
end | ||
|
||
private | ||
|
||
# expected response (examples) | ||
# | ||
# Success | ||
# { "status": "ok", "message": "Ticket sent successfully" } | ||
# | ||
# Failure | ||
# { "status": "error", "message": "Failure to deliver ticket" } | ||
def parse_response(body) | ||
decoded_body = json_decode(body) | ||
return decoded_body unless decoded_body.success? | ||
|
||
successful = (decoded_body.value["status"] == "ok") | ||
|
||
if successful | ||
Result.new(true) | ||
else | ||
error_message = decoded_body.value["message"] | ||
Result.error(:zendesk_notify_failure, error_message) | ||
end | ||
end | ||
|
||
def invalid_ticket | ||
Result.error(:zendesk_invalid_ticket) | ||
end | ||
|
||
def zendesk_notify_url | ||
ENV["ZENDESK_NOTIFY_URL"] | ||
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
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
Oops, something went wrong.