open_bd 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: 7b5522ee17be5d02e156f1074281a77db9c5e3c0
4
+ data.tar.gz: d00ca27118a9dcd4744cf1e1ac016386ce2e6e25
5
+ SHA512:
6
+ metadata.gz: 1ad0f929c7b186d7d1f89b996924fc3b07d0ff2b6ff67e70097f3c6cde49430bd22de7c0fc860867a215f6be9bdca511820a05c84dd6311de4ada43d65ed7395
7
+ data.tar.gz: e0fa21c3551921c56c13aa2d76d4937cb95e0d0839698bf207c22e0c0afde79c5e71152c13d33a27f20e48a5752e9e10a8810581742031f3c463700dffb060b0
data/.gitignore ADDED
@@ -0,0 +1,12 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+
11
+ # rspec failure tracking
12
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.4.1
5
+ before_install: gem install bundler -v 1.15.4
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in open_bd.gemspec
6
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2018 ryosuke-endo
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,58 @@
1
+ # OpenBD
2
+
3
+ An API client library for openBD API, written in Ruby.
4
+
5
+ Please refer to the following for more information
6
+
7
+ [openBD](https://openbd.jp/)
8
+
9
+ ## Installation
10
+
11
+ Add this line to your application's Gemfile:
12
+
13
+ ```ruby
14
+ gem 'open_bd'
15
+ ```
16
+
17
+ And then execute:
18
+
19
+ $ bundle
20
+
21
+ Or install it yourself as:
22
+
23
+ $ gem install open_bd
24
+
25
+ ## Usage
26
+
27
+ ```
28
+ client = OpenBD.new
29
+ # Pass the value of isbn to isbns
30
+ res = client.search(isbns: [])
31
+
32
+ res.empty?
33
+ res.body
34
+ res.status
35
+
36
+ # [OpenBD::Resource]
37
+ res.resources.each do |resource|
38
+ res.content
39
+ res.content_detail
40
+ res.contributors # [OpenBD::Contributor]
41
+ res.cover_image
42
+ res.height
43
+ res.isbn
44
+ res.main_title
45
+ res.paper_size
46
+ res.paper_size_detail
47
+ res.publisher
48
+ res.release_date
49
+ res.sub_title
50
+ res.table_of_contents
51
+ res.title
52
+ res.width
53
+ end
54
+ ```
55
+
56
+ ## License
57
+
58
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "open_bd"
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(__FILE__)
data/bin/setup ADDED
@@ -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
data/lib/open_bd.rb ADDED
@@ -0,0 +1,8 @@
1
+ require "open_bd/version"
2
+ require "open_bd/client"
3
+ require "open_bd/content"
4
+ require "open_bd/contributor"
5
+ require "open_bd/paper"
6
+ require "open_bd/resource"
7
+ require "open_bd/response"
8
+ require "open_bd/title"
@@ -0,0 +1,26 @@
1
+ require "faraday"
2
+ require "faraday_middleware"
3
+
4
+ module OpenBD
5
+ class Client
6
+ BASE_URL = "https://api.openbd.jp/".freeze
7
+ VERSION = "v1".freeze
8
+ URL = "#{BASE_URL}#{VERSION}".freeze
9
+ SEARCH_PATH = "get"
10
+
11
+ def search(isbns: [])
12
+ query = [*isbns].join(',')
13
+ response = connection.get(SEARCH_PATH, isbn: query)
14
+ OpenBD::Response.new(response)
15
+ end
16
+
17
+ private
18
+
19
+ def connection
20
+ @connection ||= Faraday.new(URL) do |connection|
21
+ connection.response :json
22
+ connection.adapter Faraday.default_adapter
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,30 @@
1
+ module OpenBD
2
+ class Content
3
+ attr_reader :source
4
+
5
+ def initialize(source)
6
+ @source = source
7
+ end
8
+
9
+ def content
10
+ value = source.find { |x| x["TextType"] == "02" }
11
+ if !value.nil?
12
+ value["Text"]
13
+ end
14
+ end
15
+
16
+ def content_detail
17
+ value = source.find { |x| x["TextType"] == "03" }
18
+ if !value.nil?
19
+ value["Text"]
20
+ end
21
+ end
22
+
23
+ def table_of_contents
24
+ value = source.find { |x| x["TextType"] == "04" }
25
+ if !value.nil?
26
+ value["Text"]
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,36 @@
1
+ module OpenBD
2
+ class Contributor
3
+ attr_reader :source
4
+
5
+ ROLE_MAP = {
6
+ "A01" => "著者",
7
+ "B06" => "翻訳者"
8
+ }.freeze
9
+
10
+ def initialize(source)
11
+ @source = source
12
+ end
13
+
14
+ def description
15
+ source.dig("BiographicalNote")
16
+ end
17
+
18
+ def kana_name
19
+ source.dig("PersonName", "collationkey")
20
+ end
21
+
22
+ def name
23
+ source.dig("PersonName", "content")
24
+ end
25
+
26
+ def role
27
+ roles.first
28
+ end
29
+
30
+ def roles
31
+ source.dig("ContributorRole").map do |role|
32
+ ROLE_MAP[role]
33
+ end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,33 @@
1
+ module OpenBD
2
+ class Paper
3
+ attr_reader :source
4
+
5
+ def initialize(source)
6
+ @source = source
7
+ end
8
+
9
+ def size
10
+ source.dig("ProductForm")
11
+ end
12
+
13
+ def size_detail
14
+ source.dig("ProductFormDetail")
15
+ end
16
+
17
+ def height
18
+ values = source.dig("Measure")
19
+ if !values.empty?
20
+ value = values.find { |v| v["MeasureType"] == "01" }
21
+ value["Measurement"]
22
+ end
23
+ end
24
+
25
+ def width
26
+ values = source.dig("Measure")
27
+ if !values.empty?
28
+ value = values.find { |v| v["MeasureType"] == "00" }
29
+ value["Measurement"]
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,84 @@
1
+ module OpenBD
2
+ class Resource
3
+ attr_reader :source
4
+
5
+ def initialize(source)
6
+ @source = source
7
+ end
8
+
9
+ def content
10
+ if !content_source.nil?
11
+ Content.new(content_source).content
12
+ end
13
+ end
14
+
15
+ def content_detail
16
+ if !content_source.nil?
17
+ Content.new(content_source).content_detail
18
+ end
19
+ end
20
+
21
+ def contributors
22
+ values = source.dig("onix", "DescriptiveDetail", "Contributor")
23
+ if !values.nil?
24
+ values.map { |v| Contributor.new(v) }
25
+ end
26
+ end
27
+
28
+ def cover_image
29
+ source.dig("summary", "cover")
30
+ end
31
+
32
+ def height
33
+ Paper.new(source.dig("onix", "DescriptiveDetail")).height
34
+ end
35
+
36
+ def isbn
37
+ source.dig("summary", "isbn")
38
+ end
39
+
40
+ def main_title
41
+ Title.new(source.dig("onix", "DescriptiveDetail")).main_title
42
+ end
43
+
44
+ def paper_size
45
+ Paper.new(source.dig("onix", "DescriptiveDetail")).size
46
+ end
47
+
48
+ def paper_size_detail
49
+ Paper.new(source.dig("onix", "DescriptiveDetail")).size_detail
50
+ end
51
+
52
+ def publisher
53
+ source.dig("summary", "publisher")
54
+ end
55
+
56
+ def release_date
57
+ source.dig("summary", "pubdate")
58
+ end
59
+
60
+ def sub_title
61
+ Title.new(source.dig("onix", "DescriptiveDetail")).sub_title
62
+ end
63
+
64
+ def table_of_contents
65
+ if !content_source.nil?
66
+ Content.new(content_source).table_of_contents
67
+ end
68
+ end
69
+
70
+ def title
71
+ Title.new(source.dig("onix", "DescriptiveDetail")).title
72
+ end
73
+
74
+ def width
75
+ Paper.new(source.dig("onix", "DescriptiveDetail")).width
76
+ end
77
+
78
+ private
79
+
80
+ def content_source
81
+ source.dig("onix", "CollateralDetail", "TextContent")
82
+ end
83
+ end
84
+ end
@@ -0,0 +1,25 @@
1
+ module OpenBD
2
+ class Response
3
+ def initialize(response)
4
+ @response = response
5
+ end
6
+
7
+ def body
8
+ @response.body
9
+ end
10
+
11
+ def empty?
12
+ @response.body.all?(&:nil?)
13
+ end
14
+
15
+ def resources
16
+ body.map do |source|
17
+ OpenBD::Resource.new(source)
18
+ end
19
+ end
20
+
21
+ def status
22
+ @response.status
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,25 @@
1
+ module OpenBD
2
+ class Title
3
+ attr_reader :source
4
+
5
+ def initialize(source)
6
+ @source = source
7
+ end
8
+
9
+ def title
10
+ if sub_title.nil?
11
+ return main_title
12
+ end
13
+
14
+ "#{main_title} #{sub_title}"
15
+ end
16
+
17
+ def main_title
18
+ source.dig("TitleDetail", "TitleElement", "TitleText", "content")
19
+ end
20
+
21
+ def sub_title
22
+ source.dig("TitleDetail", "TitleElement", "Subtitle", "content")
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,3 @@
1
+ module OpenBD
2
+ VERSION = "0.1.0"
3
+ end
data/open_bd.gemspec ADDED
@@ -0,0 +1,28 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "open_bd/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "open_bd"
8
+ spec.version = OpenBD::VERSION
9
+ spec.authors = ["ryosuke-endo"]
10
+ spec.email = ["frozen_faithjp2@yahoo.co.jp"]
11
+
12
+ spec.summary = "An API client library for openBD API, written in Ruby."
13
+ spec.homepage = "https://github.com/ryosuke-endo/open_bd"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
17
+ f.match(%r{^(test|spec|features)/})
18
+ end
19
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
+ spec.require_paths = ["lib"]
21
+ spec.required_ruby_version = ">= 2.3"
22
+
23
+ spec.add_dependency "faraday"
24
+ spec.add_dependency "faraday_middleware"
25
+ spec.add_development_dependency "bundler", "~> 1.15"
26
+ spec.add_development_dependency "rake", "~> 10.0"
27
+ spec.add_development_dependency "rspec", "~> 3.0"
28
+ end
metadata ADDED
@@ -0,0 +1,133 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: open_bd
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - ryosuke-endo
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2018-02-15 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: faraday
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: faraday_middleware
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.15'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.15'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '10.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '10.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '3.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '3.0'
83
+ description:
84
+ email:
85
+ - frozen_faithjp2@yahoo.co.jp
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - ".gitignore"
91
+ - ".rspec"
92
+ - ".travis.yml"
93
+ - Gemfile
94
+ - LICENSE.txt
95
+ - README.md
96
+ - Rakefile
97
+ - bin/console
98
+ - bin/setup
99
+ - lib/open_bd.rb
100
+ - lib/open_bd/client.rb
101
+ - lib/open_bd/content.rb
102
+ - lib/open_bd/contributor.rb
103
+ - lib/open_bd/paper.rb
104
+ - lib/open_bd/resource.rb
105
+ - lib/open_bd/response.rb
106
+ - lib/open_bd/title.rb
107
+ - lib/open_bd/version.rb
108
+ - open_bd.gemspec
109
+ homepage: https://github.com/ryosuke-endo/open_bd
110
+ licenses:
111
+ - MIT
112
+ metadata: {}
113
+ post_install_message:
114
+ rdoc_options: []
115
+ require_paths:
116
+ - lib
117
+ required_ruby_version: !ruby/object:Gem::Requirement
118
+ requirements:
119
+ - - ">="
120
+ - !ruby/object:Gem::Version
121
+ version: '2.3'
122
+ required_rubygems_version: !ruby/object:Gem::Requirement
123
+ requirements:
124
+ - - ">="
125
+ - !ruby/object:Gem::Version
126
+ version: '0'
127
+ requirements: []
128
+ rubyforge_project:
129
+ rubygems_version: 2.6.11
130
+ signing_key:
131
+ specification_version: 4
132
+ summary: An API client library for openBD API, written in Ruby.
133
+ test_files: []