serrano 0.0.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +36 -0
- data/.travis.yml +4 -0
- data/CONDUCT.md +25 -0
- data/Gemfile +3 -0
- data/Gemfile.lock +56 -0
- data/LICENSE +7 -0
- data/NEWS.md +3 -0
- data/README.md +128 -0
- data/Rakefile +41 -0
- data/lib/serrano.rb +440 -0
- data/lib/serrano/cn.rb +30 -0
- data/lib/serrano/cnrequest.rb +83 -0
- data/lib/serrano/constants.rb +36 -0
- data/lib/serrano/errors.rb +67 -0
- data/lib/serrano/filterhandler.rb +58 -0
- data/lib/serrano/filters.rb +84 -0
- data/lib/serrano/helpers/configuration.rb +26 -0
- data/lib/serrano/mine_utils.rb +65 -0
- data/lib/serrano/mined.rb +31 -0
- data/lib/serrano/miner.rb +42 -0
- data/lib/serrano/request.rb +99 -0
- data/lib/serrano/version.rb +3 -0
- data/serrano.gemspec +35 -0
- metadata +253 -0
@@ -0,0 +1,31 @@
|
|
1
|
+
require "nokogiri"
|
2
|
+
|
3
|
+
##
|
4
|
+
# Serrano::Mined
|
5
|
+
#
|
6
|
+
# Class to give back text mining object
|
7
|
+
module Serrano
|
8
|
+
class Mined #:nodoc:
|
9
|
+
attr_accessor :url
|
10
|
+
attr_accessor :path
|
11
|
+
attr_accessor :type
|
12
|
+
|
13
|
+
def initialize(url, path, type)
|
14
|
+
self.url = url
|
15
|
+
self.path = path
|
16
|
+
self.type = type
|
17
|
+
end
|
18
|
+
|
19
|
+
def parse
|
20
|
+
case self.type
|
21
|
+
when 'xml'
|
22
|
+
parse_xml(self.path)
|
23
|
+
when 'plain'
|
24
|
+
parse_plain(self.path)
|
25
|
+
when 'pdf'
|
26
|
+
parse_pdf(self.path)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
require "faraday"
|
2
|
+
require "multi_json"
|
3
|
+
require "serrano/errors"
|
4
|
+
require "serrano/constants"
|
5
|
+
require 'serrano/helpers/configuration'
|
6
|
+
require 'serrano/mined'
|
7
|
+
require 'serrano/mine_utils'
|
8
|
+
|
9
|
+
##
|
10
|
+
# Serrano::Miner
|
11
|
+
#
|
12
|
+
# Class to give back text mining object
|
13
|
+
module Serrano
|
14
|
+
class Miner #:nodoc:
|
15
|
+
attr_accessor :url
|
16
|
+
attr_accessor :type
|
17
|
+
|
18
|
+
def initialize(url, type)
|
19
|
+
self.url = url
|
20
|
+
self.type = type
|
21
|
+
end
|
22
|
+
|
23
|
+
def perform
|
24
|
+
conn = Faraday.new(:url => self.url)
|
25
|
+
|
26
|
+
if is_elsevier(self.url)
|
27
|
+
res = conn.get do |req|
|
28
|
+
req.headers['X-ELS-APIKey'] = Serrano.elsevier_key
|
29
|
+
end
|
30
|
+
else
|
31
|
+
res = conn.get
|
32
|
+
end
|
33
|
+
|
34
|
+
type = detect_type(res)
|
35
|
+
path = make_path(type)
|
36
|
+
write_disk(res, path)
|
37
|
+
|
38
|
+
return Mined.new(self.url, path, type)
|
39
|
+
end
|
40
|
+
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,99 @@
|
|
1
|
+
require "faraday"
|
2
|
+
require "multi_json"
|
3
|
+
require "serrano/errors"
|
4
|
+
require "serrano/constants"
|
5
|
+
require 'serrano/helpers/configuration'
|
6
|
+
|
7
|
+
##
|
8
|
+
# Serrano::Request
|
9
|
+
#
|
10
|
+
# Class to perform HTTP requests to the Crossref API
|
11
|
+
module Serrano
|
12
|
+
class Request #:nodoc:
|
13
|
+
|
14
|
+
attr_accessor :endpt
|
15
|
+
attr_accessor :id
|
16
|
+
attr_accessor :query
|
17
|
+
attr_accessor :filter
|
18
|
+
attr_accessor :offset
|
19
|
+
attr_accessor :limit
|
20
|
+
attr_accessor :sample
|
21
|
+
attr_accessor :sort
|
22
|
+
attr_accessor :order
|
23
|
+
attr_accessor :facet
|
24
|
+
attr_accessor :works
|
25
|
+
attr_accessor :agency
|
26
|
+
attr_accessor :options
|
27
|
+
attr_accessor :verbose
|
28
|
+
|
29
|
+
def initialize(endpt, id, query, filter, offset,
|
30
|
+
limit, sample, sort, order, facet, works, agency,
|
31
|
+
options, verbose)
|
32
|
+
|
33
|
+
self.endpt = endpt
|
34
|
+
self.id = id
|
35
|
+
self.query = query
|
36
|
+
self.filter = filter
|
37
|
+
self.offset = offset
|
38
|
+
self.limit = limit
|
39
|
+
self.sample = sample
|
40
|
+
self.sort = sort
|
41
|
+
self.order = order
|
42
|
+
self.facet = facet
|
43
|
+
self.works = works
|
44
|
+
self.agency = agency
|
45
|
+
self.options = options
|
46
|
+
self.verbose = verbose
|
47
|
+
end
|
48
|
+
|
49
|
+
def perform
|
50
|
+
filt = filter_handler(self.filter)
|
51
|
+
|
52
|
+
args = { query: self.query, filter: filt, offset: self.offset,
|
53
|
+
rows: self.limit, sample: self.sample, sort: self.sort,
|
54
|
+
order: self.order, facet: self.facet }
|
55
|
+
opts = args.delete_if { |k, v| v.nil? }
|
56
|
+
|
57
|
+
if verbose
|
58
|
+
conn = Faraday.new(:url => Serrano.base_url, :request => options) do |f|
|
59
|
+
f.response :logger
|
60
|
+
f.adapter Faraday.default_adapter
|
61
|
+
end
|
62
|
+
else
|
63
|
+
conn = Faraday.new(:url => Serrano.base_url, :request => options)
|
64
|
+
end
|
65
|
+
|
66
|
+
if self.id.nil?
|
67
|
+
# begin
|
68
|
+
res = conn.get self.endpt, opts
|
69
|
+
return MultiJson.load(res.body)
|
70
|
+
# rescue *NETWORKABLE_EXCEPTIONS => e
|
71
|
+
# rescue_faraday_error(endpt, e)
|
72
|
+
# end
|
73
|
+
else
|
74
|
+
coll = []
|
75
|
+
Array(self.id).each do |x|
|
76
|
+
if self.works
|
77
|
+
endpt = self.endpt + '/' + x.to_s + "/works"
|
78
|
+
else
|
79
|
+
if self.agency
|
80
|
+
endpt = self.endpt + '/' + x.to_s + "/agency"
|
81
|
+
else
|
82
|
+
endpt = self.endpt + '/' + x.to_s
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
res = conn.get endpt, opts
|
87
|
+
coll << MultiJson.load(res.body)
|
88
|
+
# begin
|
89
|
+
# res = conn.get endpt, opts
|
90
|
+
# coll << MultiJson.load(res.body)
|
91
|
+
# rescue *NETWORKABLE_EXCEPTIONS => e
|
92
|
+
# rescue_faraday_error(endpt, e)
|
93
|
+
# end
|
94
|
+
end
|
95
|
+
return coll
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
data/serrano.gemspec
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'serrano/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = 'serrano'
|
8
|
+
s.version = Serrano::VERSION
|
9
|
+
s.platform = Gem::Platform::RUBY
|
10
|
+
s.required_ruby_version = '>= 2.0'
|
11
|
+
s.date = '2015-11-04'
|
12
|
+
s.summary = "Crossref Client"
|
13
|
+
s.description = "Low Level Ruby Client for the Crossref Search API"
|
14
|
+
s.authors = "Scott Chamberlain"
|
15
|
+
s.email = 'myrmecocystus@gmail.com'
|
16
|
+
s.homepage = 'http://github.com/sckott/serrano'
|
17
|
+
s.licenses = 'MIT'
|
18
|
+
|
19
|
+
s.files = `git ls-files -z`.split("\x0").reject {|f| f.match(%r{^(test|spec|features)/}) }
|
20
|
+
s.require_paths = ["lib"]
|
21
|
+
|
22
|
+
s.add_development_dependency "bundler", '~> 1.6'
|
23
|
+
s.add_development_dependency "rake", '~> 10.4'
|
24
|
+
s.add_development_dependency "test-unit", '~> 3.1'
|
25
|
+
s.add_development_dependency "simplecov", '~> 0.10'
|
26
|
+
s.add_development_dependency "codecov", '~> 0.1'
|
27
|
+
s.add_development_dependency 'json', '~> 1.8', '>= 1.8.3'
|
28
|
+
|
29
|
+
s.add_runtime_dependency 'faraday', '~> 0.9.1'
|
30
|
+
s.add_runtime_dependency 'faraday_middleware', '~> 0.10.0'
|
31
|
+
s.add_runtime_dependency 'thor', '~> 0.19'
|
32
|
+
s.add_runtime_dependency 'multi_json', '~> 1.0'
|
33
|
+
s.add_runtime_dependency 'nokogiri', '~> 1.6', '>= 1.6.6.2'
|
34
|
+
s.add_runtime_dependency 'uuidtools', '~> 2.1', '>= 2.1.5'
|
35
|
+
end
|
metadata
ADDED
@@ -0,0 +1,253 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: serrano
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.7
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Scott Chamberlain
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-11-04 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.6'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.6'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.4'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.4'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: test-unit
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.1'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.1'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: simplecov
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0.10'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0.10'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: codecov
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0.1'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0.1'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: json
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '1.8'
|
90
|
+
- - ">="
|
91
|
+
- !ruby/object:Gem::Version
|
92
|
+
version: 1.8.3
|
93
|
+
type: :development
|
94
|
+
prerelease: false
|
95
|
+
version_requirements: !ruby/object:Gem::Requirement
|
96
|
+
requirements:
|
97
|
+
- - "~>"
|
98
|
+
- !ruby/object:Gem::Version
|
99
|
+
version: '1.8'
|
100
|
+
- - ">="
|
101
|
+
- !ruby/object:Gem::Version
|
102
|
+
version: 1.8.3
|
103
|
+
- !ruby/object:Gem::Dependency
|
104
|
+
name: faraday
|
105
|
+
requirement: !ruby/object:Gem::Requirement
|
106
|
+
requirements:
|
107
|
+
- - "~>"
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: 0.9.1
|
110
|
+
type: :runtime
|
111
|
+
prerelease: false
|
112
|
+
version_requirements: !ruby/object:Gem::Requirement
|
113
|
+
requirements:
|
114
|
+
- - "~>"
|
115
|
+
- !ruby/object:Gem::Version
|
116
|
+
version: 0.9.1
|
117
|
+
- !ruby/object:Gem::Dependency
|
118
|
+
name: faraday_middleware
|
119
|
+
requirement: !ruby/object:Gem::Requirement
|
120
|
+
requirements:
|
121
|
+
- - "~>"
|
122
|
+
- !ruby/object:Gem::Version
|
123
|
+
version: 0.10.0
|
124
|
+
type: :runtime
|
125
|
+
prerelease: false
|
126
|
+
version_requirements: !ruby/object:Gem::Requirement
|
127
|
+
requirements:
|
128
|
+
- - "~>"
|
129
|
+
- !ruby/object:Gem::Version
|
130
|
+
version: 0.10.0
|
131
|
+
- !ruby/object:Gem::Dependency
|
132
|
+
name: thor
|
133
|
+
requirement: !ruby/object:Gem::Requirement
|
134
|
+
requirements:
|
135
|
+
- - "~>"
|
136
|
+
- !ruby/object:Gem::Version
|
137
|
+
version: '0.19'
|
138
|
+
type: :runtime
|
139
|
+
prerelease: false
|
140
|
+
version_requirements: !ruby/object:Gem::Requirement
|
141
|
+
requirements:
|
142
|
+
- - "~>"
|
143
|
+
- !ruby/object:Gem::Version
|
144
|
+
version: '0.19'
|
145
|
+
- !ruby/object:Gem::Dependency
|
146
|
+
name: multi_json
|
147
|
+
requirement: !ruby/object:Gem::Requirement
|
148
|
+
requirements:
|
149
|
+
- - "~>"
|
150
|
+
- !ruby/object:Gem::Version
|
151
|
+
version: '1.0'
|
152
|
+
type: :runtime
|
153
|
+
prerelease: false
|
154
|
+
version_requirements: !ruby/object:Gem::Requirement
|
155
|
+
requirements:
|
156
|
+
- - "~>"
|
157
|
+
- !ruby/object:Gem::Version
|
158
|
+
version: '1.0'
|
159
|
+
- !ruby/object:Gem::Dependency
|
160
|
+
name: nokogiri
|
161
|
+
requirement: !ruby/object:Gem::Requirement
|
162
|
+
requirements:
|
163
|
+
- - "~>"
|
164
|
+
- !ruby/object:Gem::Version
|
165
|
+
version: '1.6'
|
166
|
+
- - ">="
|
167
|
+
- !ruby/object:Gem::Version
|
168
|
+
version: 1.6.6.2
|
169
|
+
type: :runtime
|
170
|
+
prerelease: false
|
171
|
+
version_requirements: !ruby/object:Gem::Requirement
|
172
|
+
requirements:
|
173
|
+
- - "~>"
|
174
|
+
- !ruby/object:Gem::Version
|
175
|
+
version: '1.6'
|
176
|
+
- - ">="
|
177
|
+
- !ruby/object:Gem::Version
|
178
|
+
version: 1.6.6.2
|
179
|
+
- !ruby/object:Gem::Dependency
|
180
|
+
name: uuidtools
|
181
|
+
requirement: !ruby/object:Gem::Requirement
|
182
|
+
requirements:
|
183
|
+
- - "~>"
|
184
|
+
- !ruby/object:Gem::Version
|
185
|
+
version: '2.1'
|
186
|
+
- - ">="
|
187
|
+
- !ruby/object:Gem::Version
|
188
|
+
version: 2.1.5
|
189
|
+
type: :runtime
|
190
|
+
prerelease: false
|
191
|
+
version_requirements: !ruby/object:Gem::Requirement
|
192
|
+
requirements:
|
193
|
+
- - "~>"
|
194
|
+
- !ruby/object:Gem::Version
|
195
|
+
version: '2.1'
|
196
|
+
- - ">="
|
197
|
+
- !ruby/object:Gem::Version
|
198
|
+
version: 2.1.5
|
199
|
+
description: Low Level Ruby Client for the Crossref Search API
|
200
|
+
email: myrmecocystus@gmail.com
|
201
|
+
executables: []
|
202
|
+
extensions: []
|
203
|
+
extra_rdoc_files: []
|
204
|
+
files:
|
205
|
+
- ".gitignore"
|
206
|
+
- ".travis.yml"
|
207
|
+
- CONDUCT.md
|
208
|
+
- Gemfile
|
209
|
+
- Gemfile.lock
|
210
|
+
- LICENSE
|
211
|
+
- NEWS.md
|
212
|
+
- README.md
|
213
|
+
- Rakefile
|
214
|
+
- lib/serrano.rb
|
215
|
+
- lib/serrano/cn.rb
|
216
|
+
- lib/serrano/cnrequest.rb
|
217
|
+
- lib/serrano/constants.rb
|
218
|
+
- lib/serrano/errors.rb
|
219
|
+
- lib/serrano/filterhandler.rb
|
220
|
+
- lib/serrano/filters.rb
|
221
|
+
- lib/serrano/helpers/configuration.rb
|
222
|
+
- lib/serrano/mine_utils.rb
|
223
|
+
- lib/serrano/mined.rb
|
224
|
+
- lib/serrano/miner.rb
|
225
|
+
- lib/serrano/request.rb
|
226
|
+
- lib/serrano/version.rb
|
227
|
+
- serrano.gemspec
|
228
|
+
homepage: http://github.com/sckott/serrano
|
229
|
+
licenses:
|
230
|
+
- MIT
|
231
|
+
metadata: {}
|
232
|
+
post_install_message:
|
233
|
+
rdoc_options: []
|
234
|
+
require_paths:
|
235
|
+
- lib
|
236
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
237
|
+
requirements:
|
238
|
+
- - ">="
|
239
|
+
- !ruby/object:Gem::Version
|
240
|
+
version: '2.0'
|
241
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
242
|
+
requirements:
|
243
|
+
- - ">="
|
244
|
+
- !ruby/object:Gem::Version
|
245
|
+
version: '0'
|
246
|
+
requirements: []
|
247
|
+
rubyforge_project:
|
248
|
+
rubygems_version: 2.4.5.1
|
249
|
+
signing_key:
|
250
|
+
specification_version: 4
|
251
|
+
summary: Crossref Client
|
252
|
+
test_files: []
|
253
|
+
has_rdoc:
|