class Object
Constants
- CN_FORMAT_HEADERS
Public Instance Methods
fetch_styles()
click to toggle source
# 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 FaradayMiddleware::RaiseHttpException f.adapter Faraday.default_adapter } 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)
click to toggle source
# 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)
click to toggle source
# 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.headers[:user_agent] = make_ua cr_works.headers["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.headers["Accept"] = type req.headers[:user_agent] = make_ua req.headers["X-USER-AGENT"] = make_ua } end res.body end
make_ua()
click to toggle source
# 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 += format(' (mailto:%s)', Serrano.mailto) if Serrano.mailto ua end
rename_query_filters(foo)
click to toggle source
# 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