amazon_book 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 +7 -0
- data/LICENSE +21 -0
- data/README.md +84 -0
- data/lib/amazon_book.rb +6 -0
- data/lib/amazon_book/link.rb +50 -0
- data/lib/amazon_book/version.rb +3 -0
- metadata +106 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 7fbd9d5009d54e3c034c90047d5162c5b376ba89
|
4
|
+
data.tar.gz: 2f4b523420c15f8db46725644915c93b2fdb2835
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 331c1da6706e92b591d2519c3990a688a49679e2a094571be868be7961bcf17c8450be23909bc605166ec68a8252eb4bb80d0ffffdb7fb8709d60c40712b7f8f
|
7
|
+
data.tar.gz: ac564258810f5019db7ca5bff37ce6f06371b123cb63173ccdce4375a89a65039d5d509102d313af2d5772b24670233149d959bd1f41f7dfd2e71c067c550824
|
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2017 Altmetric LLP
|
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.
|
data/README.md
ADDED
@@ -0,0 +1,84 @@
|
|
1
|
+
# AmazonBook
|
2
|
+
|
3
|
+
A handy class used to parse Amazon book links, extract normalized ISBN13 from them and decide whether they point to a book or some other content.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'amazon_book'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install amazon_book
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
```ruby
|
24
|
+
link = AmazonBook::Link.new('https://www.amazon.co.uk/dp/009957506X/')
|
25
|
+
# => #<AmazonBook::Link:0x007fd15515d7a8 @url="https://www.amazon.co.uk/dp/009957506X/">
|
26
|
+
link.book?
|
27
|
+
# => true
|
28
|
+
link.isbn13
|
29
|
+
# => "9780099575061"
|
30
|
+
```
|
31
|
+
|
32
|
+
### Long links are supported
|
33
|
+
```ruby
|
34
|
+
link = AmazonBook::Link.new('https://www.amazon.co.uk/Behave-Biology-Humans-Best-Worst-x/dp/009957506X/ref=sr_1_1?ie=UTF8&qid=150009226&sr=8-1&keywords=behave')
|
35
|
+
# => #<AmazonBook::Link:0x007fd15682c1f0 @url="https://www.amazon.co.uk/Behave-Biology-Humans-Best-Worst-x/dp/009957506X/ref=sr_1_1?ie=UTF8&qid=1502369566&sr=8-1&keywords=behave">
|
36
|
+
link.book?
|
37
|
+
# => true
|
38
|
+
link.isbn13
|
39
|
+
# => "9780099575061"
|
40
|
+
```
|
41
|
+
|
42
|
+
### Not a book
|
43
|
+
```ruby
|
44
|
+
link = AmazonBook::Link.new('https://www.amazon.co.uk/dp/B00JS905Z4')
|
45
|
+
# => #<AmazonBook::Link:0x007fd15682c1f0 @url="https://www.amazon.co.uk/dp/B00JS905Z4">
|
46
|
+
link.book?
|
47
|
+
# => false
|
48
|
+
```
|
49
|
+
|
50
|
+
### Different url type
|
51
|
+
```ruby
|
52
|
+
link = AmazonBook::Link.new('https://www.amazon.co.uk/o/ASIN/009957506X/')
|
53
|
+
# => #<AmazonBook::Link:0x007fd15682c1f0 @url="https://www.amazon.co.uk/o/ASIN/009957506X/">
|
54
|
+
link.book?
|
55
|
+
# => true
|
56
|
+
link.isbn13
|
57
|
+
# => "9780099575061"
|
58
|
+
```
|
59
|
+
|
60
|
+
### Different country
|
61
|
+
```ruby
|
62
|
+
link = AmazonBook::Link.new('https://www.amazon.co.jp/o/ASIN/009957506X/')
|
63
|
+
# => #<AmazonBook::Link:0x007fd15682c1f0 @url="https://www.amazon.co.jp/o/ASIN/009957506X/">
|
64
|
+
link.book?
|
65
|
+
# => true
|
66
|
+
link.isbn13
|
67
|
+
# => "9780099575061"
|
68
|
+
```
|
69
|
+
|
70
|
+
## Development
|
71
|
+
|
72
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
73
|
+
|
74
|
+
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).
|
75
|
+
|
76
|
+
## Contributing
|
77
|
+
|
78
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/altmetric/amazon_book.
|
79
|
+
|
80
|
+
## License
|
81
|
+
|
82
|
+
Copyright © 2017 Altmetric LLP
|
83
|
+
|
84
|
+
Distributed under the MIT License.
|
data/lib/amazon_book.rb
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
module AmazonBook
|
2
|
+
class Link
|
3
|
+
BOOK_PATHS = [
|
4
|
+
%r{/dp/(\d{9}[\dX])},
|
5
|
+
%r{/gp/offer-listing/(\d{9}[\dX])},
|
6
|
+
%r{/gp/product/(\d{9}[\dX])},
|
7
|
+
%r{/exec/obidos/ASIN/(\d{9}[\dX])},
|
8
|
+
%r{/o/ASIN/(\d{9}[\dX])}
|
9
|
+
].freeze
|
10
|
+
|
11
|
+
AMAZON_DOMAINS = [
|
12
|
+
'amazon.ca',
|
13
|
+
'amazon.cn',
|
14
|
+
'amazon.co.jp',
|
15
|
+
'amazon.co.uk',
|
16
|
+
'amazon.com',
|
17
|
+
'amazon.com.au',
|
18
|
+
'amazon.com.br',
|
19
|
+
'amazon.com.mx',
|
20
|
+
'amazon.de',
|
21
|
+
'amazon.es',
|
22
|
+
'amazon.fr',
|
23
|
+
'amazon.in',
|
24
|
+
'amazon.it',
|
25
|
+
'amazon.nl'
|
26
|
+
].freeze
|
27
|
+
|
28
|
+
attr_reader :url
|
29
|
+
|
30
|
+
def initialize(url)
|
31
|
+
@url = url
|
32
|
+
end
|
33
|
+
|
34
|
+
def book?
|
35
|
+
correct_domain? && isbn13
|
36
|
+
end
|
37
|
+
|
38
|
+
def isbn13
|
39
|
+
BOOK_PATHS.flat_map do |path_regex|
|
40
|
+
Identifiers::ISBN.extract(url[path_regex, 1])
|
41
|
+
end.first
|
42
|
+
end
|
43
|
+
|
44
|
+
private
|
45
|
+
|
46
|
+
def correct_domain?
|
47
|
+
url.match?(Regexp.union(AMAZON_DOMAINS))
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
metadata
ADDED
@@ -0,0 +1,106 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: amazon_book
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Maciej Gajewski
|
8
|
+
- Anna Klimas
|
9
|
+
autorequire:
|
10
|
+
bindir: exe
|
11
|
+
cert_chain: []
|
12
|
+
date: 2017-08-10 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: bundler
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
requirements:
|
18
|
+
- - "~>"
|
19
|
+
- !ruby/object:Gem::Version
|
20
|
+
version: '1.15'
|
21
|
+
type: :development
|
22
|
+
prerelease: false
|
23
|
+
version_requirements: !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - "~>"
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
version: '1.15'
|
28
|
+
- !ruby/object:Gem::Dependency
|
29
|
+
name: rake
|
30
|
+
requirement: !ruby/object:Gem::Requirement
|
31
|
+
requirements:
|
32
|
+
- - "~>"
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: '10.0'
|
35
|
+
type: :development
|
36
|
+
prerelease: false
|
37
|
+
version_requirements: !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - "~>"
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: '10.0'
|
42
|
+
- !ruby/object:Gem::Dependency
|
43
|
+
name: rspec
|
44
|
+
requirement: !ruby/object:Gem::Requirement
|
45
|
+
requirements:
|
46
|
+
- - "~>"
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: '3.0'
|
49
|
+
type: :development
|
50
|
+
prerelease: false
|
51
|
+
version_requirements: !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - "~>"
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: '3.0'
|
56
|
+
- !ruby/object:Gem::Dependency
|
57
|
+
name: identifiers
|
58
|
+
requirement: !ruby/object:Gem::Requirement
|
59
|
+
requirements:
|
60
|
+
- - "~>"
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: '0.9'
|
63
|
+
type: :runtime
|
64
|
+
prerelease: false
|
65
|
+
version_requirements: !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - "~>"
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0.9'
|
70
|
+
description: Use it to parse Amazon book links (extract ISBNs etc.)
|
71
|
+
email:
|
72
|
+
- support@altmetric.com
|
73
|
+
executables: []
|
74
|
+
extensions: []
|
75
|
+
extra_rdoc_files: []
|
76
|
+
files:
|
77
|
+
- LICENSE
|
78
|
+
- README.md
|
79
|
+
- lib/amazon_book.rb
|
80
|
+
- lib/amazon_book/link.rb
|
81
|
+
- lib/amazon_book/version.rb
|
82
|
+
homepage: https://github.com/altmetric/amazon_book
|
83
|
+
licenses:
|
84
|
+
- MIT
|
85
|
+
metadata: {}
|
86
|
+
post_install_message:
|
87
|
+
rdoc_options: []
|
88
|
+
require_paths:
|
89
|
+
- lib
|
90
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
91
|
+
requirements:
|
92
|
+
- - ">="
|
93
|
+
- !ruby/object:Gem::Version
|
94
|
+
version: '0'
|
95
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
96
|
+
requirements:
|
97
|
+
- - ">="
|
98
|
+
- !ruby/object:Gem::Version
|
99
|
+
version: '0'
|
100
|
+
requirements: []
|
101
|
+
rubyforge_project:
|
102
|
+
rubygems_version: 2.6.12
|
103
|
+
signing_key:
|
104
|
+
specification_version: 4
|
105
|
+
summary: Parses Amazon book links
|
106
|
+
test_files: []
|