serrano 0.0.7

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 00aa3283924fc74b4a2634759602caa5516b26e3
4
+ data.tar.gz: bd653f31833befbb3dd5be3a4fff893e22e13756
5
+ SHA512:
6
+ metadata.gz: 874a4e19e0ac4439c75be43782d7da74adf00a082d4352e6d13458fdaac442d5048fda4faf7db5f747c76220821a4b5a1270477bf931d5202842604358f2bfe7
7
+ data.tar.gz: ffb5ebb232ef610865833c6b147be959a7313a8b3904bdd429aa2cac17548879693df195d91cb31a40009ce8d3a59bec46e16dfad0c5a16895d04bd3fcb8ae87
data/.gitignore ADDED
@@ -0,0 +1,36 @@
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
+ /lib/bundler/man/
26
+
27
+ # for a library or gem, you might want to ignore these files since the code is
28
+ # intended to run in multiple environments; otherwise, check them in:
29
+ #Gemfile.lock
30
+ .ruby-version
31
+ .ruby-gemset
32
+
33
+ # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
34
+ .rvmrc
35
+
36
+ cache/
data/.travis.yml ADDED
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.1.7
4
+ - 2.2.3
data/CONDUCT.md ADDED
@@ -0,0 +1,25 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, we pledge to respect all people who
4
+ contribute through reporting issues, posting feature requests, updating documentation,
5
+ submitting pull requests or patches, and other activities.
6
+
7
+ We are committed to making participation in this project a harassment-free experience for
8
+ everyone, regardless of level of experience, gender, gender identity and expression,
9
+ sexual orientation, disability, personal appearance, body size, race, ethnicity, age, or religion.
10
+
11
+ Examples of unacceptable behavior by participants include the use of sexual language or
12
+ imagery, derogatory comments or personal attacks, trolling, public or private harassment,
13
+ insults, or other unprofessional conduct.
14
+
15
+ Project maintainers have the right and responsibility to remove, edit, or reject comments,
16
+ commits, code, wiki edits, issues, and other contributions that are not aligned to this
17
+ Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed
18
+ from the project team.
19
+
20
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by
21
+ opening an issue or contacting one or more of the project maintainers.
22
+
23
+ This Code of Conduct is adapted from the Contributor Covenant
24
+ (http:contributor-covenant.org), version 1.0.0, available at
25
+ http://contributor-covenant.org/version/1/0/0/
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,56 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ serrano (0.0.7)
5
+ faraday (~> 0.9.1)
6
+ faraday_middleware (~> 0.10.0)
7
+ multi_json (~> 1.0)
8
+ nokogiri (~> 1.6, >= 1.6.6.2)
9
+ thor (~> 0.19)
10
+ uuidtools (~> 2.1, >= 2.1.5)
11
+
12
+ GEM
13
+ remote: https://rubygems.org/
14
+ specs:
15
+ codecov (0.1.1)
16
+ json
17
+ simplecov
18
+ url
19
+ docile (1.1.5)
20
+ faraday (0.9.1)
21
+ multipart-post (>= 1.2, < 3)
22
+ faraday_middleware (0.10.0)
23
+ faraday (>= 0.7.4, < 0.10)
24
+ json (1.8.3)
25
+ mini_portile (0.6.2)
26
+ multi_json (1.11.2)
27
+ multipart-post (2.0.0)
28
+ nokogiri (1.6.6.2)
29
+ mini_portile (~> 0.6.0)
30
+ power_assert (0.2.4)
31
+ rake (10.4.2)
32
+ simplecov (0.10.0)
33
+ docile (~> 1.1.0)
34
+ json (~> 1.8)
35
+ simplecov-html (~> 0.10.0)
36
+ simplecov-html (0.10.0)
37
+ test-unit (3.1.3)
38
+ power_assert
39
+ thor (0.19.1)
40
+ url (0.3.2)
41
+ uuidtools (2.1.5)
42
+
43
+ PLATFORMS
44
+ ruby
45
+
46
+ DEPENDENCIES
47
+ bundler (~> 1.6)
48
+ codecov (~> 0.1)
49
+ json (~> 1.8, >= 1.8.3)
50
+ rake (~> 10.4)
51
+ serrano!
52
+ simplecov (~> 0.10)
53
+ test-unit (~> 3.1)
54
+
55
+ BUNDLED WITH
56
+ 1.10.6
data/LICENSE ADDED
@@ -0,0 +1,7 @@
1
+ Copyright (C) 2015 Scott Chamberlain
2
+
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
+
5
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6
+
7
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/NEWS.md ADDED
@@ -0,0 +1,3 @@
1
+ ## 0.0.1 (xxxx-xx-xx)
2
+
3
+ * First version to Rubygems
data/README.md ADDED
@@ -0,0 +1,128 @@
1
+ serrano
2
+ =========
3
+
4
+ [![Build Status](https://api.travis-ci.org/sckott/serrano.png)](https://travis-ci.org/sckott/serrano)
5
+ [![codecov.io](http://codecov.io/github/sckott/serrano/coverage.svg?branch=master)](http://codecov.io/github/sckott/serrano?branch=master)
6
+
7
+ `serrano` is a low level client for Crossref APIs
8
+
9
+ Docs: http://recology.info/serrano/
10
+
11
+ Other Crossref API clients:
12
+
13
+ - Python: [habanero](https://github.com/sckott/habanero)
14
+ - R: [rcrossref](https://github.com/ropensci/rcrossref)
15
+
16
+ ## Changes
17
+
18
+ For changes see the [NEWS file](NEWS.md).
19
+
20
+ ## API
21
+
22
+ Methods in relation to [Crossref search API][crapi] routes
23
+
24
+ * `/works` - `Serrano.works()`
25
+ * `/members` - `Serrano.members()`
26
+ * `/prefixes` - `Serrano.prefixes()`
27
+ * `/funders` - `Serrano.funders()`
28
+ * `/journals` - `Serrano.journals()`
29
+ * `/licenses` - `Serrano.licenses()`
30
+ * `/types` - `Serrano.types()`
31
+
32
+ Additional methods built on top of the Crossref search API:
33
+
34
+ * DOI minting agency - `Serrano.agency()`
35
+ * Get random DOIs - `Serrano.random_dois()`
36
+
37
+ Other methods:
38
+
39
+ * [Conent negotiation][cn] - `Serrano.cn()`
40
+ * [Text and data mining][tdm] - `Serrano.text()`
41
+
42
+ ## Install
43
+
44
+ ### Release version
45
+
46
+ ```
47
+ gem install serrano
48
+ ```
49
+
50
+ ### Development version
51
+
52
+ ```
53
+ git clone git@github.com:sckott/serrano.git
54
+ cd serrano
55
+ rake install
56
+ ```
57
+
58
+ ## Setup
59
+
60
+ Crossref's API will likely be used by others in the future, allowing the base URL to be swapped out. You can swap out the base URL by passing named options in a block to `Serrano.configuration`.
61
+
62
+ This will also be the way to set up other user options, as needed down the road.
63
+
64
+ ```ruby
65
+ Serrano.configuration do |config|
66
+ config.base_url = "http://api.crossref.org"
67
+ end
68
+ ```
69
+
70
+ ## Examples
71
+
72
+ Search works by DOI
73
+
74
+ ```ruby
75
+ require 'serrano'
76
+ Serrano.works(doi: '10.1371/journal.pone.0033693')
77
+ ```
78
+
79
+ Search works by query string
80
+
81
+ ```ruby
82
+ Serrano.works(query: "ecology")
83
+ ```
84
+
85
+ Search journals by publisher name
86
+
87
+ ```ruby
88
+ Serrano.journals(query: "peerj")
89
+ ```
90
+
91
+ Search funding information by DOI
92
+
93
+ ```ruby
94
+ Serrano.funders(ids: ['10.13039/100000001','10.13039/100000015'])
95
+ ```
96
+
97
+ Get agency for a set of DOIs
98
+
99
+ ```ruby
100
+ Serrano.agency(ids: ['10.1007/12080.1874-1746','10.1007/10452.1573-5125'])
101
+ ```
102
+
103
+ Get random set of DOIs
104
+
105
+ ```ruby
106
+ Serrano.random_dois(sample: 100)
107
+ ```
108
+
109
+ Content negotiation
110
+
111
+ ```ruby
112
+ Serrano.cn(ids: '10.1126/science.169.3946.635', format: "citeproc-json")
113
+ ```
114
+
115
+ Text mining
116
+
117
+ ```ruby
118
+ res = Serrano.text(url: 'http://...');
119
+ ```
120
+
121
+ ## Meta
122
+
123
+ * Please note that this project is released with a [Contributor Code of Conduct](CONDUCT.md). By participating in this project you agree to abide by its terms.
124
+ * License: MIT
125
+
126
+ [crapi]: https://github.com/CrossRef/rest-api-doc/blob/master/rest_api.md
127
+ [cn]: http://www.crosscite.org/cn/
128
+ [tdm]: http://www.crossref.org/tdm/
data/Rakefile ADDED
@@ -0,0 +1,41 @@
1
+ require "bundler/gem_tasks"
2
+ require 'rake/testtask'
3
+
4
+ Rake::TestTask.new do |t|
5
+ t.libs << "test"
6
+ t.test_files = FileList['test/test-*.rb']
7
+ t.verbose = true
8
+ end
9
+
10
+ desc "Run tests"
11
+ task :default => :test
12
+
13
+ desc "Build serrano docs"
14
+ task :docs do
15
+ system "yardoc"
16
+ end
17
+
18
+ desc "bundle install"
19
+ task :b do
20
+ system "bundle install"
21
+ end
22
+
23
+ desc "bundle install"
24
+ task :clean do
25
+ system "ls | grep [0-9].gem | xargs rm"
26
+ end
27
+
28
+ desc "Build serrano"
29
+ task :build do
30
+ system "gem build serrano.gemspec"
31
+ end
32
+
33
+ desc "Install serrano"
34
+ task :install => :build do
35
+ system "gem install serrano-#{Serrano::VERSION}.gem"
36
+ end
37
+
38
+ desc "Release to Rubygems"
39
+ task :release => :build do
40
+ system "gem push serrano-#{Serrano::VERSION}.gem"
41
+ end
data/lib/serrano.rb ADDED
@@ -0,0 +1,440 @@
1
+ require "serrano/version"
2
+ require "serrano/request"
3
+ require "serrano/filterhandler"
4
+ require "serrano/cnrequest"
5
+ require "serrano/miner"
6
+ require "serrano/filters"
7
+
8
+ require 'rexml/document'
9
+ require 'rexml/xpath'
10
+
11
+ # @!macro serrano_params
12
+ # @param ids [Array] DOIs (digital object identifier) or other identifiers
13
+ # @param offset [Fixnum] Number of record to start at, from 1 to infinity.
14
+ # @param limit [Fixnum] Number of results to return. Not relavant when searching with specific dois. Default: 20. Max: 1000
15
+ # @param sample [Fixnum] Number of random results to return. when you use the sample parameter,
16
+ # the limit and offset parameters are ignored.
17
+ # @param sort [String] Field to sort on, one of score, relevance,
18
+ # updated (date of most recent change to metadata. Currently the same as deposited),
19
+ # deposited (time of most recent deposit), indexed (time of most recent index), or
20
+ # published (publication date). Note: If the API call includes a query, then the sort
21
+ # order will be by the relevance score. If no query is included, then the sort order
22
+ # will be by DOI update date.
23
+ # @param order [String] Sort order, one of 'asc' or 'desc'
24
+ # @param facet [Boolean] Include facet results. Default: false
25
+ # @param options [Hash] Hash of options for configuring the request, passed on to Faraday.new
26
+ # :timeout - [Fixnum] open/read timeout Integer in seconds
27
+ # :open_timeout - [Fixnum] read timeout Integer in seconds
28
+ # :proxy - [Hash] hash of proxy options
29
+ # :uri - [String] Proxy Server URI
30
+ # :user - [String] Proxy server username
31
+ # :password - [String] Proxy server password
32
+ # :params_encoder - [Hash] not sure what this is
33
+ # :bind - [Hash] A hash with host and port values
34
+ # :boundary - [String] of the boundary value
35
+ # :oauth - [Hash] A hash with OAuth details
36
+ # @param verbose [Boolean] Print request headers to stdout. Default: false
37
+
38
+ ##
39
+ # Serrano - The top level module for using methods
40
+ # to access Serrano APIs
41
+ #
42
+ # The following methods, matching the main Crossref API routes, are available:
43
+ # * works - Use the /works endpoint
44
+ # * members - Use the /members endpoint
45
+ # * prefixes - Use the /prefixes endpoint
46
+ # * funders - Use the /funders endpoint
47
+ # * journals - Use the /journals endpoint
48
+ # * types - Use the /types endpoint
49
+ # * licenses - Use the /licenses endpoint
50
+ #
51
+ # Additional methods
52
+ # * agency - test the registration agency for a DOI
53
+ #
54
+ # All routes return an array of hashes
55
+ # For example, if you want to inspect headers returned from the HTTP request,
56
+ # and parse the raw result in any way you wish.
57
+ #
58
+ # @see https://github.com/CrossRef/rest-api-doc/blob/master/rest_api.md for
59
+ # detailed description of the Crossref API
60
+ module Serrano
61
+ extend Configuration
62
+
63
+ define_setting :access_token
64
+ define_setting :access_secret
65
+ define_setting :elsevier_key
66
+ define_setting :base_url, "http://api.crossref.org/"
67
+
68
+ ##
69
+ # Search the works route
70
+ #
71
+ # @!macro serrano_params
72
+ # @param query [String] A query string
73
+ # @param filter [Hash] Filter options. See ...
74
+ # @return [Array] An array of hashes
75
+ #
76
+ # @example
77
+ # require 'serrano'
78
+ # # Search by DOI, one or more
79
+ # Serrano.works(ids: '10.5555/515151')
80
+ # Serrano.works(ids: '10.1371/journal.pone.0033693')
81
+ # Serrano.works(ids: ['10.1007/12080.1874-1746','10.1007/10452.1573-5125', '10.1111/(issn)1442-9993'])
82
+ # # query
83
+ # Serrano.works(query: "ecology")
84
+ # Serrano.works(query: "renear+-ontologies")
85
+ # # Sort
86
+ # Serrano.works(query: "ecology", sort: 'relevance', order: "asc")
87
+ # # Filters
88
+ # Serrano.works(filter: {has_full_text: true})
89
+ # Serrano.works(filter: {has_funder: true, has_full_text: true})
90
+ # Serrano.works(filter: {award_number: 'CBET-0756451', award_funder: '10.13039/100000001'})
91
+ #
92
+ # # Curl options
93
+ # ## set a request timeout and an open timeout
94
+ # Serrano.works(ids: '10.1371/journal.pone.0033693', options: {timeout: 3, open_timeout: 2})
95
+ # ## log request details - uses Faraday middleware
96
+ # Serrano.works(ids: '10.1371/journal.pone.0033693', verbose: true)
97
+ def self.works(ids: nil, query: nil, filter: nil, offset: nil,
98
+ limit: nil, sample: nil, sort: nil, order: nil, facet: nil,
99
+ options: nil, verbose: false)
100
+
101
+ Request.new('works', ids, query, filter, offset,
102
+ limit, sample, sort, order, facet, nil, nil, options, verbose).perform
103
+ end
104
+
105
+ ##
106
+ # Search the members route
107
+ #
108
+ # @!macro serrano_params
109
+ # @param query [String] A query string
110
+ # @param filter [Hash] Filter options. See ...
111
+ # @param works [Boolean] If true, works returned as well. Default: false
112
+ # @return [Array] An array of hashes
113
+ #
114
+ # @example
115
+ # require 'serrano'
116
+ # # Search by DOI, one or more
117
+ # Serrano.members(ids: 98)
118
+ # Serrano.members(ids: 340)
119
+ # Serrano.members(ids: [98, 340, 45])
120
+ # # query
121
+ # Serrano.members(query: "ecology")
122
+ # Serrano.members(query: "hindawi")
123
+ # # Sort - weird, doesn't work
124
+ # Serrano.members(query: "ecology", order: "asc")
125
+ # # Works
126
+ # Serrano.members(ids: 98, works: true)
127
+ def self.members(ids: nil, query: nil, filter: nil, offset: nil,
128
+ limit: nil, sample: nil, sort: nil, order: nil, facet: nil,
129
+ works: false, options: nil, verbose: false)
130
+
131
+ Request.new('members', ids, query, filter, offset,
132
+ limit, sample, sort, order, facet, works, nil, options, verbose).perform
133
+ end
134
+
135
+ ##
136
+ # Search the prefixes route
137
+ #
138
+ # @!macro serrano_params
139
+ # @param filter [Hash] Filter options. See ...
140
+ # @param works [Boolean] If true, works returned as well. Default: false
141
+ # @return [Array] An array of hashes
142
+ #
143
+ # @example
144
+ # require 'serrano'
145
+ # # Search by DOI, one or more
146
+ # Serrano.prefixes(ids: "10.1016")
147
+ # Serrano.prefixes(ids: ['10.1016','10.1371','10.1023','10.4176','10.1093'])
148
+ # # works
149
+ # Serrano.prefixes(ids: "10.1016", works: true)
150
+ # # Limit number of results
151
+ # Serrano.prefixes(ids: "10.1016", works: true, limit: 3)
152
+ # # Sort and order
153
+ # Serrano.prefixes(ids: "10.1016", works: true, sort: 'relevance', order: "asc")
154
+ def self.prefixes(ids:, filter: nil, offset: nil,
155
+ limit: nil, sample: nil, sort: nil, order: nil, facet: nil,
156
+ works: false, options: nil, verbose: false)
157
+
158
+ Request.new('prefixes', ids, nil, filter, offset,
159
+ limit, sample, sort, order, facet, works, nil, options, verbose).perform
160
+ end
161
+
162
+ ##
163
+ # Search the funders route
164
+ #
165
+ # @!macro serrano_params
166
+ # @param query [String] A query string
167
+ # @param filter [Hash] Filter options. See ...
168
+ # @param works [Boolean] If true, works returned as well. Default: false
169
+ # @return [Array] An array of hashes
170
+ #
171
+ # @example
172
+ # require 'serrano'
173
+ # # Search by DOI, one or more
174
+ # Serrano.funders(ids: '10.13039/100000001')
175
+ # Serrano.funders(ids: ['10.13039/100000001','10.13039/100000015'])
176
+ # # query
177
+ # Serrano.funders(query: "NSF")
178
+ # # works
179
+ # Serrano.funders(ids: '10.13039/100000001', works: true)
180
+ # # Limit number of results
181
+ # Serrano.funders(ids: '10.13039/100000001', works: true, limit: 3)
182
+ # # Sort and order
183
+ # Serrano.funders(ids: "10.13039/100000001", works: true, sort: 'relevance', order: "asc")
184
+ def self.funders(ids: nil, query: nil, filter: nil, offset: nil,
185
+ limit: nil, sample: nil, sort: nil, order: nil, facet: nil,
186
+ works: false, options: nil, verbose: false)
187
+
188
+ Request.new('funders', ids, query, filter, offset,
189
+ limit, sample, sort, order, facet, works, nil, options, verbose).perform
190
+ end
191
+
192
+ ##
193
+ # Search the journals route
194
+ #
195
+ # @!macro serrano_params
196
+ # @param query [String] A query string
197
+ # @param filter [Hash] Filter options. See ...
198
+ # @param works [Boolean] If true, works returned as well. Default: false
199
+ # @return [Array] An array of hashes
200
+ #
201
+ # @example
202
+ # require 'serrano'
203
+ # Serrano.journals(ids: "2167-8359")
204
+ # Serrano.journals()
205
+ # Serrano.journals(ids: "2167-8359", works: true)
206
+ # Serrano.journals(ids: ['1803-2427', '2326-4225'])
207
+ # Serrano.journals(query: "ecology")
208
+ # Serrano.journals(query: "peerj")
209
+ # Serrano.journals(ids: "2167-8359", query: 'ecology', works: true, sort: 'score', order: "asc")
210
+ # Serrano.journals(ids: "2167-8359", query: 'ecology', works: true, sort: 'score', order: "desc")
211
+ # Serrano.journals(ids: "2167-8359", works: true, filter: {from_pub_date: '2014-03-03'})
212
+ # Serrano.journals(ids: '1803-2427', works: true)
213
+ # Serrano.journals(ids: '1803-2427', works: true)
214
+ # Serrano.journals(limit: 2)
215
+ # Serrano.journals(sample: 2)
216
+ def self.journals(ids: nil, query: nil, filter: nil, offset: nil,
217
+ limit: nil, sample: nil, sort: nil, order: nil, facet: nil,
218
+ works: false, options: nil, verbose: false)
219
+
220
+ Request.new('journals', ids, query, filter, offset,
221
+ limit, sample, sort, order, facet, works, nil, options, verbose).perform
222
+ end
223
+
224
+ ##
225
+ # Search the types route
226
+ #
227
+ # @param ids [Array] DOIs (digital object identifier) or other identifiers
228
+ # @param works [Boolean] If true, works returned as well. Default: false
229
+ # @return [Array] An array of hashes
230
+ #
231
+ # @example
232
+ # require 'serrano'
233
+ # Serrano.types()
234
+ # Serrano.types(ids: "journal")
235
+ # Serrano.types(ids: ["journal", "dissertation"])
236
+ # Serrano.types(ids: "journal", works: true)
237
+ def self.types(ids: nil, works: false, options: nil, verbose: false)
238
+
239
+ Request.new('types', ids, nil, nil, nil,
240
+ nil, nil, nil, nil, nil, works, nil, options, verbose).perform
241
+ end
242
+
243
+ ##
244
+ # Search the licenses route
245
+ #
246
+ # @!macro serrano_params
247
+ # @param query [String] A query string
248
+ # @return [Array] An array of hashes
249
+ #
250
+ # @example
251
+ # require 'serrano'
252
+ # Serrano.licenses(query: "creative")
253
+ # Serrano.licenses()
254
+ # Serrano.licenses(limit: 3)
255
+ def self.licenses(ids: nil, query: nil, offset: nil,
256
+ limit: nil, sample: nil, sort: nil, order: nil,
257
+ facet: nil, options: nil, verbose: false)
258
+
259
+ Request.new('licenses', ids, query, nil, offset,
260
+ limit, sample, sort, order, facet, nil, nil, options, verbose).perform
261
+ end
262
+
263
+ ##
264
+ # Determine registration agency for DOIs
265
+ #
266
+ # @param ids [Array] DOIs (digital object identifier) or other identifiers
267
+ # @return [Array] An array of hashes
268
+ #
269
+ # @example
270
+ # require 'serrano'
271
+ # Serrano.agency(ids: '10.1371/journal.pone.0033693')
272
+ # Serrano.agency(ids: ['10.1007/12080.1874-1746','10.1007/10452.1573-5125', '10.1111/(issn)1442-9993'])
273
+ def self.agency(ids:, options: nil, verbose: false)
274
+
275
+ Request.new('works', ids, nil, nil, nil,
276
+ nil, nil, nil, nil, nil, false, true, options, verbose).perform
277
+ end
278
+
279
+ ##
280
+ # Get a random set of DOI's
281
+ #
282
+ # @param sample [Fixnum] Number of random DOIs to return
283
+ # @return [Array] A list of strings, each a DOI
284
+ # @note This method uses {Serrano.works} internally, but doesn't allow you to pass on
285
+ # arguments to that method.
286
+ #
287
+ # @example
288
+ # require 'serrano'
289
+ # Serrano.random_dois(sample: 1)
290
+ # Serrano.random_dois(sample: 10)
291
+ # Serrano.random_dois(sample: 100)
292
+ def self.random_dois(sample:, options: nil, verbose: false)
293
+
294
+ tmp = Request.new('works', nil, nil, nil, nil,
295
+ nil, sample, nil, nil, nil, false, nil, options, verbose).perform
296
+ tmp['message']['items'].collect { |x| x['DOI'] }
297
+ end
298
+
299
+ ##
300
+ # Get citations in various formats from CrossRef
301
+ #
302
+ # @param ids [String] DOIs
303
+ # @param format [String] Format
304
+ # @param style [String] Style
305
+ # @param locale [String] Locale
306
+ # @return [Hash] A hash
307
+ #
308
+ # @example
309
+ # require 'serrano'
310
+ # # By default, you get bibtex, apa format, in en-US locale
311
+ # Serrano.cn(ids: '10.1126/science.169.3946.635')
312
+ #
313
+ # # get citeproc-json
314
+ # Serrano.cn(ids: '10.1126/science.169.3946.635', format: "citeproc-json")
315
+ # Serrano.cn(ids: "10.1126/science.169.3946.635", format: "citeproc-json")
316
+ # Serrano.cn(ids: "10.1126/science.169.3946.635", format: "rdf-xml")
317
+ # Serrano.cn(ids: "10.1126/science.169.3946.635", format: "crossref-xml")
318
+ # Serrano.cn(ids: "10.1126/science.169.3946.635", format: "text")
319
+ #
320
+ # # return an R bibentry type
321
+ # Serrano.cn(ids: "10.1126/science.169.3946.635", format: "bibentry")
322
+ # Serrano.cn(ids: "10.6084/m9.figshare.97218", format: "bibentry")
323
+ #
324
+ # # return an apa style citation
325
+ # Serrano.cn(ids: "10.1126/science.169.3946.635", format: "text", style: "apa")
326
+ # Serrano.cn(ids: "10.1126/science.169.3946.635", format: "text", style: "harvard3")
327
+ # Serrano.cn(ids: "10.1126/science.169.3946.635", format: "text", style: "elsevier-harvard")
328
+ # Serrano.cn(ids: "10.1126/science.169.3946.635", format: "text", style: "ecoscience")
329
+ # Serrano.cn(ids: "10.1126/science.169.3946.635", format: "text", style: "heredity")
330
+ # Serrano.cn(ids: "10.1126/science.169.3946.635", format: "text", style: "oikos")
331
+ #
332
+ # # example with many DOIs
333
+ # dois <- cr_r(2)
334
+ # Serrano.cn(dois, format: "text", style: "apa")
335
+ #
336
+ # # Using DataCite DOIs
337
+ # ## some formats don't work
338
+ # # Serrano.cn(ids: "10.5284/1011335", format: "text")
339
+ # # Serrano.cn(ids: "10.5284/1011335", format: "crossref-xml")
340
+ # # Serrano.cn(ids: "10.5284/1011335", format: "crossref-tdm")
341
+ #
342
+ # ## But most do work
343
+ # Serrano.cn(ids: "10.5284/1011335", format: "datacite-xml")
344
+ # Serrano.cn(ids: "10.5284/1011335", format: "rdf-xml")
345
+ # Serrano.cn(ids: "10.5284/1011335", format: "turtle")
346
+ # Serrano.cn(ids: "10.5284/1011335", format: "citeproc-json")
347
+ # Serrano.cn(ids: "10.5284/1011335", format: "ris")
348
+ # Serrano.cn(ids: "10.5284/1011335", format: "bibtex")
349
+ # Serrano.cn(ids: "10.5284/1011335", format: "bibentry")
350
+ # Serrano.cn(ids: "10.5284/1011335", format: "bibtex")
351
+ #
352
+ # # many DOIs
353
+ # dois = ['10.5167/UZH-30455','10.5167/UZH-49216','10.5167/UZH-503', '10.5167/UZH-38402','10.5167/UZH-41217']
354
+ # x = Serrano.cn(ids: dois)
355
+ # puts x
356
+ def self.cn(ids:, format: "bibtex", style: 'apa', locale: "en-US")
357
+ CNRequest.new(ids, format, style, locale).perform
358
+ end
359
+
360
+ ##
361
+ # Get full text
362
+ #
363
+ # Should work for open access papers, but for closed, requires authentication and
364
+ # likely pre-authorized IP address.
365
+ #
366
+ # @param url [String] A url for full text
367
+ # @param type [Hash] Ignored for now. One of xml, plain, or pdf. Right now, type auto-detected from the URL
368
+ # @return [Mined] An object of class Mined, with methods for extracting
369
+ # the url requested, the file path, and parsing the plain text, XML, or extracting
370
+ # text from the pdf.
371
+ #
372
+ # @example
373
+ # require 'serrano'
374
+ # # Set authorization
375
+ # Serrano.configuration do |config|
376
+ # config.elsevier_key = "<your key>"
377
+ # end
378
+ # # Get some elsevier works
379
+ # res = Serrano.members(ids: 78, works: true);
380
+ # # get full text links, here doing xml
381
+ # links = res[0]['message']['items'].collect { |x| x['link'].keep_if { |z| z['content-type'] == 'text/xml' } };
382
+ # links = links.collect { |z| z[0].select { |k,v| k[/URL/] }.values[0] };
383
+ # # Get full text for an article
384
+ # res = Serrano.text(url: links[0]);
385
+ # res.url
386
+ # res.path
387
+ # res.type
388
+ # xml = res.parse()
389
+ # puts xml
390
+ # xml.xpath('//xocs:cover-date-text', xml.root.namespaces).text
391
+ #
392
+ # ## plain text
393
+ # # get full text links, here doing xml
394
+ # links = res[0]['message']['items'].collect { |x| x['link'].keep_if { |z| z['content-type'] == 'text/plain' } };
395
+ # links = links.collect { |z| z[0].select { |k,v| k[/URL/] }.values[0] };
396
+ # # Get full text for an article
397
+ # res = Serrano.text(url: links[0]);
398
+ # res.url
399
+ # res.parse
400
+ #
401
+ # # With open access content - using Pensoft
402
+ # res = Serrano.members(ids: 2258, works: true, filter: {has_full_text: true});
403
+ # links = res[0]['message']['items'].collect { |x| x['link'].keep_if { |z| z['content-type'] == 'application/xml' } };
404
+ # links = links.collect { |z| z[0].select { |k,v| k[/URL/] }.values[0] };
405
+ # # Get full text for an article
406
+ # res = Serrano.text(url: links[0]);
407
+ # res.url
408
+ # res.parse
409
+ def self.text(url:, type: 'xml')
410
+ Miner.new(url, type).perform
411
+ end
412
+
413
+ # Lookup article info via CrossRef with DOI and get a citation count
414
+ #
415
+ # @param doi [String] DOI, digital object identifier
416
+ # @param url [String] the API url for the function (should be left to default)
417
+ # @param key [String] your API key
418
+ #
419
+ # @see http://labs.crossref.org/openurl/ for more info on this Crossref API service.
420
+ #
421
+ # @example
422
+ # require 'serrano'
423
+ # Serrano.citation_count(doi: "10.1371/journal.pone.0042793")
424
+ # Serrano.citation_count(doi: "10.1016/j.fbr.2012.01.001")
425
+ # # DOI not found
426
+ # Serrano.citation_count(doi: "10.1016/j.fbr.2012")
427
+ def self.citation_count(doi:, url: "http://www.crossref.org/openurl/",
428
+ key: "cboettig@ropensci.org", options: nil)
429
+
430
+ args = { id: "doi:" + doi, pid: key, noredirect: true }
431
+ opts = args.delete_if { |k, v| v.nil? }
432
+ conn = Faraday.new(:url => url, :request => options)
433
+ res = conn.get '', opts
434
+ x = res.body
435
+ oc = REXML::Document.new("<doc>#{x}</doc>")
436
+ value = REXML::XPath.first(oc, '//query').attributes['fl_count'].to_i
437
+ return value
438
+ end
439
+
440
+ end