openlibrary-covers 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 3005d3300710dce10002ab997b887d1d7d8e57899f2d982e2f8a6ff19bf0e14f
4
+ data.tar.gz: 79e3c02feb45bb14a190a13530c30d55578a3e1ab7db0348fad88257a2e5d3ab
5
+ SHA512:
6
+ metadata.gz: 2fc6b15a55356e037e6ab2794f4a18c002e12093878eef4c002925dd9919d7207544d747a7bc99ece856a42ae0a18e1eb1f142fa715b86b264dd8e302f819107
7
+ data.tar.gz: '0949b3817b23065a3fcfb9e6dfb4185c6dfe11dc8685ab9765376ead3663084a3c05634f6ed7725afe5efa4b92cf802d141cc564eb960491c683e1bd95774c5a'
@@ -0,0 +1,43 @@
1
+ working_dir: &working_dir ~/app
2
+
3
+ .build_template: &build_definition
4
+ steps:
5
+ - checkout
6
+ - run: gem install bundler:2.1.4
7
+ - run: bundle install --jobs=4 --retry=4 --path vendor/bundle
8
+ - run: bundle exec rake rubocop
9
+ - run:
10
+ name: Run tests
11
+ command: |
12
+ bundle exec rspec
13
+ working_directory: *working_dir
14
+
15
+ version: 2.0
16
+
17
+ jobs:
18
+ build:
19
+ docker:
20
+ - image: ruby
21
+ steps:
22
+ - checkout
23
+ build_ruby2_7:
24
+ <<: *build_definition
25
+ docker:
26
+ - image: ruby:2.7
27
+ build_ruby2_6:
28
+ <<: *build_definition
29
+ docker:
30
+ - image: ruby:2.6
31
+ build_ruby2_5:
32
+ <<: *build_definition
33
+ docker:
34
+ - image: ruby:2.5
35
+
36
+ workflows:
37
+ version: 2
38
+ build_ruby_versions:
39
+ jobs:
40
+ - build
41
+ - build_ruby2_7
42
+ - build_ruby2_6
43
+ - build_ruby2_5
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
@@ -0,0 +1,3 @@
1
+ AllCops:
2
+ NewCops: enable
3
+ TargetRubyVersion: 2.5
data/Gemfile ADDED
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ source 'https://rubygems.org'
4
+
5
+ # Specify your gem's dependencies in openlibrary-covers.gemspec
6
+ gemspec
7
+
8
+ gem 'rake', '~> 12.0'
9
+ gem 'rspec', '~> 3.0'
@@ -0,0 +1,72 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ openlibrary-covers (0.1.0)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ ast (2.4.1)
10
+ benchmark-malloc (0.2.0)
11
+ benchmark-perf (0.6.0)
12
+ benchmark-trend (0.4.0)
13
+ diff-lcs (1.4.4)
14
+ parallel (1.19.2)
15
+ parser (2.7.2.0)
16
+ ast (~> 2.4.1)
17
+ rainbow (3.0.0)
18
+ rake (12.3.3)
19
+ regexp_parser (1.8.2)
20
+ rexml (3.2.4)
21
+ rspec (3.10.0)
22
+ rspec-core (~> 3.10.0)
23
+ rspec-expectations (~> 3.10.0)
24
+ rspec-mocks (~> 3.10.0)
25
+ rspec-benchmark (0.6.0)
26
+ benchmark-malloc (~> 0.2)
27
+ benchmark-perf (~> 0.6)
28
+ benchmark-trend (~> 0.4)
29
+ rspec (>= 3.0)
30
+ rspec-core (3.10.0)
31
+ rspec-support (~> 3.10.0)
32
+ rspec-expectations (3.10.0)
33
+ diff-lcs (>= 1.2.0, < 2.0)
34
+ rspec-support (~> 3.10.0)
35
+ rspec-mocks (3.10.0)
36
+ diff-lcs (>= 1.2.0, < 2.0)
37
+ rspec-support (~> 3.10.0)
38
+ rspec-support (3.10.0)
39
+ rubocop (0.93.1)
40
+ parallel (~> 1.10)
41
+ parser (>= 2.7.1.5)
42
+ rainbow (>= 2.2.2, < 4.0)
43
+ regexp_parser (>= 1.8)
44
+ rexml
45
+ rubocop-ast (>= 0.6.0)
46
+ ruby-progressbar (~> 1.7)
47
+ unicode-display_width (>= 1.4.0, < 2.0)
48
+ rubocop-ast (1.1.0)
49
+ parser (>= 2.7.1.5)
50
+ rubocop-performance (1.8.1)
51
+ rubocop (>= 0.87.0)
52
+ rubocop-ast (>= 0.4.0)
53
+ rubocop-rspec (1.44.1)
54
+ rubocop (~> 0.87)
55
+ rubocop-ast (>= 0.7.1)
56
+ ruby-progressbar (1.10.1)
57
+ unicode-display_width (1.7.0)
58
+
59
+ PLATFORMS
60
+ x64-mingw32
61
+
62
+ DEPENDENCIES
63
+ openlibrary-covers!
64
+ rake (~> 12.0)
65
+ rspec (~> 3.0)
66
+ rspec-benchmark (~> 0.6)
67
+ rubocop (> 0.93)
68
+ rubocop-performance (~> 1.8)
69
+ rubocop-rspec (~> 1.44)
70
+
71
+ BUNDLED WITH
72
+ 2.1.4
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2020 Jane Sandberg
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,52 @@
1
+ # Openlibrary::Covers
2
+
3
+ A very small gem that wraps the OpenLibrary's Covers API (https://openlibrary.org/dev/docs/api/covers).
4
+
5
+ Note that OpenLibrary says that "a courtesy link back to Open Library is appreciated".
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'openlibrary-covers'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle install
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install openlibrary-covers
22
+
23
+ ## Usage
24
+
25
+ require 'openlibrary-covers'
26
+ image = Openlibrary::Covers::Image.new '9780786965601'
27
+ image.found? # => true
28
+ image.url # => "http://covers.openlibrary.org/b/isbn/9780786965601-M.jpg"
29
+
30
+ image_by_oclc_number = Openlibrary::Covers::Image.new '798147823', :oclc
31
+ # Get a large image
32
+ image_by_oclc_number.url :L # => "http://covers.openlibrary.org/b/oclc/798147823-L.jpg"
33
+
34
+ invalid_image = Openlibrary::Covers::Image.new 'not-a-real-identifier'
35
+ invalid_image.found? # => false
36
+ invalid_image.url # => nil
37
+
38
+
39
+ ## Development
40
+
41
+ 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.
42
+
43
+ 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).
44
+
45
+ ## Contributing
46
+
47
+ Bug reports and pull requests are welcome on GitHub at https://github.com/sandbergja/openlibrary-covers.
48
+
49
+
50
+ ## License
51
+
52
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'bundler/gem_tasks'
4
+ require 'rspec/core/rake_task'
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ task default: :spec
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require 'bundler/setup'
5
+ require 'openlibrary/covers'
6
+
7
+ # You can add fixtures and/or initialization code here to make experimenting
8
+ # with your gem easier. You can also use a different console, if you like.
9
+
10
+ # (If you use this, don't forget to add pry to your Gemfile!)
11
+ # require "pry"
12
+ # Pry.start
13
+
14
+ require 'irb'
15
+ 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,64 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'openlibrary/covers/version'
4
+ require 'net/http'
5
+
6
+ module Openlibrary
7
+ module Covers
8
+ ##
9
+ # An Image from the OpenLibrary API, if one exists
10
+ class Image
11
+ ##
12
+ # @param [String, Array<string>] identifiers the actual values to look up
13
+ # @param [String, Symbol] identifier_type
14
+ def initialize(identifiers, identifier_type = :isbn)
15
+ identifiers = Array(identifiers)
16
+ @identifier_type = identifier_type
17
+
18
+ @found = false
19
+
20
+ @successful_identifier = identifiers.detect { |identifier| image_exists(identifier) }
21
+ @found = true if @successful_identifier
22
+ end
23
+
24
+ def found?
25
+ @found
26
+ end
27
+
28
+ ##
29
+ # @param [String, Symbol] size (can be 'S', 'M', 'L', :S, :M, :L)
30
+ def url(size = 'M')
31
+ @found ? openlibrary_url(@successful_identifier, size) : nil
32
+ end
33
+
34
+ private
35
+
36
+ def openlibrary_domain
37
+ 'covers.openlibrary.org'
38
+ end
39
+
40
+ def openlibrary_port
41
+ 80
42
+ end
43
+
44
+ def openlibrary_url(identifier, size, default_behavior: true)
45
+ "http://#{openlibrary_domain}#{openlibrary_path(identifier, size, default_behavior: default_behavior)}"
46
+ end
47
+
48
+ def openlibrary_path(identifier, size, default_behavior: true)
49
+ base_path = "/b/#{@identifier_type}/#{identifier}-#{size}.jpg"
50
+ default_behavior ? base_path : "#{base_path}?default=false"
51
+ end
52
+
53
+ def image_exists(identifier)
54
+ response = nil
55
+ Net::HTTP.start(openlibrary_domain, openlibrary_port) do |http|
56
+ response = http.head(openlibrary_path(identifier, :S, default_behavior: false))
57
+ end
58
+ return true if %w[200 301 302].include? response.code
59
+
60
+ false
61
+ end
62
+ end
63
+ end
64
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Openlibrary
4
+ module Covers
5
+ VERSION = '0.1.0'
6
+ end
7
+ end
@@ -0,0 +1,34 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'lib/openlibrary/covers/version'
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = 'openlibrary-covers'
7
+ spec.version = Openlibrary::Covers::VERSION
8
+ spec.authors = ['Jane Sandberg']
9
+ spec.email = ['sandbej@linnbenton.edu']
10
+
11
+ spec.summary = 'Find cover images from openlibrary'
12
+ spec.description = 'A small gem that quickly checks openlibrary to see if '\
13
+ 'a cover image exists for the identifiers you are interested in.'
14
+ spec.homepage = 'https://github.com/sandbergja/openlibrary-covers'
15
+ spec.license = 'MIT'
16
+ spec.required_ruby_version = Gem::Requirement.new('>= 2.5')
17
+
18
+ spec.metadata['homepage_uri'] = spec.homepage
19
+ spec.metadata['source_code_uri'] = spec.homepage
20
+
21
+ # Specify which files should be added to the gem when it is released.
22
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
23
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
24
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
25
+ end
26
+ spec.bindir = 'exe'
27
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
28
+ spec.require_paths = ['lib']
29
+
30
+ spec.add_development_dependency 'rspec-benchmark', '~> 0.6'
31
+ spec.add_development_dependency 'rubocop', '> 0.93'
32
+ spec.add_development_dependency 'rubocop-performance', '~> 1.8'
33
+ spec.add_development_dependency 'rubocop-rspec', '~> 1.44'
34
+ end
metadata ADDED
@@ -0,0 +1,116 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: openlibrary-covers
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Jane Sandberg
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2020-10-31 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rspec-benchmark
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '0.6'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '0.6'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rubocop
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">"
32
+ - !ruby/object:Gem::Version
33
+ version: '0.93'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">"
39
+ - !ruby/object:Gem::Version
40
+ version: '0.93'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rubocop-performance
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.8'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.8'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rubocop-rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '1.44'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '1.44'
69
+ description: A small gem that quickly checks openlibrary to see if a cover image exists
70
+ for the identifiers you are interested in.
71
+ email:
72
+ - sandbej@linnbenton.edu
73
+ executables: []
74
+ extensions: []
75
+ extra_rdoc_files: []
76
+ files:
77
+ - ".circleci/config.yml"
78
+ - ".gitignore"
79
+ - ".rspec"
80
+ - ".rubocop.yml"
81
+ - Gemfile
82
+ - Gemfile.lock
83
+ - LICENSE.txt
84
+ - README.md
85
+ - Rakefile
86
+ - bin/console
87
+ - bin/setup
88
+ - lib/openlibrary/covers.rb
89
+ - lib/openlibrary/covers/version.rb
90
+ - openlibrary-covers.gemspec
91
+ homepage: https://github.com/sandbergja/openlibrary-covers
92
+ licenses:
93
+ - MIT
94
+ metadata:
95
+ homepage_uri: https://github.com/sandbergja/openlibrary-covers
96
+ source_code_uri: https://github.com/sandbergja/openlibrary-covers
97
+ post_install_message:
98
+ rdoc_options: []
99
+ require_paths:
100
+ - lib
101
+ required_ruby_version: !ruby/object:Gem::Requirement
102
+ requirements:
103
+ - - ">="
104
+ - !ruby/object:Gem::Version
105
+ version: '2.5'
106
+ required_rubygems_version: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ requirements: []
112
+ rubygems_version: 3.0.3
113
+ signing_key:
114
+ specification_version: 4
115
+ summary: Find cover images from openlibrary
116
+ test_files: []