Class: Localeapp::CLI::Pull

Inherits:
Command
  • Object
show all
Includes:
ApiCall
Defined in:
lib/localeapp/cli/pull.rb

Instance Method Summary collapse

Methods included from ApiCall

#api_call

Methods inherited from Command

#initialize, #initialize_config, #load_config_file, #set_command_line_arguments

Constructor Details

This class inherits a constructor from Localeapp::CLI::Command

Instance Method Details

#execute(locale_key = nil) ⇒ Object



6
7
8
9
10
11
12
13
14
15
# File 'lib/localeapp/cli/pull.rb', line 6

def execute(locale_key = nil)
  @locale_key = locale_key
  @output.puts "Localeapp Pull\n\n" \
    "Fetching#{locale_key ? ' ' << locale_key : ''} translations:"

  api_call :export,
    :success => :update_backend,
    :failure => :report_failure,
    :max_connection_attempts => 1
end

#report_failure(response) ⇒ Object



25
26
27
28
# File 'lib/localeapp/cli/pull.rb', line 25

def report_failure(response)
  @output.puts "Failed!"
  fail APIResponseError, "API returned #{response.code} status code"
end

#update_backend(response) ⇒ Object



17
18
19
20
21
22
23
# File 'lib/localeapp/cli/pull.rb', line 17

def update_backend(response)
  @output.puts "Success!"
  @output.puts "Updating backend:"
  Localeapp.updater.dump(Localeapp.yaml_data(response, @locale_key))
  @output.puts "Success!"
  Localeapp.poller.write_synchronization_data!(Time.now.to_i, Time.now.to_i)
end