open_access_reporter 0.2.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: c25d9482db9a4c05de39c6026b679040dd6c1e9a2aa9153752a0808bb2132b72
4
+ data.tar.gz: 141b2a753f43400b3dbb1c018e45c6fa02b135958d0006dec8fd0c2af15c62a5
5
+ SHA512:
6
+ metadata.gz: c85f4a1acc439653201f048a60a58127c321555413fc6587223618cb178bc36f0583959561523ce88b4b4a92334bb289e2fd522aafc561e6cf8c08d813194520
7
+ data.tar.gz: 50aa91f8703abe2aecafcc59e5ac51acb854eb35e638f8d18a9a6388e6524dfd8b71c1c50f4b24da0bdd9d236f5a8bfbe0144281fe8fcc85ad386a1c2d027883
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+ .idea
data/CHANGELOG.md ADDED
@@ -0,0 +1,11 @@
1
+ # Change Log
2
+ All notable changes to this project will be documented in this file.
3
+ This project adheres to [Semantic Versioning](http://semver.org/).
4
+
5
+ ## 0.2.0 - 2019-01-08
6
+ ### Added
7
+ - Bump for documentation.
8
+
9
+ ## 0.1.0 - 2019-01-08
10
+ ### Added
11
+ - Working product finds salient Open Access data and derives a classification for a research output with a DOI.
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in open_access_reporter.gemspec
6
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2019 Adrian Albin-Clark
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,50 @@
1
+ # Open Access Reporter
2
+
3
+ Find salient Open Access data and derive a classification for a research output with a DOI.
4
+
5
+ ## Status
6
+
7
+ [![Gem Version](https://badge.fury.io/rb/open_access_reporter.svg)](https://badge.fury.io/rb/open_access_reporter)
8
+ [![Maintainability](https://api.codeclimate.com/v1/badges/f05eda4aa8b19c3d232c/maintainability)](https://codeclimate.com/github/lulibrary/open_access_reporter/maintainability)
9
+
10
+ ## Installation
11
+
12
+ Add this line to your application's Gemfile:
13
+
14
+ ```ruby
15
+ gem 'open_access_reporter'
16
+ ```
17
+
18
+ And then execute:
19
+
20
+ $ bundle
21
+
22
+ Or install it yourself as:
23
+
24
+ $ gem install open_access_reporter
25
+
26
+ ## Usage
27
+
28
+ ### Configuration
29
+ ```ruby
30
+ reporter = OpenAccessReporter::Reporter.new 'YOUR_EMAIL'
31
+ ```
32
+
33
+ ### Find
34
+ ```ruby
35
+ report = reporter.find '10.1234/foo'
36
+ #=> #<OpenAccessReporter::Report:0x00c0ffee>
37
+
38
+ report.open?
39
+ #=> true
40
+
41
+ report.classification
42
+ #=> "gold"
43
+
44
+ report.license
45
+ #=> "cc-by"
46
+ ```
47
+
48
+ ## License
49
+
50
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
@@ -0,0 +1,5 @@
1
+ require "open_access_reporter/report"
2
+ require "open_access_reporter/reporter"
3
+
4
+ module OpenAccessReporter
5
+ end
@@ -0,0 +1,24 @@
1
+ module OpenAccessReporter
2
+ class Report
3
+
4
+ # @return [String, nil]
5
+ attr_accessor :classification
6
+
7
+ # @return [String, nil]
8
+ attr_accessor :license
9
+
10
+ # @return [String] ISO 8601 timestamp
11
+ attr_accessor :modified_at
12
+
13
+ attr_writer :open
14
+
15
+ # @return [String]
16
+ attr_accessor :title
17
+
18
+ # @return [Boolean]
19
+ def open?
20
+ @open === true ? true : false
21
+ end
22
+
23
+ end
24
+ end
@@ -0,0 +1,79 @@
1
+ require 'http'
2
+ require 'libdoi'
3
+ require_relative 'report'
4
+
5
+ module OpenAccessReporter
6
+ class Reporter
7
+ # @param email [String] Email for Unpaywall API
8
+ def initialize(email)
9
+ raise ArgumentError, 'Unpaywall email not set' unless email && !email.empty?
10
+ @email = email
11
+ @http_client = HTTP::Client.new
12
+ end
13
+
14
+ # Find open access data for a research output (makes one Unpaywall API call, see documentation for restrictions)
15
+ # @param doi [String] DOI e.g. 10.1234/abc, doi:10.1234/abc, https://doi.org/10.1234/abc
16
+ # @return [OpenAccessReporter::Report, nil]
17
+ def find(doi)
18
+ unpaywall_object = fetch(doi)
19
+ return nil if unpaywall_object[:error] === true
20
+ report = OpenAccessReporter::Report.new
21
+ report.classification = classification unpaywall_object
22
+ report.open = open? unpaywall_object
23
+ report.license = license unpaywall_object
24
+ report.modified_at = modified_at unpaywall_object
25
+ report.title = title unpaywall_object
26
+ report
27
+ end
28
+
29
+ private
30
+
31
+ # @return [Hash<Symbol>] Verbatim Unpaywall API JSON response
32
+ def fetch(doi)
33
+ doi = DOI.parse doi
34
+ encoded_doi = encode_doi doi
35
+ unpaywall_entry encoded_doi
36
+ end
37
+
38
+ def open?(unpaywall_object)
39
+ unpaywall_object[:is_oa]
40
+ end
41
+
42
+ def title(unpaywall_object)
43
+ unpaywall_object[:title]
44
+ end
45
+
46
+ def modified_at(unpaywall_object)
47
+ unpaywall_object[:updated]
48
+ end
49
+
50
+ def license(unpaywall_object)
51
+ if unpaywall_object[:is_oa] === true
52
+ if !unpaywall_object[:best_oa_location].empty?
53
+ unpaywall_object[:best_oa_location][:license]
54
+ end
55
+ end
56
+ end
57
+
58
+ def classification(unpaywall_object)
59
+ if unpaywall_object[:is_oa] === true
60
+ if unpaywall_object[:best_oa_location][:host_type] === 'repository'
61
+ 'green'
62
+ elsif unpaywall_object[:best_oa_location][:host_type] === 'publisher' && unpaywall_object[:best_oa_location][:license].nil?
63
+ 'bronze'
64
+ elsif unpaywall_object[:best_oa_location][:host_type] === 'publisher' && unpaywall_object[:best_oa_location][:license]
65
+ 'gold'
66
+ end
67
+ end
68
+ end
69
+
70
+ def unpaywall_entry(encoded_doi)
71
+ unpaywall_object = @http_client.get "https://api.unpaywall.org/v2/#{encoded_doi}?email=#{@email}"
72
+ JSON.parse unpaywall_object, symbolize_names: true
73
+ end
74
+
75
+ def encode_doi(doi)
76
+ doi.to_uri.to_s.gsub 'https://doi.org/', ''
77
+ end
78
+ end
79
+ end
@@ -0,0 +1,3 @@
1
+ module OpenAccessReporter
2
+ VERSION = "0.2.0"
3
+ end
@@ -0,0 +1,23 @@
1
+
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "open_access_reporter/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "open_access_reporter"
8
+ spec.version = OpenAccessReporter::VERSION
9
+ spec.authors = ["Adrian Albin-Clark"]
10
+ spec.email = ["a.albin-clark@lancaster.ac.uk"]
11
+ spec.summary = %q{Find salient Open Access data and derive a classification for a research output with a DOI.}
12
+ spec.metadata = {
13
+ 'source_code_uri' => 'https://github.com/lulibrary/open_access_reporter'
14
+ }
15
+ spec.license = "MIT"
16
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
17
+ f.match(%r{^(test|spec|features)/})
18
+ end
19
+ spec.require_paths = ["lib"]
20
+ spec.add_development_dependency 'minitest-reporters', '~> 1.1'
21
+ spec.add_dependency 'http', '~> 2.0'
22
+ spec.add_dependency 'libdoi', '~> 1.0'
23
+ end
metadata ADDED
@@ -0,0 +1,98 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: open_access_reporter
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.0
5
+ platform: ruby
6
+ authors:
7
+ - Adrian Albin-Clark
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2019-01-08 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: minitest-reporters
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.1'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.1'
27
+ - !ruby/object:Gem::Dependency
28
+ name: http
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '2.0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '2.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: libdoi
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.0'
55
+ description:
56
+ email:
57
+ - a.albin-clark@lancaster.ac.uk
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - ".gitignore"
63
+ - CHANGELOG.md
64
+ - Gemfile
65
+ - LICENSE.txt
66
+ - README.md
67
+ - lib/open_access_reporter.rb
68
+ - lib/open_access_reporter/report.rb
69
+ - lib/open_access_reporter/reporter.rb
70
+ - lib/open_access_reporter/version.rb
71
+ - open_access_reporter.gemspec
72
+ homepage:
73
+ licenses:
74
+ - MIT
75
+ metadata:
76
+ source_code_uri: https://github.com/lulibrary/open_access_reporter
77
+ post_install_message:
78
+ rdoc_options: []
79
+ require_paths:
80
+ - lib
81
+ required_ruby_version: !ruby/object:Gem::Requirement
82
+ requirements:
83
+ - - ">="
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ required_rubygems_version: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - ">="
89
+ - !ruby/object:Gem::Version
90
+ version: '0'
91
+ requirements: []
92
+ rubyforge_project:
93
+ rubygems_version: 2.7.3
94
+ signing_key:
95
+ specification_version: 4
96
+ summary: Find salient Open Access data and derive a classification for a research
97
+ output with a DOI.
98
+ test_files: []