plos 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -23,9 +23,12 @@ require 'plos'
23
23
 
24
24
  client = PLOS::Client.new(ENV["API_KEY"])
25
25
  hits = client.search("xenograft")
26
- hits.each do |hits|
27
- puts "#{hit.score} - #{hit.title}"
26
+ hits.each do |hit|
27
+ puts "#{hit.score} - #{hit.title} - #{hit.article_url}"
28
28
  end
29
+
30
+ xml = hit[2].article_xml
31
+ puts hit[2].citation
29
32
  ```
30
33
 
31
34
  ## Contributing
@@ -11,6 +11,7 @@ module PLOS
11
11
  attr_accessor :journal
12
12
  attr_accessor :published_at
13
13
  attr_accessor :title
14
+
14
15
  alias :article_type= :type=
15
16
  alias :author_display= :authors=
16
17
  alias :title_display= :title=
@@ -39,5 +40,31 @@ module PLOS
39
40
  ArticleRef.parse_node(child, self)
40
41
  end
41
42
  end
43
+
44
+ def article_xml
45
+ Nokogiri::XML(RestClient.get(article_url))
46
+ end
47
+
48
+ def citation(format="RIS")
49
+ url = (format == "RIS" ? ris_citation_url : bib_tex_citation_url)
50
+ RestClient.get(url)
51
+ end
52
+
53
+ def base_url
54
+ "http://www.plosone.org"
55
+ end
56
+
57
+ def article_url(format="XML")
58
+ # format = "XML|PDF"
59
+ "#{base_url}/article/fetchObjectAttachment.action?uri=info:doi/#{id}&representation=#{format}"
60
+ end
61
+
62
+ def ris_citation_url
63
+ "#{base_url}/article/getRisCitation.action?articleURI=info:doi/#{id}"
64
+ end
65
+
66
+ def bib_tex_citation_url
67
+ "#{base_url}/article/getBibTexCitation.action?articleURI=info:doi/#{id}"
68
+ end
42
69
  end
43
70
  end
data/lib/plos/client.rb CHANGED
@@ -11,9 +11,13 @@ module PLOS
11
11
  self.base_url = base_url
12
12
  end
13
13
 
14
- def search(query)
14
+ def all(rows=50, start=0)
15
+ search("*:*", rows, start)
16
+ end
17
+
18
+ def search(query, rows=50, start=0)
15
19
  result = []
16
- doc = execute( search_url, { :q => query } )
20
+ doc = execute( search_url, { :q => query, :rows => rows, :start => start } )
17
21
  if doc && doc.root
18
22
  doc.root.children.each do |child|
19
23
  next unless child.name == "result"
data/lib/plos/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Plos
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
data/spec/plos_spec.rb CHANGED
@@ -1,42 +1,79 @@
1
1
  require 'plos'
2
2
 
3
3
  describe PLOS do
4
- context "A single document" do
5
- it "should parse an ArticleRef" do
6
- xml =<<END
7
- <doc>
8
- <float name="score">0.6637922</float>
9
- <str name="article_type">Research Article</str>
10
- <arr name="author_display">
11
- <str>Thomas D. Pfister</str>
12
- <str>Melinda Hollingshead</str>
13
- <str>Robert J. Kinders</str>
14
- <str>Yiping Zhang</str>
15
- <str>Yvonne A. Evrard</str>
16
- <str>Jiuping Ji</str>
17
- <str>Sonny A. Khin</str>
18
- <str>Suzanne Borgel</str>
19
- <str>Howard Stotler</str>
20
- <str>John Carter</str>
21
- <str>Raymond Divelbiss</str>
22
- <str>Shivaani Kummar</str>
23
- <str>Yves Pommier</str>
24
- <str>Ralph E. Parchment</str>
25
- <str>Joseph E. Tomaszewski</str>
26
- <str>James H. Doroshow</str>
27
- </arr>
28
- <str name="eissn">1932-6203</str>
29
- <str name="id">10.1371/journal.pone.0050494</str>
30
- <str name="journal">PLoS ONE</str>
31
- <date name="publication_date">2012-12-28T00:00:00Z</date>
32
- <str name="title_display">
33
- Development and Validation of an Immunoassay for Quantification of Topoisomerase I in Solid Tumor Tissues
34
- </str>
35
- </doc>
36
- END
37
- client = PLOS::Client.new("API_KEY")
38
- article = PLOS::ArticleRef.new(client, Nokogiri::XML(xml).root)
39
- article.type.should == "Research Article"
4
+ context "A client" do
5
+ let(:client) { client = PLOS::Client.new("API_KEY") }
6
+
7
+ it "should call the correct search url" do
8
+ RestClient.should_receive(:post).with("http://api.plos.org/search", {:api_key=>"API_KEY", :q=>"xenograft", :rows=>50, :start=>0}).and_return("")
9
+ client.search("xenograft")
10
+ end
11
+
12
+ it "should call the correct search url when rows and start are specified" do
13
+ RestClient.should_receive(:post).with("http://api.plos.org/search", {:api_key=>"API_KEY", :q=>"xenograft", :rows=>100, :start=>200}).and_return("")
14
+ client.search("xenograft", 100, 200)
15
+ end
16
+
17
+ it "should call the correct search url when finding all" do
18
+ RestClient.should_receive(:post).with("http://api.plos.org/search", {:api_key=>"API_KEY", :q=>"*:*", :rows=>50, :start=>0}).and_return("")
19
+ client.all
20
+ end
21
+
22
+ context "A single document" do
23
+ let(:article) {
24
+ xml =<<-END
25
+ <doc>
26
+ <float name="score">0.6637922</float>
27
+ <str name="article_type">Research Article</str>
28
+ <arr name="author_display">
29
+ <str>Thomas D. Pfister</str>
30
+ <str>Melinda Hollingshead</str>
31
+ <str>Robert J. Kinders</str>
32
+ <str>Yiping Zhang</str>
33
+ <str>Yvonne A. Evrard</str>
34
+ <str>Jiuping Ji</str>
35
+ <str>Sonny A. Khin</str>
36
+ <str>Suzanne Borgel</str>
37
+ <str>Howard Stotler</str>
38
+ <str>John Carter</str>
39
+ <str>Raymond Divelbiss</str>
40
+ <str>Shivaani Kummar</str>
41
+ <str>Yves Pommier</str>
42
+ <str>Ralph E. Parchment</str>
43
+ <str>Joseph E. Tomaszewski</str>
44
+ <str>James H. Doroshow</str>
45
+ </arr>
46
+ <str name="eissn">1932-6203</str>
47
+ <str name="id">10.1371/journal.pone.0050494</str>
48
+ <str name="journal">PLoS ONE</str>
49
+ <date name="publication_date">2012-12-28T00:00:00Z</date>
50
+ <str name="title_display">
51
+ Development and Validation of an Immunoassay for Quantification of Topoisomerase I in Solid Tumor Tissues
52
+ </str>
53
+ </doc>
54
+ END
55
+ article = PLOS::ArticleRef.new(client, Nokogiri::XML(xml).root)
56
+ }
57
+
58
+ it "should parse an ArticleRef" do
59
+ article.type.should == "Research Article"
60
+ end
61
+
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"
64
+ end
65
+
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"
68
+ end
69
+
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"
72
+ end
73
+
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"
76
+ end
40
77
  end
41
78
  end
42
79
  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.1
4
+ version: 0.0.2
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-01-24 00:00:00.000000000 Z
12
+ date: 2013-01-28 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: nokogiri
@@ -109,7 +109,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
109
109
  version: '0'
110
110
  segments:
111
111
  - 0
112
- hash: -583380218853756903
112
+ hash: 3325667330743682461
113
113
  required_rubygems_version: !ruby/object:Gem::Requirement
114
114
  none: false
115
115
  requirements:
@@ -118,7 +118,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
118
118
  version: '0'
119
119
  segments:
120
120
  - 0
121
- hash: -583380218853756903
121
+ hash: 3325667330743682461
122
122
  requirements: []
123
123
  rubyforge_project:
124
124
  rubygems_version: 1.8.24