Class: Fronde::Sync::Neocities
- Inherits:
-
Object
- Object
- Fronde::Sync::Neocities
- Defined in:
- lib/fronde/sync/neocities.rb
Overview
Everything needed to connect to neocities
Constant Summary collapse
- PROTECTED_FILES =
%w[index.html neocities.png not_found.html].freeze
Instance Method Summary collapse
- #finish ⇒ Object
- #info ⇒ Object
-
#initialize(connection_spec, public_folder, verbose: false) {|_self| ... } ⇒ Neocities
constructor
A new instance of Neocities.
- #local_list ⇒ Object
- #pull(test: false) ⇒ Object
- #push(test: false) ⇒ Object
- #remote_list ⇒ Object
Constructor Details
#initialize(connection_spec, public_folder, verbose: false) {|_self| ... } ⇒ Neocities
Returns a new instance of Neocities.
16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/fronde/sync/neocities.rb', line 16 def initialize(connection_spec, public_folder, verbose: false, &block) @verbose = verbose @endpoint = @website_name = @authorization = nil extract_connection_details connection_spec @public_folder = public_folder @connection = init_connection return unless block yield self finish end |
Instance Method Details
#finish ⇒ Object
47 48 49 |
# File 'lib/fronde/sync/neocities.rb', line 47 def finish @connection.finish if @connection.started? end |
#info ⇒ Object
42 43 44 45 |
# File 'lib/fronde/sync/neocities.rb', line 42 def info info = call build_request('/info') JSON.parse(info.body)['info'] end |
#local_list ⇒ Object
36 37 38 39 40 |
# File 'lib/fronde/sync/neocities.rb', line 36 def local_list Dir.chdir(@public_folder) do Dir.glob('**/*').map { |file| neocities_stat(file) } end end |
#pull(test: false) ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/fronde/sync/neocities.rb', line 51 def pull(test: false) file_list = remote_list finish orphans = select_orphans(file_list, local_list) do |path| puts I18n.t('fronde.neocities.deleting', path:) if @verbose "#{@public_folder}/#{path}" end File.unlink(*orphans) unless test download_all(file_list, test:) nil # Mute this method end |
#push(test: false) ⇒ Object
64 65 66 67 68 69 |
# File 'lib/fronde/sync/neocities.rb', line 64 def push(test: false) file_list = local_list remove_remote_orphans(file_list, test:) upload_all(file_list, test:) finish end |
#remote_list ⇒ Object
28 29 30 31 32 33 34 |
# File 'lib/fronde/sync/neocities.rb', line 28 def remote_list remote = call build_request('/list') JSON.parse(remote.body)['files'].map do |stat| stat['updated_at'] = Time.parse(stat['updated_at']) stat end end |