cinii 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: bdddfda97f7ce4c7b87252fe855ee475709426aea97af3ec34e63a18058c223c
4
+ data.tar.gz: 694ead145ae17211646dc394633a1e1ddaf601bd31faef6a7859e3ee5f5b7e83
5
+ SHA512:
6
+ metadata.gz: 473165ce82370e7e47145a52873d16ea4285af9c19cf5c150edcb37dce5c3876c5c6bb453ea514a325ab4ca3480cee524cdf26af9dbeb66a5de0d9fed41637ea
7
+ data.tar.gz: '00187c8dbeedd3eba48fb8932fddb6806719f1f6a763a4fdb5d96a2a493771d3c6853390abcaf3c5c76b91d98565e321cef0c70079bbee3dec0118b217334cf7'
@@ -0,0 +1,13 @@
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
12
+
13
+ .idea
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
@@ -0,0 +1,7 @@
1
+ ---
2
+ sudo: false
3
+ language: ruby
4
+ cache: bundler
5
+ rvm:
6
+ - 2.5.1
7
+ before_install: gem install bundler -v 1.17.2
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at nashirox@gmail.com. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/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 cinii-ruby.gemspec
6
+ gemspec
@@ -0,0 +1,42 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ cinii (0.1.0)
5
+ faraday
6
+ faraday_middleware
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ diff-lcs (1.3)
12
+ faraday (0.15.4)
13
+ multipart-post (>= 1.2, < 3)
14
+ faraday_middleware (0.13.1)
15
+ faraday (>= 0.7.4, < 1.0)
16
+ multipart-post (2.0.0)
17
+ rake (10.5.0)
18
+ rspec (3.8.0)
19
+ rspec-core (~> 3.8.0)
20
+ rspec-expectations (~> 3.8.0)
21
+ rspec-mocks (~> 3.8.0)
22
+ rspec-core (3.8.0)
23
+ rspec-support (~> 3.8.0)
24
+ rspec-expectations (3.8.2)
25
+ diff-lcs (>= 1.2.0, < 2.0)
26
+ rspec-support (~> 3.8.0)
27
+ rspec-mocks (3.8.0)
28
+ diff-lcs (>= 1.2.0, < 2.0)
29
+ rspec-support (~> 3.8.0)
30
+ rspec-support (3.8.0)
31
+
32
+ PLATFORMS
33
+ ruby
34
+
35
+ DEPENDENCIES
36
+ bundler (~> 1.17)
37
+ cinii!
38
+ rake (~> 10.0)
39
+ rspec (~> 3.0)
40
+
41
+ BUNDLED WITH
42
+ 1.17.3
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2019 Daisuke Nashiro
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,171 @@
1
+ # Cinii
2
+
3
+ Cinii API client library, written in Ruby
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'cinii'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install cinii
20
+
21
+ https://support.nii.ac.jp/ja/cinii/api/developer
22
+
23
+ ## Usage
24
+ ### CiNii Articles
25
+ #### Initialization
26
+
27
+ ```ruby
28
+ client = Cinii::Client::Article.new(app_id: 'YOUR_APP_ID')
29
+ ```
30
+
31
+ #### Search article
32
+
33
+ ```ruby
34
+ result = client.list_articles(q: 'computer science')
35
+ #=> Cinii::SearchResult::Article object
36
+
37
+ # First article in search result
38
+ article = result.items.first
39
+ #=> Cinii::Item::Article object
40
+ #
41
+ # Article title
42
+ article.title
43
+ #=> "Effect of storage and aging conditions on the flexural strength and flexural modulus of CAD/CAM materials"
44
+
45
+ article.link
46
+ #=> "https://ci.nii.ac.jp/naid/130007529119"
47
+ ```
48
+ #### Full-text search
49
+ Just pass `full_text: true` to `list_articles` method.
50
+
51
+ ```ruby
52
+ result = client.list_articles(q: 'computer science', full_text: true)
53
+ ```
54
+
55
+ #### Search author
56
+
57
+ ```ruby
58
+ result = client.list_authors(q: '山中伸弥')
59
+ #=> Cinii::SearchResult::Article object
60
+
61
+ author = result.items.first
62
+ #=> Cinii::Item::Author object
63
+
64
+ author.link
65
+ #=> "https://ci.nii.ac.jp/nrid/1000010295694"
66
+ ```
67
+
68
+ ### CiNii Books
69
+ #### Initialization
70
+ ```ruby
71
+ # Initialization
72
+ client = Cinii::Client::Book.new(app_id: 'YOUR_APP_ID')
73
+ ```
74
+
75
+ #### Search books
76
+
77
+ ```ruby
78
+ result = client.list_books(q: '機械学習')
79
+ #=> Cinii::SearchResult::Book object
80
+
81
+ book = result.items.first
82
+ #=> Cinii::Item::Book object
83
+
84
+ book.title
85
+ #=> "Rによる機械学習入門"
86
+
87
+ book.link
88
+ #=> "http://ci.nii.ac.jp/ncid/BB24928243"
89
+ ```
90
+
91
+ #### Search authors
92
+
93
+ ```ruby
94
+ result = client.list_authors(name: '山中')
95
+ #=> Cinii::SearchResult::Book object
96
+ ```
97
+
98
+ #### Search libraries
99
+
100
+ ```ruby
101
+ result = client.list_libraries(name: '東京')
102
+ #=> Cinii::SearchResult::Book object
103
+
104
+ library = result.items[10]
105
+ #=> Cinii::Item::Library object
106
+
107
+ library.title
108
+ #=> "東京音楽大学 付属図書館"
109
+ ```
110
+
111
+ #### Search holders
112
+
113
+ ```ruby
114
+ result = client.list_holders(ncid: 'BB24928243')
115
+ #=> Cinii::SearchResult::Book object
116
+
117
+ library = result.items[25]
118
+ #=> Cinii::Item::Library object
119
+
120
+ library.title
121
+ #=> "島根大学 附属図書館"
122
+ ```
123
+
124
+ ### CiNii Dissertation
125
+ #### Initialization
126
+ ```ruby
127
+ # Initialization
128
+ client = Cinii::Client::Dissertation.new(app_id: 'YOUR_APP_ID')
129
+ ```
130
+
131
+ #### Search dissertation
132
+
133
+ ```ruby
134
+ result = client.list_dissertations(author: '落合, 陽一')
135
+ #=> Cinii::SearchResult::Book object
136
+
137
+ dissertation = result.items.first
138
+ #=> Cinii::Item::Dissertation object
139
+
140
+ dissertation.title
141
+ #=> "Graphics by Computational Acoustic Fields"
142
+
143
+ dissertation.publisher
144
+ #=> "University of Tokyo(東京大学)"
145
+
146
+ dissertation.source
147
+ #=> [{:id=>"http://dl.ndl.go.jp/info:ndljp/pid/10981946", :title=>"NDLデジタルコレクション"}, {:id=>"http://hdl.handle.net/2261/00072859", :title=>"東京大学"}]
148
+ ```
149
+
150
+ ## TODO
151
+ - Add test
152
+ - Write API documents
153
+ - Add rest of Web API
154
+
155
+ ## Development
156
+
157
+ 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.
158
+
159
+ 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).
160
+
161
+ ## Contributing
162
+
163
+ Bug reports and pull requests are welcome on GitHub at https://github.com/nashirox/cinii. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
164
+
165
+ ## License
166
+
167
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
168
+
169
+ ## Code of Conduct
170
+
171
+ Everyone interacting in the Cinii project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/cinii-ruby/blob/master/CODE_OF_CONDUCT.md).
@@ -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
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "cinii"
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__)
@@ -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,42 @@
1
+
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "cinii/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "cinii"
8
+ spec.version = Cinii::VERSION
9
+ spec.authors = ["Daisuke Nashiro"]
10
+ spec.email = ["nashirox@gmail.com"]
11
+
12
+ spec.summary = %q{Cinii API cilent library, Written in Ruby}
13
+ spec.description = %q{Cinii API cilent library, Written in Ruby}
14
+ spec.homepage = "https://github.com/nashirox/cinii-ruby"
15
+ spec.license = "MIT"
16
+
17
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
18
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
19
+ if spec.respond_to?(:metadata)
20
+ spec.metadata["homepage_uri"] = spec.homepage
21
+ spec.metadata["source_code_uri"] = "https://github.com/nashirox/cinii-ruby"
22
+ spec.metadata["changelog_uri"] = "https://github.com/nashirox/cinii-ruby"
23
+ else
24
+ raise "RubyGems 2.0 or newer is required to protect against " \
25
+ "public gem pushes."
26
+ end
27
+
28
+ # Specify which files should be added to the gem when it is released.
29
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
30
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
31
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
32
+ end
33
+ spec.bindir = "exe"
34
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
35
+ spec.require_paths = ["lib"]
36
+
37
+ spec.add_runtime_dependency "faraday"
38
+ spec.add_runtime_dependency "faraday_middleware"
39
+ spec.add_development_dependency "bundler", "~> 1.17"
40
+ spec.add_development_dependency "rake", "~> 10.0"
41
+ spec.add_development_dependency "rspec", "~> 3.0"
42
+ end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'faraday'
4
+ require 'faraday_middleware'
5
+
6
+ require 'cinii/version'
7
+ require 'cinii/client'
8
+ require 'cinii/search_result'
9
+ require 'cinii/item'
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'cinii/client/base'
4
+ require 'cinii/client/article'
5
+ require 'cinii/client/book'
6
+ require 'cinii/client/dissertation'
@@ -0,0 +1,97 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Cinii
4
+ class Client
5
+ class Article < Base
6
+ ARTICLE_REQUIRED_KEYS = %I(
7
+ q title author author_id issn publisher affiliation journal volume
8
+ issue page references year_from year_to
9
+ )
10
+
11
+ # https://support.nii.ac.jp/ja/cia/api/a_opensearch
12
+ # https://support.nii.ac.jp/ja/cia/api/a_opensearch_full
13
+ def list_articles(**params)
14
+ if params[:full_text] == true
15
+ raise ArgumentError unless has_required_params?(params, [:q])
16
+
17
+ response = send_get('/opensearch/fulltext', full_text_params(params))
18
+ else
19
+ raise ArgumentError unless has_required_params?(params, ARTICLE_REQUIRED_KEYS)
20
+
21
+ response = send_get('/opensearch/search', article_params(params))
22
+ end
23
+
24
+ Cinii::SearchResult::Article.new(response)
25
+ end
26
+
27
+ # https://support.nii.ac.jp/ja/cia/api/a_opensearch_auth
28
+ def list_authors(**params)
29
+ raise ArgumentError unless has_required_params?(params, [:q])
30
+
31
+ response = send_get('/opensearch/author', author_params(params))
32
+
33
+ Cinii::SearchResult::Article.new(response)
34
+ end
35
+
36
+ # https://support.nii.ac.jp/ja/cia/api/a_json
37
+ def article(naid)
38
+ raise 'Not implemented yet.'
39
+
40
+ response = send_get("/naid/#{naid}")
41
+ end
42
+
43
+ # https://support.nii.ac.jp/ja/cia/api/a_json_auth
44
+ def author(nrid)
45
+ raise 'Not implemented yet.'
46
+
47
+ response = send_get("/nrid/#{nrid}")
48
+ end
49
+
50
+ private
51
+
52
+ def article_params(params)
53
+ {
54
+ q: params[:q],
55
+ count: params[:count],
56
+ lang: params[:lang],
57
+ start: params[:start],
58
+ title: params[:title],
59
+ author: params[:author],
60
+ authorid: params[:author_id],
61
+ issn: params[:issn],
62
+ publisher: params[:publisher],
63
+ affiliation: params[:affiliation],
64
+ journal: params[:journal],
65
+ volume: params[:volume],
66
+ issue: params[:issue],
67
+ page: params[:page],
68
+ references: params[:references],
69
+ year_from: params[:year_from],
70
+ year_to: params[:year_to],
71
+ range: params[:range],
72
+ sortorder: params[:sortorder]
73
+ }.compact
74
+ end
75
+
76
+ def full_text_params(params)
77
+ {
78
+ q: params[:q],
79
+ count: params[:count],
80
+ lang: params[:lang],
81
+ start: params[:start],
82
+ sortorder: params[:sortorder]
83
+ }.compact
84
+ end
85
+
86
+ def author_params(params)
87
+ {
88
+ q: params[:q],
89
+ count: params[:count],
90
+ lang: params[:lang],
91
+ start: params[:start],
92
+ sortorder: params[:sortorder]
93
+ }.compact
94
+ end
95
+ end
96
+ end
97
+ end
@@ -0,0 +1,70 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'cinii/errors'
4
+
5
+ module Cinii
6
+ class Client
7
+ class Base
8
+ def initialize(app_id: nil)
9
+ @app_id = app_id
10
+ end
11
+
12
+ def send_get(path, params = nil)
13
+ send_request(:get, path, params)
14
+ end
15
+
16
+ def has_required_params?(params, required_keys)
17
+ !!required_keys.find { |p| params[p] }
18
+ end
19
+
20
+ private
21
+
22
+ def send_request(method, path, params = nil)
23
+ params = params ? default_params.merge(params) : default_params
24
+ response = cinii_connection.send(method, path, params)
25
+ raise RemoteURLNotAvailableError, "#{path} is not available." unless response.status == 200
26
+ response
27
+ end
28
+
29
+ def cinii_connection
30
+ @cinii_connection ||= Faraday.new(faraday_options) do |con|
31
+ con.request :json
32
+ con.response :json
33
+ con.adapter Faraday.default_adapter
34
+ con.response :logger do | logger |
35
+ logger.filter(/(appid=)(\w+)/,'\1[REMOVED]')
36
+ end
37
+ end
38
+ end
39
+
40
+ def default_params
41
+ {
42
+ appid: app_id,
43
+ format: 'json'
44
+ }
45
+ end
46
+
47
+ def faraday_options
48
+ {
49
+ url: faraday_url,
50
+ headers: faraday_headers
51
+ }
52
+ end
53
+
54
+ def faraday_url
55
+ 'https://ci.nii.ac.jp'
56
+ end
57
+
58
+ def faraday_headers
59
+ {
60
+ 'Accept' => 'application/json',
61
+ 'User-Agent' => "Cinii Ruby Gem #{Cinii::VERSION}"
62
+ }
63
+ end
64
+
65
+ def app_id
66
+ @app_id || ENV['CINII_APP_ID']
67
+ end
68
+ end
69
+ end
70
+ end
@@ -0,0 +1,117 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Cinii
4
+ class Client
5
+ class Book < Base
6
+ # https://support.nii.ac.jp/ja/cib/api/b_opensearch
7
+ def list_books(**params)
8
+ response = send_get('/books/opensearch/search', book_params(params))
9
+ Cinii::SearchResult::Book.new(response)
10
+ end
11
+
12
+ # https://support.nii.ac.jp/ja/cib/api/b_opensearch_auth
13
+ def list_authors(**params)
14
+ raise ArgumentError unless has_required_params?(params, [:name])
15
+
16
+ response = send_get('/books/opensearch/author', author_params(params))
17
+ Cinii::SearchResult::Book.new(response)
18
+ end
19
+
20
+ # https://support.nii.ac.jp/ja/cib/api/b_opensearch_lib
21
+ def list_libraries(**params)
22
+ raise ArgumentError unless has_required_params?(params, [:name])
23
+
24
+ response = send_get('/books/opensearch/library', library_params(params))
25
+ Cinii::SearchResult::Book.new(response)
26
+ end
27
+
28
+ # https://support.nii.ac.jp/ja/cib/api/b_opensearch_hold
29
+ def list_holders(**params)
30
+ raise ArgumentError unless has_required_params?(params, [:ncid])
31
+
32
+ response = send_get('/books/opensearch/holder', holder_params(params))
33
+ Cinii::SearchResult::Book.new(response)
34
+ end
35
+
36
+ # https://support.nii.ac.jp/ja/cib/api/b_json
37
+ def book(ncid)
38
+ raise 'Not implemented yet.'
39
+ end
40
+
41
+ # https://support.nii.ac.jp/ja/cib/api/b_json_auth
42
+ def author(author_id)
43
+ raise 'Not implemented yet.'
44
+ end
45
+
46
+ # https://support.nii.ac.jp/ja/cib/api/b_json
47
+ def library(library_id)equal?
48
+ raise 'Not implemented yet.'
49
+ end
50
+
51
+ private
52
+
53
+ def book_params(params)
54
+ {
55
+ q: params[:q],
56
+ title: params[:title],
57
+ title_exact: params[:title_exact],
58
+ include_utl: params[:include_utl],
59
+ author: params[:author],
60
+ include_alias: params[:include_alias],
61
+ publisher: params[:publisher],
62
+ subject: params[:subject],
63
+ note: params[:note],
64
+ authorid: params[:author_id],
65
+ utid: params[:utid],
66
+ isbn: params[:isbn],
67
+ issn: params[:issn],
68
+ ncid: params[:ncid],
69
+ clas: params[:clas],
70
+ gmd: params[:gmd],
71
+ lang: params[:lang],
72
+ fano: params[:fano],
73
+ kid: params[:kid],
74
+ area: params[:area],
75
+ year_from: params[:year_from],
76
+ year_to: params[:year_to],
77
+ type: params[:type],
78
+ sortorder: params[:sortorder],
79
+ p: params[:page],
80
+ count: params[:count]
81
+ }.compact
82
+ end
83
+
84
+ def author_params(params)
85
+ {
86
+ name: params[:name],
87
+ sortorder: params[:sortorder],
88
+ p: params[:page],
89
+ count: params[:count]
90
+ }.compact
91
+ end
92
+
93
+ def library_params(params)
94
+ author_params(params)
95
+ end
96
+
97
+ def holder_params(params)
98
+ {
99
+ ncid: params[:ncid],
100
+ ill: params[:ill],
101
+ ill_stat: params[:ill_stat],
102
+ ill_copys: params[:ill_copys],
103
+ ill_loans: params[:ill_loans],
104
+ ill_faxs: params[:ill_faxs],
105
+ ill_oclc: params[:ill_oclc],
106
+ ill_keris: params[:ill_keris],
107
+ ill_offset: params[:ill_offset],
108
+ fano: params[:fano],
109
+ year: params[:year],
110
+ vol: params[:vol],
111
+ issue: params[:issue],
112
+ count: params[:count]
113
+ }.compact
114
+ end
115
+ end
116
+ end
117
+ end
@@ -0,0 +1,40 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Cinii
4
+ class Client
5
+ class Dissertation < Base
6
+ # https://support.nii.ac.jp/ja/cid/api/d_opensearch
7
+ def list_dissertations(**params)
8
+ response = send_get('/d/search', dissertation_params(params))
9
+ Cinii::SearchResult::Dissertation.new(response)
10
+ end
11
+
12
+ # https://support.nii.ac.jp/ja/cid/api/d_json
13
+ def book(naid)
14
+ raise 'Not implemented yet.'
15
+ end
16
+
17
+ private
18
+
19
+ def dissertation_params(params)
20
+ {
21
+ q: params[:q],
22
+ title: params[:title],
23
+ description: params[:description],
24
+ author: params[:author],
25
+ grantor: params[:grantor],
26
+ grantorid: params[:grantor_id],
27
+ grantid: params[:grant_id],
28
+ degreename: params[:degree_name],
29
+ year_from: params[:year_from],
30
+ year_to: params[:year_to],
31
+ fulltext: params[:full_text],
32
+ range: params[:range],
33
+ sortorder: params[:sortorder],
34
+ p: params[:page],
35
+ count: params[:count]
36
+ }.compact
37
+ end
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Cinii
4
+ class CiniiError < StandardError; end
5
+ class RemoteURLNotAvailableError < CiniiError; end
6
+ class APIResponseError < CiniiError; end
7
+ class UnKnownResponseTypeError < CiniiError; end
8
+ end
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'cinii/item/base'
4
+ require 'cinii/item/article'
5
+ require 'cinii/item/author'
6
+ require 'cinii/item/book'
7
+ require 'cinii/item/dissertation'
8
+ require 'cinii/item/library'
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Cinii
4
+ class Item
5
+ class Article < Base
6
+ attr_reader :creator, :publisher, :publication_date, :publication_name,
7
+ :issn, :volume, :number, :starting_page, :ending_page, :page_range,
8
+ :description
9
+
10
+ def initialize(item)
11
+ @creator = item['dc:creator'].map { |c| c['@value'] }
12
+ @publisher = item['dc:publisher']
13
+ @publication_date = item['prism:publicationDate']
14
+ @publication_name = item['prism:publicationName']
15
+ @issn = item['prism:issn']
16
+ @volume = item['prism:volume']
17
+ @number = item['prism:number']
18
+ @starting_page = item['prism:startingPage']
19
+ @ending_page = item['prism:endingPage']
20
+ @page_range = item['prism:pageRange']
21
+ @description = item['description']
22
+
23
+ super(item)
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Cinii
4
+ class Item
5
+ class Author < Base
6
+ attr_reader :description, :subject
7
+
8
+ def initialize(item)
9
+ @description = item['description']
10
+ @subject = item['dc:subject']
11
+
12
+ super(item)
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Cinii
4
+ class Item
5
+ class Base
6
+ attr_reader :id, :type, :title, :link, :see_also, :date
7
+
8
+ def initialize(item)
9
+ @id = item['@id']
10
+ @type = item['@type']
11
+ @title = item['title']
12
+ @link = item['link']['@id']
13
+ @see_also = item['rdfs:seeAlso']['@id']
14
+ @date = item['dc:date']
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Cinii
4
+ class Item
5
+ class Book < Base
6
+ attr_reader :creator, :publisher, :publication_date, :is_part, :has_part, :owner_count
7
+
8
+ def initialize(item)
9
+ @publisher = item['dc:publisher']
10
+ @publication_date = item['prism:publicationDate']
11
+ @creator = item['dc:creator']
12
+ @is_part = item['dcterms:isPartOf']&.map { |c| { id: c['@id'], title: c['dc:title']} }
13
+ @has_part = item['dcterms:hasPart']&.map { |c| c['@id'] }
14
+ @owner_count = item['cinii:ownerCount']
15
+
16
+ super(item)
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Cinii
4
+ class Item
5
+ class Dissertation < Base
6
+ attr_reader :creator, :publisher, :degree_name, :dissertation_number, :source
7
+
8
+ def initialize(item)
9
+ @creator = item['dc:creator'].map { |c| c['@value'] }
10
+ @publisher = item['dc:publisher']
11
+ @degree_name = item['ndl:degreeName']
12
+ @dissertation_number = item['ndl:dissertationNumber']
13
+ @source = item['dc:source']&.map { |c| { id: c['@id'], title: c['dc:title']} }
14
+
15
+ super(item)
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Cinii
4
+ class Item
5
+ class Library < Base
6
+ def initialize(item)
7
+ super(item)
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'cinii/search_result/base'
4
+ require 'cinii/search_result/article'
5
+ require 'cinii/search_result/book'
6
+ require 'cinii/search_result/dissertation'
@@ -0,0 +1,28 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Cinii
4
+ class SearchResult
5
+ class Article < Base
6
+ def items
7
+ items = graph['items']
8
+
9
+ @items ||= items ? items.map { |i| item_class.new(i) } : []
10
+ end
11
+
12
+ private
13
+
14
+ def item_class
15
+ case title
16
+ when /CiNii OpenSearch/
17
+ Cinii::Item::Article
18
+ when /CiNii Author OpenSearch/
19
+ Cinii::Item::Author
20
+ when /CiNii FullText OpenSearch/
21
+ Cinii::Item::Article
22
+ else
23
+ raise UnKnownResponseTypeError
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,100 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'date'
4
+
5
+ module Cinii
6
+ class SearchResult
7
+ class Base
8
+ def initialize(faraday_response)
9
+ @raw_body = faraday_response.body
10
+
11
+ raise APIResponseError, 'レスポンスに@graph属性が含まれていません' unless body['@graph']
12
+ end
13
+
14
+ def items
15
+ raise 'This method must be overridden.'
16
+ end
17
+
18
+ # タイトル
19
+ def title
20
+ @title ||= graph['title']
21
+ end
22
+
23
+ # タイトルと同じ
24
+ def description
25
+ @description ||= graph['description']
26
+ end
27
+
28
+ # リクエストURI
29
+ def link
30
+ @link ||= graph['link']['@id']
31
+ end
32
+
33
+ # 検索日時
34
+ def date
35
+ @date ||= DateTime.parse(graph['dc:date'])
36
+ end
37
+
38
+ # 検索結果総数
39
+ def total_items
40
+ @total_items ||= graph['opensearch:totalResults'].to_i
41
+ end
42
+
43
+ # 検索結果の開始番号
44
+ def start_index
45
+ @start_index ||= graph['opensearch:startIndex'].to_i
46
+ end
47
+
48
+ # 検索結果件数
49
+ def items_per_page
50
+ @items_per_page ||= graph['opensearch:itemsPerPage'].to_i
51
+ end
52
+
53
+ # 現在のページ数
54
+ def current_page
55
+ (start_index.to_f / items_per_page.to_f).ceil
56
+ end
57
+
58
+ # 全てのページ数
59
+ def total_pages
60
+ (total_items.to_f / items_per_page.to_f).ceil
61
+ end
62
+
63
+ # 最初のページ判定
64
+ def first_page?
65
+ start_index.between?(1, items_per_page)
66
+ end
67
+
68
+ # 最終ページ判定
69
+ def last_page?
70
+ start_index.between?(last_page_start_index, total_items)
71
+ end
72
+
73
+ # 次ページの開始番号
74
+ def next_page_start_index
75
+ start_index + items_per_page
76
+ end
77
+
78
+ # 前ページの開始番号
79
+ def prev_page_start_index
80
+ index = start_index - items_per_page
81
+ index >= 1 ? index : 1
82
+ end
83
+
84
+ # 最終ページの開始番号
85
+ def last_page_start_index
86
+ total_items - items_per_page
87
+ end
88
+
89
+ private
90
+
91
+ def body
92
+ @raw_body
93
+ end
94
+
95
+ def graph
96
+ body['@graph'].first
97
+ end
98
+ end
99
+ end
100
+ end
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Cinii
4
+ class SearchResult
5
+ class Book < Base
6
+ def items
7
+ items = graph['items']
8
+
9
+ @items ||= items ? items.map { |i| item_class.new(i) } : []
10
+ end
11
+
12
+ private
13
+
14
+ def item_class
15
+ case title
16
+ when /CiNii Books OpenSearch/
17
+ Cinii::Item::Book
18
+ when /CiNii Books Author/
19
+ Cinii::Item::Author
20
+ when /CiNii Books Library/
21
+ Cinii::Item::Library
22
+ when /CiNii Books Holder/
23
+ Cinii::Item::Library
24
+ else
25
+ raise UnKnownResponseTypeError
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Cinii
4
+ class SearchResult
5
+ class Dissertation < Base
6
+ def items
7
+ items = graph['items']
8
+
9
+ @items ||= items ? items.map { |i| Cinii::Item::Dissertation.new(i) } : []
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Cinii
4
+ VERSION = '0.1.0'
5
+ end
metadata ADDED
@@ -0,0 +1,148 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: cinii
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Daisuke Nashiro
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2019-02-14 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.17'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.17'
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: Cinii API cilent library, Written in Ruby
84
+ email:
85
+ - nashirox@gmail.com
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - ".gitignore"
91
+ - ".rspec"
92
+ - ".travis.yml"
93
+ - CODE_OF_CONDUCT.md
94
+ - Gemfile
95
+ - Gemfile.lock
96
+ - LICENSE.txt
97
+ - README.md
98
+ - Rakefile
99
+ - bin/console
100
+ - bin/setup
101
+ - cinii.gemspec
102
+ - lib/cinii.rb
103
+ - lib/cinii/client.rb
104
+ - lib/cinii/client/article.rb
105
+ - lib/cinii/client/base.rb
106
+ - lib/cinii/client/book.rb
107
+ - lib/cinii/client/dissertation.rb
108
+ - lib/cinii/errors.rb
109
+ - lib/cinii/item.rb
110
+ - lib/cinii/item/article.rb
111
+ - lib/cinii/item/author.rb
112
+ - lib/cinii/item/base.rb
113
+ - lib/cinii/item/book.rb
114
+ - lib/cinii/item/dissertation.rb
115
+ - lib/cinii/item/library.rb
116
+ - lib/cinii/search_result.rb
117
+ - lib/cinii/search_result/article.rb
118
+ - lib/cinii/search_result/base.rb
119
+ - lib/cinii/search_result/book.rb
120
+ - lib/cinii/search_result/dissertation.rb
121
+ - lib/cinii/version.rb
122
+ homepage: https://github.com/nashirox/cinii-ruby
123
+ licenses:
124
+ - MIT
125
+ metadata:
126
+ homepage_uri: https://github.com/nashirox/cinii-ruby
127
+ source_code_uri: https://github.com/nashirox/cinii-ruby
128
+ changelog_uri: https://github.com/nashirox/cinii-ruby
129
+ post_install_message:
130
+ rdoc_options: []
131
+ require_paths:
132
+ - lib
133
+ required_ruby_version: !ruby/object:Gem::Requirement
134
+ requirements:
135
+ - - ">="
136
+ - !ruby/object:Gem::Version
137
+ version: '0'
138
+ required_rubygems_version: !ruby/object:Gem::Requirement
139
+ requirements:
140
+ - - ">="
141
+ - !ruby/object:Gem::Version
142
+ version: '0'
143
+ requirements: []
144
+ rubygems_version: 3.0.2
145
+ signing_key:
146
+ specification_version: 4
147
+ summary: Cinii API cilent library, Written in Ruby
148
+ test_files: []