Top Level Namespace
Defined Under Namespace
Modules: Configuration, Faraday, Helpers, Serrano
Classes: Hash
Constant Summary
collapse
{"rdf-xml" => "application/rdf+xml",
"turtle" => "text/turtle",
"citeproc-json" => "transform/application/vnd.citationstyles.csl+json",
"text" => "text/x-bibliography",
"ris" => "application/x-research-info-systems",
"bibtex" => "application/x-bibtex",
"crossref-xml" => "application/vnd.crossref.unixref+xml",
"datacite-xml" => "application/vnd.datacite.datacite+xml",
"bibentry" => "application/x-bibtex",
"crossref-tdm" => "application/vnd.crossref.unixsd+xml"}.freeze
Instance Method Summary
collapse
Instance Method Details
#fetch_styles ⇒ Object
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
|
# File 'lib/serrano/styles.rb', line 6
def fetch_styles
base = "https://api.github.com/repos/citation-style-language/styles"
conn = Faraday.new(url: base) { |f|
f.use Faraday::Response::RaiseError
}
args = {per_page: 1}
tt = conn.get "commits", args
commres = MultiJson.load(tt.body)
sha = commres[0]["sha"]
sty = conn.get "git/trees/" + sha
res = MultiJson.load(sty.body)
files = res["tree"].collect { |x| x["path"] }
matches = files.collect { |x|
if x.match("csl").nil?
nil
else
x.match("csl").string
end
}
csls = matches.compact
csls.collect { |z| z.gsub(".csl", "") }
end
|
#field_query_handler(x) ⇒ Object
14
15
16
17
|
# File 'lib/serrano/utils.rb', line 14
def field_query_handler(x)
tmp = x.keep_if { |z| z.match(/query_/) }
rename_query_filters(tmp)
end
|
#make_request(conn, ids, format, style, locale) ⇒ Object
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
|
# File 'lib/serrano/cnrequest.rb', line 68
def make_request(conn, ids, format, style, locale)
type = CN_FORMAT_HEADERS.select { |x, _| x.include? format }.values[0]
if format == "citeproc-json"
endpt = "https://api.crossref.org/works/" + ids + "/" + type
cr_works = Faraday.new(url: endpt)
cr_works.[:user_agent] = make_ua
cr_works.["X-USER-AGENT"] = make_ua
res = cr_works.get
else
if format == "text"
type = type + "; style = " + style + "; locale = " + locale
end
res = conn.get { |req|
req.url ids
req.["Accept"] = type
req.[:user_agent] = make_ua
req.["X-USER-AGENT"] = make_ua
}
end
res.body if res.success?
end
|
#make_ua ⇒ Object
3
4
5
6
7
8
9
10
11
12
|
# File 'lib/serrano/utils.rb', line 3
def make_ua
requa = "Faraday/v" + Faraday::VERSION
habua = "Serrano/v" + Serrano::VERSION
ua = requa + " " + habua
if Serrano.mailto
ua += " (mailto:%s)" % Serrano.mailto
end
ua
end
|
#rename_query_filters(foo) ⇒ Object
19
20
21
22
23
|
# File 'lib/serrano/utils.rb', line 19
def rename_query_filters(foo)
foo = foo.tostrings
foo = foo.map { |x, y| [x.to_s.sub("container_title", "container-title"), y] }.to_h
foo.map { |x, y| [x.to_s.sub("query_", "query."), y] }.to_h
end
|