crossrefapi 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: a0a8e0c79a1640c0924f60c8c583fc178e86911f3a7545f0dd4bfcd178cad9fe
4
+ data.tar.gz: e01aa77e9d3260f92d17344a4f9cf0bc5ab7483c6fb37b28f58bbae7416cff55
5
+ SHA512:
6
+ metadata.gz: fc4d62d8155aca0f974339c68018aceb67b89a1b7f49bacd081c94a4d77b6d7f7bec08b4dad3312b2ee53eb063d6bedffa77005b0d50e1e80212974d6d2cfaf8
7
+ data.tar.gz: 4ffcef5fff1cf305197f40e228a58d0a2f737e1da4db39eb485c2128b7842d9a94eff533df69ab16c442ca6d0b0c42619b41b289c723ac59bd6e52bf5322bce9
@@ -0,0 +1,53 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Crossrefapi
4
+ # Crossrefapi::Client
5
+ #
6
+ # This class serves as the main entry point for interacting with the CrossRef API. It delegates to
7
+ # the Crossrefapi::Works and Crossrefapi::Prefixes classes to provide access to the various endpoints
8
+ # available in the CrossRef API.
9
+ #
10
+ # For detailed API documentation, visit:
11
+ # https://api.crossref.org/swagger-ui/index.html#/
12
+ #
13
+ # Example usage:
14
+ #
15
+ # client = Crossrefapi::Client.new
16
+ # response = client.works.by_doi('10.2305/IUCN.UK.2016-1.RLTS.T56003281A22157381.en')
17
+ # pp response
18
+ #
19
+ class Client
20
+ API_BASE = "https://api.crossref.org/"
21
+
22
+ attr_reader :funders, :journals, :licenses, :members, :prefixes, :types, :works
23
+
24
+ def initialize
25
+ @connection = initialize_connection
26
+ @funders = Crossrefapi::Funders.new(self)
27
+ @journals = Crossrefapi::Journals.new(self)
28
+ @licenses = Crossrefapi::Licenses.new(self)
29
+ @members = Crossrefapi::Members.new(self)
30
+ @prefixes = Crossrefapi::Prefixes.new(self)
31
+ @types = Crossrefapi::Types.new(self)
32
+ @works = Crossrefapi::Works.new(self)
33
+ end
34
+
35
+ def get(endpoint, query = {})
36
+ response = @connection.get(endpoint, query)
37
+
38
+ if response.success?
39
+ response.body
40
+ else
41
+ "Error! Status: #{response.status} #{response.body}"
42
+ end
43
+ end
44
+
45
+ private
46
+
47
+ def initialize_connection
48
+ Faraday.new(url: API_BASE) do |connection|
49
+ connection.response :json
50
+ end
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,33 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Crossrefapi
4
+ # This class serves as the main entry point for interacting with the CrossRef API funders endpoints.
5
+ #
6
+ # For detailed API documentation, visit:
7
+ # https://api.crossref.org/swagger-ui/index.html#/Funders
8
+ #
9
+ # Example usage:
10
+ #
11
+ # client = Crossrefapi::Client.new
12
+ # query = { "query": "red+list" }
13
+ # response = client.funders.all(query)
14
+ # pp response
15
+ #
16
+ class Funders
17
+ def initialize(client)
18
+ @client = client
19
+ end
20
+
21
+ def all(query)
22
+ @client.get("funders", query)
23
+ end
24
+
25
+ def by_id(id)
26
+ @client.get("funders/#{id}")
27
+ end
28
+
29
+ def by_id_works(id, query = {})
30
+ @client.get("funders/#{id}/works", query)
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,33 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Crossrefapi
4
+ # This class serves as the main entry point for interacting with the CrossRef API journals endpoints.
5
+ #
6
+ # For detailed API documentation, visit:
7
+ # https://api.crossref.org/swagger-ui/index.html#/Journals
8
+ #
9
+ # Example usage:
10
+ #
11
+ # client = Crossrefapi::Client.new
12
+ # query = { "query": "red+list" }
13
+ # response = client.journals.all(query)
14
+ # pp response
15
+ #
16
+ class Journals
17
+ def initialize(client)
18
+ @client = client
19
+ end
20
+
21
+ def all(query)
22
+ @client.get("journals", query)
23
+ end
24
+
25
+ def by_issn(issn)
26
+ @client.get("journals/#{issn}")
27
+ end
28
+
29
+ def by_issn_works(issn, query = {})
30
+ @client.get("journals/#{issn}/works", query)
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Crossrefapi
4
+ # This class serves as the main entry point for interacting with the CrossRef API licences endpoints.
5
+ #
6
+ # For detailed API documentation, visit:
7
+ # https://api.crossref.org/swagger-ui/index.html#/Licenses
8
+ #
9
+ # Example usage:
10
+ #
11
+ # client = Crossrefapi::Client.new
12
+ # query = { "query": "red+list" }
13
+ # response = client.licenses.all(query)
14
+ # pp response
15
+ #
16
+ class Licenses
17
+ def initialize(client)
18
+ @client = client
19
+ end
20
+
21
+ def all(query)
22
+ @client.get("licenses", query)
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,33 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Crossrefapi
4
+ # This class serves as the main entry point for interacting with the CrossRef API members endpoints.
5
+ #
6
+ # For detailed API documentation, visit:
7
+ # https://api.crossref.org/swagger-ui/index.html#/Members
8
+ #
9
+ # Example usage:
10
+ #
11
+ # client = Crossrefapi::Client.new
12
+ # query = { "query": "red+list" }
13
+ # response = client.members.all(query)
14
+ # pp response
15
+ #
16
+ class Members
17
+ def initialize(client)
18
+ @client = client
19
+ end
20
+
21
+ def all(query)
22
+ @client.get("members", query)
23
+ end
24
+
25
+ def by_id(id)
26
+ @client.get("members/#{id}")
27
+ end
28
+
29
+ def by_id_works(id, query = {})
30
+ @client.get("members/#{id}/works", query)
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,33 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Crossrefapi
4
+ # This class serves as the main entry point for interacting with the CrossRef API prefixes endpoints.
5
+ #
6
+ # For detailed API documentation, visit:
7
+ # https://api.crossref.org/swagger-ui/index.html#/Prefixes/
8
+ #
9
+ # Example usage:
10
+
11
+ # client = Crossrefapi::Client.new
12
+ # response = client.prefixes.by_prefix('10.2305')
13
+ # pp response
14
+ #
15
+ # client = Crossrefapi::Client.new
16
+ # query = { 'query.container-title' => 'IUCN Red List of Threatened Species', 'offset' => '9980' }
17
+ # response = client.prefixes.by_prefix_works('10.2305', query)
18
+ # pp response
19
+ #
20
+ class Prefixes
21
+ def initialize(client)
22
+ @client = client
23
+ end
24
+
25
+ def by_prefix(prefix)
26
+ @client.get("prefixes/#{prefix}")
27
+ end
28
+
29
+ def by_prefix_works(prefix, query = {})
30
+ @client.get("prefixes/#{prefix}/works", query)
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,33 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Crossrefapi
4
+ # This class serves as the main entry point for interacting with the CrossRef API types endpoints.
5
+ #
6
+ # For detailed API documentation, visit:
7
+ # https://api.crossref.org/swagger-ui/index.html#/Types
8
+ #
9
+ # Example usage:
10
+ #
11
+ # client = Crossrefapi::Client.new
12
+ # query = { "query": "red+list" }
13
+ # response = client.types.all(query)
14
+ # pp response
15
+ #
16
+ class Types
17
+ def initialize(client)
18
+ @client = client
19
+ end
20
+
21
+ def all(query)
22
+ @client.get("types", query)
23
+ end
24
+
25
+ def by_id(id)
26
+ @client.get("types/#{id}")
27
+ end
28
+
29
+ def by_id_works(id, query = {})
30
+ @client.get("types/#{id}/works", query)
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Crossrefapi
4
+ VERSION = "0.1.0"
5
+ end
@@ -0,0 +1,32 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Crossrefapi
4
+ # This class serves as the main entry point for interacting with the CrossRef API prefixes endpoints.
5
+ #
6
+ # For detailed API documentation, visit:
7
+ # https://api.crossref.org/swagger-ui/index.html#/Works
8
+ #
9
+ # Example usage:
10
+ #
11
+ # client = Crossrefapi::Client.new
12
+ # response = client.works.by_doi('10.2305/IUCN.UK.2016-1.RLTS.T56003281A22157381.en')
13
+ # pp response
14
+ #
15
+ class Works
16
+ def initialize(client)
17
+ @client = client
18
+ end
19
+
20
+ def all(query)
21
+ @client.get("works", query)
22
+ end
23
+
24
+ def by_doi(doi)
25
+ @client.get("works/#{doi}")
26
+ end
27
+
28
+ def by_doi_agency(doi)
29
+ @client.get("works/#{doi}/agency")
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "net/http"
4
+ require "faraday"
5
+ require "json"
6
+
7
+ require_relative "crossrefapi/client"
8
+ require_relative "crossrefapi/funders"
9
+ require_relative "crossrefapi/journals"
10
+ require_relative "crossrefapi/licenses"
11
+ require_relative "crossrefapi/members"
12
+ require_relative "crossrefapi/prefixes"
13
+ require_relative "crossrefapi/types"
14
+ require_relative "crossrefapi/version"
15
+ require_relative "crossrefapi/works"
16
+
17
+ module Crossrefapi
18
+ class Error < StandardError; end
19
+ end
metadata ADDED
@@ -0,0 +1,74 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: crossrefapi
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Simon Tarr
8
+ - Miguel Torres
9
+ - Ian Townsend
10
+ autorequire:
11
+ bindir: exe
12
+ cert_chain: []
13
+ date: 2025-03-21 00:00:00.000000000 Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: faraday
17
+ requirement: !ruby/object:Gem::Requirement
18
+ requirements:
19
+ - - ">="
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ requirements:
26
+ - - ">="
27
+ - !ruby/object:Gem::Version
28
+ version: '0'
29
+ description: This gem provides a simple interface to interact with the CrossRef API.
30
+ It allows users to search for works, retrieve metadata by DOI, and access citation
31
+ information, helping to integrate scholarly data into Ruby applications.
32
+ email:
33
+ - conservation.informatics@iucn.org
34
+ executables: []
35
+ extensions: []
36
+ extra_rdoc_files: []
37
+ files:
38
+ - lib/crossrefapi.rb
39
+ - lib/crossrefapi/client.rb
40
+ - lib/crossrefapi/funders.rb
41
+ - lib/crossrefapi/journals.rb
42
+ - lib/crossrefapi/licenses.rb
43
+ - lib/crossrefapi/members.rb
44
+ - lib/crossrefapi/prefixes.rb
45
+ - lib/crossrefapi/types.rb
46
+ - lib/crossrefapi/version.rb
47
+ - lib/crossrefapi/works.rb
48
+ homepage: https://github.com/IUCN-UK/crossrefapi
49
+ licenses:
50
+ - MIT
51
+ metadata:
52
+ allowed_push_host: https://rubygems.org
53
+ homepage_uri: https://github.com/IUCN-UK/crossrefapi
54
+ post_install_message:
55
+ rdoc_options: []
56
+ require_paths:
57
+ - lib
58
+ required_ruby_version: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - ">="
61
+ - !ruby/object:Gem::Version
62
+ version: 3.0.0
63
+ required_rubygems_version: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - ">="
66
+ - !ruby/object:Gem::Version
67
+ version: '0'
68
+ requirements: []
69
+ rubygems_version: 3.5.16
70
+ signing_key:
71
+ specification_version: 4
72
+ summary: A Ruby Gem that wraps the CrossRef API for fetching metadata and DOI-related
73
+ information.
74
+ test_files: []