Class: OpenAccessReporter::Reporter

Inherits:
Object
  • Object
show all
Defined in:
lib/open_access_reporter/reporter.rb

Instance Method Summary collapse

Constructor Details

#initialize(email) ⇒ Reporter

Returns a new instance of Reporter.

Parameters:

  • email (String)

    Email for Unpaywall API

Raises:

  • (ArgumentError)


8
9
10
11
12
# File 'lib/open_access_reporter/reporter.rb', line 8

def initialize(email)
  raise ArgumentError, 'Unpaywall email not set' unless email && !email.empty?
  @email = email
  @http_client = HTTP::Client.new
end

Instance Method Details

#find(doi) ⇒ OpenAccessReporter::Report?

Find open access data for a research output (makes one Unpaywall API call, see documentation for restrictions)

Parameters:

Returns:



17
18
19
20
21
22
23
24
25
26
27
# File 'lib/open_access_reporter/reporter.rb', line 17

def find(doi)
  unpaywall_object = fetch(doi)
  return nil if unpaywall_object[:error] === true
  report = OpenAccessReporter::Report.new
  report.classification = classification unpaywall_object
  report.open = open? unpaywall_object
  report.license = license unpaywall_object
  report.modified_at = modified_at unpaywall_object
  report.title = title unpaywall_object
  report
end