archive_today 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: ad131a62edbb1b182f34c8beccaff07cb2e6f73414cd7391c8c8487bfe5ba3b4
4
+ data.tar.gz: a30538c8a90aeec34e003c51de6efcefc4f2b8985a3c66c8bb47355ce2fcbd28
5
+ SHA512:
6
+ metadata.gz: 92b10f61076a7b1e2c44b93bdad340ed71a5be366b3766f00743e33eec0ca4b3515758fda76a3ee6c140006528cbfd9dc97837bb06a8f466d72ac9e671d82a38
7
+ data.tar.gz: fb4d2613c9417dcf16cfce535596574f367a8da48ad25dda967667d918b5ad32c49585de8b32eb1072988de8693e321d85995366760b6215724e1448f5ba7a7b
@@ -0,0 +1,8 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
@@ -0,0 +1,3 @@
1
+ # 0.1.0
2
+
3
+ Initial commit
data/Gemfile ADDED
@@ -0,0 +1,9 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in archive_today.gemspec
4
+ gemspec
5
+
6
+ gem 'faraday', '~> 1.0'
7
+ gem 'faraday_middleware', '~> 1.0'
8
+ gem 'nokogiri', '~> 1.10'
9
+ gem 'rake', '~> 12.0'
@@ -0,0 +1,30 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ archive_today (0.1.0)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ faraday (1.0.1)
10
+ multipart-post (>= 1.2, < 3)
11
+ faraday_middleware (1.0.0)
12
+ faraday (~> 1.0)
13
+ mini_portile2 (2.4.0)
14
+ multipart-post (2.1.1)
15
+ nokogiri (1.10.10)
16
+ mini_portile2 (~> 2.4.0)
17
+ rake (12.3.2)
18
+
19
+ PLATFORMS
20
+ ruby
21
+
22
+ DEPENDENCIES
23
+ archive_today!
24
+ faraday (~> 1.0)
25
+ faraday_middleware (~> 1.0)
26
+ nokogiri (~> 1.10)
27
+ rake (~> 12.0)
28
+
29
+ BUNDLED WITH
30
+ 2.1.4
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2020 TODO: Write your name
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,48 @@
1
+ # ArchiveToday
2
+
3
+ A simple Ruby wrapper for the [Archive.today](https://archive.today) web capture service (formerly known as Archive.is)
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'archive_today'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle install
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install archive_today
20
+
21
+ ## Usage
22
+
23
+ ```ruby
24
+ require 'archive_today'
25
+
26
+ ArchiveToday.submit(url: 'https://example.com')
27
+
28
+ # => 'https://archive.is/a1b2c3
29
+ ```
30
+
31
+ ## Roadmap
32
+
33
+ - proxies
34
+ - optionally return URL of captured screenshot
35
+
36
+ ## Development
37
+
38
+ After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
39
+
40
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
41
+
42
+ ## Contributing
43
+
44
+ Bug reports and pull requests are welcome on GitHub at https://github.com/tomholford/archive_today.
45
+
46
+ ## Credit
47
+
48
+ Inspired by [this Python implementation](https://github.com/pastpages/archiveis), thanks to those contributors.
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+ task :default => :spec
@@ -0,0 +1,27 @@
1
+ require_relative 'lib/archive_today/version'
2
+
3
+ Gem::Specification.new do |spec|
4
+ spec.name = "archive_today"
5
+ spec.version = ArchiveToday::VERSION
6
+ spec.authors = ["tomholford"]
7
+ spec.email = ["tomholford@users.noreply.github.com"]
8
+
9
+ spec.summary = %q{A Ruby gem for submitting links to Archive.today (AKA Archive.is)}
10
+ spec.description = %q{Submit a URL to the Archive.today service to preserve it's contents in a Memento-compatible format}
11
+ spec.homepage = "https://github.com/tomholford/archive-today"
12
+ spec.license = "MIT"
13
+ spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0")
14
+
15
+ spec.metadata["homepage_uri"] = spec.homepage
16
+ spec.metadata["source_code_uri"] = spec.homepage
17
+ spec.metadata["changelog_uri"] = "#{spec.homepage}/CHANGELOG.md"
18
+
19
+ # Specify which files should be added to the gem when it is released.
20
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
21
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
22
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
23
+ end
24
+ spec.bindir = "exe"
25
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
26
+ spec.require_paths = ["lib"]
27
+ end
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "archive_today"
5
+
6
+ require "irb"
7
+ IRB.start(__FILE__)
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,12 @@
1
+ require 'archive_today/version'
2
+ require 'archive_today/archiver'
3
+
4
+ module ArchiveToday
5
+ class Error < StandardError; end
6
+
7
+ class << self
8
+ def submit(url:, debug: false)
9
+ Archiver.new(url: url, debug: debug).submit
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,75 @@
1
+ require 'faraday'
2
+ require 'faraday_middleware'
3
+ require 'nokogiri'
4
+ require_relative 'version'
5
+
6
+ module ArchiveToday
7
+ class Archiver
8
+ BASE_URL = 'https://archive.today/'.freeze
9
+ DEFAULT_USER_AGENT = "archive_today #{ArchiveToday::VERSION}".freeze
10
+
11
+ attr_reader :debug, :url, :user_agent
12
+
13
+ def initialize(url:, user_agent: DEFAULT_USER_AGENT, debug: false)
14
+ @debug = debug
15
+ @url = url
16
+ @user_agent = user_agent
17
+ end
18
+
19
+ def submit
20
+ puts 'Submitting URL ...'
21
+ response = connection.post('/submit/') do |req|
22
+ req.body = submission_body
23
+ end
24
+ raise unless response.success?
25
+
26
+ handle_response(response)
27
+ end
28
+
29
+ private
30
+
31
+ def handle_response(response)
32
+ headers = response.headers
33
+
34
+ return headers[:location] if headers.has_key?('location')
35
+ return headers[:refresh].split(';url=').last if headers.has_key?('refresh')
36
+
37
+ # TODO: handle the history case mentioned here?
38
+ # https://github.com/pastpages/archiveis/blob/master/archiveis/api.py#L81
39
+ response.env.url
40
+ end
41
+
42
+ def submission_body
43
+ URI.encode_www_form(
44
+ {
45
+ url: url,
46
+ anyway: 1,
47
+ submitid: unique_submission_id
48
+ }
49
+ )
50
+ end
51
+
52
+ def unique_submission_id
53
+ puts 'Getting unique submission ID ...'
54
+ response = connection.get('/')
55
+ raise unless response.success?
56
+
57
+ html = Nokogiri::HTML(response.body)
58
+ node = html.at_css('input[name="submitid"]')
59
+ id = node.attr('value')
60
+ puts "Got ID: #{id}" and return if id
61
+
62
+ nil
63
+ end
64
+
65
+ def connection
66
+ @connection ||= begin
67
+ Faraday.new(BASE_URL) do |faraday|
68
+ faraday.headers = { 'User-Agent' => user_agent }
69
+ faraday.use FaradayMiddleware::FollowRedirects
70
+ faraday.response :logger if debug
71
+ end
72
+ end
73
+ end
74
+ end
75
+ end
@@ -0,0 +1,3 @@
1
+ module ArchiveToday
2
+ VERSION = "0.1.0"
3
+ end
metadata ADDED
@@ -0,0 +1,60 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: archive_today
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - tomholford
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2020-07-13 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Submit a URL to the Archive.today service to preserve it's contents in
14
+ a Memento-compatible format
15
+ email:
16
+ - tomholford@users.noreply.github.com
17
+ executables: []
18
+ extensions: []
19
+ extra_rdoc_files: []
20
+ files:
21
+ - ".gitignore"
22
+ - CHANGELOG.md
23
+ - Gemfile
24
+ - Gemfile.lock
25
+ - LICENSE.txt
26
+ - README.md
27
+ - Rakefile
28
+ - archive_today.gemspec
29
+ - bin/console
30
+ - bin/setup
31
+ - lib/archive_today.rb
32
+ - lib/archive_today/archiver.rb
33
+ - lib/archive_today/version.rb
34
+ homepage: https://github.com/tomholford/archive-today
35
+ licenses:
36
+ - MIT
37
+ metadata:
38
+ homepage_uri: https://github.com/tomholford/archive-today
39
+ source_code_uri: https://github.com/tomholford/archive-today
40
+ changelog_uri: https://github.com/tomholford/archive-today/CHANGELOG.md
41
+ post_install_message:
42
+ rdoc_options: []
43
+ require_paths:
44
+ - lib
45
+ required_ruby_version: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - ">="
48
+ - !ruby/object:Gem::Version
49
+ version: 2.3.0
50
+ required_rubygems_version: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ requirements: []
56
+ rubygems_version: 3.1.2
57
+ signing_key:
58
+ specification_version: 4
59
+ summary: A Ruby gem for submitting links to Archive.today (AKA Archive.is)
60
+ test_files: []