Skip to content

Commit

Permalink
Merge pull request #473 from roomorama/release/0.12.11
Browse files Browse the repository at this point in the history
Release/0.12.11
  • Loading branch information
keang authored Oct 21, 2016
2 parents c4e5083 + 4d12e46 commit 3f37af3
Show file tree
Hide file tree
Showing 97 changed files with 617 additions and 182 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ 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.

## [0.12.11] - 2016-10-21
### Added
- Atleisure, Ciirus, Poplidays, Kigo, Waytostay, RentalsUnited: add error.data reporting to Rollbar
- Translations for title, description, t&c, check_in_instructions and
description_append on Roomorama::Property

## [0.12.10] - 2016-10-19
### Fixed
- Poplidays: metadata sync is safe for `nil` availabilities response
Expand Down
1 change: 1 addition & 0 deletions apps/api/controllers/kigo/image.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ def announce_error(result)
operation: 'image',
supplier: Kigo::Legacy::SUPPLIER_NAME,
code: result.error.code,
description: result.error.data,
context: Concierge.context.to_h,
happened_at: Time.now
})
Expand Down
1 change: 1 addition & 0 deletions apps/workers/comparison/property.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ def extract_diff
diff = Roomorama::Diff.new(original.identifier)

extract_metadata_diff(original, new, diff)
Workers::Comparison::Translations.new(original.translations, new.translations).apply_to(diff)
compare_images(original.images, new.images, diff)

if original.multi_unit?
Expand Down
48 changes: 48 additions & 0 deletions apps/workers/comparison/translations.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
module Workers::Comparison

# +Workers::Comparison::Translations+
#
# This class performs a comparison between two hash of translations.
#
# Usage:
# original = old_roomorama_property.translations
# new = new_roomorama_property.translations
#
# diff = Roomorama::Diff.new(old_roomorama_property.identifier)
#
# Workers::Comparison::Translations.(original, new).apply_to(diff)
#
class Translations

attr_reader :original, :new

def initialize(original, new)
@original = original || {}
@new = new || {}
end

def apply_to(diff)
Roomorama::Translated::TRANSLATED_LOCALES.each do |locale|
new_t = new[locale] || {}
old_t = original[locale] || {}
next if new_t.empty? && old_t.empty?
translation = diff.public_send(locale)

added = new_t.keys - old_t.keys
added.each do |attr|
translation[attr] = new_t[attr]
end

removed = old_t.keys - new_t.keys
removed.each do |attr|
translation.erase(attr)
end

common = old_t.keys & new_t.keys
common.each do |attr|
translation[attr] = new_t[attr] if new_t[attr] != old_t[attr]
end
end
end
end
end
3 changes: 2 additions & 1 deletion apps/workers/suppliers/atleisure/availabilities.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def availability_error(availability)
message = "Error during fetching availabilities for property `#{property_id}`: `#{error_message}`"
augment_context_error(message)

Result.error(:availability_error)
Result.error(:availability_error, message)
end

def valid_availability?(availability)
Expand Down Expand Up @@ -85,6 +85,7 @@ def announce_error(message, result)
operation: 'sync',
supplier: ::AtLeisure::Client::SUPPLIER_NAME,
code: result.error.code,
description: result.error.data,
context: Concierge.context.to_h,
happened_at: Time.now
})
Expand Down
1 change: 1 addition & 0 deletions apps/workers/suppliers/atleisure/metadata.rb
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ def announce_error(message, result)
operation: 'sync',
supplier: AtLeisure::Client::SUPPLIER_NAME,
code: result.error.code,
description: result.error.data,
context: Concierge.context.to_h,
happened_at: Time.now
})
Expand Down
1 change: 1 addition & 0 deletions apps/workers/suppliers/ciirus/metadata.rb
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,7 @@ def announce_error(message, result)
operation: 'sync',
supplier: Ciirus::Client::SUPPLIER_NAME,
code: result.error.code,
description: result.error.data,
context: Concierge.context.to_h,
happened_at: Time.now
})
Expand Down
3 changes: 2 additions & 1 deletion apps/workers/suppliers/kigo/availabilities.rb
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ def announce_error(message, result)
operation: 'sync',
supplier: supplier.name,
code: result.error.code,
description: result.error.data,
context: Concierge.context.to_h,
happened_at: Time.now
})
Expand All @@ -88,4 +89,4 @@ def initial_args_result

Concierge::Announcer.on("availabilities.Kigo") do |supplier, args|
Workers::Suppliers::Kigo::Availabilities.new(supplier, args).perform
end
end
3 changes: 2 additions & 1 deletion apps/workers/suppliers/kigo/legacy/availabilities.rb
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ def announce_error(message, result)
operation: 'sync',
supplier: supplier.name,
code: result.error.code,
description: result.error.data,
context: Concierge.context.to_h,
happened_at: Time.now
})
Expand All @@ -90,4 +91,4 @@ def initial_args_result

Concierge::Announcer.on("availabilities.KigoLegacy") do |supplier, args|
Workers::Suppliers::Kigo::Legacy::Availabilities.new(supplier, args).perform
end
end
1 change: 1 addition & 0 deletions apps/workers/suppliers/kigo/legacy/metadata.rb
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ def announce_error(message, result)
operation: 'sync',
supplier: supplier_name,
code: result.error.code,
description: result.error.data,
context: Concierge.context.to_h,
happened_at: Time.now
})
Expand Down
1 change: 1 addition & 0 deletions apps/workers/suppliers/kigo/metadata.rb
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ def announce_error(message, result)
operation: 'sync',
supplier: supplier_name,
code: result.error.code,
description: result.error.data,
context: Concierge.context.to_h,
happened_at: Time.now
})
Expand Down
3 changes: 2 additions & 1 deletion apps/workers/suppliers/poplidays/availabilities.rb
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ def announce_error(message, result)
operation: 'sync',
supplier: Poplidays::Client::SUPPLIER_NAME,
code: result.error.code,
description: result.error.data,
context: Concierge.context.to_h,
happened_at: Time.now
})
Expand All @@ -104,4 +105,4 @@ def announce_error(message, result)
Concierge::Announcer.on('availabilities.Poplidays') do |host, args|
Workers::Suppliers::Poplidays::Availabilities.new(host).perform
Result.new({})
end
end
2 changes: 1 addition & 1 deletion apps/workers/suppliers/poplidays/metadata.rb
Original file line number Diff line number Diff line change
Expand Up @@ -135,4 +135,4 @@ def announce_error(message, result)
Concierge::Announcer.on('metadata.Poplidays') do |host, args|
Workers::Suppliers::Poplidays::Metadata.new(host).perform
Result.new({})
end
end
5 changes: 3 additions & 2 deletions apps/workers/suppliers/rentals_united/metadata.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,15 @@ def perform

unless location
message = "Failed to find location with id `#{location_id}`"
announce_context_error(message, Result.error(:location_not_found))
announce_context_error(message, Result.error(:location_not_found, message))
next
end

location.currency = currencies[location.id]

unless location.currency
message = "Failed to find currency for location with id `#{location_id}`"
announce_context_error(message, Result.error(:currency_not_found))
announce_context_error(message, Result.error(:currency_not_found, message))
next
end

Expand Down Expand Up @@ -239,6 +239,7 @@ def announce_context_error(message, result)
operation: 'sync',
supplier: RentalsUnited::Client::SUPPLIER_NAME,
code: result.error.code,
description: result.error.data,
context: Concierge.context.to_h,
happened_at: Time.now
})
Expand Down
1 change: 1 addition & 0 deletions apps/workers/suppliers/waytostay.rb
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ def announce_error(result)
operation: "sync",
supplier: ::Waytostay::Client::SUPPLIER_NAME,
code: result.error.code,
description: result.error.data,
context: Concierge.context.to_h,
happened_at: Time.now
})
Expand Down
4 changes: 4 additions & 0 deletions lib/concierge/roomorama/diff.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
require_relative "mappers"
require_relative "property"
require_relative "unit"
require_relative "translated"

module Roomorama

Expand All @@ -17,6 +18,7 @@ def initialize(message)

attr_accessor *Roomorama::Property::ATTRIBUTES

include Roomorama::Translated
include Roomorama::Mappers

ChangeSet = Struct.new(:created, :updated, :deleted)
Expand Down Expand Up @@ -106,6 +108,8 @@ def to_h
subtype: subtype,
title: title,
description: description,
description_append: description_append,
translations: translations,
address: address,
apartment_number: apartment_number,
postal_code: postal_code,
Expand Down
12 changes: 11 additions & 1 deletion lib/concierge/roomorama/property.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
require_relative "translated"
module Roomorama

# +Roomorama::Property+
Expand All @@ -23,6 +24,7 @@ module Roomorama
# property.add_image(image)
class Property
include Roomorama::Mappers
include Roomorama::Translated

# +Roomorama::Property::ValidationError+
#
Expand Down Expand Up @@ -57,6 +59,12 @@ def self.load(attributes)
instance.add_unit(Roomorama::Unit.load(data))
end

attributes[:translations].to_h.each do |locale, translation|
translation.each do |key, value|
instance.send(locale)[key] = value
end
end

instance.validate!
Result.new(instance)
rescue Roomorama::Error => err
Expand All @@ -82,7 +90,7 @@ def self.load(attributes)
:services_cleaning_required, :services_airport_pickup, :services_car_rental,
:services_car_rental_rate, :services_airport_pickup_rate, :services_concierge,
:services_concierge_rate, :disabled, :instant_booking, :owner_name,
:owner_email, :owner_phone_number, :owner_city]
:owner_email, :owner_phone_number, :owner_city, :description_append]

attr_accessor *ATTRIBUTES

Expand Down Expand Up @@ -175,6 +183,8 @@ def to_h
subtype: subtype,
title: title,
description: description,
description_append: description_append,
translations: translations,
address: address,
apartment_number: apartment_number,
postal_code: postal_code,
Expand Down
74 changes: 74 additions & 0 deletions lib/concierge/roomorama/translated.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
# This module adds some translated fields to the class that includes it.
# The default locale (:en) should be accessed directly on the base class.
#
# Usage
#
# class Property
# attr_accessor :title, :description, :terms_and_conditions
# include Roomorama::Translated
# end
#
# p = Property.new
# p.title = "Default title in english"
# p.es.title = "Translated title in spanish"
#
module Roomorama::Translated
TRANSLATED_LOCALES = %i(es de zh zh_tw)

class Translation
TRANSLATED_FIELDS = [:title,
:description,
:terms_and_conditions,
:check_in_instructions,
:description_append]

attr_accessor *TRANSLATED_FIELDS

def initialize
@erased = []
end

def erase(key)
@erased << key
end

def []=(attr, value)
attr = attr.to_sym
if TRANSLATED_FIELDS.include?(attr)
setter = [attr, "="].join
public_send(setter, value)
end
end

def to_h
{
title: title,
description: description,
terms_and_conditions: terms_and_conditions,
check_in_instructions: check_in_instructions,
description_append: description_append,
}.tap do |hash|
hash.delete_if { |k, v| v.nil? && !@erased.include?(k) }
end
end
end

def self.included(base)

def es; @es ||= Translation.new() end
def de; @de ||= Translation.new() end
def zh; @zh ||= Translation.new() end
def zh_tw; @zh_tw ||= Translation.new() end

def translations
hash = {}
TRANSLATED_LOCALES.collect do |locale|
locale_hash = self.send(locale).to_h
hash[locale] = locale_hash unless locale_hash.empty?
end

hash.empty? ? nil : hash
end
end

end
3 changes: 3 additions & 0 deletions lib/concierge/roomorama/unit.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
require_relative "translated"
module Roomorama

# +Roomorama::Unit+
Expand All @@ -16,6 +17,7 @@ module Roomorama
# unit.add_image(image)
class Unit
include Roomorama::Mappers
include Roomorama::Translated

# +Roomorama::Unit::ValidationError+
#
Expand Down Expand Up @@ -105,6 +107,7 @@ def to_h
identifier: identifier,
title: title,
description: description,
translations: translations,
nightly_rate: nightly_rate,
weekly_rate: weekly_rate,
monthly_rate: monthly_rate,
Expand Down
Loading

0 comments on commit 3f37af3

Please sign in to comment.