bookcrawler 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: d599e5d0be33f3bb0f0f6c1f8fbc01fcf682a3e6
4
+ data.tar.gz: a24d09141afaa07e1f243528b442bd3186efffd8
5
+ SHA512:
6
+ metadata.gz: 73e59026328d672ae3ee5f46b8c08f795cb3facf85c485f204166e62579314541cddb28787f792d55c3886d1187bf9f19af09a6f6e1a385c0dec02ca17b15d31
7
+ data.tar.gz: b418b4dae3f2d4e5a1bc4c2cfd8f8c12b37911b9f416b9652f846fa9c2db81137db4dcc4aad5bfeff11664c208bcfaf3ff258b8bfe8635350ef87489cec05897
data/.gitignore ADDED
@@ -0,0 +1,37 @@
1
+ *.gem
2
+ *.rbc
3
+ /.config
4
+ /coverage/
5
+ /InstalledFiles
6
+ /pkg/
7
+ /spec/reports/
8
+ /test/tmp/
9
+ /test/version_tmp/
10
+ /tmp/
11
+
12
+ ## Specific to RubyMotion:
13
+ .dat*
14
+ .repl_history
15
+ build/
16
+
17
+ ## Documentation cache and generated files:
18
+ /.yardoc/
19
+ /_yardoc/
20
+ /doc/
21
+ /rdoc/
22
+
23
+ ## Environment normalisation:
24
+ /.bundle/
25
+ /vendor/bundle
26
+ /lib/bundler/man/
27
+
28
+ # for a library or gem, you might want to ignore these files since the code is
29
+ # intended to run in multiple environments; otherwise, check them in:
30
+ # Gemfile.lock
31
+ # .ruby-version
32
+ # .ruby-gemset
33
+
34
+ # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
35
+ .rvmrc
36
+ .idea/
37
+
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 2.2.2
data/Gemfile ADDED
@@ -0,0 +1,5 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in bookcrawler.gemspec
4
+ gemspec
5
+
data/Gemfile.lock ADDED
@@ -0,0 +1,42 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ bookcrawler (0.1.0)
5
+ vacuum (~> 1.3.0)
6
+ vcr (~> 2.9.3)
7
+ webmock (~> 1.19.0)
8
+
9
+ GEM
10
+ remote: https://rubygems.org/
11
+ specs:
12
+ addressable (2.3.8)
13
+ awesome_print (1.2.0)
14
+ crack (0.4.2)
15
+ safe_yaml (~> 1.0.0)
16
+ excon (0.45.4)
17
+ jeff (1.5.1)
18
+ excon (>= 0.22.1)
19
+ minitest (5.5.1)
20
+ multi_xml (0.5.5)
21
+ rake (10.4.2)
22
+ safe_yaml (1.0.4)
23
+ vacuum (1.3.0)
24
+ jeff (~> 1.0)
25
+ multi_xml (~> 0.5.0)
26
+ vcr (2.9.3)
27
+ webmock (1.19.0)
28
+ addressable (>= 2.3.6)
29
+ crack (>= 0.3.2)
30
+
31
+ PLATFORMS
32
+ ruby
33
+
34
+ DEPENDENCIES
35
+ awesome_print
36
+ bookcrawler!
37
+ bundler (~> 1.10)
38
+ minitest
39
+ rake (~> 10.0)
40
+
41
+ BUNDLED WITH
42
+ 1.10.6
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Jorge Manrubia
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 all
13
+ 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 THE
21
+ SOFTWARE.
22
+
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Jorge Manrubia
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,50 @@
1
+ # Bookcrawler
2
+
3
+ ## Installation
4
+
5
+ Add this line to your application's Gemfile:
6
+
7
+ ```ruby
8
+ gem 'bookcrawler'
9
+ ```
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install bookcrawler
18
+
19
+ ## Usage
20
+
21
+ Set your [Amazon credentials](https://affiliateprogram.amazon.com/gp/flex/advertising/api/sign-in.html) as env vars:
22
+
23
+ ```
24
+ export AWS_ACCESS_KEY_ID=...
25
+ export AWS_SECRET_ACCESS_KEY=...
26
+ export AMAZON_ASSOCIATES_TRACKING_ID=...
27
+ ```
28
+
29
+ Find a book:
30
+
31
+ ```ruby
32
+ crawler = Bookcrawler::Client.new
33
+ book = crawler.find_by_title('A Clash of Kings')
34
+
35
+ # <Bookcrawler::Book:
36
+ # asin: "0553579908",
37
+ # title: "A Clash of Kings (A Song of Ice and Fire, Book 2)",
38
+ # author: "George R. R. Martin",
39
+ # detail_page_url: "http://...",
40
+ # cover_url: "http://...">
41
+ ```
42
+
43
+ You can fetch the book cover from `cover_url`. Support for covers is not official in the [Amazon Product Advertising API](https://affiliate-program.amazon.com/gp/advertising/api/detail/main.html). The url is generated according to [this article](http://aaugh.com/imageabuse.html).
44
+
45
+ This gem uses [Vacuum](https://github.com/hakanensari/vacuum) under the hood.
46
+
47
+ ## License
48
+
49
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
50
+
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ Rake::TestTask.new(:test) do |t|
5
+ t.libs << "test"
6
+ t.libs << "lib"
7
+ t.test_files = FileList['test/**/*_test.rb']
8
+ end
9
+
10
+ task :default => :test
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "bookcrawler"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,31 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'bookcrawler/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "bookcrawler"
8
+ spec.version = Bookcrawler::VERSION
9
+ spec.authors = ["Jorge Manrubia"]
10
+ spec.email = ["jorge.manrubia@gmail.com"]
11
+
12
+ spec.summary = %q{Simple mechanism for fetching books metadata using Amazon Product Advertising API}
13
+ spec.description = %q{}
14
+ spec.homepage = "https://github.com/jorgemanrubia/bookcrawler"
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
+ spec.bindir = "exe"
19
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
+ spec.require_paths = ["lib"]
21
+
22
+
23
+ spec.add_dependency "vcr", "~> 2.9.3"
24
+ spec.add_dependency "vacuum", "~> 1.3.0"
25
+ spec.add_dependency "webmock", "~> 1.19.0"
26
+
27
+ spec.add_development_dependency "bundler", "~> 1.10"
28
+ spec.add_development_dependency "rake", "~> 10.0"
29
+ spec.add_development_dependency "minitest"
30
+ spec.add_development_dependency "awesome_print"
31
+ end
@@ -0,0 +1,18 @@
1
+ require 'ostruct'
2
+
3
+ module Bookcrawler
4
+ class Book
5
+ attr_accessor :asin, :title, :author, :detail_page_url
6
+
7
+ def initialize(properties)
8
+ properties.each do |key, value|
9
+ self.send("#{key}=", value)
10
+ end
11
+ end
12
+
13
+ def cover_url
14
+ #see http://aaugh.com/imageabuse.html
15
+ "http://images.amazon.com/images/P/#{asin}.01.ZTZZZZZZ.jpg"
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,66 @@
1
+ require 'ostruct'
2
+ require 'vacuum'
3
+
4
+ module Bookcrawler
5
+ class Client
6
+ def find_by_title(title)
7
+ entries = find_all_entries_by_title(title)
8
+ target_entry = entries[0]
9
+
10
+ if target_entry
11
+ create_book_from_vacuum_entry(target_entry)
12
+ else
13
+ nil
14
+ end
15
+ end
16
+
17
+ private
18
+
19
+ def vacuum_client
20
+ @vacuum_client ||= configure_vacuum_client
21
+ end
22
+
23
+ def configure_vacuum_client
24
+ Vacuum.new.tap do |client|
25
+ client.configure(
26
+ associate_tag: ENV['AMAZON_ASSOCIATES_TRACKING_ID']
27
+ )
28
+ end
29
+ end
30
+
31
+ def find_all_entries_by_title(title)
32
+ response = search_book_in_vacuum_by_title(title)
33
+
34
+ results = response.to_h
35
+ ['ItemSearchResponse', 'Items', 'Item'].each do |attribute_name|
36
+ next unless results
37
+ results = results[attribute_name]
38
+ end
39
+
40
+ (results || []).collect { |result| vacuum_result_as_object(result) }
41
+ end
42
+
43
+ def search_book_in_vacuum_by_title(title)
44
+ vacuum_client.item_search(
45
+ query: {
46
+ 'Keywords' => title,
47
+ 'SearchIndex' => 'Books'
48
+ }
49
+ )
50
+ end
51
+
52
+ def vacuum_result_as_object(entry)
53
+ attributes = entry['ItemAttributes']
54
+ attributes.merge!('ASIN' => entry['ASIN'], 'DetailPageURL' => entry['DetailPageURL'])
55
+ OpenStruct.new(attributes)
56
+ end
57
+
58
+ def create_book_from_vacuum_entry(target_entry)
59
+ Book.new asin: target_entry['ASIN'],
60
+ title: target_entry['Title'],
61
+ author: target_entry['Author'],
62
+ detail_page_url: target_entry['DetailPageURL']
63
+ end
64
+
65
+ end
66
+ end
@@ -0,0 +1,3 @@
1
+ module Bookcrawler
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,7 @@
1
+ require "bookcrawler/version"
2
+ require "bookcrawler/book"
3
+ require "bookcrawler/client"
4
+
5
+ module Bookcrawler
6
+ # Your code goes here...
7
+ end
metadata ADDED
@@ -0,0 +1,158 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: bookcrawler
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Jorge Manrubia
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2015-10-01 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: vcr
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 2.9.3
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 2.9.3
27
+ - !ruby/object:Gem::Dependency
28
+ name: vacuum
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 1.3.0
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 1.3.0
41
+ - !ruby/object:Gem::Dependency
42
+ name: webmock
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 1.19.0
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 1.19.0
55
+ - !ruby/object:Gem::Dependency
56
+ name: bundler
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '1.10'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '1.10'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rake
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '10.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '10.0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: minitest
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: awesome_print
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ description: ''
112
+ email:
113
+ - jorge.manrubia@gmail.com
114
+ executables: []
115
+ extensions: []
116
+ extra_rdoc_files: []
117
+ files:
118
+ - ".gitignore"
119
+ - ".ruby-version"
120
+ - Gemfile
121
+ - Gemfile.lock
122
+ - LICENSE
123
+ - LICENSE.txt
124
+ - README.md
125
+ - Rakefile
126
+ - bin/console
127
+ - bin/setup
128
+ - bookcrawler.gemspec
129
+ - lib/bookcrawler.rb
130
+ - lib/bookcrawler/book.rb
131
+ - lib/bookcrawler/client.rb
132
+ - lib/bookcrawler/version.rb
133
+ homepage: https://github.com/jorgemanrubia/bookcrawler
134
+ licenses:
135
+ - MIT
136
+ metadata: {}
137
+ post_install_message:
138
+ rdoc_options: []
139
+ require_paths:
140
+ - lib
141
+ required_ruby_version: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - ">="
144
+ - !ruby/object:Gem::Version
145
+ version: '0'
146
+ required_rubygems_version: !ruby/object:Gem::Requirement
147
+ requirements:
148
+ - - ">="
149
+ - !ruby/object:Gem::Version
150
+ version: '0'
151
+ requirements: []
152
+ rubyforge_project:
153
+ rubygems_version: 2.4.5
154
+ signing_key:
155
+ specification_version: 4
156
+ summary: Simple mechanism for fetching books metadata using Amazon Product Advertising
157
+ API
158
+ test_files: []