Class: Theoj::PublishedPaper
- Inherits:
-
Object
- Object
- Theoj::PublishedPaper
- Includes:
- Git
- Defined in:
- lib/theoj/published_paper.rb
Instance Attribute Summary collapse
-
#metadata ⇒ Object
Returns the value of attribute metadata.
Instance Method Summary collapse
-
#initialize(doi) ⇒ PublishedPaper
constructor
A new instance of PublishedPaper.
- #json_metadata ⇒ Object
- #yaml_metadata ⇒ Object
Methods included from Git
Constructor Details
#initialize(doi) ⇒ PublishedPaper
Returns a new instance of PublishedPaper.
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/theoj/published_paper.rb', line 11 def initialize(doi) doi_url = "https://doi.org/#{doi}" doi_response = Faraday.get(doi_url) if doi_response.status == 302 paper_url = doi_response.headers[:location] else raise Theoj::Error, "The DOI is invalid, url does not resolve #{doi_url}" end paper_data = Faraday.get(paper_url + ".json") if paper_data.status == 200 @metadata = JSON.parse(paper_data.body, symbolize_names: true) else raise Theoj::Error, "Could not find the paper data at #{paper_url + ".json"}" end end |
Instance Attribute Details
#metadata ⇒ Object
Returns the value of attribute metadata.
9 10 11 |
# File 'lib/theoj/published_paper.rb', line 9 def @metadata end |
Instance Method Details
#json_metadata ⇒ Object
41 42 43 |
# File 'lib/theoj/published_paper.rb', line 41 def .to_json end |
#yaml_metadata ⇒ Object
37 38 39 |
# File 'lib/theoj/published_paper.rb', line 37 def .transform_keys(&:to_s).to_yaml end |