theoj 1.0.0 → 1.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 984f9feb0bdcfeaf7d9533aa94c09dde7877ca2381e75e60b0f05d73cb390eb7
4
- data.tar.gz: 749c5b08e99824f720c5ed4e820d45b7d2b772c345f820d4332393376b215512
3
+ metadata.gz: 23579418555d490f75911e9894fd4c8bb8abaf3225fc6ee93eacd4d60de621fb
4
+ data.tar.gz: 8a05d5d50b4a6e22d5ea9dc420c11e4529f71c217727249178226fae5e14d4c1
5
5
  SHA512:
6
- metadata.gz: 5fa3741bb127abcfb1c590c197fa8ea9631b510624b25b615ccfc60131cdf7ce68af2d400ab16f339cc6705a5aae1129403ac0c1d24e41e04209704bdfbcb076
7
- data.tar.gz: 246621ddee2c0495eccad79723727205b724ec36b4b401b24ae60f22c1e1cb7a8ece320ab2ccefb6a5074e4423a4eabcbf401272d40e137b0eb831bf0dafd662
6
+ metadata.gz: faa8c6b8ada15280342a218da6485f762ed9535e3f4f9527d8378a66e852635254cbc7bae220827fa08162d1253992ccf0b25c9e8096345e37c502c7a4268bd8
7
+ data.tar.gz: 4ac1b3347391848f66ea6b1e3f0a648313c62ee1873d2d8d0e1d610732c860a2d656353f44ba8ce07b96ad0da08f13d3ded3f5dacee5e50a7d46a6abe6496b69
data/CHANGELOG.md CHANGED
@@ -1,5 +1,10 @@
1
1
  # Changelog
2
2
 
3
+ ## 1.1.0 (2021-10-29)
4
+
5
+ - Added Theoj::PublishedPaper object with metadata from Journal's API
6
+ - Added custom Error class
7
+
3
8
  ## 1.0.0 (2021-10-20)
4
9
 
5
10
  - Added method to Journal to create paper_id from issue_id
data/lib/theoj/author.rb CHANGED
@@ -62,7 +62,7 @@ module Theoj
62
62
  if validator.valid?
63
63
  return author_orcid.strip
64
64
  else
65
- raise "Problem with ORCID (#{author_orcid}) for #{self.name}. #{validator.error}"
65
+ raise Theoj::Error, "Problem with ORCID (#{author_orcid}) for #{self.name}. #{validator.error}"
66
66
  end
67
67
  end
68
68
 
@@ -82,7 +82,7 @@ module Theoj
82
82
  # Raise if we can't parse the string, might be because of this bug :-(
83
83
  # https://bugs.ruby-lang.org/issues/12451
84
84
  affiliations.each do |a|
85
- raise "Problem with affiliations for #{self.name}, perhaps the " +
85
+ raise Theoj::Error, "Problem with affiliations for #{self.name}, perhaps the " +
86
86
  "affiliations index need quoting?" unless affiliations_hash.has_key?(a)
87
87
 
88
88
  author_affiliations << affiliations_hash[a].strip
data/lib/theoj/paper.rb CHANGED
@@ -152,7 +152,7 @@ module Theoj
152
152
 
153
153
  def failure(msg)
154
154
  cleanup
155
- raise(msg)
155
+ raise Theoj::Error, msg
156
156
  end
157
157
  end
158
158
  end
@@ -0,0 +1,46 @@
1
+ require "faraday"
2
+ require "yaml"
3
+ require "json"
4
+
5
+ module Theoj
6
+ class PublishedPaper
7
+ include Theoj::Git
8
+
9
+ attr_accessor :metadata
10
+
11
+ def initialize(doi)
12
+ doi_url = "https://doi.org/#{doi}"
13
+ doi_response = Faraday.get(doi_url)
14
+ if doi_response.status == 302
15
+ paper_url = doi_response.headers[:location]
16
+ else
17
+ raise Theoj::Error, "The DOI is invalid, url does not resolve #{doi_url}"
18
+ end
19
+
20
+ paper_data = Faraday.get(paper_url + ".json")
21
+ if paper_data.status == 200
22
+ @metadata = JSON.parse(paper_data.body, symbolize_names: true)
23
+ else
24
+ raise Theoj::Error, "Could not find the paper data at #{paper_url + ".json"}"
25
+ end
26
+ end
27
+
28
+ [:title, :state, :submitted_at, :doi, :published_at,
29
+ :volume, :issue, :year, :page, :authors, :editor,
30
+ :editor_name, :editor_url, :editor_orcid, :reviewers,
31
+ :languages, :tags, :software_repository, :paper_review,
32
+ :pdf_url, :software_archive].each do |method_name|
33
+ define_method(method_name) { metadata[method_name] }
34
+ define_method("#{method_name}=") {|value| @metadata[method_name] = value }
35
+ end
36
+
37
+ def yaml_metadata
38
+ metadata.to_yaml
39
+ end
40
+
41
+ def json_metadata
42
+ metadata.to_json
43
+ end
44
+
45
+ end
46
+ end
data/lib/theoj/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Theoj
2
- VERSION = "1.0.0"
2
+ VERSION = "1.1.0"
3
3
  end
data/lib/theoj.rb CHANGED
@@ -2,6 +2,7 @@ require_relative "theoj/version"
2
2
  require_relative "theoj/git"
3
3
  require_relative "theoj/github"
4
4
  require_relative "theoj/orcid"
5
+ require_relative "theoj/published_paper"
5
6
  require_relative "theoj/submission"
6
7
  require_relative "theoj/journal"
7
8
  require_relative "theoj/review_issue"
@@ -9,4 +10,5 @@ require_relative "theoj/paper"
9
10
  require_relative "theoj/author"
10
11
 
11
12
  module Theoj
13
+ class Error < StandardError; end
12
14
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: theoj
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Juanjo Bazán
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-10-20 00:00:00.000000000 Z
11
+ date: 2021-10-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: octokit
@@ -126,6 +126,7 @@ files:
126
126
  - lib/theoj/journals_data.rb
127
127
  - lib/theoj/orcid.rb
128
128
  - lib/theoj/paper.rb
129
+ - lib/theoj/published_paper.rb
129
130
  - lib/theoj/review_issue.rb
130
131
  - lib/theoj/submission.rb
131
132
  - lib/theoj/version.rb