Sha256: 8d69251b8f58249c203479d94bdc14e8617436661951439fd6c82122da819ee9

Contents?: true

Size: 1.43 KB

Versions: 94

Compression:

Stored size: 1.43 KB

Contents

module Translator
  class SmartlingDownloader
    include ::Translator::Utils

    attr_reader :file_uris

    def self.call(attrs = {})
      new(attrs).call
    end

    def initialize(file_uris: nil)
      @file_uris = file_uris || file_uris_from_smartling
    end

    def call
      raise ArgumentError, "The 'file_uris' parameter cannot be empty" unless @file_uris

      @file_uris.map do |uri|
        locales = get_file_status(file_uri: uri)
        next unless locales

        locales.map { |locale| download_file(locale: locale, file_uri: uri) }
      end
    end

    def file_uris_from_smartling
      ::Translator::Smartling::ApiRequestsGenerator.file_uris
    end

    def get_file_status(file_uri:)
      ::Translator::Smartling::ApiRequestsGenerator.get_file_status(
        file_uri: file_uri
      )
    end

    def download_file(locale:, file_uri:)
      doc = ::Translator::Smartling::ApiRequestsGenerator.download_file(
        locale: locale,
        file_uri: file_uri
      )

      return unless doc

      save_file(doc, locale, file_uri)
    end

    def save_file(doc, locale, file_uri)
      locale = locale_without_region(locale.to_s)
      folder = storage_folder(file_uri, locale)
      FileUtils.mkdir_p(folder) unless File.exist?(folder)
      File.open(file_path(file_uri, locale), 'w+') do |file|
        file.binmode
        file.write(Nexmo::Markdown::Pipelines::Smartling::Download.call(doc))
      end
    end
  end
end

Version data entries

94 entries across 94 versions & 1 rubygems

Version Path
station-0.5.16 lib/nexmo_developer/app/services/translator/smartling_downloader.rb
station-0.5.15 lib/nexmo_developer/app/services/translator/smartling_downloader.rb
station-0.5.14 lib/nexmo_developer/app/services/translator/smartling_downloader.rb
station-0.5.13 lib/nexmo_developer/app/services/translator/smartling_downloader.rb
station-0.5.12 lib/nexmo_developer/app/services/translator/smartling_downloader.rb
station-0.5.11 lib/nexmo_developer/app/services/translator/smartling_downloader.rb
station-0.5.10 lib/nexmo_developer/app/services/translator/smartling_downloader.rb
station-0.5.9 lib/nexmo_developer/app/services/translator/smartling_downloader.rb
station-0.5.8 lib/nexmo_developer/app/services/translator/smartling_downloader.rb
station-0.5.7 lib/nexmo_developer/app/services/translator/smartling_downloader.rb
station-0.5.6 lib/nexmo_developer/app/services/translator/smartling_downloader.rb
station-0.5.5 lib/nexmo_developer/app/services/translator/smartling_downloader.rb
station-0.5.4 lib/nexmo_developer/app/services/translator/smartling_downloader.rb
station-0.5.3 lib/nexmo_developer/app/services/translator/smartling_downloader.rb
station-0.5.2 lib/nexmo_developer/app/services/translator/smartling_downloader.rb
station-0.5.1 lib/nexmo_developer/app/services/translator/smartling_downloader.rb
station-0.5.0 lib/nexmo_developer/app/services/translator/smartling_downloader.rb
station-0.4.9 lib/nexmo_developer/app/services/translator/smartling_downloader.rb
station-0.4.8 lib/nexmo_developer/app/services/translator/smartling_downloader.rb
station-0.4.7 lib/nexmo_developer/app/services/translator/smartling_downloader.rb