Class: Localeapp::CLI::Push

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

Instance Method Summary collapse

Methods included from ApiCall

#api_call

Constructor Details

#initialize(output = $stdout) ⇒ Push

Returns a new instance of Push.



6
7
8
# File 'lib/localeapp/cli/push.rb', line 6

def initialize(output = $stdout)
  @output = output
end

Instance Method Details

#execute(path = nil) ⇒ Object



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

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



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/localeapp/cli/push.rb', line 21

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 => 3
  else
    @output.puts "Could not load file"
  end
end

#report_failure(response) ⇒ Object



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

def report_failure(response)
  @output.puts "Failed!"
end

#report_success(response) ⇒ Object



37
38
39
40
41
# File 'lib/localeapp/cli/push.rb', line 37

def report_success(response)
  @output.puts "Success!"
  @output.puts ""
  @output.puts "#{@file_path} queued for processing."
end