Class: Theoj::PublishedPaper

Inherits:
Object
  • Object
show all
Includes:
Git
Defined in:
lib/theoj/published_paper.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Git

#change_branch, #clone_repo

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

#metadataObject

Returns the value of attribute metadata.



9
10
11
# File 'lib/theoj/published_paper.rb', line 9

def 
  @metadata
end

Instance Method Details

#json_metadataObject



41
42
43
# File 'lib/theoj/published_paper.rb', line 41

def 
  .to_json
end

#yaml_metadataObject



37
38
39
# File 'lib/theoj/published_paper.rb', line 37

def 
  .transform_keys(&:to_s).to_yaml
end