serrano 0.5.0 → 0.5.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -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
-