Class: Localeapp::Sender

Inherits:
Object
  • Object
show all
Includes:
ApiCall, Routes
Defined in:
lib/localeapp/sender.rb

Constant Summary

Constants included from Routes

Routes::VERSION

Instance Method Summary collapse

Methods included from Routes::Copy

#copy_endpoint, #copy_url

Methods included from Routes::Import

#import_endpoint, #import_url

Methods included from Routes::MissingTranslations

#missing_translations_endpoint, #missing_translations_url

Methods included from Routes::Rename

#rename_endpoint, #rename_url

Methods included from Routes::Remove

#remove_endpoint, #remove_url

Methods included from Routes::Export

#export_endpoint, #export_url

Methods included from Routes::Translations

#create_translation_endpoint, #translations_endpoint, #translations_url

Methods included from Routes::Projects

#project_endpoint, #project_url

Methods included from ApiCall

#api_call

Instance Method Details

#handle_missing_translation_failure(response) ⇒ Object



49
50
51
52
# File 'lib/localeapp/sender.rb', line 49

def handle_missing_translation_failure(response)
   Localeapp.log([translations_url, response.code, @data.inspect].join(' - '))
   fail APIResponseError, "API returned #{response.code} status code"
end

#handle_missing_translation_success(response) ⇒ Object



45
46
47
# File 'lib/localeapp/sender.rb', line 45

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

#handle_single_translation_failure(response) ⇒ Object



29
30
31
# File 'lib/localeapp/sender.rb', line 29

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

#handle_single_translation_success(response) ⇒ Object



25
26
27
# File 'lib/localeapp/sender.rb', line 25

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

#post_missing_translationsObject



33
34
35
36
37
38
39
40
41
42
43
# File 'lib/localeapp/sender.rb', line 33

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,
    :headers => { :content_type => :json },
    :success => :handle_missing_translation_success,
    :failure => :handle_missing_translation_failure,
    :max_connection_attempts => 1
end

#post_translation(locale, key, options, value = nil) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/localeapp/sender.rb', line 9

def post_translation(locale, key, options, value = nil)
  options ||= {}
  options.delete(:default)
  scope = options.delete(:scope)
  normalized_key = I18n.normalize_keys(nil, key, scope).join('.')

  translation = { :key => normalized_key, :locale => locale, :substitutions => options.keys.sort, :description => value}
  @data = { :translation => translation }
  api_call :create_translation,
    :payload => @data.to_json,
    :headers => { :content_type => :json },
    :success => :handle_single_translation_success,
    :failure => :handle_single_translation_failure,
    :max_connection_attempts => 1
end