theoj 1.0.0 → 1.2.1

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: c1ad9ac2e66ed16201c855e064d879df50c722e84c9b2178ebce0951ef76c56a
4
+ data.tar.gz: 93b83ab12f5d6416e3e2147a94fda33cde91b1d294df40c9f9d6a4b91f798c42
5
5
  SHA512:
6
- metadata.gz: 5fa3741bb127abcfb1c590c197fa8ea9631b510624b25b615ccfc60131cdf7ce68af2d400ab16f339cc6705a5aae1129403ac0c1d24e41e04209704bdfbcb076
7
- data.tar.gz: 246621ddee2c0495eccad79723727205b724ec36b4b401b24ae60f22c1e1cb7a8ece320ab2ccefb6a5074e4423a4eabcbf401272d40e137b0eb831bf0dafd662
6
+ metadata.gz: 046fc9a6df0c72d2a69bcd98c303becab7adac7eebdaff4608fbfe65e47e7e7f4ed63b951c45871eb6437c6d2900e2d3cbe5684cfcd3e9d0124a148d4a421d2d
7
+ data.tar.gz: 7a5048156f8f55f54aa3141f7073ffb13a4a8803cacd7fe520aa7c67b1590f116dd39d6986c90fe0650ac5c4b95e9c365710871a83416575992f3a025615edec
data/CHANGELOG.md CHANGED
@@ -1,5 +1,27 @@
1
1
  # Changelog
2
2
 
3
+ ## 1.2.1 (2021-11-30)
4
+
5
+ - Changed metadata dates format to ISO
6
+ - Changed editor and reviewers metadata values to github login
7
+ - Removed languages from article metadata
8
+
9
+ ## 1.2.0 (2021-11-23)
10
+
11
+ - Added reviews_repository_url to Journal
12
+ - Added article_metadata to Submission
13
+ - Added editor and paper dates lookup information in Submission
14
+ - Fixed error reading reviewers list from issue body
15
+
16
+ ## 1.1.1 (2021-11-05)
17
+
18
+ - Added support for test-journal
19
+
20
+ ## 1.1.0 (2021-10-29)
21
+
22
+ - Added Theoj::PublishedPaper object with metadata from Journal's API
23
+ - Added custom Error class
24
+
3
25
  ## 1.0.0 (2021-10-20)
4
26
 
5
27
  - 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/github.rb CHANGED
@@ -52,7 +52,7 @@ module Theoj
52
52
 
53
53
  # Returns the user login (removes the @ from the username)
54
54
  def user_login(username)
55
- username.strip.sub(/^@/, "").downcase
55
+ username.to_s.strip.sub(/^@/, "").downcase
56
56
  end
57
57
 
58
58
  # Returns true if the string is a valid GitHub isername (starts with @)
data/lib/theoj/journal.rb CHANGED
@@ -34,6 +34,14 @@ module Theoj
34
34
  "#@doi_prefix/#{paper_id}"
35
35
  end
36
36
 
37
+ def reviews_repository_url(issue_id=nil)
38
+ reviews_url = "https://github.com/#{data[:reviews_repository]}"
39
+ if issue_id
40
+ reviews_url += "/issues/" + issue_id.to_s
41
+ end
42
+ reviews_url
43
+ end
44
+
37
45
  private
38
46
 
39
47
  def set_data(custom_data)
@@ -19,6 +19,16 @@ module Theoj
19
19
  papers_repository: "openjournals/jose-papers",
20
20
  reviews_repository: "openjournals/jose-reviews",
21
21
  deposit_url: "https://joss.theoj.org/papers/api_deposit"
22
+ },
23
+ test_journal: {
24
+ doi_prefix: "10.21105",
25
+ url: "https://test.joss.theoj.org/",
26
+ name: "Test Journal",
27
+ alias: "test_journal",
28
+ launch_date: "2016-05-05",
29
+ papers_repository: "openjournals/joss-papers-testing",
30
+ reviews_repository: "openjournals/joss-reviews-testing",
31
+ deposit_url: "https://test.joss.theoj.org/papers/api_deposit"
22
32
  }
23
33
  }
24
34
  end
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.transform_keys(&:to_s).to_yaml
39
+ end
40
+
41
+ def json_metadata
42
+ metadata.to_json
43
+ end
44
+
45
+ end
46
+ end
@@ -28,7 +28,7 @@ module Theoj
28
28
  end
29
29
 
30
30
  def reviewers
31
- @reviewers ||= read_value_from_body("reviewers").split(",").map{|r| r.strip} - ["Pending", "TBD"]
31
+ @reviewers ||= read_value_from_body("reviewers-list").split(",").map{|r| r.strip} - ["Pending", "TBD"]
32
32
  end
33
33
 
34
34
  def editor
@@ -1,9 +1,12 @@
1
1
  require "json"
2
+ require "date"
2
3
  require "base64"
3
4
  require "faraday"
4
5
 
5
6
  module Theoj
6
7
  class Submission
8
+ include Theoj::GitHub
9
+
7
10
  attr_accessor :journal
8
11
  attr_accessor :review_issue
9
12
  attr_accessor :paper
@@ -49,6 +52,65 @@ module Theoj
49
52
  metadata.to_json
50
53
  end
51
54
 
55
+ # Create metadata used to generate PDF/JATS outputs
56
+ def article_metadata
57
+ metadata = {
58
+ title: paper.title,
59
+ tags: paper.tags,
60
+ authors: paper.authors.collect { |a| a.to_h },
61
+ doi: paper_doi,
62
+ software_repository_url: review_issue.target_repository,
63
+ reviewers: review_issue.reviewers.collect{|r| user_login(r)},
64
+ volume: journal.current_volume,
65
+ issue: journal.current_issue,
66
+ year: journal.current_year,
67
+ page: review_issue.issue_id,
68
+ journal_alias: journal.alias,
69
+ software_review_url: journal.reviews_repository_url(review_issue.issue_id),
70
+ archive_doi: review_issue.archive,
71
+ citation_string: citation_string
72
+ }
73
+
74
+ metadata.merge(editor_info, dates_info)
75
+ end
76
+
77
+ def editor_info
78
+ editor_info = { editor: {
79
+ github_user: user_login(review_issue.editor),
80
+ name: nil,
81
+ url: nil,
82
+ orcid: nil
83
+ }
84
+ }
85
+
86
+ if review_issue.editor
87
+ editor_lookup = Faraday.get(journal.url + "/editors/lookup/" + user_login(review_issue.editor))
88
+ if editor_lookup.status == 200
89
+ info = JSON.parse(editor_lookup.body, symbolize_names: true)
90
+ editor_info[:editor][:name] = info[:name]
91
+ editor_info[:editor][:url] = info[:url]
92
+ editor_info[:editor][:orcid] = info[:orcid]
93
+ end
94
+ end
95
+
96
+ editor_info
97
+ end
98
+
99
+ def dates_info
100
+ dates_info = { submitted_at: nil, published_at: nil }
101
+
102
+ if review_issue.issue_id
103
+ paper_lookup = Faraday.get(journal.url + "/papers/lookup/" + review_issue.issue_id.to_s)
104
+ if paper_lookup.status == 200
105
+ info = JSON.parse(paper_lookup.body, symbolize_names: true)
106
+ dates_info[:submitted_at] = format_date(info[:submitted]) if info[:submitted]
107
+ dates_info[:published_at] = format_date(info[:accepted]) if info[:accepted]
108
+ end
109
+ end
110
+
111
+ dates_info
112
+ end
113
+
52
114
  def deposit!(secret)
53
115
  parameters = deposit_payload.merge(secret: secret)
54
116
  Faraday.post(journal.data[:deposit_url], parameters.to_json, {"Content-Type" => "application/json"})
@@ -66,5 +128,12 @@ module Theoj
66
128
  def paper_doi
67
129
  journal.paper_doi_for_id(paper_id)
68
130
  end
131
+
132
+ private
133
+ def format_date(date_string)
134
+ Date.parse(date_string.to_s).strftime("%Y-%m-%d")
135
+ rescue Date::Error
136
+ nil
137
+ end
69
138
  end
70
139
  end
data/lib/theoj/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Theoj
2
- VERSION = "1.0.0"
2
+ VERSION = "1.2.1"
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.2.1
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-11-30 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