Module: Ompload::UploadsHandler
Instance Method Summary
collapse
Methods included from Shell
curl_installed?, piped_data_given?, xclip_installed?
Instance Method Details
#handle_data(data, options = {}) ⇒ Object
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
|
# File 'lib/ompload.rb', line 131
def handle_data(data, options = {})
file_name = options[:file_name] || 'piped data'
if data.bytesize > MAX_FILE_SIZE
STDERR.puts Message.payload_too_big(file_name, data.bytesize)
ErrorCounter.instance.increment!
else
puts Message.progress(file_name) if !options[:quiet] && !options[:url]
response = upload_with_curl({ :data => data,
:file_name => file_name,
:silent => options[:quiet] || options[:url] })
handle_response!(response, file_name, options)
end
rescue ThrottledError
STDERR.puts Message.throttled(file_name)
sleep(60) and retry
end
|
#handle_file(file_path, options = {}) ⇒ Object
107
108
109
110
111
112
113
114
115
|
# File 'lib/ompload.rb', line 107
def handle_file(file_path, options = {})
puts Message.progress(file_path) if !options[:quiet] && !options[:url]
response = upload_with_curl({ :file_path => file_path,
:silent => options[:quiet] || options[:url] })
handle_response!(response, file_path, options)
rescue ThrottledError
STDERR.puts Message.throttled(file_path)
sleep(60) and retry
end
|
#handle_files(file_paths, options = {}) ⇒ Object
117
118
119
120
121
122
123
124
125
126
127
128
129
|
# File 'lib/ompload.rb', line 117
def handle_files(file_paths, options = {})
file_paths.each do |file_path|
if !File.file?(file_path)
STDERR.puts Message.invalid_file(file_path)
ErrorCounter.instance.increment!
elsif File.size(file_path) > MAX_FILE_SIZE
STDERR.puts Message.payload_too_big(file_path,File.size(file_path))
ErrorCounter.instance.increment!
else
handle_file(file_path, options)
end
end
end
|