Class: ArchiveToday::Archiver
- Inherits:
-
Object
- Object
- ArchiveToday::Archiver
- Defined in:
- lib/archive_today/archiver.rb
Constant Summary collapse
- BASE_URL =
'https://archive.today/'.freeze
- DEFAULT_USER_AGENT =
"archive_today #{ArchiveToday::VERSION}".freeze
Instance Attribute Summary collapse
-
#debug ⇒ Object
readonly
Returns the value of attribute debug.
-
#response ⇒ Object
Returns the value of attribute response.
-
#target_url ⇒ Object
readonly
Returns the value of attribute target_url.
-
#user_agent ⇒ Object
readonly
Returns the value of attribute user_agent.
Instance Method Summary collapse
- #capture ⇒ Object
-
#initialize(url:, user_agent: DEFAULT_USER_AGENT, debug: false) ⇒ Archiver
constructor
A new instance of Archiver.
Constructor Details
#initialize(url:, user_agent: DEFAULT_USER_AGENT, debug: false) ⇒ Archiver
Returns a new instance of Archiver.
11 12 13 14 15 |
# File 'lib/archive_today/archiver.rb', line 11 def initialize(url:, user_agent: DEFAULT_USER_AGENT, debug: false) @debug = debug @target_url = url @user_agent = user_agent end |
Instance Attribute Details
#debug ⇒ Object (readonly)
Returns the value of attribute debug.
9 10 11 |
# File 'lib/archive_today/archiver.rb', line 9 def debug @debug end |
#response ⇒ Object
Returns the value of attribute response.
8 9 10 |
# File 'lib/archive_today/archiver.rb', line 8 def response @response end |
#target_url ⇒ Object (readonly)
Returns the value of attribute target_url.
9 10 11 |
# File 'lib/archive_today/archiver.rb', line 9 def target_url @target_url end |
#user_agent ⇒ Object (readonly)
Returns the value of attribute user_agent.
9 10 11 |
# File 'lib/archive_today/archiver.rb', line 9 def user_agent @user_agent end |
Instance Method Details
#capture ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/archive_today/archiver.rb', line 17 def capture puts 'Submitting URL ...' if debug response = connection.post('/submit/') do |req| req.body = submission_body end raise unless response.success? self.response = response { url: finalized_url, screenshot_url: screenshot_url } rescue Faraday::ClientError, Faraday::ServerError => e puts "[archive_today] Error capturing URL: #{e.response[:status]} #{e.response[:body]}" nil end |