Class: NeocitiesRed::Services::FileUploader
- Inherits:
-
Object
- Object
- NeocitiesRed::Services::FileUploader
- Defined in:
- lib/neocities_red/services/file_uploader.rb
Instance Method Summary collapse
-
#initialize(client, filepath, remote_path = nil) ⇒ FileUploader
constructor
A new instance of FileUploader.
- #upload ⇒ Object
Constructor Details
#initialize(client, filepath, remote_path = nil) ⇒ FileUploader
Returns a new instance of FileUploader.
11 12 13 14 15 16 |
# File 'lib/neocities_red/services/file_uploader.rb', line 11 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
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/neocities_red/services/file_uploader.rb', line 18 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 |