serrano 0.5.0 → 0.5.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +2 -0
- data/.rubocop.yml +14 -0
- data/.rubocop_todo.yml +122 -0
- data/.travis.yml +7 -3
- data/CHANGELOG.md +5 -0
- data/Gemfile +2 -0
- data/Gemfile.lock +42 -26
- data/LICENSE +1 -1
- data/README.md +5 -0
- data/Rakefile +25 -18
- data/bin/serrano +96 -98
- data/lib/serrano.rb +112 -85
- data/lib/serrano/cn.rb +6 -8
- data/lib/serrano/cnrequest.rb +41 -27
- data/lib/serrano/error.rb +2 -0
- data/lib/serrano/faraday.rb +15 -14
- data/lib/serrano/filterhandler.rb +13 -15
- data/lib/serrano/filters.rb +72 -70
- data/lib/serrano/helpers/configuration.rb +2 -2
- data/lib/serrano/request.rb +41 -39
- data/lib/serrano/request_cursor.rb +62 -61
- data/lib/serrano/styles.rb +14 -9
- data/lib/serrano/utils.rb +16 -13
- data/lib/serrano/version.rb +3 -1
- data/serrano.gemspec +19 -17
- metadata +77 -52
- data/lib/serrano/constants.rb +0 -36
- data/lib/serrano/cursor_testing.rb +0 -52
data/lib/serrano/constants.rb
DELETED
@@ -1,36 +0,0 @@
|
|
1
|
-
require 'net/http'
|
2
|
-
|
3
|
-
NETWORKABLE_EXCEPTIONS = [Faraday::Error::ClientError,
|
4
|
-
URI::InvalidURIError,
|
5
|
-
Encoding::UndefinedConversionError,
|
6
|
-
ArgumentError,
|
7
|
-
NoMethodError,
|
8
|
-
TypeError]
|
9
|
-
|
10
|
-
$cn_formats = ["rdf-xml", "turtle", "citeproc-json",
|
11
|
-
"citeproc-json-ish", "text", "ris", "bibtex",
|
12
|
-
"crossref-xml", "datacite-xml", "bibentry",
|
13
|
-
"crossref-tdm"]
|
14
|
-
|
15
|
-
$cn_format_headers = {"rdf-xml" => "application/rdf+xml",
|
16
|
-
"turtle" => "text/turtle",
|
17
|
-
"citeproc-json" => "transform/application/vnd.citationstyles.csl+json",
|
18
|
-
"text" => "text/x-bibliography",
|
19
|
-
"ris" => "application/x-research-info-systems",
|
20
|
-
"bibtex" => "application/x-bibtex",
|
21
|
-
"crossref-xml" => "application/vnd.crossref.unixref+xml",
|
22
|
-
"datacite-xml" => "application/vnd.datacite.datacite+xml",
|
23
|
-
"bibentry" => "application/x-bibtex",
|
24
|
-
"crossref-tdm" => "application/vnd.crossref.unixsd+xml"}
|
25
|
-
|
26
|
-
$cn_types = {"rdf-xml" => "text/xml",
|
27
|
-
"turtle" => "text/plain",
|
28
|
-
"citeproc-json" => "application/json",
|
29
|
-
"citeproc-json-ish" => "application/json",
|
30
|
-
"text" => "text/plain",
|
31
|
-
"ris" => "text/plain",
|
32
|
-
"bibtex" => "text/plain",
|
33
|
-
"crossref-xml" => "text/xml",
|
34
|
-
"datacite-xml" => "text/xml",
|
35
|
-
"bibentry" => "text/plain",
|
36
|
-
"crossref-tdm" => "text/xml"}
|
@@ -1,52 +0,0 @@
|
|
1
|
-
require 'faraday'
|
2
|
-
require "multi_json"
|
3
|
-
|
4
|
-
query = "widget"
|
5
|
-
cursor = "*"
|
6
|
-
limit = 100
|
7
|
-
cursor_max = 500
|
8
|
-
rows = limit
|
9
|
-
|
10
|
-
filter = nil
|
11
|
-
offset = nil
|
12
|
-
sample = nil
|
13
|
-
sort = nil
|
14
|
-
order = nil
|
15
|
-
facet = nil
|
16
|
-
|
17
|
-
args = { query: query, filter: filter, offset: offset,
|
18
|
-
rows: limit, sample: sample, sort: sort,
|
19
|
-
order: order, facet: facet, cursor: cursor }
|
20
|
-
opts = args.delete_if { |k, v| v.nil? }
|
21
|
-
|
22
|
-
conn = Faraday.new(:url => "http://api.crossref.org/", :request => nil)
|
23
|
-
|
24
|
-
def _req(conn, path, opts)
|
25
|
-
res = conn.get path, opts
|
26
|
-
return MultiJson.load(res.body)
|
27
|
-
end
|
28
|
-
|
29
|
-
def _redo_req(conn, path, js, opts, cu, max_avail, cursor_max)
|
30
|
-
if !cu.nil? and cursor_max > js['message']['items'].length
|
31
|
-
res = [js]
|
32
|
-
total = js['message']['items'].length
|
33
|
-
while (!cu.nil? and cursor_max > total and total < max_avail)
|
34
|
-
opts[:cursor] = cu
|
35
|
-
out = _req(conn, path, opts)
|
36
|
-
cu = out['message']['next-cursor']
|
37
|
-
res << out
|
38
|
-
total = res.collect { |x| x['message']['items'].length }.inject(:+)
|
39
|
-
end
|
40
|
-
return res
|
41
|
-
else
|
42
|
-
return js
|
43
|
-
end
|
44
|
-
end
|
45
|
-
|
46
|
-
path = 'works'
|
47
|
-
|
48
|
-
js = _req(conn, path, opts)
|
49
|
-
cu = js['message']['next-cursor']
|
50
|
-
max_avail = js['message']['total-results']
|
51
|
-
res = _redo_req(conn, path, js, opts, cu, max_avail, cursor_max)
|
52
|
-
|