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

#create_translation_endpoint, #import_endpoint, #import_url, #missing_translations_endpoint, #missing_translations_url, #project_endpoint, #project_url, #translations_endpoint, #translations_url

Methods included from ApiCall

#api_call

Instance Method Details

#handle_missing_translation_failure(response) ⇒ Object



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

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

#handle_missing_translation_success(response) ⇒ Object



41
42
43
# File 'lib/localeapp/sender.rb', line 41

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

#handle_single_translation_failure(response) ⇒ Object



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

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

#handle_single_translation_success(response) ⇒ Object



21
22
23
# File 'lib/localeapp/sender.rb', line 21

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

#post_missing_translationsObject



29
30
31
32
33
34
35
36
37
38
39
# File 'lib/localeapp/sender.rb', line 29

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

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



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

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