Class: NeocitiesRed::Services::File::Uploader
- Inherits:
-
Object
- Object
- NeocitiesRed::Services::File::Uploader
- Defined in:
- lib/neocities_red/services/file/uploader.rb
Instance Method Summary collapse
-
#initialize(client, filepath, remote_path = nil) ⇒ Uploader
constructor
A new instance of Uploader.
- #upload ⇒ Object
Constructor Details
#initialize(client, filepath, remote_path = nil) ⇒ Uploader
Returns a new instance of Uploader.
12 13 14 15 16 17 |
# File 'lib/neocities_red/services/file/uploader.rb', line 12 def initialize(client, filepath, remote_path = nil) @client = client @filepath = filepath @remote_path = remote_path @pastel = Pastel.new(eachline: "\n") end |
Instance Method Details
#upload ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/neocities_red/services/file/uploader.rb', line 19 def upload path = Pathname.new(@filepath) raise FileIsNotExists, "#{path} does not exist locally." unless path.exist? if path.directory? puts @pastel.bold("#{path} is a directory, skipping") return end puts @pastel.bold("Uploading #{path} to #{@remote_path} ...") response = @client.upload(path, @remote_path) puts response if response[:result] == "error" if response[:result] == "error" && response[:error_type] == "file_exists" puts @pastel.yellow.bold("EXISTS") elsif response[:result] == "success" puts @pastel.green.bold("SUCCESS") end response end |