Class: Serrano::CNRequest
- Inherits:
-
Object
- Object
- Serrano::CNRequest
- Defined in:
- lib/serrano/cnrequest.rb
Overview
:nodoc:
Instance Attribute Summary collapse
-
#format ⇒ Object
Returns the value of attribute format.
-
#ids ⇒ Object
Returns the value of attribute ids.
-
#locale ⇒ Object
Returns the value of attribute locale.
-
#style ⇒ Object
Returns the value of attribute style.
Instance Method Summary collapse
-
#initialize(ids, format, style, locale) ⇒ CNRequest
constructor
A new instance of CNRequest.
- #perform ⇒ Object
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
#format ⇒ Object
Returns the value of attribute format.
17 18 19 |
# File 'lib/serrano/cnrequest.rb', line 17 def format @format end |
#ids ⇒ Object
Returns the value of attribute ids.
16 17 18 |
# File 'lib/serrano/cnrequest.rb', line 16 def ids @ids end |
#locale ⇒ Object
Returns the value of attribute locale.
19 20 21 |
# File 'lib/serrano/cnrequest.rb', line 19 def locale @locale end |
#style ⇒ Object
Returns the value of attribute style.
18 19 20 |
# File 'lib/serrano/cnrequest.rb', line 18 def style @style end |
Instance Method Details
#perform ⇒ Object
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 |