plos 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +18 -0
- data/.travis.yml +2 -0
- data/Gemfile +4 -0
- data/LICENSE +22 -0
- data/README.md +37 -0
- data/Rakefile +8 -0
- data/lib/plos.rb +3 -0
- data/lib/plos/article_ref.rb +43 -0
- data/lib/plos/client.rb +36 -0
- data/lib/plos/version.rb +3 -0
- data/plos.gemspec +22 -0
- data/spec/plos_spec.rb +42 -0
- metadata +130 -0
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Christopher Petersen
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
# PLoS [![Build Status](https://travis-ci.org/cpetersen/plos.png?branch=master)](https://travis-ci.org/cpetersen/plos)
|
2
|
+
|
3
|
+
A Ruby library for interacting with the Public Library of Science (PLoS) API
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'plos'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install plos
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
```ruby
|
22
|
+
require 'plos'
|
23
|
+
|
24
|
+
client = PLOS::Client.new(ENV["API_KEY"])
|
25
|
+
hits = client.search("xenograft")
|
26
|
+
hits.each do |hits|
|
27
|
+
puts "#{hit.score} - #{hit.title}"
|
28
|
+
end
|
29
|
+
```
|
30
|
+
|
31
|
+
## Contributing
|
32
|
+
|
33
|
+
1. Fork it
|
34
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
35
|
+
3. Commit your changes (`git commit -am 'Added some feature'`)
|
36
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
37
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
data/lib/plos.rb
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
require "rest_client"
|
2
|
+
|
3
|
+
module PLOS
|
4
|
+
class ArticleRef
|
5
|
+
attr_accessor :client
|
6
|
+
attr_accessor :score
|
7
|
+
attr_accessor :type
|
8
|
+
attr_accessor :authors
|
9
|
+
attr_accessor :eissn
|
10
|
+
attr_accessor :id
|
11
|
+
attr_accessor :journal
|
12
|
+
attr_accessor :published_at
|
13
|
+
attr_accessor :title
|
14
|
+
alias :article_type= :type=
|
15
|
+
alias :author_display= :authors=
|
16
|
+
alias :title_display= :title=
|
17
|
+
alias :publication_date= :published_at=
|
18
|
+
|
19
|
+
def self.parse_node(node, obj=nil)
|
20
|
+
value = case(node.name)
|
21
|
+
when "arr"
|
22
|
+
node.children.collect { |child| parse_node(child) }
|
23
|
+
when "date"
|
24
|
+
DateTime.parse(node.content)
|
25
|
+
when "float"
|
26
|
+
node.content.to_f
|
27
|
+
else
|
28
|
+
node.content
|
29
|
+
end
|
30
|
+
if node.attr("name") && obj
|
31
|
+
obj.send("#{node.attr("name")}=",value)
|
32
|
+
end
|
33
|
+
value
|
34
|
+
end
|
35
|
+
|
36
|
+
def initialize(client, node)
|
37
|
+
self.client = client
|
38
|
+
node.children.each do |child|
|
39
|
+
ArticleRef.parse_node(child, self)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
data/lib/plos/client.rb
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
require "nokogiri"
|
2
|
+
require "rest_client"
|
3
|
+
|
4
|
+
module PLOS
|
5
|
+
class Client
|
6
|
+
attr_accessor :api_key
|
7
|
+
attr_accessor :base_url
|
8
|
+
|
9
|
+
def initialize(api_key, base_url="http://api.plos.org")
|
10
|
+
self.api_key = api_key
|
11
|
+
self.base_url = base_url
|
12
|
+
end
|
13
|
+
|
14
|
+
def search(query)
|
15
|
+
result = []
|
16
|
+
doc = execute( search_url, { :q => query } )
|
17
|
+
if doc && doc.root
|
18
|
+
doc.root.children.each do |child|
|
19
|
+
next unless child.name == "result"
|
20
|
+
child.children.each do |doc|
|
21
|
+
result << PLOS::ArticleRef.new(self, doc)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
result
|
26
|
+
end
|
27
|
+
|
28
|
+
def search_url
|
29
|
+
"/search"
|
30
|
+
end
|
31
|
+
|
32
|
+
def execute(url, params={})
|
33
|
+
Nokogiri::XML(RestClient.post( "#{self.base_url}#{url}", { :api_key => self.api_key }.merge(params) ) )
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
data/lib/plos/version.rb
ADDED
data/plos.gemspec
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path('../lib/plos/version', __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |gem|
|
5
|
+
gem.authors = ["Christopher Petersen"]
|
6
|
+
gem.email = ["christopher.petersen@gmail.com"]
|
7
|
+
gem.description = %q{A Ruby library for interacting with the Public Library of Science (PLoS) API}
|
8
|
+
gem.summary = %q{A Ruby library for interacting with the Public Library of Science (PLoS) API}
|
9
|
+
gem.homepage = "https://github.com/cpetersen/plos"
|
10
|
+
|
11
|
+
gem.add_dependency('nokogiri')
|
12
|
+
gem.add_dependency('rest-client')
|
13
|
+
gem.add_development_dependency('rake')
|
14
|
+
gem.add_development_dependency('rspec')
|
15
|
+
|
16
|
+
gem.files = `git ls-files`.split($\)
|
17
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
18
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
19
|
+
gem.name = "plos"
|
20
|
+
gem.require_paths = ["lib"]
|
21
|
+
gem.version = Plos::VERSION
|
22
|
+
end
|
data/spec/plos_spec.rb
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
require 'plos'
|
2
|
+
|
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"
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
metadata
ADDED
@@ -0,0 +1,130 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: plos
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Christopher Petersen
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-01-24 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: nokogiri
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: rest-client
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :runtime
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: rake
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: rspec
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ! '>='
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
type: :development
|
71
|
+
prerelease: false
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ! '>='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
78
|
+
description: A Ruby library for interacting with the Public Library of Science (PLoS)
|
79
|
+
API
|
80
|
+
email:
|
81
|
+
- christopher.petersen@gmail.com
|
82
|
+
executables: []
|
83
|
+
extensions: []
|
84
|
+
extra_rdoc_files: []
|
85
|
+
files:
|
86
|
+
- .gitignore
|
87
|
+
- .travis.yml
|
88
|
+
- Gemfile
|
89
|
+
- LICENSE
|
90
|
+
- README.md
|
91
|
+
- Rakefile
|
92
|
+
- lib/plos.rb
|
93
|
+
- lib/plos/article_ref.rb
|
94
|
+
- lib/plos/client.rb
|
95
|
+
- lib/plos/version.rb
|
96
|
+
- plos.gemspec
|
97
|
+
- spec/plos_spec.rb
|
98
|
+
homepage: https://github.com/cpetersen/plos
|
99
|
+
licenses: []
|
100
|
+
post_install_message:
|
101
|
+
rdoc_options: []
|
102
|
+
require_paths:
|
103
|
+
- lib
|
104
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
105
|
+
none: false
|
106
|
+
requirements:
|
107
|
+
- - ! '>='
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: '0'
|
110
|
+
segments:
|
111
|
+
- 0
|
112
|
+
hash: -583380218853756903
|
113
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
114
|
+
none: false
|
115
|
+
requirements:
|
116
|
+
- - ! '>='
|
117
|
+
- !ruby/object:Gem::Version
|
118
|
+
version: '0'
|
119
|
+
segments:
|
120
|
+
- 0
|
121
|
+
hash: -583380218853756903
|
122
|
+
requirements: []
|
123
|
+
rubyforge_project:
|
124
|
+
rubygems_version: 1.8.24
|
125
|
+
signing_key:
|
126
|
+
specification_version: 3
|
127
|
+
summary: A Ruby library for interacting with the Public Library of Science (PLoS)
|
128
|
+
API
|
129
|
+
test_files:
|
130
|
+
- spec/plos_spec.rb
|