-
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 #532 from roomorama/release/1.1.0
Release/1.1.0
- Loading branch information
Showing
70 changed files
with
4,860 additions
and
4 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
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,20 @@ | ||
require_relative "../booking" | ||
|
||
module API::Controllers::THH | ||
|
||
# +API::Controllers::THH::Booking+ | ||
# | ||
# Performs create booking for properties from THH. | ||
class Booking | ||
include API::Controllers::Booking | ||
|
||
def create_booking(params) | ||
credentials = Concierge::Credentials.for(supplier_name) | ||
THH::Client.new(credentials).book(params) | ||
end | ||
|
||
def supplier_name | ||
THH::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,20 @@ | ||
require_relative "../cancel" | ||
|
||
module API::Controllers::THH | ||
|
||
# API::Controllers::THH::Cancel | ||
# | ||
# Cancels reservation from THH. | ||
class Cancel | ||
include API::Controllers::Cancel | ||
|
||
def cancel_reservation(params) | ||
credentials = Concierge::Credentials.for(supplier_name) | ||
THH::Client.new(credentials).cancel(params) | ||
end | ||
|
||
def supplier_name | ||
THH::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,20 @@ | ||
require_relative "../quote" | ||
|
||
module API::Controllers::THH | ||
|
||
# API::Controllers::THH::Quote | ||
# | ||
# Performs booking quotations for properties from THH. | ||
class Quote | ||
include API::Controllers::Quote | ||
|
||
def quote_price(params) | ||
credentials = Concierge::Credentials.for(supplier_name) | ||
THH::Client.new(credentials).quote(params) | ||
end | ||
|
||
def supplier_name | ||
THH::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,75 @@ | ||
module Workers::Suppliers::THH | ||
# +Workers::Suppliers::THH::Availabilities+ | ||
# | ||
# Performs properties availabilities synchronisation with supplier | ||
class Availabilities | ||
attr_reader :synchronisation, :host | ||
|
||
def initialize(host) | ||
@host = host | ||
@synchronisation = Workers::CalendarSynchronisation.new(host) | ||
end | ||
|
||
def perform | ||
identifiers = all_identifiers | ||
|
||
identifiers.each do |property_id| | ||
synchronisation.start(property_id) do | ||
result = fetch_property(property_id) | ||
next result unless result.success? | ||
property = result.value | ||
|
||
roomorama_calendar = mapper.build(property) | ||
Result.new(roomorama_calendar) | ||
end | ||
end | ||
synchronisation.finish! | ||
end | ||
|
||
private | ||
|
||
def report_error(message) | ||
yield.tap do |result| | ||
augment_context_error(message) unless result.success? | ||
end | ||
end | ||
|
||
def fetch_property(property_id) | ||
report_error("Failed to fetch details for property `#{property_id}`") do | ||
importer.fetch_property(property_id) | ||
end | ||
end | ||
|
||
def all_identifiers | ||
PropertyRepository.from_host(host).only(:identifier).map(&:identifier) | ||
end | ||
|
||
def mapper | ||
@mapper ||= ::THH::Mappers::RoomoramaCalendar.new | ||
end | ||
|
||
def importer | ||
@importer ||= ::THH::Importer.new(credentials) | ||
end | ||
|
||
def credentials | ||
Concierge::Credentials.for(THH::Client::SUPPLIER_NAME) | ||
end | ||
|
||
def augment_context_error(message) | ||
message = { | ||
label: 'Synchronisation Failure', | ||
message: message, | ||
backtrace: caller | ||
} | ||
context = Concierge::Context::Message.new(message) | ||
Concierge.context.augment(context) | ||
end | ||
end | ||
end | ||
|
||
# listen supplier worker | ||
Concierge::Announcer.on('availabilities.THH') do |host, args| | ||
Workers::Suppliers::THH::Availabilities.new(host).perform | ||
Result.new({}) | ||
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,110 @@ | ||
module Workers::Suppliers::THH | ||
# +Workers::Suppliers::THH::Metadata+ | ||
# | ||
# Performs properties synchronisation with supplier | ||
class Metadata | ||
SKIPPABLE_ERROR_CODES = [:no_available_dates] | ||
|
||
attr_reader :synchronisation, :host | ||
|
||
def initialize(host) | ||
@host = host | ||
@synchronisation = Workers::PropertySynchronisation.new(host) | ||
end | ||
|
||
def perform | ||
result = synchronisation.new_context { importer.fetch_properties } | ||
|
||
if result.success? | ||
properties = result.value | ||
properties.each do |property| | ||
property_id = property['property_id'] | ||
if validator(property).valid? | ||
synchronisation.start(property_id) do | ||
# Puts property info to context for analyze in case of error | ||
augment_property_info(property) | ||
|
||
result = mapper.build(property) | ||
if !result.success? && SKIPPABLE_ERROR_CODES.include?(result.error.code) | ||
synchronisation.skip_property(property_id, result.error.data) | ||
else | ||
result | ||
end | ||
end | ||
else | ||
synchronisation.skip_property(property_id, 'Invalid property') | ||
end | ||
end | ||
else | ||
synchronisation.failed! | ||
message = 'Failed to perform the `#fetch_properties` operation' | ||
announce_error(message, result) | ||
end | ||
synchronisation.finish! | ||
end | ||
|
||
private | ||
|
||
def report_error(message) | ||
yield.tap do |result| | ||
augment_context_error(message) unless result.success? | ||
end | ||
end | ||
|
||
def mapper | ||
@mapper ||= ::THH::Mappers::RoomoramaProperty.new | ||
end | ||
|
||
def importer | ||
@importer ||= ::THH::Importer.new(credentials) | ||
end | ||
|
||
def validator(property) | ||
THH::Validators::PropertyValidator.new(property) | ||
end | ||
|
||
def credentials | ||
Concierge::Credentials.for(THH::Client::SUPPLIER_NAME) | ||
end | ||
|
||
def augment_property_info(property) | ||
message = { | ||
label: 'Property Info', | ||
message: property.to_h.to_json, | ||
backtrace: caller, | ||
content_type: 'json' | ||
} | ||
context = Concierge::Context::Message.new(message) | ||
Concierge.context.augment(context) | ||
end | ||
|
||
def augment_context_error(message) | ||
message = { | ||
label: 'Synchronisation Failure', | ||
message: message, | ||
backtrace: caller | ||
} | ||
context = Concierge::Context::Message.new(message) | ||
Concierge.context.augment(context) | ||
end | ||
|
||
def announce_error(message, result) | ||
augment_context_error(message) | ||
|
||
Concierge::Announcer.trigger(Concierge::Errors::EXTERNAL_ERROR, { | ||
operation: 'sync', | ||
supplier: THH::Client::SUPPLIER_NAME, | ||
code: result.error.code, | ||
description: result.error.data, | ||
context: Concierge.context.to_h, | ||
happened_at: Time.now | ||
}) | ||
end | ||
end | ||
end | ||
|
||
# listen supplier worker | ||
Concierge::Announcer.on('metadata.THH') do |host, args| | ||
Workers::Suppliers::THH::Metadata.new(host).perform | ||
Result.new({}) | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -63,3 +63,7 @@ avantio: | |
password: "password" | ||
code_partner: "123" | ||
test: true | ||
|
||
thh: | ||
url: "http://www.example.org" | ||
key: "1234" |
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.