Class: Crossrefapi::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/crossrefapi/client.rb

Overview

Crossrefapi::Client

This class serves as the main entry point for interacting with the CrossRef API. It delegates to the Crossrefapi::Works and Crossrefapi::Prefixes classes to provide access to the various endpoints available in the CrossRef API.

For detailed API documentation, visit: api.crossref.org/swagger-ui/index.html#/

Example usage:

client = Crossrefapi::Client.new
response = client.works.by_doi('10.2305/IUCN.UK.2016-1.RLTS.T56003281A22157381.en')
pp response

Constant Summary collapse

API_BASE =
"https://api.crossref.org/"
RESOURCES =
%w[funders journals licenses members prefixes types works].freeze

Instance Method Summary collapse

Constructor Details

#initializeClient

Returns a new instance of Client.



24
25
26
# File 'lib/crossrefapi/client.rb', line 24

def initialize
  @connection = initialize_connection
end

Instance Method Details

#get(endpoint, query = {}) ⇒ Object



34
35
36
37
38
39
40
41
42
# File 'lib/crossrefapi/client.rb', line 34

def get(endpoint, query = {})
  response = @connection.get(endpoint, query)

  if response.success?
    response.body
  else
    "Error! Status: #{response.status} #{response.body}"
  end
end