serrano 0.5.0 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/ruby.yml +30 -0
- data/.gitignore +3 -1
- data/CHANGELOG.md +26 -0
- data/CODE_OF_CONDUCT.md +2 -2
- data/Gemfile +3 -1
- data/LICENSE +1 -1
- data/README.md +21 -7
- data/Rakefile +12 -8
- data/bin/serrano +96 -98
- data/lib/serrano.rb +112 -63
- data/lib/serrano/cn.rb +4 -6
- data/lib/serrano/cnrequest.rb +36 -22
- data/lib/serrano/error.rb +2 -0
- data/lib/serrano/faraday.rb +16 -15
- data/lib/serrano/filterhandler.rb +26 -28
- data/lib/serrano/filters.rb +91 -85
- data/lib/serrano/helpers/configuration.rb +2 -2
- data/lib/serrano/request.rb +31 -29
- data/lib/serrano/request_cursor.rb +59 -58
- data/lib/serrano/styles.rb +14 -9
- data/lib/serrano/utils.rb +19 -17
- data/lib/serrano/version.rb +3 -1
- data/serrano.gemspec +41 -28
- metadata +75 -48
- data/.travis.yml +0 -8
- data/Gemfile.lock +0 -64
- data/lib/serrano/constants.rb +0 -36
- data/lib/serrano/cursor_testing.rb +0 -52
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 75729f32a4cfabb79a33d78638a91c253fb76a8ec3abc8d9ecc743056464d38d
|
4
|
+
data.tar.gz: 8e47227794125651a8c35450a8f7f5aaa5c377ac461ea2433836d00b76fdb699
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a1be1549ce95a4fa7bac8d417f28f9c2d70e800b48f1f7b8c4471cf8461ca37288dd9a2f06c5c15376364e3af4f8d4e61589ad0b4e0f8cdbbd6c1bf46fc170db
|
7
|
+
data.tar.gz: d21603574250c471ea20c3fe7f433d5ef56715307442d8067814757b522306afdca717bbcd612eda4055c1e1b41fc2a8a3f9d340d45dd57127c9a3950b24f70a
|
@@ -0,0 +1,30 @@
|
|
1
|
+
name: Ruby
|
2
|
+
|
3
|
+
on:
|
4
|
+
push:
|
5
|
+
branches: [ master ]
|
6
|
+
pull_request:
|
7
|
+
branches: [ master ]
|
8
|
+
|
9
|
+
jobs:
|
10
|
+
test:
|
11
|
+
strategy:
|
12
|
+
fail-fast: false
|
13
|
+
matrix:
|
14
|
+
os: [ ubuntu-latest, macos-latest ]
|
15
|
+
ruby: [ 2.5, 2.6, 2.7 ]
|
16
|
+
runs-on: ${{ matrix.os }}
|
17
|
+
env:
|
18
|
+
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
|
19
|
+
steps:
|
20
|
+
- uses: actions/checkout@v2
|
21
|
+
- name: Setup Ruby
|
22
|
+
uses: ruby/setup-ruby@v1
|
23
|
+
with:
|
24
|
+
ruby-version: ${{ matrix.ruby }}
|
25
|
+
- name: Install dependencies
|
26
|
+
run: bundle install
|
27
|
+
- name: Run tests
|
28
|
+
run: |
|
29
|
+
bundle exec rake install
|
30
|
+
bundle exec rake test TESTOPTS="-v"
|
data/.gitignore
CHANGED
@@ -26,7 +26,7 @@ build/
|
|
26
26
|
|
27
27
|
# for a library or gem, you might want to ignore these files since the code is
|
28
28
|
# intended to run in multiple environments; otherwise, check them in:
|
29
|
-
|
29
|
+
Gemfile.lock
|
30
30
|
.ruby-version
|
31
31
|
.ruby-gemset
|
32
32
|
|
@@ -36,3 +36,5 @@ build/
|
|
36
36
|
cache/
|
37
37
|
|
38
38
|
lib/serrano/response.rb
|
39
|
+
|
40
|
+
cursor_testing.rb
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,29 @@
|
|
1
|
+
## 1.0.0 (2020-10-19)
|
2
|
+
|
3
|
+
* updated dependency versions
|
4
|
+
|
5
|
+
## 0.6.2 (2020-05-29)
|
6
|
+
|
7
|
+
* put documentation link back in rubygems page (#132)
|
8
|
+
|
9
|
+
## 0.6.0 (2020-02-18)
|
10
|
+
|
11
|
+
* query.title (`query_title` query filter as used here) has been removed; use `query_bibliographic` instead (#111)
|
12
|
+
* bump `faraday` to version 0.17.1 from 0.17.0 (via dependabot) (#107)
|
13
|
+
* bump `json` to version 2.3 from 2.2 (via dependabot) (#109)
|
14
|
+
* bump `thor` minimum version (via dependabot) (#110)
|
15
|
+
* better checking of filters; always check filters for proper formatting and acceptable types; improve filter tests; link to information on filters (#105) via PR from @beechnut
|
16
|
+
|
17
|
+
## 0.5.4 (2019-11-27)
|
18
|
+
|
19
|
+
* `Serrano.registration_agency` fixed: a change in an internal function caused this function to fail; tests added to prevent this in the future (#106)
|
20
|
+
* bundle update, changes in gemfile.lock
|
21
|
+
|
22
|
+
## 0.5.2 (2019-08-07)
|
23
|
+
|
24
|
+
* fix url encoding (#51)
|
25
|
+
* started using Rubocop; many styling changes (#52)
|
26
|
+
|
1
27
|
## 0.5.0 (2018-04-08)
|
2
28
|
|
3
29
|
* Updated dependency versions
|
data/CODE_OF_CONDUCT.md
CHANGED
@@ -21,5 +21,5 @@ Instances of abusive, harassing, or otherwise unacceptable behavior may be repor
|
|
21
21
|
opening an issue or contacting one or more of the project maintainers.
|
22
22
|
|
23
23
|
This Code of Conduct is adapted from the Contributor Covenant
|
24
|
-
(
|
25
|
-
|
24
|
+
(https://contributor-covenant.org), version 1.0.0, available at
|
25
|
+
https://contributor-covenant.org/version/1/0/0/
|
data/Gemfile
CHANGED
data/LICENSE
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
Copyright (C)
|
1
|
+
Copyright (C) 2020 Scott Chamberlain
|
2
2
|
|
3
3
|
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
4
4
|
|
data/README.md
CHANGED
@@ -2,19 +2,22 @@ serrano
|
|
2
2
|
=========
|
3
3
|
|
4
4
|
[![gem version](https://img.shields.io/gem/v/serrano.svg)](https://rubygems.org/gems/serrano)
|
5
|
-
[![
|
6
|
-
[![codecov.io](
|
5
|
+
[![Ruby](https://github.com/sckott/serrano/workflows/Ruby/badge.svg)](https://github.com/sckott/serrano/actions)
|
6
|
+
[![codecov.io](https://codecov.io/github/sckott/serrano/coverage.svg?branch=master)](https://codecov.io/github/sckott/serrano?branch=master)
|
7
7
|
[![DOI](https://zenodo.org/badge/2600/sckott/serrano.svg)](https://zenodo.org/badge/latestdoi/2600/sckott/serrano)
|
8
|
+
[![Ruby Style Guide](https://img.shields.io/badge/code_style-standard-brightgreen.svg)](https://github.com/testdouble/standard)
|
8
9
|
|
9
10
|
`serrano` is a low level client for Crossref APIs
|
10
11
|
|
11
|
-
Docs:
|
12
|
+
Docs: https://www.rubydoc.info/gems/serrano
|
12
13
|
|
13
14
|
Other Crossref API clients:
|
14
15
|
|
15
16
|
- Python: [habanero](https://github.com/sckott/habanero)
|
16
17
|
- R: [rcrossref](https://github.com/ropensci/rcrossref)
|
17
18
|
|
19
|
+
Crossref's API issue tracker: https://gitlab.com/crossref/issues
|
20
|
+
|
18
21
|
## Changes
|
19
22
|
|
20
23
|
For changes see the [Changelog][changelog]
|
@@ -44,7 +47,7 @@ Other methods:
|
|
44
47
|
|
45
48
|
Note about searching:
|
46
49
|
|
47
|
-
You are using the Crossref search API described at https://github.com/CrossRef/rest-api-doc
|
50
|
+
You are using the Crossref search API described at https://github.com/CrossRef/rest-api-doc When you search with query terms, on Crossref servers they are not searching full text, or even abstracts of articles, but only what is available in the data that is returned to you. That is, they search article titles, authors, etc. For some discussion on this, see https://gitlab.com/crossref/issues/issues/101
|
48
51
|
|
49
52
|
Rate limits:
|
50
53
|
|
@@ -60,6 +63,11 @@ To get in the polite pool it's a good idea now to include a `mailto` email
|
|
60
63
|
address. See docs for more information. TLDR: set your email in an env var `CROSSREF_EMAIL`.
|
61
64
|
|
62
65
|
|
66
|
+
URL Encoding:
|
67
|
+
|
68
|
+
We do URL encoding of DOIs for you for all methods except `Serrano.citation_count` which doesn't work if you encode DOIs beforehand. We use `ERB::Util.url_encode` to encode.
|
69
|
+
|
70
|
+
|
63
71
|
## Install
|
64
72
|
|
65
73
|
### Release version
|
@@ -115,6 +123,12 @@ Search works by query string
|
|
115
123
|
Serrano.works(query: "ecology")
|
116
124
|
```
|
117
125
|
|
126
|
+
Search works using metadata filters. See [CrossRef filter docs](https://github.com/CrossRef/rest-api-doc#filter-names).
|
127
|
+
|
128
|
+
```ruby
|
129
|
+
Serrano.works(query: "ecology", filter: { has_abstract: true })
|
130
|
+
```
|
131
|
+
|
118
132
|
Search journals by publisher name
|
119
133
|
|
120
134
|
```ruby
|
@@ -181,8 +195,8 @@ Commands:
|
|
181
195
|
* License: MIT
|
182
196
|
|
183
197
|
[crapi]: https://github.com/CrossRef/rest-api-doc/blob/master/rest_api.md
|
184
|
-
[cn]:
|
185
|
-
[tdm]:
|
186
|
-
[ccount]:
|
198
|
+
[cn]: https://citation.crosscite.org/docs.html
|
199
|
+
[tdm]: https://www.crossref.org/education/retrieve-metadata/rest-api/text-and-data-mining/
|
200
|
+
[ccount]: https://labs.crossref.org/openurl/
|
187
201
|
[csl]: https://github.com/citation-style-language/styles
|
188
202
|
[changelog]: https://github.com/sckott/serrano/blob/master/CHANGELOG.md
|
data/Rakefile
CHANGED
@@ -1,19 +1,23 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require "bundler/gem_tasks"
|
2
|
-
require
|
4
|
+
require "rake/testtask"
|
5
|
+
require "standard"
|
6
|
+
require "standard/rake"
|
3
7
|
|
4
8
|
Rake::TestTask.new do |t|
|
5
9
|
t.libs << "test"
|
6
|
-
t.test_files = FileList[
|
10
|
+
t.test_files = FileList["test/test_*.rb"]
|
7
11
|
t.verbose = true
|
8
12
|
t.warning = false
|
9
13
|
end
|
10
14
|
|
11
15
|
desc "Run tests"
|
12
|
-
task :
|
16
|
+
task default: :test
|
13
17
|
|
14
18
|
desc "Build serrano docs"
|
15
19
|
task :docs do
|
16
|
-
|
20
|
+
system "yardoc"
|
17
21
|
end
|
18
22
|
|
19
23
|
desc "bundle install"
|
@@ -28,15 +32,15 @@ end
|
|
28
32
|
|
29
33
|
desc "Build serrano"
|
30
34
|
task :build do
|
31
|
-
|
35
|
+
system "gem build serrano.gemspec"
|
32
36
|
end
|
33
37
|
|
34
38
|
desc "Install serrano"
|
35
|
-
task :
|
36
|
-
|
39
|
+
task install: %i[bundle build] do
|
40
|
+
system "gem install serrano-#{Serrano::VERSION}.gem"
|
37
41
|
end
|
38
42
|
|
39
43
|
desc "Release to Rubygems"
|
40
|
-
task :
|
44
|
+
task release: :build do
|
41
45
|
system "gem push serrano-#{Serrano::VERSION}.gem"
|
42
46
|
end
|
data/bin/serrano
CHANGED
@@ -1,14 +1,15 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
2
3
|
|
3
|
-
require
|
4
|
-
require
|
5
|
-
require
|
4
|
+
require 'thor'
|
5
|
+
require 'serrano'
|
6
|
+
require 'multi_json'
|
6
7
|
|
7
8
|
class Sr < Thor
|
8
9
|
include Thor::Actions
|
9
10
|
# class_option :json, :type => :boolean, :default => false
|
10
11
|
|
11
|
-
desc
|
12
|
+
desc 'works [DOIs]', 'Get works by DOIs'
|
12
13
|
long_desc <<-LONGDESC
|
13
14
|
`serrano works` accepts one or more DOIs to search for works
|
14
15
|
|
@@ -47,17 +48,17 @@ class Sr < Thor
|
|
47
48
|
\x5"http://orcid.org/0000-0003-4087-8021"
|
48
49
|
\x5"http://orcid.org/0000-0002-2076-5452"
|
49
50
|
LONGDESC
|
50
|
-
option :json, :
|
51
|
-
option :filter, :
|
52
|
-
option :limit, :
|
53
|
-
def works(ids=nil)
|
54
|
-
if ids.nil?
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
51
|
+
option :json, type: :boolean, default: false
|
52
|
+
option :filter, type: :hash, default: nil
|
53
|
+
option :limit, type: :numeric, default: nil
|
54
|
+
def works(ids = nil)
|
55
|
+
out = if ids.nil?
|
56
|
+
Serrano.works(filter: options[:filter], limit: options[:limit])
|
57
|
+
else
|
58
|
+
Serrano.works(ids: ids.split(','), filter: options[:filter])
|
59
|
+
end
|
59
60
|
if !options[:json]
|
60
|
-
out = out.collect { |x| x['message'].select { |k,
|
61
|
+
out = out.collect { |x| x['message'].select { |k, _v| k[/DOI|type|title/] } }
|
61
62
|
out.each do |x|
|
62
63
|
puts 'DOI: ' + x['DOI'].to_s
|
63
64
|
puts 'type: ' + x['type']
|
@@ -69,7 +70,7 @@ class Sr < Thor
|
|
69
70
|
end
|
70
71
|
end
|
71
72
|
|
72
|
-
desc
|
73
|
+
desc 'members [member IDs]', 'Get members by id'
|
73
74
|
long_desc <<-LONGDESC
|
74
75
|
`serrano members` accepts one or more Crossref member IDs
|
75
76
|
|
@@ -96,26 +97,26 @@ class Sr < Thor
|
|
96
97
|
|
97
98
|
24 7 45 31 22 67 72 17 53 75 0 68 12 16 50 79 40 18 40 195
|
98
99
|
LONGDESC
|
99
|
-
option :json, :
|
100
|
-
option :query, :
|
101
|
-
option :limit, :
|
102
|
-
option :works, :
|
103
|
-
def members(ids=nil)
|
100
|
+
option :json, type: :boolean, default: false
|
101
|
+
option :query, type: :string, default: nil
|
102
|
+
option :limit, type: :numeric, default: nil
|
103
|
+
option :works, type: :boolean, default: false
|
104
|
+
def members(ids = nil)
|
104
105
|
if ids.nil?
|
105
106
|
out = Serrano.members(query: options[:query], limit: options[:limit],
|
106
|
-
|
107
|
+
works: options[:works])
|
107
108
|
else
|
108
|
-
out = Serrano.members(ids: ids.split(
|
109
|
-
|
109
|
+
out = Serrano.members(ids: ids.split(','), query: options[:query], limit: options[:limit],
|
110
|
+
works: options[:works])
|
110
111
|
end
|
111
112
|
|
112
113
|
if !options[:json]
|
113
114
|
if !options[:works]
|
114
|
-
if out.class == Hash
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
115
|
+
out = if out.class == Hash
|
116
|
+
out['message']['items']
|
117
|
+
else
|
118
|
+
out.collect { |x| x['message'] }
|
119
|
+
end
|
119
120
|
|
120
121
|
# out = out.collect { |x| x['message'].select { |k,v| k[/id|primary-name/] } }
|
121
122
|
out.each do |x|
|
@@ -131,8 +132,7 @@ class Sr < Thor
|
|
131
132
|
end
|
132
133
|
end
|
133
134
|
|
134
|
-
|
135
|
-
desc "prefixes [DOI prefixes]", "Search for prefixes by DOI prefix"
|
135
|
+
desc 'prefixes [DOI prefixes]', 'Search for prefixes by DOI prefix'
|
136
136
|
long_desc <<-LONGDESC
|
137
137
|
`serrano prefixes` accepts one or more Crossref member IDs
|
138
138
|
|
@@ -162,24 +162,24 @@ class Sr < Thor
|
|
162
162
|
\x5"Co-Action Publishing"
|
163
163
|
\x5"Oxford University Press (OUP)"
|
164
164
|
LONGDESC
|
165
|
-
option :json, :
|
166
|
-
option :limit, :
|
167
|
-
option :works, :
|
168
|
-
def prefixes(ids=nil)
|
169
|
-
if ids.nil?
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
165
|
+
option :json, type: :boolean, default: false
|
166
|
+
option :limit, type: :numeric, default: nil
|
167
|
+
option :works, type: :boolean, default: false
|
168
|
+
def prefixes(ids = nil)
|
169
|
+
out = if ids.nil?
|
170
|
+
Serrano.prefixes(limit: options[:limit], works: options[:works])
|
171
|
+
else
|
172
|
+
Serrano.prefixes(ids: ids.split(','), limit: options[:limit],
|
173
|
+
works: options[:works])
|
174
|
+
end
|
175
175
|
|
176
176
|
if !options[:json]
|
177
177
|
if !options[:works]
|
178
|
-
if out.class == Hash
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
178
|
+
out = if out.class == Hash
|
179
|
+
out['message']['items']
|
180
|
+
else
|
181
|
+
out.collect { |x| x['message'] }
|
182
|
+
end
|
183
183
|
|
184
184
|
out.each do |x|
|
185
185
|
puts 'member: ' + x['member']
|
@@ -195,7 +195,7 @@ class Sr < Thor
|
|
195
195
|
end
|
196
196
|
end
|
197
197
|
|
198
|
-
desc
|
198
|
+
desc 'funders [funder IDs]', 'Search for funders by DOI prefix'
|
199
199
|
long_desc <<-LONGDESC
|
200
200
|
`serrano funders` accepts one or more Crossref funder IDs
|
201
201
|
|
@@ -226,26 +226,26 @@ class Sr < Thor
|
|
226
226
|
|
227
227
|
$ serrano funders 10.13039/100000001 --works=true --limit=2
|
228
228
|
LONGDESC
|
229
|
-
option :json, :
|
230
|
-
option :query, :
|
231
|
-
option :limit, :
|
232
|
-
option :works, :
|
233
|
-
def funders(ids=nil)
|
229
|
+
option :json, type: :boolean, default: false
|
230
|
+
option :query, type: :string, default: nil
|
231
|
+
option :limit, type: :numeric, default: nil
|
232
|
+
option :works, type: :boolean, default: false
|
233
|
+
def funders(ids = nil)
|
234
234
|
if ids.nil?
|
235
235
|
out = Serrano.funders(query: options[:query], limit: options[:limit],
|
236
|
-
|
236
|
+
works: options[:works])
|
237
237
|
else
|
238
|
-
out = Serrano.funders(ids: ids.split(
|
239
|
-
|
238
|
+
out = Serrano.funders(ids: ids.split(','), query: options[:query], limit: options[:limit],
|
239
|
+
works: options[:works])
|
240
240
|
end
|
241
241
|
|
242
242
|
if !options[:json]
|
243
243
|
if !options[:works]
|
244
|
-
if out.class == Hash
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
244
|
+
out = if out.class == Hash
|
245
|
+
out['message']['items']
|
246
|
+
else
|
247
|
+
out.collect { |x| x['message'] }
|
248
|
+
end
|
249
249
|
|
250
250
|
out.each do |x|
|
251
251
|
puts 'id: ' + x['id']
|
@@ -261,8 +261,7 @@ class Sr < Thor
|
|
261
261
|
end
|
262
262
|
end
|
263
263
|
|
264
|
-
|
265
|
-
desc "journals [journal ISSNs]", "Search for journals by ISSNs"
|
264
|
+
desc 'journals [journal ISSNs]', 'Search for journals by ISSNs'
|
266
265
|
long_desc <<-LONGDESC
|
267
266
|
`serrano journals` accepts one or more journal ISSNs
|
268
267
|
|
@@ -293,26 +292,26 @@ class Sr < Thor
|
|
293
292
|
|
294
293
|
$ serrano journals 2167-8359 --query=ecology --works=true --limit=2
|
295
294
|
LONGDESC
|
296
|
-
option :json, :
|
297
|
-
option :query, :
|
298
|
-
option :limit, :
|
299
|
-
option :works, :
|
300
|
-
def journals(ids=nil)
|
295
|
+
option :json, type: :boolean, default: false
|
296
|
+
option :query, type: :string, default: nil
|
297
|
+
option :limit, type: :numeric, default: nil
|
298
|
+
option :works, type: :boolean, default: false
|
299
|
+
def journals(ids = nil)
|
301
300
|
if ids.nil?
|
302
301
|
out = Serrano.journals(query: options[:query], limit: options[:limit],
|
303
|
-
|
302
|
+
works: options[:works])
|
304
303
|
else
|
305
|
-
out = Serrano.journals(ids: ids.split(
|
306
|
-
|
304
|
+
out = Serrano.journals(ids: ids.split(','), query: options[:query], limit: options[:limit],
|
305
|
+
works: options[:works])
|
307
306
|
end
|
308
307
|
|
309
308
|
if !options[:json]
|
310
309
|
if !options[:works]
|
311
|
-
if out.class == Hash
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
|
310
|
+
out = if out.class == Hash
|
311
|
+
out['message']['items']
|
312
|
+
else
|
313
|
+
out.collect { |x| x['message'] }
|
314
|
+
end
|
316
315
|
|
317
316
|
out.each do |x|
|
318
317
|
puts 'ISSN: ' + x['ISSN'][0]
|
@@ -328,7 +327,7 @@ class Sr < Thor
|
|
328
327
|
end
|
329
328
|
end
|
330
329
|
|
331
|
-
desc
|
330
|
+
desc 'types [type name]', 'Search for types by name'
|
332
331
|
long_desc <<-LONGDESC
|
333
332
|
`serrano types` accepts one or more type names
|
334
333
|
|
@@ -359,20 +358,20 @@ class Sr < Thor
|
|
359
358
|
|
360
359
|
$ serrano types dissertation --works --limit=2
|
361
360
|
LONGDESC
|
362
|
-
option :json, :
|
363
|
-
option :works, :
|
364
|
-
option :limit, :
|
361
|
+
option :json, type: :boolean, default: false
|
362
|
+
option :works, type: :boolean, default: false
|
363
|
+
option :limit, type: :numeric, default: nil
|
365
364
|
def types(*ids)
|
366
365
|
out = Serrano.types(ids: ids, limit: options[:limit],
|
367
|
-
|
366
|
+
works: options[:works])
|
368
367
|
|
369
368
|
if !options[:json]
|
370
369
|
if !options[:works]
|
371
|
-
if out.class == Hash
|
372
|
-
|
373
|
-
|
374
|
-
|
375
|
-
|
370
|
+
out = if out.class == Hash
|
371
|
+
out['message']['items']
|
372
|
+
else
|
373
|
+
out.collect { |x| x['message'] }
|
374
|
+
end
|
376
375
|
|
377
376
|
out.each do |x|
|
378
377
|
puts 'id: ' + x['id']
|
@@ -387,7 +386,7 @@ class Sr < Thor
|
|
387
386
|
end
|
388
387
|
end
|
389
388
|
|
390
|
-
desc
|
389
|
+
desc 'licenses', 'Search for licenses by name'
|
391
390
|
long_desc <<-LONGDESC
|
392
391
|
`serrano licenses` accepts one or more type names
|
393
392
|
|
@@ -416,8 +415,8 @@ class Sr < Thor
|
|
416
415
|
"National Science Foundation"
|
417
416
|
\x5"U.S. Department of Energy"
|
418
417
|
LONGDESC
|
419
|
-
option :json, :
|
420
|
-
option :query, :
|
418
|
+
option :json, type: :boolean, default: false
|
419
|
+
option :query, type: :string, default: nil
|
421
420
|
def licenses
|
422
421
|
out = Serrano.licenses(query: options[:query])
|
423
422
|
if !options[:json]
|
@@ -432,7 +431,7 @@ class Sr < Thor
|
|
432
431
|
end
|
433
432
|
end
|
434
433
|
|
435
|
-
desc
|
434
|
+
desc 'contneg', 'Content negotiation'
|
436
435
|
long_desc <<-LONGDESC
|
437
436
|
`serrano contneg` accepts a DOI
|
438
437
|
|
@@ -444,15 +443,15 @@ class Sr < Thor
|
|
444
443
|
|
445
444
|
Murtaugh PA (2014). In defense of P values . Ecology 95: 611–617.
|
446
445
|
LONGDESC
|
447
|
-
option :format, :
|
448
|
-
option :style, :
|
449
|
-
option :locale, :
|
446
|
+
option :format, type: :string, default: 'text'
|
447
|
+
option :style, type: :string, default: 'apa'
|
448
|
+
option :locale, type: :string, default: 'en-US'
|
450
449
|
def contneg(ids)
|
451
450
|
puts Serrano.content_negotiation(ids: ids, format: options[:format], style:
|
452
451
|
options[:style], locale: options[:locale])
|
453
452
|
end
|
454
453
|
|
455
|
-
desc
|
454
|
+
desc 'version', 'Get serrano version'
|
456
455
|
def version
|
457
456
|
puts Serrano::VERSION
|
458
457
|
end
|
@@ -460,11 +459,11 @@ class Sr < Thor
|
|
460
459
|
private
|
461
460
|
|
462
461
|
def print_works(data)
|
463
|
-
if data.is_a? Array
|
464
|
-
|
465
|
-
|
466
|
-
|
467
|
-
|
462
|
+
data = if data.is_a? Array
|
463
|
+
data[0]['message']['items']
|
464
|
+
else
|
465
|
+
data.collect { |x| x['message'].select { |k, _v| k[/DOI|type|title/] } }
|
466
|
+
end
|
468
467
|
data.each do |x|
|
469
468
|
puts 'DOI: ' + x['DOI']
|
470
469
|
puts 'type: ' + x['type']
|
@@ -472,7 +471,6 @@ class Sr < Thor
|
|
472
471
|
puts
|
473
472
|
end
|
474
473
|
end
|
475
|
-
|
476
474
|
end
|
477
475
|
|
478
476
|
Sr.start(ARGV)
|