Class: Localeapp::Sender
Constant Summary
Constants included
from Routes
Routes::VERSION
Instance Method Summary
collapse
#copy_endpoint, #copy_url
#import_endpoint, #import_url
#missing_translations_endpoint, #missing_translations_url
#rename_endpoint, #rename_url
#remove_endpoint, #remove_url
#export_endpoint, #export_url
#create_translation_endpoint, #translations_endpoint, #translations_url
#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_translations ⇒ Object
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
|