Class: NeocitiesRed::Services::File::Remover

Inherits:
Object
  • Object
show all
Defined in:
lib/neocities_red/services/file/remover.rb

Overview

Deletes a single file from the remote Neocities site.

Displays progress and result feedback via CliDisplay.

Examples:

remover = NeocitiesRed::Services::File::Remover.new(client, "old-file.html", display: display)
remover.remove

See Also:

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client, filepath, display: NeocitiesRed::CliDisplay.new) ⇒ Remover

Returns a new instance of Remover.

Parameters:



25
26
27
28
29
# File 'lib/neocities_red/services/file/remover.rb', line 25

def initialize(client, filepath, display: NeocitiesRed::CliDisplay.new)
  @client = client
  @filepath = filepath
  @display = display
end

Instance Attribute Details

#clientNeocitiesRed::Client (readonly)

Returns the authenticated API client.

Returns:



17
18
19
# File 'lib/neocities_red/services/file/remover.rb', line 17

def client
  @client
end

#filepathString

Returns the remote file path to delete.

Returns:

  • (String)

    the remote file path to delete



20
21
22
# File 'lib/neocities_red/services/file/remover.rb', line 20

def filepath
  @filepath
end

Instance Method Details

#removeHash

Deletes the file from the remote site.

Returns:

  • (Hash)

    API response with :result key ("success" or "error")



34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/neocities_red/services/file/remover.rb', line 34

def remove
  @display.display_delete_progress(filepath)

  response = @client.delete(filepath)

  if response[:result] == "success"
    @display.display_delete_success
  else
    @display.display_delete_error(response)
  end

  response
end