class TripAdvisor::ResourceManager
Attributes
api_client[RW]
output_dir[RW]
Public Class Methods
new(options={})
click to toggle source
# File lib/trip_advisor/resource_manager.rb, line 5 def initialize(options={}) options.each { |k,v| self.send("#{k}=", v) } end
Public Instance Methods
dump_airlines()
click to toggle source
# File lib/trip_advisor/resource_manager.rb, line 31 def dump_airlines provision_locale_projects puts "Dumping Airline fixtures for #{locales.size} locales..." locales.each do |locale| locale_identifier = locale['locale'] begin json = api_client.get(:airlines, locale: locale_identifier) rescue RestClient::Exception => ex puts "ERROR: Failed Fetching Airlines fixture for '#{locale_identifier}' locale_identifier: #{ex}" next end language_code = TripAdvisor::Translation.locale_identifier_to_language_codes_mapping[locale_identifier] || locale_identifier path = File.join(output_dir, "#{language_code}.lproj", "airlines.json") File.open(path, 'w') { |f| f << json } puts " Wrote Airlines fixture for '#{locale_identifier}' locale to #{path}" end end
dump_airports()
click to toggle source
# File lib/trip_advisor/resource_manager.rb, line 13 def dump_airports provision_locale_projects puts "Dumping Airport fixtures for #{locales.size} locales..." locales.each do |locale| locale_identifier = locale['locale'] begin json = api_client.get(:airports, locale: locale_identifier) rescue RestClient::Exception => ex puts "ERROR: Failed Fetching Airports fixture for '#{locale_identifier}' locale_identifier: #{ex}" next end language_code = TripAdvisor::Translation.locale_identifier_to_language_codes_mapping[locale_identifier] || locale_identifier path = File.join(output_dir, "#{language_code}.lproj", "airports.json") File.open(path, 'w') { |f| f << json } puts " Wrote Airports fixture for '#{locale_identifier}' locale to #{path}" end end
dump_purchase_link_providers()
click to toggle source
# File lib/trip_advisor/resource_manager.rb, line 49 def dump_purchase_link_providers provision_locale_projects puts "Dumping Purchase Link Provider fixtures for #{locales.size} locales..." locales.each do |locale| locale_identifier = locale['locale'] begin json = api_client.get(:flight_purchase_link_providers, locale: locale_identifier) rescue RestClient::Exception => ex puts "ERROR: Failed Fetching Purchase Link Provider fixture for '#{locale_identifier}' locale_identifier: #{ex}" next end language_code = TripAdvisor::Translation.locale_identifier_to_language_codes_mapping[locale_identifier] || locale_identifier path = File.join(output_dir, "#{language_code}.lproj", "flight_purchase_link_providers.json") File.open(path, 'w') { |f| f << json } puts " Wrote Purchase Link Provider fixture for '#{locale_identifier}' locale to #{path}" end end
locales()
click to toggle source
# File lib/trip_advisor/resource_manager.rb, line 9 def locales @locales ||= api_client.get_flights_locales end
provision_locale_projects(language_tags = self.language_tags_from_locales_api) { |path| ... }
click to toggle source
# File lib/trip_advisor/resource_manager.rb, line 71 def provision_locale_projects(language_tags = self.language_tags_from_locales_api) FileUtils.mkdir(output_dir) unless File.exists?(output_dir) language_tags.inject([]) do |paths, language_tag| language_tag = TripAdvisor::Translation.locale_identifier_to_language_codes_mapping[language_tag] || language_tag path = File.join(output_dir, "#{language_tag}.lproj") unless File.exist?(path) FileUtils.mkdir(path) paths << path yield path if block_given? end paths end end
provision_localized_android_resources(language_tags = self.language_tags_from_locales_api) { |path| ... }
click to toggle source
# File lib/trip_advisor/resource_manager.rb, line 85 def provision_localized_android_resources(language_tags = self.language_tags_from_locales_api) FileUtils.mkdir(output_dir) unless File.exists?(output_dir) language_tags.inject([]) do |paths, language_tag| language_tag = TripAdvisor::Translation.locale_identifier_to_language_codes_mapping[language_tag] || language_tag language_tag.gsub!(/-/,'_') language_tag.gsub!(/_/,'-r') path = File.join(output_dir, "values-#{language_tag}") unless File.exist?(path) FileUtils.mkdir(path) paths << path yield path if block_given? end paths end end