Sha256: 7ba81200e3a3f4481560a44d16ade4dd2e7072f3221173b50ef76b4594921c2e

Contents?: true

Size: 1.66 KB

Versions: 1

Compression:

Stored size: 1.66 KB

Contents

require 'rest-client'
require 'json'

module LocaleApp
  class Sender
    include ::LocaleApp::ApiCall
    include ::LocaleApp::Routes

    def post_translation(locale, key, options, value = nil)
      options ||= {}
      translation = { :key => key, :locale => locale, :substitutions => options.keys, :description => value}
      @data = { :translation => translation }
      api_call :create_translation,
        :payload => @data.to_json,
        :request_options => { :content_type => :json },
        :success => :handle_single_translation_success,
        :failure => :handle_single_translation_failure,
        :max_connection_attempts => 1
    end

    def handle_single_translation_success(response)
       LocaleApp.log([translations_url, response.code, @data.inspect].join(' - '))
    end

    def handle_single_translation_failure(response)
       LocaleApp.log([translations_url, response.code, @data.inspect].join(' - '))
    end

    def post_missing_translations
      to_send = LocaleApp.missing_translations.to_send
      return if to_send.empty?
      @data = { :translations => to_send }
      api_call :missing_translations,
        :payload => @data.to_json,
        :request_options => { :content_type => :json },
        :success => :handle_missing_translation_success,
        :failure => :handle_missing_translation_failure,
        :max_connection_attempts => 1
    end

    def handle_missing_translation_success(response)
       LocaleApp.log([translations_url, response.code, @data.inspect].join(' - '))
    end

    def handle_missing_translation_failure(response)
       LocaleApp.log([translations_url, response.code, @data.inspect].join(' - '))
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
localeapp-0.0.7 lib/locale_app/sender.rb