Class: Serrano::CNRequest

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

Overview

:nodoc:

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of CNRequest.



21
22
23
24
25
26
# File 'lib/serrano/cnrequest.rb', line 21

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.



17
18
19
# File 'lib/serrano/cnrequest.rb', line 17

def format
  @format
end

#idsObject

Returns the value of attribute ids.



16
17
18
# File 'lib/serrano/cnrequest.rb', line 16

def ids
  @ids
end

#localeObject

Returns the value of attribute locale.



19
20
21
# File 'lib/serrano/cnrequest.rb', line 19

def locale
  @locale
end

#styleObject

Returns the value of attribute style.



18
19
20
# File 'lib/serrano/cnrequest.rb', line 18

def style
  @style
end

Instance Method Details

#performObject



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/serrano/cnrequest.rb', line 28

def perform
  if !$cn_formats.include? self.format
    raise "format not one of accepted types"
  end

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

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