Class: Serrano::CNRequest

Inherits:
Object
  • Object
show all
Defined in:
lib/serrano/cnrequest.rb

Overview

:nodoc:

Constant Summary collapse

CN_FORMATS =
%w[rdf-xml turtle citeproc-json
citeproc-json-ish text ris bibtex
crossref-xml datacite-xml bibentry
crossref-tdm].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(ids, format, style, locale) ⇒ CNRequest

Returns a new instance of CNRequest.



37
38
39
40
41
42
# File 'lib/serrano/cnrequest.rb', line 37

def initialize(ids, format, style, locale)
  self.ids = ids
  self.format = format
  self.style = style
  self.locale = locale
end

Instance Attribute Details

#formatObject

Returns the value of attribute format.



28
29
30
# File 'lib/serrano/cnrequest.rb', line 28

def format
  @format
end

#idsObject

Returns the value of attribute ids.



27
28
29
# File 'lib/serrano/cnrequest.rb', line 27

def ids
  @ids
end

#localeObject

Returns the value of attribute locale.



30
31
32
# File 'lib/serrano/cnrequest.rb', line 30

def locale
  @locale
end

#styleObject

Returns the value of attribute style.



29
30
31
# File 'lib/serrano/cnrequest.rb', line 29

def style
  @style
end

Instance Method Details

#performObject



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/serrano/cnrequest.rb', line 44

def perform
  unless CN_FORMATS.include? format
    raise "format not one of accepted types"
  end

  conn = Faraday.new "https://doi.org/" do |c|
    c.use Faraday::FollowRedirects::Middleware
    c.adapter :net_http
  end

  if ids.length == 1
    self.ids = ids[0] if ids.instance_of?(Array)
    make_request(conn, ids, format, style, locale)
  else
    coll = []
    Array(ids).each do |x|
      coll << make_request(conn, x, format, style, locale)
    end
    coll
  end
end