Skip to content

Commit

Permalink
Merge pull request #532 from roomorama/release/1.1.0
Browse files Browse the repository at this point in the history
Release/1.1.0
  • Loading branch information
keang authored Nov 15, 2016
2 parents ed2720d + 6b211af commit 479eb75
Show file tree
Hide file tree
Showing 70 changed files with 4,860 additions and 4 deletions.
1 change: 1 addition & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ ROOMORAMA_SECRET_CIIRUS=xxx
ROOMORAMA_SECRET_SAW=xxx
ROOMORAMA_SECRET_RENTALS_UNITED=xxx
ROOMORAMA_SECRET_AVANTIO=xxx
ROOMORAMA_SECRET_THH=xxx
ROLLBAR_ACCESS_TOKEN=not_used_in_development
CONCIERGE_WEB_APP_SECRET=12345
SERVE_STATIC_ASSETS=true
Expand Down
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@ This file summarises the most important changes that went live on each release
of Concierge. Please check the Wiki entry on the release process to understand
how this file is formatted and how the process works.

## [1.1.0]
### Fixed
- Avantio: add House(Casa) property type

### Added
- THH integrations: quote, book, cancel and synchronisation

## [1.0.0]
### Fixed
- Avantio: add handling of `check_in_too_near` response code
Expand Down
1 change: 1 addition & 0 deletions apps/api/config/environment_variables.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@
- ROOMORAMA_SECRET_SAW
- ROOMORAMA_SECRET_RENTALS_UNITED
- ROOMORAMA_SECRET_AVANTIO
- ROOMORAMA_SECRET_THH
- ZENDESK_NOTIFY_URL
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
saw: %w(username password url),
poplidays: %w(url client_key passphrase),
rentalsunited: %w(username password url),
avantio: %w(username password)
avantio: %w(username password),
thh: %w(key url)
})
end
3 changes: 3 additions & 0 deletions apps/api/config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
post '/saw/quote', to: 's_a_w#quote'
post '/rentalsunited/quote', to: 'rentals_united#quote'
post '/avantio/quote', to: 'avantio#quote'
post '/thh/quote', to: 't_h_h#quote'

post '/jtb/booking', to: 'j_t_b#booking'
post '/atleisure/booking', to: 'at_leisure#booking'
Expand All @@ -19,6 +20,7 @@
post '/poplidays/booking', to: 'poplidays#booking'
post '/rentalsunited/booking', to: 'rentals_united#booking'
post '/avantio/booking', to: 'avantio#booking'
post '/thh/booking', to: 't_h_h#booking'

post '/waytostay/cancel', to: 'waytostay#cancel'
post '/ciirus/cancel', to: 'ciirus#cancel'
Expand All @@ -29,6 +31,7 @@
post '/atleisure/cancel', to: 'at_leisure#cancel'
post '/rentalsunited/cancel', to: 'rentals_united#cancel'
post '/avantio/cancel', to: 'avantio#cancel'
post '/thh/cancel', to: 't_h_h#cancel'

post '/checkout', to: 'static#checkout'
get '/kigo/image/:property_id/:image_id', to: 'kigo#image'
2 changes: 1 addition & 1 deletion apps/api/controllers/poplidays/quote.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class Quote
include API::Controllers::Quote

def quote_price(params)
credentials = Concierge::Credentials.for(Poplidays::Client::SUPPLIER_NAME)
credentials = Concierge::Credentials.for(supplier_name)
Poplidays::Client.new(credentials).quote(params)
end

Expand Down
20 changes: 20 additions & 0 deletions apps/api/controllers/thh/booking.rb
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
20 changes: 20 additions & 0 deletions apps/api/controllers/thh/cancel.rb
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
20 changes: 20 additions & 0 deletions apps/api/controllers/thh/quote.rb
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
3 changes: 2 additions & 1 deletion apps/api/middlewares/authentication.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ class Secrets
"/ciirus" => ENV["ROOMORAMA_SECRET_CIIRUS"],
"/saw" => ENV["ROOMORAMA_SECRET_SAW"],
"/rentalsunited" => ENV["ROOMORAMA_SECRET_RENTALS_UNITED"],
"/avantio" => ENV["ROOMORAMA_SECRET_AVANTIO"]
"/avantio" => ENV["ROOMORAMA_SECRET_AVANTIO"],
"/thh" => ENV["ROOMORAMA_SECRET_THH"]
}

attr_reader :mapping
Expand Down
75 changes: 75 additions & 0 deletions apps/workers/suppliers/thh/availabilities.rb
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
110 changes: 110 additions & 0 deletions apps/workers/suppliers/thh/metadata.rb
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
4 changes: 4 additions & 0 deletions config/credentials/production.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,7 @@ avantio:
password: <%= ENV["AVANTIO_PASSWORD"] %>
code_partner: <%= ENV["AVANTIO_CODE_PARTNER"] %>
test: false

thh:
url: <%= ENV["THH_URL"] %>
key: <%= ENV["THH_KEY"] %>
4 changes: 4 additions & 0 deletions config/credentials/staging.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,7 @@ avantio:
password: <%= ENV["AVANTIO_PASSWORD"] %>
code_partner: <%= ENV["AVANTIO_CODE_PARTNER"] %>
test: true

thh:
url: <%= ENV["THH_URL"] %>
key: <%= ENV["THH_KEY"] %>
4 changes: 4 additions & 0 deletions config/credentials/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,3 +63,7 @@ avantio:
password: "password"
code_partner: "123"
test: true

thh:
url: "http://www.example.org"
key: "1234"
7 changes: 7 additions & 0 deletions config/suppliers.yml
Original file line number Diff line number Diff line change
Expand Up @@ -71,3 +71,10 @@ Avantio:
availabilities:
every: "3h"
aggregated: true

THH:
workers:
metadata:
every: "1d"
availabilities:
every: "5h"
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ class RoomoramaProperty
14 => {type: 'apartment', subtype: 'studio_bachelor'}, # Studio
20 => {type: 'house', subtype: 'cottage'}, # Chalet
9 => {type: 'house', subtype: 'cottage'}, # Cottage
19 => {type: 'house', subtype: 'cottage'}, # House
21 => {type: 'house', subtype: 'bungalow'} # Bungalow
})

Expand Down
Loading

0 comments on commit 479eb75

Please sign in to comment.