Sha256: b54f706d41b76da5f22031cc31708d7d53f815006575be2fa8a671389f472c88

Contents?: true

Size: 1.66 KB

Versions: 5

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

5 entries across 5 versions & 1 rubygems

Version Path
localeapp-0.1.2 lib/localeapp/sender.rb
localeapp-0.1.1 lib/localeapp/sender.rb
localeapp-0.0.11 lib/localeapp/sender.rb
localeapp-0.0.10 lib/localeapp/sender.rb
localeapp-0.0.8 lib/localeapp/sender.rb