web-archive 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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 9487f0ac4de71dde7587ceb8fac573b209b4312f
4
+ data.tar.gz: fd87dd71b6d587407d310bbe50d7a2d254aedabb
5
+ SHA512:
6
+ metadata.gz: c8cf5951d6b2d43e1e6fee65361f0d8b3a6b962dcf73f34e1b73e4130ea9b5716aa3b7d772271b9fc21d134c08e75449e05052195af3c9b226d5f4e9cef1fe17
7
+ data.tar.gz: 82357e0bef425711632353985a9afe36212c77d8ed56d5e3fa0bce4dc0b5fd20b16073b68a1039158b7dda0a0b3de047c9240a9d65e09289d6b7e940fc0a5055
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/CHANGELOG.md ADDED
@@ -0,0 +1,2 @@
1
+ ## 0.0.1
2
+ - 1st Release
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in web_archive.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2016 giiko
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,23 @@
1
+ # WebArchive
2
+
3
+ - Archive target url
4
+ - Get archived url of target url
5
+
6
+ ```
7
+ $ gem i web-archive
8
+ ```
9
+
10
+ ## Example
11
+
12
+ ```
13
+ require 'web_archive'
14
+ WebArchive.save!(target_url) #=> url string
15
+ WebArchive.latest(target_url) #=> url string or nil
16
+ WebArchive.oldest(target_url) #=> url string or nil
17
+ ```
18
+
19
+
20
+ ## Contributing
21
+
22
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/web_archive.
23
+
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+ task :default => :spec
@@ -0,0 +1,27 @@
1
+ require "web-archive/version"
2
+ require "open-uri"
3
+
4
+ module WebArchive
5
+ extend self
6
+ BASE = 'http://web.archive.org'
7
+
8
+ def save!(url)
9
+ s = open( "#{BASE}/save/#{url}", &:read )
10
+ BASE + s[%r{"(/web/\d+/.*?)"},1]
11
+ end
12
+
13
+ def latest(url)
14
+ get_archived_urls(url).last
15
+ end
16
+
17
+ def oldest(url)
18
+ get_archived_urls(url).first
19
+ end
20
+
21
+ def get_archived_urls(url)
22
+ html = open("#{BASE}/web/*/#{url}", &:read) rescue (return [])
23
+ html.scan(%r{"(/web/\d+/.*?)"}).flatten.uniq.sort.map do |str|
24
+ BASE + str
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,3 @@
1
+ module WebArchive
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,9 @@
1
+ $LOAD_PATH.unshift File.expand_path("../../lib", __FILE__)
2
+
3
+ require 'minitest'
4
+ require 'rspec-power_assert'
5
+
6
+ RSpec.configure do |config|
7
+ config.expect_with :rspec, :minitest
8
+ config.default_formatter = "doc" if config.files_to_run.one?
9
+ end
@@ -0,0 +1,36 @@
1
+ require 'spec_helper'
2
+ require 'web-archive'
3
+
4
+ class String
5
+ def uri?
6
+ !!(self =~ URI::regexp)
7
+ end
8
+ end
9
+
10
+ RSpec.describe 'Methods for http://web.archive.org/' do
11
+ target_url = "http://example.com/"
12
+
13
+ describe 'WebArchive::BASE' do
14
+ it 'must be url' do
15
+ is_asserted_by { WebArchive::BASE.uri? }
16
+ end
17
+ end
18
+
19
+ describe 'WebArchive#.save!' do
20
+ it 'is making archive and getting snapshot url' do
21
+ is_asserted_by { WebArchive.save!(target_url).uri? }
22
+ end
23
+ end
24
+
25
+ describe 'WebArchive#.latest' do
26
+ it 'is getting latest snapshot url' do
27
+ is_asserted_by { WebArchive.latest(target_url).uri? }
28
+ end
29
+ end
30
+
31
+ describe 'WebArchive#.oldest' do
32
+ it 'is getting oldest snapshot url' do
33
+ is_asserted_by { WebArchive.oldest(target_url).uri? }
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,22 @@
1
+ lib = File.expand_path("../lib", __FILE__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require 'web-archive/version'
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "web-archive"
7
+ spec.version = WebArchive::VERSION
8
+ spec.authors = ["giiko"]
9
+ spec.email = [""]
10
+ spec.summary = "Util for web.archive.org"
11
+ spec.homepage = "https://github.com/giiko/web-archive"
12
+ spec.license = "MIT"
13
+
14
+ spec.files = `git ls-files -z`.split("\x0")
15
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
16
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
17
+ spec.require_paths = ["lib"]
18
+
19
+ spec.add_development_dependency "bundler", "~> 1.11"
20
+ spec.add_development_dependency "rake", "~> 10.0"
21
+ spec.add_development_dependency "pry"
22
+ end
metadata ADDED
@@ -0,0 +1,100 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: web-archive
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - giiko
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-02-19 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.11'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.11'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: pry
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ description:
56
+ email:
57
+ - ''
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - ".gitignore"
63
+ - CHANGELOG.md
64
+ - Gemfile
65
+ - LICENSE.txt
66
+ - README.md
67
+ - Rakefile
68
+ - lib/web-archive.rb
69
+ - lib/web-archive/version.rb
70
+ - spec/spec_helper.rb
71
+ - spec/web-archive/web-archive_spec.rb
72
+ - web-archive.gemspec
73
+ homepage: https://github.com/giiko/web-archive
74
+ licenses:
75
+ - MIT
76
+ metadata: {}
77
+ post_install_message:
78
+ rdoc_options: []
79
+ require_paths:
80
+ - lib
81
+ required_ruby_version: !ruby/object:Gem::Requirement
82
+ requirements:
83
+ - - ">="
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ required_rubygems_version: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - ">="
89
+ - !ruby/object:Gem::Version
90
+ version: '0'
91
+ requirements: []
92
+ rubyforge_project:
93
+ rubygems_version: 2.5.1
94
+ signing_key:
95
+ specification_version: 4
96
+ summary: Util for web.archive.org
97
+ test_files:
98
+ - spec/spec_helper.rb
99
+ - spec/web-archive/web-archive_spec.rb
100
+ has_rdoc: