plos 0.0.3 → 0.0.4

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.
data/README.md CHANGED
@@ -20,16 +20,13 @@ Or install it yourself as:
20
20
 
21
21
  ### Searching
22
22
 
23
- You can perform a basic search using the ```PLOS::Client.search(query, rows, start)``` method. The second two parameters are optional. That method returns a ```PLOS::ArtcleSet``` object. ```ArticleSet``` inherits from Array and includes some meta-information about the search. The following example show the information that's available:
23
+ You can perform a basic search using the ```PLOS::Client.search(query, start, rows)``` method. The second two parameters are optional. That method returns a ```PLOS::ArticleSet``` object. ```ArticleSet``` inherits from Array and includes some meta-information about the search. The following example show the information that's available:
24
24
 
25
25
  ```ruby
26
26
  require 'plos'
27
27
 
28
28
  client = PLOS::Client.new(ENV["API_KEY"])
29
29
  hits = client.search("xenograft")
30
- hits.each do |hit|
31
- puts "#{hit.score} - #{hit.title} - #{hit.article_url}"
32
- end
33
30
 
34
31
  hits.status # Return status of the query (0 is success)
35
32
  hits.time # The amount of time the query took (in ms)
@@ -37,8 +34,9 @@ hits.num_found # Total number of results
37
34
  hits.max_score # Score of the closest matching document
38
35
  hits.start # Index of the first result
39
36
 
40
- xml = hits[2].article_xml
41
- puts hits[2].citation
37
+ hits.each do |hit|
38
+ puts "#{hit.score} - #{hit.title} - #{hit.id}"
39
+ end
42
40
  ```
43
41
 
44
42
  Change the number of results starting position. The following retrieves 50 results starting at result 100:
@@ -46,7 +44,7 @@ Change the number of results starting position. The following retrieves 50 resul
46
44
  ```ruby
47
45
  require 'plos'
48
46
  client = PLOS::Client.new(ENV["API_KEY"])
49
- hits = client.search("xenograft", 50, 100)
47
+ hits = client.search("xenograft", 100, 50)
50
48
  ```
51
49
 
52
50
  Retrieve all results (paged). The following retrieves all results 200 - 300:
@@ -54,38 +52,39 @@ Retrieve all results (paged). The following retrieves all results 200 - 300:
54
52
  ```ruby
55
53
  require 'plos'
56
54
  client = PLOS::Client.new(ENV["API_KEY"])
57
- hits = client.all(100, 200)
55
+ hits = client.all(200, 100)
58
56
  ```
59
57
 
60
58
  ### Getting the Article Details
61
59
 
62
- You can get the full article from the ```ArticleRef``` in a number of ways.
63
-
64
- You can get the raw xml content using ```ArticleRef.article_content```. For example, the following returns a string:
60
+ You may get an ```Article``` object using ```ArticleRef.article```. For example, the following returns a ```PLOS::Article```:
65
61
 
66
62
  ```ruby
67
63
  require 'plos'
68
64
  client = PLOS::Client.new(ENV["API_KEY"])
69
65
  hits = client.search("xenograft")
70
- str = hits.first.article_content
66
+ article = hits.first.article
71
67
  ```
72
68
 
73
- You may also get the parsed xml content using ```ArticleRef.article_xml```. For example, the following returns a ```Nokogiri::XML::Document```:
69
+ ### Getting the Article's Citation
70
+
71
+ You may get a citation for the article using the ```citation``` method.
74
72
 
75
73
  ```ruby
76
74
  require 'plos'
77
75
  client = PLOS::Client.new(ENV["API_KEY"])
78
76
  hits = client.search("xenograft")
79
- xml_doc = hits.first.article_xml
77
+ citation = hits.first.citation # returns the RIS citation for the first ArticleRef
80
78
  ```
81
79
 
82
- Finally you may get an ```Article``` object using ```ArticleRef.article```. For example, the following returns a ```PLOS::Article```:
80
+ You may also get the citation from the ```Article``` object. The following code get the citation. Both ```Article```'s and ```ArticleRef```'s can return BibTex and RIS citations.
83
81
 
84
82
  ```ruby
85
83
  require 'plos'
86
84
  client = PLOS::Client.new(ENV["API_KEY"])
87
85
  hits = client.search("xenograft")
88
86
  article = hits.first.article
87
+ citation = article.citation("bibtex") # returns the BibTex citation for the Article
89
88
  ```
90
89
 
91
90
  ### Working with Articles
@@ -113,6 +112,48 @@ article.sections # Returns an Array of PLOS::Section objects containing the
113
112
  article.named_content # Returns an Array of Hash objects. Each representing a piece of "named-content". Named content is often used to separate genes from other text.
114
113
  ```
115
114
 
115
+ ### Other Helper Methods
116
+
117
+ If you have the id of an ```Article```, you can get the content in various ways. You can get the raw content:
118
+
119
+ ```ruby
120
+ require 'plos'
121
+ client = PLOS::Client.new(ENV["API_KEY"])
122
+ hits = client.search("xenograft")
123
+ article_id = hits.first.id
124
+ PLOS::Article.content(id) # Returns the xml as a string
125
+ ```
126
+
127
+ ```PLOS::Article.xml(id)``` returns a ```Nokogiri::XML``` object of the xml contents.
128
+
129
+ ```ruby
130
+ require 'plos'
131
+ client = PLOS::Client.new(ENV["API_KEY"])
132
+ hits = client.search("xenograft")
133
+ article_id = hits.first.id
134
+ PLOS::Article.xml(article_id) # Returns the xml
135
+ ```
136
+
137
+ ```PLOS::Article.get(id)``` returns a ```PLOS::Article``` object.
138
+
139
+ ```ruby
140
+ require 'plos'
141
+ client = PLOS::Client.new(ENV["API_KEY"])
142
+ hits = client.search("xenograft")
143
+ article_id = hits.first.id
144
+ PLOS::Article.get(article_id) # Returns the Article object
145
+ ```
146
+
147
+ ```PLOS::Article.citation(id)``` returns a ```PLOS::Article``` object.
148
+
149
+ ```ruby
150
+ require 'plos'
151
+ client = PLOS::Client.new(ENV["API_KEY"])
152
+ hits = client.search("xenograft")
153
+ article_id = hits.first.id
154
+ PLOS::Article.citation(article_id) # Returns the RIS citation as a String (could pass "BibTex" as the second parameter to get the BibTex format)
155
+ ```
156
+
116
157
  ## Contributing
117
158
 
118
159
  1. Fork it
data/lib/plos/article.rb CHANGED
@@ -2,6 +2,8 @@ module PLOS
2
2
  class Article
3
3
  include XmlHelpers
4
4
 
5
+ attr_accessor :node
6
+ attr_accessor :id
5
7
  attr_accessor :article_title
6
8
  attr_accessor :article_ids
7
9
  attr_accessor :journal_title
@@ -14,7 +16,10 @@ module PLOS
14
16
  attr_writer :sections
15
17
  attr_writer :named_content
16
18
 
17
- def initialize(node)
19
+ def initialize(id, node)
20
+ self.id = id
21
+ self.node = node
22
+
18
23
  self.article_title = tag_value(node.search("title-group"), "article-title")
19
24
  self.journal_title = tag_value(node.search("journal-title-group"), "journal-title")
20
25
 
@@ -49,6 +54,40 @@ module PLOS
49
54
  end
50
55
  end
51
56
 
57
+ def self.base_url
58
+ "http://www.plosone.org"
59
+ end
60
+
61
+ def self.get(id)
62
+ PLOS::Article.new(id, self.xml(id))
63
+ end
64
+
65
+ def self.xml(id)
66
+ Nokogiri::XML(self.content(id))
67
+ end
68
+
69
+ def self.content(id)
70
+ RestClient.get(self.url(id))
71
+ end
72
+
73
+ def self.url(id, format="XML")
74
+ # format = "XML|PDF"
75
+ "#{base_url}/article/fetchObjectAttachment.action?uri=info:doi/#{id}&representation=#{format}"
76
+ end
77
+
78
+ def self.ris_citation_url(id)
79
+ "#{base_url}/article/getRisCitation.action?articleURI=info:doi/#{id}"
80
+ end
81
+
82
+ def self.bib_tex_citation_url(id)
83
+ "#{base_url}/article/getBibTexCitation.action?articleURI=info:doi/#{id}"
84
+ end
85
+
86
+ def self.citation(id, format="RIS")
87
+ url = (format == "RIS" ? PLOS::Article.ris_citation_url(id) : PLOS::Article.bib_tex_citation_url(id))
88
+ RestClient.get(url)
89
+ end
90
+
52
91
  def authors
53
92
  contributors.collect { |contrib| contrib.name if contrib.type == "author" }.compact
54
93
  end
@@ -80,7 +119,9 @@ module PLOS
80
119
  def named_content
81
120
  @named_content ||= []
82
121
  end
122
+
123
+ def citation(format="RIS")
124
+ PLOS::Article.citation(id, format)
125
+ end
83
126
  end
84
127
  end
85
-
86
- # <named-content content-type="gene" xlink:type="simple">5′- AGGACGCAAGGAGGGTTTG -3′</named-content>
@@ -2,6 +2,7 @@ module PLOS
2
2
  class ArticleRef
3
3
  include PLOS::XmlHelpers
4
4
 
5
+ attr_accessor :node
5
6
  attr_accessor :client
6
7
  attr_accessor :score
7
8
  attr_accessor :type
@@ -18,6 +19,8 @@ module PLOS
18
19
  alias :publication_date= :published_at=
19
20
 
20
21
  def initialize(client, node)
22
+ self.node = node
23
+
21
24
  self.client = client
22
25
  node.children.each do |child|
23
26
  parse_node(child, self)
@@ -25,37 +28,11 @@ module PLOS
25
28
  end
26
29
 
27
30
  def article
28
- @article ||= PLOS::Article.new(article_xml)
29
- end
30
-
31
- def article_xml
32
- Nokogiri::XML(article_content)
33
- end
34
-
35
- def article_content
36
- RestClient.get(article_url)
31
+ @article ||= PLOS::Article.get(id)
37
32
  end
38
33
 
39
34
  def citation(format="RIS")
40
- url = (format == "RIS" ? ris_citation_url : bib_tex_citation_url)
41
- RestClient.get(url)
42
- end
43
-
44
- def base_url
45
- "http://www.plosone.org"
46
- end
47
-
48
- def article_url(format="XML")
49
- # format = "XML|PDF"
50
- "#{base_url}/article/fetchObjectAttachment.action?uri=info:doi/#{id}&representation=#{format}"
51
- end
52
-
53
- def ris_citation_url
54
- "#{base_url}/article/getRisCitation.action?articleURI=info:doi/#{id}"
55
- end
56
-
57
- def bib_tex_citation_url
58
- "#{base_url}/article/getBibTexCitation.action?articleURI=info:doi/#{id}"
35
+ PLOS::Article.citation(id, format)
59
36
  end
60
37
  end
61
38
  end
data/lib/plos/client.rb CHANGED
@@ -11,11 +11,11 @@ module PLOS
11
11
  self.base_url = base_url
12
12
  end
13
13
 
14
- def all(rows=50, start=0)
14
+ def all(start=0, rows=50)
15
15
  search("*:*", rows, start)
16
16
  end
17
17
 
18
- def search(query, rows=50, start=0)
18
+ def search(query, start=0, rows=50)
19
19
  result = PLOS::ArticleSet.new
20
20
  doc = execute( search_url, { :q => query, :rows => rows, :start => start } )
21
21
  if doc && doc.root
data/lib/plos/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Plos
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
3
3
  end
@@ -2,7 +2,7 @@ require 'plos'
2
2
 
3
3
  describe PLOS do
4
4
  context "Article 1" do
5
- let(:article) { PLOS::Article.new(Nokogiri::XML(File.read("spec/article1.xml"))) }
5
+ let(:article) { PLOS::Article.new("10.1371/journal.pone.0028384", Nokogiri::XML(File.read("spec/article1.xml"))) }
6
6
 
7
7
  it "should have the proper article title" do
8
8
  article.article_title.should == "Assessment of a Novel VEGF Targeted Agent Using Patient-Derived Tumor Tissue Xenograft Models of Colon Carcinoma with Lymphatic and Hepatic Metastases"
@@ -2,7 +2,7 @@ require 'plos'
2
2
 
3
3
  describe PLOS do
4
4
  context "Article 2" do
5
- let(:article) { PLOS::Article.new(Nokogiri::XML(File.read("spec/article2.xml"))) }
5
+ let(:article) { PLOS::Article.new("10.1371/journal.pmed.0040075", Nokogiri::XML(File.read("spec/article2.xml"))) }
6
6
 
7
7
  it "should have the proper article title" do
8
8
  article.article_title.should == "Clinical Xenotransplantation of Organs: Why Aren't We There Yet?"
data/spec/plos_spec.rb CHANGED
@@ -60,19 +60,19 @@ describe PLOS do
60
60
  end
61
61
 
62
62
  it "should have the proper xml article url" do
63
- article.article_url.should == "http://www.plosone.org/article/fetchObjectAttachment.action?uri=info:doi/10.1371/journal.pone.0050494&representation=XML"
63
+ PLOS::Article.url(article.id).should == "http://www.plosone.org/article/fetchObjectAttachment.action?uri=info:doi/10.1371/journal.pone.0050494&representation=XML"
64
64
  end
65
65
 
66
66
  it "should have the proper pdf article url" do
67
- article.article_url("PDF").should == "http://www.plosone.org/article/fetchObjectAttachment.action?uri=info:doi/10.1371/journal.pone.0050494&representation=PDF"
67
+ PLOS::Article.url(article.id, "PDF").should == "http://www.plosone.org/article/fetchObjectAttachment.action?uri=info:doi/10.1371/journal.pone.0050494&representation=PDF"
68
68
  end
69
69
 
70
70
  it "should have the proper ris citation url" do
71
- article.ris_citation_url.should == "http://www.plosone.org/article/getRisCitation.action?articleURI=info:doi/10.1371/journal.pone.0050494"
71
+ PLOS::Article.ris_citation_url(article.id).should == "http://www.plosone.org/article/getRisCitation.action?articleURI=info:doi/10.1371/journal.pone.0050494"
72
72
  end
73
73
 
74
74
  it "should have the proper bib tex citation url" do
75
- article.bib_tex_citation_url.should == "http://www.plosone.org/article/getBibTexCitation.action?articleURI=info:doi/10.1371/journal.pone.0050494"
75
+ PLOS::Article.bib_tex_citation_url(article.id).should == "http://www.plosone.org/article/getBibTexCitation.action?articleURI=info:doi/10.1371/journal.pone.0050494"
76
76
  end
77
77
  end
78
78
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: plos
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-02-02 00:00:00.000000000 Z
12
+ date: 2013-02-04 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: nokogiri
@@ -122,7 +122,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
122
122
  version: '0'
123
123
  segments:
124
124
  - 0
125
- hash: 2041436036673742898
125
+ hash: -2910391070543665259
126
126
  required_rubygems_version: !ruby/object:Gem::Requirement
127
127
  none: false
128
128
  requirements:
@@ -131,7 +131,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
131
131
  version: '0'
132
132
  segments:
133
133
  - 0
134
- hash: 2041436036673742898
134
+ hash: -2910391070543665259
135
135
  requirements: []
136
136
  rubyforge_project:
137
137
  rubygems_version: 1.8.24