Class: Localeapp::CLI::Push

Inherits:
Command
  • Object
show all
Includes:
ApiCall
Defined in:
lib/localeapp/cli/push.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(path = nil) ⇒ Object



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

def execute(path = nil)
  @output.puts "Localeapp Push"
  if path_is_directory?(path)
    yaml_files_in_directory(path).each do |path|
      push_file(path)
    end
  else
    push_file(path)
  end
end

#push_file(file_path) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/localeapp/cli/push.rb', line 17

def push_file(file_path)
  @output.puts ""
  @file_path = file_path # for callbacks
  file = sanitize_file(file_path)
  if file
    @output.puts "Pushing file #{File.basename(file_path)}:"
    api_call :import,
      :payload => { :file => file },
      :success => :report_success,
      :failure => :report_failure,
      :max_connection_attempts => 1
  else
    @output.puts "Could not load file"
  end
end

#report_failure(response) ⇒ Object



42
43
44
45
# File 'lib/localeapp/cli/push.rb', line 42

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

#report_success(response) ⇒ Object



33
34
35
36
37
38
39
40
# File 'lib/localeapp/cli/push.rb', line 33

def report_success(response)
  id = JSON.parse(response.body)["id"]
  @output.puts <<-eoh
Success!

#{@file_path} queued for processing. (id: #{id})
  eoh
end