rubyBHL 0.1.0 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.env +1 -0
- data/.gitignore +7 -0
- data/.rspec +2 -0
- data/.ruby-version +1 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +44 -0
- data/LICENSE +16 -0
- data/README.rdoc +120 -7
- data/Rakefile +6 -15
- data/lib/rubyBHL.rb +18 -106
- data/lib/rubyBHL/mine.rb +48 -0
- data/lib/rubyBHL/request.rb +151 -0
- data/lib/rubyBHL/response.rb +47 -0
- data/lib/rubyBHL/version.rb +3 -0
- data/rubyBHL.gemspec +26 -26
- data/spec/lib/mine_spec.rb +24 -0
- data/spec/lib/request_spec.rb +114 -0
- data/spec/lib/response_spec.rb +21 -0
- data/spec/lib/ruby_bhl_spec.rb +41 -0
- data/spec/spec_helper.rb +17 -0
- metadata +181 -52
- data/Manifest +0 -7
- data/init.rb +0 -1
- data/test/helper.rb +0 -3
- data/test/rubyBHL_test.rb +0 -36
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 4fe4ab96d43bf545970f210e8206eade90e44ae1
|
4
|
+
data.tar.gz: fad6f419ccccf43eed88fbb6161194fa40f84f17
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 1d7c31281e01a8bd1c1dcf7ffc3b7c8d1d0ec7633302a0b58fccf40e85ef06abf5790694d55c54a0daac9162c40874039f43b29df33a8e72e941bd30536206d2
|
7
|
+
data.tar.gz: 5c7a705dd079fb25288b2fdf46ae70ecdebe295150ef15cc1cebdf5844e40a2ee78f4fe8176c3a5890965f80c9610180683952befd2c44c71ddd3bfe10e6be52
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
2.0.0-p353
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
rubyBHL (0.2.1)
|
5
|
+
dotenv
|
6
|
+
json (~> 1.8)
|
7
|
+
|
8
|
+
GEM
|
9
|
+
remote: https://rubygems.org/
|
10
|
+
specs:
|
11
|
+
awesome_print (1.2.0)
|
12
|
+
columnize (0.3.6)
|
13
|
+
debugger (1.6.5)
|
14
|
+
columnize (>= 0.3.1)
|
15
|
+
debugger-linecache (~> 1.2.0)
|
16
|
+
debugger-ruby_core_source (~> 1.3.1)
|
17
|
+
debugger-linecache (1.2.0)
|
18
|
+
debugger-ruby_core_source (1.3.1)
|
19
|
+
diff-lcs (1.2.5)
|
20
|
+
dotenv (0.9.0)
|
21
|
+
git (1.2.6)
|
22
|
+
json (1.8.1)
|
23
|
+
rake (10.1.1)
|
24
|
+
rspec (2.14.1)
|
25
|
+
rspec-core (~> 2.14.0)
|
26
|
+
rspec-expectations (~> 2.14.0)
|
27
|
+
rspec-mocks (~> 2.14.0)
|
28
|
+
rspec-core (2.14.7)
|
29
|
+
rspec-expectations (2.14.5)
|
30
|
+
diff-lcs (>= 1.1.3, < 2.0)
|
31
|
+
rspec-mocks (2.14.5)
|
32
|
+
|
33
|
+
PLATFORMS
|
34
|
+
ruby
|
35
|
+
|
36
|
+
DEPENDENCIES
|
37
|
+
awesome_print (~> 1.2)
|
38
|
+
bundler (~> 1.3)
|
39
|
+
debugger (~> 1.6)
|
40
|
+
dotenv
|
41
|
+
git (~> 1.2)
|
42
|
+
rake (~> 10.1)
|
43
|
+
rspec (~> 2.14)
|
44
|
+
rubyBHL!
|
data/LICENSE
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
University of Illinois/NCSA Open Source License
|
2
|
+
|
3
|
+
Copyright (c) 2014 Species File Group
|
4
|
+
All rights reserved.
|
5
|
+
|
6
|
+
Developed by: Species File Group
|
7
|
+
Illinois Natural History Survey
|
8
|
+
http://speciesfilegroup.blogspot.com/
|
9
|
+
|
10
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal with the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimers.
|
13
|
+
Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimers in the documentation and/or other materials provided with the distribution.
|
14
|
+
Neither the names of <Name of Development Group, Name of Institution>, nor the names of its contributors may be used to endorse or promote products derived from this Software without specific prior written permission.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS WITH THE SOFTWARE.
|
data/README.rdoc
CHANGED
@@ -1,16 +1,129 @@
|
|
1
1
|
= RubyBHL
|
2
2
|
|
3
|
-
A
|
3
|
+
A simple Ruby wrapper to {version 2.5.x of the BHL API}[http://www.biodiversitylibrary.org/api2/docs/docs.html].
|
4
4
|
|
5
|
-
==
|
5
|
+
== Really quick start
|
6
6
|
|
7
|
-
|
7
|
+
Add your key (http://www.biodiversitylibrary.org/getapikey.aspx) to <em>~/.bhl_api_key</em>.
|
8
8
|
|
9
|
-
|
9
|
+
gem install rubyBHL
|
10
10
|
|
11
|
-
|
11
|
+
require 'rubyBHL'
|
12
|
+
RubyBHL.quick_request() # => {"Status":"ok","ErrorMessage":null,"Result":[]}
|
12
13
|
|
13
|
-
==
|
14
|
+
== API Key
|
14
15
|
|
15
|
-
|
16
|
+
You need a BHL key from http://www.biodiversitylibrary.org/getapikey.aspx. Do one of:
|
17
|
+
|
18
|
+
1) Add it to the file <em>~/.bhl_api_key</em>.
|
19
|
+
|
20
|
+
2) Add it to the file _.env_ in the root of your application:
|
21
|
+
BHL_API_KEY=sekret_key_here
|
22
|
+
|
23
|
+
3) Set BHL_API_KEY in your shell profile.
|
24
|
+
|
25
|
+
4) Pass it explicitly to your request:
|
26
|
+
RubyBHL::Request.new(api_key: '123_343_etc')
|
27
|
+
|
28
|
+
If the key is set in multiple places priority is reverse order listed here.
|
29
|
+
|
30
|
+
== Requests
|
31
|
+
|
32
|
+
Construct one all at once:
|
33
|
+
|
34
|
+
r = RubyBHL::Request.new(method: :TitleSearch, params: {'title' => 'Dark and Storm Night'}, format: 'xml', api_key: 'top_sekret_key')
|
35
|
+
|
36
|
+
Build it piece by piece if you need to
|
37
|
+
|
38
|
+
r = RubyBHL::Request.new() # => #<RubyBHL::Request:0x0000010189bf28
|
39
|
+
@api_key="redacted_secret_key",
|
40
|
+
@method=:NameSearch, @format="json", @params={}>
|
41
|
+
|
42
|
+
The method defaults to :NameSearch
|
43
|
+
|
44
|
+
r.method # => :NameSearch
|
45
|
+
r.method = :TitleSearchSimple # => :TitleSearchSimple
|
46
|
+
|
47
|
+
Parameters are passed as a hash, keys are strings:
|
48
|
+
|
49
|
+
r.params = {'title' => 'Hen in the Foxhouse.'} # => {"title"=>"Hen in the Foxhouse."}
|
50
|
+
|
51
|
+
Format is one of `xml` or `json` (default):
|
52
|
+
|
53
|
+
r.format = 'xml' # => "xml"
|
54
|
+
|
55
|
+
It's possible to set your API key per request:
|
56
|
+
|
57
|
+
r.api_key = 'top_sekret_key' # => "top_sekret_key"
|
58
|
+
|
59
|
+
Test that your params are supported:
|
60
|
+
|
61
|
+
r.params = {'foo' => 'bar'} # => {"foo"=>"bar"}
|
62
|
+
r.params_are_supported? # => false
|
63
|
+
|
64
|
+
Test that method has the required params?
|
65
|
+
|
66
|
+
r.params = {} # => {}
|
67
|
+
r.method = :NameSearch # => :NameSearch
|
68
|
+
r.has_required_params? # false => false
|
69
|
+
r.params = {'name' => "Yeti"} # => {"name"=>"Yeti"}
|
70
|
+
r.has_required_params? # => true
|
71
|
+
|
72
|
+
Test the overall validity of the present request:
|
73
|
+
|
74
|
+
r.valid? # => true
|
75
|
+
|
76
|
+
Return the search_url:
|
77
|
+
|
78
|
+
r.search_url # => "http://www.biodiversitylibrary.org/api2/httpquery.ashx?op=NameSearch&name=Yeti&format=xml&apikey=top_sekret_key"
|
79
|
+
|
80
|
+
Get a response
|
81
|
+
|
82
|
+
r.response # => #<RubyBHL::Response: ... >
|
83
|
+
|
84
|
+
== Responses
|
85
|
+
|
86
|
+
Require a RubyBHL::Request:
|
87
|
+
|
88
|
+
request = RubyBHL::Request.new(params: {'name' => 'blorf'})
|
89
|
+
response = RubyBHL::Response.new(request: request)
|
90
|
+
|
91
|
+
Get the json:
|
92
|
+
|
93
|
+
response.json # => {"Status"=>"ok", "ErrorMessage"=>nil, "Result"=>[]}
|
94
|
+
|
95
|
+
== Mining
|
96
|
+
|
97
|
+
Just some examples at present.
|
98
|
+
|
99
|
+
For a taxon name, and a list of "attributes", generate a CSV table with one page per row, and 0 (absent) or 1 (present) for each "attribute". You can limit the number of pages returned.
|
100
|
+
|
101
|
+
require 'rubyBHL'
|
102
|
+
r = RubyBHL::Mine.taxon_attribute_table('Apis melifera', ['honey', 'disease', 'parasite'], 5)
|
103
|
+
# => "honey\tdisease\tparasite\tPageID\n0\t0\t0\t15995011\n0\t0\t0\t16445239\n0\t0\t0\t27274823\n0\t0\t0\t18188723\n0\t0\t0\t37765472\n1\t0\t0\t34216230\n1\t0\t1\t31898980\n0\t0\t1\t32014594\n0\t0\t0\t32014638\n1\t1\t0\t32015159\n"
|
104
|
+
CSV.parse(r, col_sep: "\t")
|
105
|
+
# => [["honey", "disease", "parasite", "PageID"],
|
106
|
+
["0", "0", "0", "15995011"],
|
107
|
+
["0", "0", "0", "16445239"],
|
108
|
+
["0", "0", "0", "27274823"],
|
109
|
+
["0", "0", "0", "18188723"],
|
110
|
+
["0", "0", "0", "37765472"],
|
111
|
+
["1", "0", "0", "34216230"],
|
112
|
+
["1", "0", "1", "31898980"],
|
113
|
+
["0", "0", "1", "32014594"],
|
114
|
+
["0", "0", "0", "32014638"],
|
115
|
+
["1", "1", "0", "32015159"]]
|
116
|
+
# ... <clickity> R-stats </clickity>
|
117
|
+
|
118
|
+
== Contributing
|
119
|
+
|
120
|
+
Fork the repo, hack, test, submit a pull request.
|
121
|
+
|
122
|
+
== Acknowledgements
|
123
|
+
|
124
|
+
Katja Seltmann provided code and requirements for the original incarnation of the gem. The general pattern for this gem, including some baseline tests, is pilfered from dwc-archive by Dmitry Mozzherin. Mx A. Matienzo (@anarchivist) wrote a {Python translation of the original version}[http://www.biodiversitylibrary.org/api2/docs/docs.html], and inspired the different architecture used now. Thanks BHL for being awesome!
|
125
|
+
|
126
|
+
== License
|
127
|
+
|
128
|
+
Open, NCSA[http://opensource.org/licenses/NCSA]. See LICENSE.
|
16
129
|
|
data/Rakefile
CHANGED
@@ -1,18 +1,9 @@
|
|
1
|
-
|
1
|
+
require "bundler/gem_tasks"
|
2
|
+
require 'rspec/core/rake_task'
|
2
3
|
|
3
|
-
|
4
|
-
|
5
|
-
require 'echoe'
|
6
|
-
|
7
|
-
Echoe.new('rubyBHL', '0.1.0') do |p|
|
8
|
-
p.description = "Hook to the Biodiversity Heritage Library API plus some screen scraping for OCR."
|
9
|
-
p.url = "http://github.com/mjy/rubyBHL"
|
10
|
-
p.author = "Yoder & Seltmann"
|
11
|
-
p.email = "diapriid@gmail.com"
|
12
|
-
p.ignore_pattern = ["tmp/*", "script/*"]
|
13
|
-
p.development_dependencies = []
|
4
|
+
RSpec::Core::RakeTask.new(:spec) do |spec|
|
5
|
+
spec.pattern = 'spec/**/*_spec.rb'
|
14
6
|
end
|
15
7
|
|
16
|
-
|
17
|
-
|
18
|
-
|
8
|
+
task :default => :spec
|
9
|
+
|
data/lib/rubyBHL.rb
CHANGED
@@ -1,116 +1,28 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
# Some quick hacks, only configured for json right now.
|
4
|
-
|
5
|
-
require 'net/http'
|
6
|
-
# require 'json'
|
7
|
-
require 'json/add/rails'
|
1
|
+
# encoding: UTF-8
|
8
2
|
|
9
|
-
|
10
|
-
|
3
|
+
recent_ruby = RUBY_VERSION >= '2.0.0'
|
4
|
+
raise "IMPORTANT: gem requires ruby >= 2.0.0" unless recent_ruby
|
11
5
|
|
12
|
-
|
13
|
-
|
14
|
-
# some notes
|
15
|
-
#http://www.biodiversitylibrary.org/openurl?url_ver=Z39.88-2004&ctx_ver=Z39.88-2004
|
16
|
-
#rft_val_fmt=info%3Aofi%2Ffmt%3Akev%3Amtx%3Abook
|
17
|
-
#rft.btitle
|
18
|
-
#rft.jtitle
|
19
|
-
#rft.au
|
20
|
-
#rft.aufirst
|
21
|
-
#rft.aulast
|
22
|
-
#rft.publisher
|
23
|
-
#rft.pub
|
24
|
-
#rft.place
|
25
|
-
#rft.date
|
26
|
-
#rft.issn
|
27
|
-
#rft.isbn
|
28
|
-
# rft.coden
|
29
|
-
# rft.stitle
|
30
|
-
# rft.volume
|
31
|
-
# rft.issue
|
32
|
-
# rft.spage
|
33
|
-
# rft_id=info:oclcnum/XXXX
|
34
|
-
# rft_id=info:lccn/XXXX
|
35
|
-
# rft_id=http://www.biodiversitylibrary.org/bibliography/XXXX
|
36
|
-
# rft_id=http://www.biodiversitylibrary.org/page/XXXX
|
37
|
-
|
38
|
-
# "constants" (defaults really)
|
39
|
-
SEARCH_URL = 'http://www.biodiversitylibrary.org/openurl?'
|
40
|
-
FORMAT = 'json'
|
41
|
-
# METHOD = '' # openURL0.1, openURL1.0
|
6
|
+
require "json"
|
7
|
+
require 'net/http'
|
42
8
|
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
:aufirst,
|
47
|
-
:aulast,
|
48
|
-
:publisher,
|
49
|
-
:date,
|
50
|
-
:issn,
|
51
|
-
:isbn,
|
52
|
-
:coden,
|
53
|
-
:stitle,
|
54
|
-
:volume,
|
55
|
-
:issue,
|
56
|
-
:spage]
|
57
|
-
|
58
|
-
# created from response
|
59
|
-
attr_reader(:json_data)
|
60
|
-
attr_reader(:citations)
|
61
|
-
attr :search_url
|
9
|
+
require_relative 'rubyBHL/request'
|
10
|
+
require_relative 'rubyBHL/response'
|
11
|
+
require_relative 'rubyBHL/mine'
|
62
12
|
|
63
|
-
|
64
|
-
@opt = {
|
65
|
-
# :method => METHOD,
|
66
|
-
:format => FORMAT,
|
67
|
-
:params => {}
|
68
|
-
}.merge!(options)
|
69
|
-
|
70
|
-
# check for legal parameters
|
71
|
-
@opt[:params].keys.each do |p|
|
72
|
-
raise RbhlError, "#{p} is not a valid parameter" if !PARAMETERS.include?(p)
|
73
|
-
end
|
74
|
-
|
75
|
-
@json_data = {}
|
76
|
-
|
77
|
-
@search_url = SEARCH_URL +
|
78
|
-
@opt[:params].keys.sort{|a,b| a.to_s <=> b.to_s}.collect{|k| "#{k}=#{@opt[:params][k].gsub(/\s/, "+")}"}.join("&") +
|
79
|
-
'&format=' + @opt[:format]
|
80
|
-
|
81
|
-
@json_data = JSON.parse(Net::HTTP.get_response(URI.parse(@search_url)).body)
|
82
|
-
@citations = @json_data['citations'] if @json_data['Status'] == 1 # a simpler reference
|
83
|
-
|
84
|
-
true
|
85
|
-
end
|
13
|
+
class RubyBHL
|
86
14
|
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
limit = 10 # Justin Case we get in some redirect loop
|
97
|
-
raise RbhlError, 'HTTP redirect too deep' if limit == 0 # should tweak
|
98
|
-
response = Net::HTTP.get_response(URI.parse(uri_string))
|
99
|
-
case response
|
100
|
-
when Net::HTTPSuccess then response.body
|
101
|
-
when Net::HTTPRedirection then fetch(response['location'], limit - 1)
|
102
|
-
else
|
103
|
-
response.error!
|
104
|
-
end
|
15
|
+
#DEFAULT_TMP_DIR = "/tmp"
|
16
|
+
|
17
|
+
def self.quick_request(options = {})
|
18
|
+
opts = {
|
19
|
+
params: {'name' => 'blorf'},
|
20
|
+
method: :NameSearch
|
21
|
+
}.merge!(options)
|
22
|
+
request = RubyBHL::Request.new(opts)
|
23
|
+
request.response
|
105
24
|
end
|
106
25
|
|
107
|
-
# Since the API doesn't return a link to the OCR we screen scrape it the URL
|
108
|
-
def OCR_url(citation_index)
|
109
|
-
Net::HTTP.get_response(URI.parse(@citations[citation_index]["Url"])).body =~ /http:\/\/.*?\.txt/
|
110
|
-
return $& # the matched results
|
111
|
-
end
|
112
|
-
|
113
26
|
end
|
114
27
|
|
115
28
|
|
116
|
-
end
|
data/lib/rubyBHL/mine.rb
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
class RubyBHL
|
2
|
+
|
3
|
+
require 'csv'
|
4
|
+
|
5
|
+
# Some rudimentary methods for mining the BHL.
|
6
|
+
class Mine
|
7
|
+
|
8
|
+
# Takes a string, and a list of "attributes" (keyword).
|
9
|
+
# Returns a CSV object with one line per page,
|
10
|
+
# one column per attribute,
|
11
|
+
# 1 if keyword was found, 0 if not.
|
12
|
+
def self.taxon_attribute_table(taxon_name = nil, attributes = [], page_limit = 10)
|
13
|
+
name_search = RubyBHL::Request.new(method: :NameGetDetail , params: {'name' => taxon_name})
|
14
|
+
|
15
|
+
json = name_search.response.json
|
16
|
+
pages = pages_from_result(json['Result'])
|
17
|
+
|
18
|
+
csv = CSV.generate(col_sep: "\t") do |csv|
|
19
|
+
csv << [*attributes, 'PageID']
|
20
|
+
pages[0..page_limit - 1].each do |p|
|
21
|
+
result = []
|
22
|
+
ocr = RubyBHL::Request.new(method: :GetPageOcrText, params: {'pageid' => p['PageID']}).response.json['Result']
|
23
|
+
result += bit_vector_for_keywords(ocr, attributes)
|
24
|
+
result.push p['PageID']
|
25
|
+
csv << [*result]
|
26
|
+
end
|
27
|
+
end
|
28
|
+
csv
|
29
|
+
end
|
30
|
+
|
31
|
+
# Return an Array of 0 or 1 given the presence or absence of each keyword in the text.
|
32
|
+
def self.bit_vector_for_keywords(text = "", keywords = [])
|
33
|
+
keywords.inject([]) {|ary, k| ary.push(text =~ /#{k}/ ? 1 : 0) }
|
34
|
+
end
|
35
|
+
|
36
|
+
# TODO: Use JSON fu to make this simpler
|
37
|
+
def self.pages_from_result(results = [])
|
38
|
+
pages = []
|
39
|
+
results['Titles'].each do |t|
|
40
|
+
t['Items'].each do |i|
|
41
|
+
pages += i['Pages']
|
42
|
+
end
|
43
|
+
end
|
44
|
+
pages
|
45
|
+
end
|
46
|
+
|
47
|
+
end
|
48
|
+
end
|
@@ -0,0 +1,151 @@
|
|
1
|
+
class RubyBHL
|
2
|
+
|
3
|
+
API_KEY_FILE_PATH = File.expand_path("~/.bhl_api_key")
|
4
|
+
key = nil
|
5
|
+
key = File.read(API_KEY_FILE_PATH).strip if File.exists?(API_KEY_FILE_PATH)
|
6
|
+
API_KEY_FILE = key
|
7
|
+
API_KEY_ENV = ENV['BHL_API_KEY']
|
8
|
+
|
9
|
+
API_KEY = API_KEY_FILE || API_KEY_ENV || nil
|
10
|
+
|
11
|
+
warn "\n\n !! API key not set in ~/.bhl_api_key, .env, or ENV. You must pass requests an :api_key. !! \n\n" if API_KEY.nil? || API_KEY == 'sekret_key_here'
|
12
|
+
|
13
|
+
# Target API http://www.biodiversitylibrary.org/api2/docs/docs.html
|
14
|
+
class RubyBHL::Request
|
15
|
+
BASE_URL = 'http://www.biodiversitylibrary.org'
|
16
|
+
API_VERSION = 'api2'
|
17
|
+
INTERFACE = 'httpquery.ashx?'
|
18
|
+
FORMAT = 'json'
|
19
|
+
SEARCH_BASE = [BASE_URL, API_VERSION, INTERFACE].join("/")
|
20
|
+
|
21
|
+
METHODS = {
|
22
|
+
AuthorSearch: %w{name},
|
23
|
+
BookSearch: %w{title lname volume edition year subject language collectionid},
|
24
|
+
GetAuthorParts: %w{creatorid},
|
25
|
+
GetAuthorTitles: %w{creatorid},
|
26
|
+
GetCollections: %w{}, # no params
|
27
|
+
GetItemByIdentifier: %w{type value},
|
28
|
+
GetItemMetadata: %w{itemid pages oc parts},
|
29
|
+
GetItemPages: %w{itemid ocr},
|
30
|
+
GetItemParts: %w{itemid},
|
31
|
+
GetLanguages: %w{}, # no params
|
32
|
+
GetPageMetadata: %w{pageid ocr names},
|
33
|
+
GetPageNames: %w{pageid},
|
34
|
+
GetPageOcrText: %w{pageid},
|
35
|
+
GetPartBibTeX: %w{partid},
|
36
|
+
GetPartByIdentifier: %w{type value},
|
37
|
+
GetPartEndNote: %w{partid},
|
38
|
+
GetPartMetadata: %w{partid},
|
39
|
+
GetPartNames: %w{partid},
|
40
|
+
GetSubjectParts: %w{subject},
|
41
|
+
GetSubjectTitles: %w{subject},
|
42
|
+
GetTitleBibTex: %w{titleid},
|
43
|
+
GetTitleByIdentifier: %w{type value},
|
44
|
+
GetTitleEndNote: %w{titleid},
|
45
|
+
GetTitleItems: %w{titleid},
|
46
|
+
GetTitleMetadata: %w{titleid items},
|
47
|
+
GetUnpublishedItems: %w{}, # No params
|
48
|
+
GetUnpublishedParts: %w{}, # No params
|
49
|
+
GetUnpublishedTitles: %w{}, # No params
|
50
|
+
NameCount: %w{startdate enddate},
|
51
|
+
NameGetDetail: %w{namebankid name}, # !! Not in list below part of V1, see || criteria
|
52
|
+
NameCountBetweenDates: %w{}, # !! No documentation provided
|
53
|
+
# NameGetDetailForName: %w{}, # !! No documentation provided, can't confirm it works
|
54
|
+
# NameGetDetailForNameBankID: %w{}, # !! No documentation provided, can't confirm it works
|
55
|
+
NameList: %w{startrow batchsize stardate enddate}, # part of V1 !! may be problems
|
56
|
+
NameListBetweenDates: %w{}, # !! No documentation provided
|
57
|
+
NameSearch: %w{name}, # part of V1 !! may be problems
|
58
|
+
PartSearch: %w{title containerTitle author date volume series issue},
|
59
|
+
SubjectSearch: %w{subject},
|
60
|
+
TitleSearchSimple: %w{title},
|
61
|
+
}
|
62
|
+
|
63
|
+
REQUIRED_PARAMS = {
|
64
|
+
'name' => [:AuthorSearch, :NameSearch],
|
65
|
+
'creatorid' => [:GetAuthorParts, :GetAuthorTitles],
|
66
|
+
'type' => [:GetItemByIdentifier, :GetPartByIdentifier, :GetTitleByIdentifier],
|
67
|
+
'value' => [:GetItemByIdentifier, :GetPartByIdentifier, :GetTitleByIdentifier],
|
68
|
+
'itemid' => [:GetItemMetadata, :GetItemPages, :GetItemParts],
|
69
|
+
'pageid' => [:GetPageMetadata, :GetPageNames, :GetPageOcrText, :GetPartBibTeX],
|
70
|
+
'partid' => [:GetPartBibTeX, :GetPartEndNote, :GetPartMetadata, :GetPartNames],
|
71
|
+
'subject' => [:GetSubjectParts, :GetSubjectTitles, :SubjectSearch],
|
72
|
+
'titleid' => [:GetTitleBibTex, :GetTitleEndNote, :GetTitleItems, :GetTitleMetadata],
|
73
|
+
'title' => [:TitleSearchSimple]
|
74
|
+
}
|
75
|
+
|
76
|
+
mrp = {}
|
77
|
+
REQUIRED_PARAMS.each do |k,v|
|
78
|
+
v.each do |m|
|
79
|
+
mrp[m].push(k) if mrp[m]
|
80
|
+
mrp[m] ||= [k]
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
METHODS_REQUIRED_PARAMS = mrp
|
85
|
+
|
86
|
+
attr_accessor :params, :method, :format, :api_key
|
87
|
+
attr_reader :search_url
|
88
|
+
|
89
|
+
def initialize(options = {})
|
90
|
+
opts = {
|
91
|
+
api_key: RubyBHL::API_KEY,
|
92
|
+
format: RubyBHL::Request::FORMAT,
|
93
|
+
method: :NameSearch,
|
94
|
+
params: { }
|
95
|
+
}.merge!(options)
|
96
|
+
|
97
|
+
assign_options(opts)
|
98
|
+
build_url if valid?
|
99
|
+
end
|
100
|
+
|
101
|
+
def assign_options(opts)
|
102
|
+
@api_key = opts[:api_key]
|
103
|
+
@method = opts[:method]
|
104
|
+
@format = opts[:format]
|
105
|
+
@params = opts[:params]
|
106
|
+
end
|
107
|
+
|
108
|
+
def search_url
|
109
|
+
build_url
|
110
|
+
@search_url
|
111
|
+
end
|
112
|
+
|
113
|
+
def response
|
114
|
+
build_url
|
115
|
+
if valid?
|
116
|
+
Response.new(request: self)
|
117
|
+
else
|
118
|
+
false # raise?
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|
122
|
+
def params_are_supported?
|
123
|
+
return false if @method.nil?
|
124
|
+
return true if METHODS[@method] == []
|
125
|
+
@params.keys - METHODS[@method] == []
|
126
|
+
end
|
127
|
+
|
128
|
+
def has_required_params?
|
129
|
+
return false if @method.nil?
|
130
|
+
return true if METHODS_REQUIRED_PARAMS[@method].nil?
|
131
|
+
METHODS_REQUIRED_PARAMS[@method].select{|v| !@params.keys.include?(v)} == []
|
132
|
+
end
|
133
|
+
|
134
|
+
def valid?
|
135
|
+
raise API_KEY_MESSAGE if @api_key.nil?
|
136
|
+
raise "Method #{@method} not recognized." if @method && !RubyBHL::Request::METHODS.keys.include?(@method)
|
137
|
+
raise "Format #{@format} not recognized." if @format && !%w{json xml}.include?(@format)
|
138
|
+
|
139
|
+
!@method.nil? && !@format.nil? && params_are_supported? && has_required_params?
|
140
|
+
end
|
141
|
+
|
142
|
+
private
|
143
|
+
|
144
|
+
def build_url
|
145
|
+
@search_url = SEARCH_BASE + 'op=' + @method.to_s +
|
146
|
+
@params.keys.sort{|a,b| a.to_s <=> b.to_s}.collect{|k| "&#{k}=#{@params[k].to_s.gsub(/\s/, "+")}"}.join +
|
147
|
+
'&format=' + @format + '&apikey=' + @api_key
|
148
|
+
end
|
149
|
+
|
150
|
+
end
|
151
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
|
2
|
+
class RubyBHL
|
3
|
+
|
4
|
+
class Response
|
5
|
+
attr_reader :json
|
6
|
+
|
7
|
+
def initialize(options = {})
|
8
|
+
opts = {
|
9
|
+
request: nil
|
10
|
+
}.merge!(options)
|
11
|
+
|
12
|
+
raise if opts[:request].nil? || opts[:request].class != RubyBHL::Request
|
13
|
+
|
14
|
+
@json = {}
|
15
|
+
@json = JSON.parse(Net::HTTP.get_response(URI.parse(opts[:request].search_url)).body)
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
|
22
|
+
# Crud from 0.1.0
|
23
|
+
# # # from the ruby doc
|
24
|
+
# def fetch(uri_string, limit = 10)
|
25
|
+
# return nil if !uri_string
|
26
|
+
# limit = 10 # Justin Case we get in some redirect loop
|
27
|
+
# raise RbhlError, 'HTTP redirect too deep' if limit == 0 # should tweak
|
28
|
+
# response = Net::HTTP.get_response(URI.parse(uri_string))
|
29
|
+
# case response
|
30
|
+
# when Net::HTTPSuccess then response.body
|
31
|
+
# when Net::HTTPRedirection then fetch(response['location'], limit - 1)
|
32
|
+
# else
|
33
|
+
# response.error!
|
34
|
+
# end
|
35
|
+
# end
|
36
|
+
#
|
37
|
+
# # this works on a redirect
|
38
|
+
# def OCR_text(citation_index)
|
39
|
+
# return nil if !citation_index
|
40
|
+
# fetch(OCR_url(citation_index))
|
41
|
+
# end
|
42
|
+
|
43
|
+
# # Since the API doesn't return a link to the OCR we screen scrape the URL
|
44
|
+
# def OCR_url(citation_index)
|
45
|
+
# Net::HTTP.get_response(URI.parse(@citations[citation_index]["Url"])).body =~ /http:\/\/.*?\.txt/
|
46
|
+
# return $& # the matched results
|
47
|
+
# end
|
data/rubyBHL.gemspec
CHANGED
@@ -1,31 +1,31 @@
|
|
1
|
-
|
1
|
+
require File.expand_path('../lib/rubyBHL/version', __FILE__)
|
2
2
|
|
3
|
-
Gem::Specification.new do |
|
4
|
-
|
5
|
-
|
3
|
+
Gem::Specification.new do |gem|
|
4
|
+
gem.name = 'rubyBHL'
|
5
|
+
gem.version = RubyBHL::VERSION #"0.1.0
|
6
|
+
gem.authors = ["Matt Yoder"]
|
7
|
+
gem.email = %q{diapriid@gmail.com}
|
6
8
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
s.email = %q{diapriid@gmail.com}
|
12
|
-
s.extra_rdoc_files = ["README.rdoc", "lib/rubyBHL.rb"]
|
13
|
-
s.files = ["Manifest", "README.rdoc", "Rakefile", "init.rb", "lib/rubyBHL.rb", "test/helper.rb", "test/rubyBHL_test.rb", "rubyBHL.gemspec"]
|
14
|
-
s.homepage = %q{http://github.com/mjy/rubyBHL}
|
15
|
-
s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "rubyBHL", "--main", "README.rdoc"]
|
16
|
-
s.require_paths = ["lib"]
|
17
|
-
s.rubyforge_project = %q{rubybhl}
|
18
|
-
s.rubygems_version = %q{1.3.5}
|
19
|
-
s.summary = %q{Hook to the Biodiversity Heritage Library API plus some screen scraping for OCR.}
|
20
|
-
s.test_files = ["test/rubyBHL_test.rb"]
|
9
|
+
gem.description = %q{RubyBHL is a simple but flexible request/response wrapper for the Biodiversity Heritage Libary API. It includes (some) validation for request formatting. It has excellent unit-test coverage.}
|
10
|
+
gem.summary = %q{RubyBHL is a simple request/response wrapper for the Biodiversity Heritage Libary API.}
|
11
|
+
gem.homepage = 'http://github.com/SpeciesFileGroup/rubyBHL'
|
12
|
+
gem.license = "University of Illinois/NCSA Open Source License (NCSA)"
|
21
13
|
|
22
|
-
|
23
|
-
|
24
|
-
|
14
|
+
gem.files = `git ls-files`.split($/) # be sure to commit!
|
15
|
+
gem.test_files = gem.files.grep(%r{^(spec|features)/})
|
16
|
+
gem.require_paths = ["lib"]
|
17
|
+
|
18
|
+
gem.required_ruby_version = '~> 2.0'
|
19
|
+
|
20
|
+
gem.add_runtime_dependency 'json', '~> 1.8'
|
21
|
+
gem.add_runtime_dependency 'dotenv'
|
22
|
+
|
23
|
+
gem.add_development_dependency 'rake', '~> 10.1'
|
24
|
+
gem.add_development_dependency 'bundler', '~> 1.3'
|
25
|
+
gem.add_development_dependency 'rspec', '~> 2.14'
|
26
|
+
gem.add_development_dependency 'debugger', '~> 1.6'
|
27
|
+
gem.add_development_dependency 'git', '~> 1.2'
|
28
|
+
gem.add_development_dependency 'dotenv'
|
29
|
+
gem.add_development_dependency 'awesome_print', '~> 1.2'
|
25
30
|
|
26
|
-
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
27
|
-
else
|
28
|
-
end
|
29
|
-
else
|
30
|
-
end
|
31
31
|
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require_relative '../spec_helper'
|
2
|
+
describe RubyBHL::Mine do
|
3
|
+
subject { RubyBHL::Mine }
|
4
|
+
|
5
|
+
describe "`taxon_attribute_table`" do
|
6
|
+
|
7
|
+
it 'can be called with multiple attributes ' do
|
8
|
+
expect(RubyBHL::Mine.taxon_attribute_table('Apis melifera', ['honey', 'yellow', 'plant'], 3)).to be_true
|
9
|
+
end
|
10
|
+
|
11
|
+
it 'can be limited to a number of pages' do
|
12
|
+
t = RubyBHL::Mine.taxon_attribute_table('Apis melifera', ['honey'], 5)
|
13
|
+
expect(CSV.parse(t, col_sep: "\t").count).to eq(6)
|
14
|
+
end
|
15
|
+
|
16
|
+
it 'returns a CSV formatted text string (tab delimited)' do
|
17
|
+
t = RubyBHL::Mine.taxon_attribute_table('Apis melifera', ['honey'], 1)
|
18
|
+
expect(t.class).to eq(String)
|
19
|
+
expect(CSV.parse(t, col_sep: "\t", headers: true)).to be_true
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
|
24
|
+
end
|
@@ -0,0 +1,114 @@
|
|
1
|
+
require_relative '../spec_helper'
|
2
|
+
describe RubyBHL::Request do
|
3
|
+
|
4
|
+
subject { RubyBHL::Request }
|
5
|
+
|
6
|
+
describe 'instance' do
|
7
|
+
it 'has a default FORMAT' do
|
8
|
+
expect(RubyBHL::Request::FORMAT).to eq('json')
|
9
|
+
end
|
10
|
+
|
11
|
+
it 'uses API version 2' do
|
12
|
+
expect(RubyBHL::Request::API_VERSION).to eq('api2')
|
13
|
+
end
|
14
|
+
|
15
|
+
it 'uses the http interface' do
|
16
|
+
expect(RubyBHL::Request::INTERFACE).to eq('httpquery.ashx?')
|
17
|
+
end
|
18
|
+
|
19
|
+
it 'knows the API methods' do
|
20
|
+
expect(RubyBHL::Request::METHODS).to have(37).things
|
21
|
+
end
|
22
|
+
|
23
|
+
it 'has a base URL' do
|
24
|
+
expect(RubyBHL::Request::BASE_URL).to eq('http://www.biodiversitylibrary.org')
|
25
|
+
end
|
26
|
+
|
27
|
+
it 'has a SEARCH_BASE' do
|
28
|
+
expect(RubyBHL::Request::SEARCH_BASE).to eq('http://www.biodiversitylibrary.org/api2/httpquery.ashx?')
|
29
|
+
end
|
30
|
+
|
31
|
+
|
32
|
+
describe 'search_url' do
|
33
|
+
before(:each) {
|
34
|
+
@r = RubyBHL::Request.new()
|
35
|
+
}
|
36
|
+
|
37
|
+
it 'can validate that "foo" is not a supported param for :NameSearch `params_are_supported?`' do
|
38
|
+
@r.params = {'foo' => 'bar'}
|
39
|
+
expect(@r.params_are_supported?).to be_false
|
40
|
+
end
|
41
|
+
|
42
|
+
it 'can validate that "name" is a supported param for :NameSearch `params_are_supported?`' do
|
43
|
+
@r.params = {"name" => 'bar'}
|
44
|
+
expect(@r.params_are_supported?).to be_true
|
45
|
+
end
|
46
|
+
|
47
|
+
it 'can validate that required params are not present with `has_required_params?`' do
|
48
|
+
@r.params = {'foo' => 'bar'}
|
49
|
+
expect(@r.has_required_params?).to be_false
|
50
|
+
end
|
51
|
+
|
52
|
+
it 'can validate that required params are present with `has_required_params?`' do
|
53
|
+
@r.params = {'name' => 'bar'}
|
54
|
+
expect(@r.has_required_params?).to be_true
|
55
|
+
end
|
56
|
+
|
57
|
+
it 'can be invalidated with `valid?`' do
|
58
|
+
expect(@r.valid?).to be_false
|
59
|
+
end
|
60
|
+
|
61
|
+
it 'can be validated with `valid?`' do
|
62
|
+
@r.params = {'name' => 'bar'}
|
63
|
+
expect(@r.valid?).to be_true
|
64
|
+
end
|
65
|
+
|
66
|
+
it 'replaces spaces with plus in params' do
|
67
|
+
@r.params = {'name' => 'Aus bus'}
|
68
|
+
expect(@r.search_url =~ /\s/).to_not be_true
|
69
|
+
end
|
70
|
+
|
71
|
+
end
|
72
|
+
|
73
|
+
describe 'API keys' do
|
74
|
+
it "are stored in an `api_key` attribute" do
|
75
|
+
expect(RubyBHL::Request.new()).to respond_to(:api_key)
|
76
|
+
end
|
77
|
+
|
78
|
+
it 'are required' do
|
79
|
+
expect{RubyBHL::Request.new(api_key: nil)}.to raise_error
|
80
|
+
end
|
81
|
+
|
82
|
+
it "can come from `ENV['BHL_API_KEY']`" do
|
83
|
+
expect(RubyBHL::Request.new(api_key: RubyBHL::API_KEY_ENV).api_key).to eq('sekret_key_here')
|
84
|
+
end
|
85
|
+
|
86
|
+
it 'can come from `~/.bhl_api_key`' do
|
87
|
+
if File.exists?(RubyBHL::API_KEY_FILE_PATH)
|
88
|
+
expect(RubyBHL::Request.new()).to be_true
|
89
|
+
else
|
90
|
+
expect{RubyBHL::Request.new()}.to raise_error, API_KEY_MESSAGE
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
it "are from ~/.bhl_api_key instead of ENV['BHL_API_KEY'] when both provided" do
|
95
|
+
if RubyBHL::API_KEY_FILE.nil? || RubyBHL::API_KEY_ENV.nil?
|
96
|
+
pending API_KEY_MESSAGE
|
97
|
+
else
|
98
|
+
expect(RubyBHL::Request.new().api_key).to eq(RubyBHL::API_KEY_FILE )
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
it "are from opts(:api_key) instead of ENV or ~/.bhl_api_key when provided" do
|
103
|
+
if RubyBHL::API_KEY_FILE.nil? || RubyBHL::API_KEY_ENV.nil?
|
104
|
+
pending API_KEY_MESSAGE
|
105
|
+
else
|
106
|
+
expect(RubyBHL::Request.new(api_key: 'foo').api_key).to eq('foo')
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
end
|
114
|
+
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require_relative '../spec_helper'
|
2
|
+
describe RubyBHL::Response do
|
3
|
+
subject { RubyBHL::Response }
|
4
|
+
|
5
|
+
it 'requires a response' do
|
6
|
+
expect{ RubyBHL::Response.new() }.to raise_error
|
7
|
+
end
|
8
|
+
|
9
|
+
it 'a valid request does not raise' do
|
10
|
+
request = RubyBHL::Request.new(params: {'name' => 'blorf'})
|
11
|
+
expect(request.valid?).to be_true
|
12
|
+
expect{ RubyBHL::Response.new(request: request) }.to_not raise_error
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
# def test_OCR_text_scraping
|
17
|
+
# @bhl = RubyBHL::Rbhl.new(:params => {:title => "Manual of North American Diptera"})
|
18
|
+
# assert @bhl.OCR_text(0).size > 0
|
19
|
+
# assert @bhl.OCR_text(0) =~ /Diptera/
|
20
|
+
# end
|
21
|
+
|
@@ -0,0 +1,41 @@
|
|
1
|
+
require_relative '../spec_helper'
|
2
|
+
|
3
|
+
describe RubyBHL do
|
4
|
+
subject { RubyBHL }
|
5
|
+
|
6
|
+
it 'breaks for ruby 1.9.3 and older' do
|
7
|
+
%w{1.8.7 1.9.2 1.9.3}.each do |v|
|
8
|
+
stub_const('RUBY_VERSION', v)
|
9
|
+
expect{load File.expand_path('../../../lib/rubyBHL.rb', __FILE__)}.
|
10
|
+
to raise_error
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
it 'has version' do
|
15
|
+
expect(RubyBHL::VERSION =~ /\d+\.\d+\.\d/).to be_true
|
16
|
+
end
|
17
|
+
|
18
|
+
it 'has API_KEY_FILE_PATH' do
|
19
|
+
expect(RubyBHL::API_KEY_FILE_PATH).to eq( File.expand_path("~/.bhl_api_key") )
|
20
|
+
end
|
21
|
+
|
22
|
+
describe '`quick_request`' do
|
23
|
+
it 'exists as a class method' do
|
24
|
+
expect(RubyBHL.public_methods.include?(:quick_request)).to be_true
|
25
|
+
end
|
26
|
+
|
27
|
+
it 'responds with a RubyBHL::Response' do
|
28
|
+
expect(RubyBHL.quick_request().class).to eq(RubyBHL::Response)
|
29
|
+
end
|
30
|
+
|
31
|
+
it 'makes a Net::HTTP request, and turns it into json' do
|
32
|
+
expect(RubyBHL.quick_request().json).to eq({"Status"=>"ok", "ErrorMessage"=>nil, "Result"=>[]})
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
36
|
+
|
37
|
+
|
38
|
+
|
39
|
+
|
40
|
+
end
|
41
|
+
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
# require 'coveralls'
|
2
|
+
# Coveralls.wear!
|
3
|
+
|
4
|
+
require 'dotenv'
|
5
|
+
Dotenv.load
|
6
|
+
|
7
|
+
require 'rubyBHL'
|
8
|
+
require 'awesome_print'
|
9
|
+
# require 'rspec'
|
10
|
+
# require 'rspec/mocks'
|
11
|
+
# require 'socket'
|
12
|
+
|
13
|
+
API_KEY_MESSAGE = "Add a key to ~/.bhl_api_key and/or ensure ENV['BHL_API_KEY'] is set for this test to pass or be tested."
|
14
|
+
|
15
|
+
RSpec.configure do |config|
|
16
|
+
|
17
|
+
end
|
metadata
CHANGED
@@ -1,68 +1,197 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: rubyBHL
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
|
-
authors:
|
7
|
-
- Yoder
|
6
|
+
authors:
|
7
|
+
- Matt Yoder
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
11
|
+
date: 2014-02-07 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: json
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.8'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.8'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: dotenv
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ~>
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '10.1'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ~>
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '10.1'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: bundler
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ~>
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '1.3'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ~>
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '1.3'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rspec
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ~>
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '2.14'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ~>
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '2.14'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: debugger
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ~>
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '1.6'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ~>
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '1.6'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: git
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ~>
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '1.2'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ~>
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '1.2'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: dotenv
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - '>='
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - '>='
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: awesome_print
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - ~>
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '1.2'
|
132
|
+
type: :development
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - ~>
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '1.2'
|
139
|
+
description: RubyBHL is a simple but flexible request/response wrapper for the Biodiversity
|
140
|
+
Heritage Libary API. It includes (some) validation for request formatting. It
|
141
|
+
has excellent unit-test coverage.
|
17
142
|
email: diapriid@gmail.com
|
18
143
|
executables: []
|
19
|
-
|
20
144
|
extensions: []
|
21
|
-
|
22
|
-
|
23
|
-
-
|
24
|
-
-
|
25
|
-
|
26
|
-
-
|
145
|
+
extra_rdoc_files: []
|
146
|
+
files:
|
147
|
+
- .env
|
148
|
+
- .gitignore
|
149
|
+
- .rspec
|
150
|
+
- .ruby-version
|
151
|
+
- Gemfile
|
152
|
+
- Gemfile.lock
|
153
|
+
- LICENSE
|
27
154
|
- README.rdoc
|
28
155
|
- Rakefile
|
29
|
-
- init.rb
|
30
156
|
- lib/rubyBHL.rb
|
31
|
-
-
|
32
|
-
-
|
157
|
+
- lib/rubyBHL/mine.rb
|
158
|
+
- lib/rubyBHL/request.rb
|
159
|
+
- lib/rubyBHL/response.rb
|
160
|
+
- lib/rubyBHL/version.rb
|
33
161
|
- rubyBHL.gemspec
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
162
|
+
- spec/lib/mine_spec.rb
|
163
|
+
- spec/lib/request_spec.rb
|
164
|
+
- spec/lib/response_spec.rb
|
165
|
+
- spec/lib/ruby_bhl_spec.rb
|
166
|
+
- spec/spec_helper.rb
|
167
|
+
homepage: http://github.com/SpeciesFileGroup/rubyBHL
|
168
|
+
licenses:
|
169
|
+
- University of Illinois/NCSA Open Source License (NCSA)
|
170
|
+
metadata: {}
|
38
171
|
post_install_message:
|
39
|
-
rdoc_options:
|
40
|
-
|
41
|
-
- --inline-source
|
42
|
-
- --title
|
43
|
-
- rubyBHL
|
44
|
-
- --main
|
45
|
-
- README.rdoc
|
46
|
-
require_paths:
|
172
|
+
rdoc_options: []
|
173
|
+
require_paths:
|
47
174
|
- lib
|
48
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
49
|
-
requirements:
|
50
|
-
- -
|
51
|
-
- !ruby/object:Gem::Version
|
52
|
-
version:
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
version: "1.2"
|
59
|
-
version:
|
175
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
176
|
+
requirements:
|
177
|
+
- - ~>
|
178
|
+
- !ruby/object:Gem::Version
|
179
|
+
version: '2.0'
|
180
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
181
|
+
requirements:
|
182
|
+
- - '>='
|
183
|
+
- !ruby/object:Gem::Version
|
184
|
+
version: '0'
|
60
185
|
requirements: []
|
61
|
-
|
62
|
-
|
63
|
-
rubygems_version: 1.3.5
|
186
|
+
rubyforge_project:
|
187
|
+
rubygems_version: 2.1.11
|
64
188
|
signing_key:
|
65
|
-
specification_version:
|
66
|
-
summary:
|
67
|
-
|
68
|
-
|
189
|
+
specification_version: 4
|
190
|
+
summary: RubyBHL is a simple request/response wrapper for the Biodiversity Heritage
|
191
|
+
Libary API.
|
192
|
+
test_files:
|
193
|
+
- spec/lib/mine_spec.rb
|
194
|
+
- spec/lib/request_spec.rb
|
195
|
+
- spec/lib/response_spec.rb
|
196
|
+
- spec/lib/ruby_bhl_spec.rb
|
197
|
+
- spec/spec_helper.rb
|
data/Manifest
DELETED
data/init.rb
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
#require 'ruby_BHL'
|
data/test/helper.rb
DELETED
data/test/rubyBHL_test.rb
DELETED
@@ -1,36 +0,0 @@
|
|
1
|
-
require File.expand_path(File.join(File.dirname(__FILE__), 'helper'))
|
2
|
-
require File.expand_path(File.join(File.dirname(__FILE__), '../lib/rubyBHL'))
|
3
|
-
|
4
|
-
class RubyBHLTest < Test::Unit::TestCase
|
5
|
-
|
6
|
-
def setup
|
7
|
-
end
|
8
|
-
|
9
|
-
def test_foo_is_not_a_legal_param
|
10
|
-
assert_raise(RubyBHL::RbhlError) {RubyBHL::Rbhl.new(:params => {:foo => "BAR!"}) }
|
11
|
-
end
|
12
|
-
|
13
|
-
def test_search_url_for_default_url_is_properly_formed
|
14
|
-
@bhl = RubyBHL::Rbhl.new(:params => {:title => "BAR!", :volume => "2"})
|
15
|
-
assert_equal "http://www.biodiversitylibrary.org/openurl?title=BAR!&volume=2&format=json", @bhl.search_url
|
16
|
-
end
|
17
|
-
|
18
|
-
def test_search_url_convert_space_to_plus
|
19
|
-
@bhl = RubyBHL::Rbhl.new(:params => {:title => "BAR FOO"})
|
20
|
-
assert_equal "http://www.biodiversitylibrary.org/openurl?title=BAR+FOO&format=json", @bhl.search_url
|
21
|
-
end
|
22
|
-
|
23
|
-
def test_basic_response_is_returned
|
24
|
-
# this is a crummy test, we need a reference to the status codes.
|
25
|
-
@bhl = RubyBHL::Rbhl.new(:params => {:title => "BAR FOO"}) # should match nothing, I hope
|
26
|
-
assert @bhl.json_data["Status"] == 1
|
27
|
-
assert @bhl.json_data["citations"].size == 0
|
28
|
-
end
|
29
|
-
|
30
|
-
def test_response_with_citations_is_returned
|
31
|
-
# this is a crummy test, we need a reference to the status codes.
|
32
|
-
@bhl = RubyBHL::Rbhl.new(:params => {:title => "Manual of North American Diptera"}) # should match nothing, I hope
|
33
|
-
assert @bhl.json_data["citations"].size > 0
|
34
|
-
end
|
35
|
-
|
36
|
-
end
|