Class: Archaeo::Cli

Inherits:
Thor
  • Object
show all
Defined in:
lib/archaeo/cli.rb

Overview

Command-line interface powered by Thor.

Constant Summary collapse

CDX_OPTION_MAP =
{
  from: :from,
  to: :to,
  match_type: :match_type,
  filter: :filters,
  collapse: :collapse,
  sort: :sort,
  limit: :limit,
}.freeze

Instance Method Summary collapse

Instance Method Details

#available(url) ⇒ Object



46
47
48
49
50
51
52
53
54
# File 'lib/archaeo/cli.rb', line 46

def available(url)
  result = AvailabilityApi.new.near(url)
  if result.available?
    puts "Available: #{result.archive_url}"
  else
    puts "Not available"
    exit 1
  end
end

#fetch(url, timestamp) ⇒ Object



67
68
69
70
71
72
73
# File 'lib/archaeo/cli.rb', line 67

def fetch(url, timestamp)
  page = Fetcher.new.fetch(
    url, timestamp: timestamp,
         identity: options[:identity]
  )
  $stdout.write(page.content)
end

#near(url, timestamp) ⇒ Object



28
29
30
31
# File 'lib/archaeo/cli.rb', line 28

def near(url, timestamp)
  snap = CdxApi.new.near(url, timestamp: timestamp)
  puts snap.archive_url
end

#newest(url) ⇒ Object



40
41
42
43
# File 'lib/archaeo/cli.rb', line 40

def newest(url)
  snap = CdxApi.new.newest(url)
  puts snap.archive_url
end

#oldest(url) ⇒ Object



34
35
36
37
# File 'lib/archaeo/cli.rb', line 34

def oldest(url)
  snap = CdxApi.new.oldest(url)
  puts snap.archive_url
end

#save(url) ⇒ Object



57
58
59
60
61
# File 'lib/archaeo/cli.rb', line 57

def save(url)
  result = SaveApi.new.save(url)
  label = result.cached? ? "Cached" : "Saved"
  puts "#{label}: #{result.archive_url}"
end

#snapshots(url) ⇒ Object



17
18
19
20
21
22
23
24
# File 'lib/archaeo/cli.rb', line 17

def snapshots(url)
  cdx = CdxApi.new
  opts = build_cdx_options(options)
  cdx.snapshots(url, **opts).each do |snap|
    puts "#{snap.timestamp}  #{snap.status_code}  " \
         "#{snap.original_url}"
  end
end