bark 0.0.2
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.
- checksums.yaml +7 -0
- data/.gitignore +43 -0
- data/.travis.yml +3 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +45 -0
- data/LICENSE.txt +4 -0
- data/README.md +96 -0
- data/Rakefile +10 -0
- data/bark.gemspec +39 -0
- data/lib/bark.rb +109 -0
- data/lib/bark/request.rb +77 -0
- data/lib/bark/request/graph_of_life.rb +76 -0
- data/lib/bark/request/studies.rb +82 -0
- data/lib/bark/request/taxonomy.rb +78 -0
- data/lib/bark/request/tnrs.rb +75 -0
- data/lib/bark/request/tree_of_life.rb +91 -0
- data/lib/bark/response.rb +51 -0
- data/lib/bark/version.rb +3 -0
- data/spec/lib/bark_spec.rb +87 -0
- data/spec/lib/request/graph_of_life_spec.rb +44 -0
- data/spec/lib/request/studies_spec.rb +74 -0
- data/spec/lib/request/taxonomy_spec.rb +44 -0
- data/spec/lib/request/tnrs_spec.rb +44 -0
- data/spec/lib/request/tree_of_life_spec.rb +44 -0
- data/spec/lib/request_spec.rb +20 -0
- data/spec/lib/response_spec.rb +22 -0
- data/spec/lib/shared_tests_spec.rb +29 -0
- data/spec/shared_tests.rb +87 -0
- data/spec/shared_tests_helper.rb +115 -0
- data/spec/spec_helper.rb +23 -0
- metadata +184 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 64137c4a6b66b733c2cc125a2c8328bfd8f021e4
|
4
|
+
data.tar.gz: d2e60f6436a709252da45057b6790164c09aa117
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 29eaf4ab4a85a67e24fa1f94298646514bab4233ca36ec6dc6bb62baf4198e2caf23e9f1c10e8ed4eecfd0b5dc1f347db5861c91641a6986e5df75ffcd372b3d
|
7
|
+
data.tar.gz: 941bfaf1929a7cc3e04b294ab86b943336e498deadf5a3544ab9feca346d5d8db731dcf930e9856a555cbb429fbe5e9a92c777f401a105ba82784b0153130fe3
|
data/.gitignore
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
/.config
|
4
|
+
/coverage/
|
5
|
+
/InstalledFiles
|
6
|
+
/pkg/
|
7
|
+
/spec/reports/
|
8
|
+
/test/tmp/
|
9
|
+
/test/version_tmp/
|
10
|
+
/tmp/
|
11
|
+
|
12
|
+
## Specific to RubyMotion:
|
13
|
+
.dat*
|
14
|
+
.repl_history
|
15
|
+
build/
|
16
|
+
|
17
|
+
## Documentation cache and generated files:
|
18
|
+
/.yardoc/
|
19
|
+
/_yardoc/
|
20
|
+
/doc/
|
21
|
+
/rdoc/
|
22
|
+
|
23
|
+
## Environment normalisation:
|
24
|
+
/.bundle/
|
25
|
+
/lib/bundler/man/
|
26
|
+
|
27
|
+
# for a library or gem, you might want to ignore these files since the code is
|
28
|
+
# intended to run in multiple environments; otherwise, check them in:
|
29
|
+
# Gemfile.lock
|
30
|
+
# .ruby-version
|
31
|
+
# .ruby-gemset
|
32
|
+
|
33
|
+
# unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
|
34
|
+
.rvmrc
|
35
|
+
|
36
|
+
*~
|
37
|
+
*.swp
|
38
|
+
.DS_Store
|
39
|
+
|
40
|
+
.idea
|
41
|
+
idea/
|
42
|
+
.idea/
|
43
|
+
|
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
bark (0.0.1)
|
5
|
+
hashie (~> 3.3)
|
6
|
+
json (~> 1.8)
|
7
|
+
|
8
|
+
GEM
|
9
|
+
remote: https://rubygems.org/
|
10
|
+
specs:
|
11
|
+
awesome_print (1.2.0)
|
12
|
+
byebug (3.4.0)
|
13
|
+
columnize (~> 0.8)
|
14
|
+
debugger-linecache (~> 1.2)
|
15
|
+
slop (~> 3.6)
|
16
|
+
columnize (0.8.9)
|
17
|
+
debugger-linecache (1.2.0)
|
18
|
+
diff-lcs (1.2.5)
|
19
|
+
hashie (3.3.1)
|
20
|
+
json (1.8.1)
|
21
|
+
rake (10.3.2)
|
22
|
+
rspec (3.1.0)
|
23
|
+
rspec-core (~> 3.1.0)
|
24
|
+
rspec-expectations (~> 3.1.0)
|
25
|
+
rspec-mocks (~> 3.1.0)
|
26
|
+
rspec-core (3.1.0)
|
27
|
+
rspec-support (~> 3.1.0)
|
28
|
+
rspec-expectations (3.1.0)
|
29
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
30
|
+
rspec-support (~> 3.1.0)
|
31
|
+
rspec-mocks (3.1.0)
|
32
|
+
rspec-support (~> 3.1.0)
|
33
|
+
rspec-support (3.1.0)
|
34
|
+
slop (3.6.0)
|
35
|
+
|
36
|
+
PLATFORMS
|
37
|
+
ruby
|
38
|
+
|
39
|
+
DEPENDENCIES
|
40
|
+
awesome_print (~> 1.2)
|
41
|
+
bark!
|
42
|
+
bundler (~> 1.5)
|
43
|
+
byebug (~> 3.4)
|
44
|
+
rake (~> 10.3)
|
45
|
+
rspec (~> 3.1)
|
data/LICENSE.txt
ADDED
data/README.md
ADDED
@@ -0,0 +1,96 @@
|
|
1
|
+
bark
|
2
|
+
====
|
3
|
+
|
4
|
+
[![Continuous Integration Status][6]][7]
|
5
|
+
[![Dependency Status][8]][9]
|
6
|
+
[rubydoc][1]
|
7
|
+
|
8
|
+
Bark is a Ruby Gem wrapper on the [Open Tree of Life API][3]. It was written over the course of the [OpenTree hackathon][2] At present it seeks to provide a simple (level 1 in terms of hackathon speak) wrapper over all of the API calls available, returning a native json object for each response. It also acts as a sanity checker on the API calls themselves, running a suite of unit tests shared by related wrappers in [Python][5] and [R][4].
|
9
|
+
|
10
|
+
## Installation
|
11
|
+
|
12
|
+
Bark is written targetting Ruby 2.1.x.
|
13
|
+
|
14
|
+
Add this line to your application's Gemfile:
|
15
|
+
|
16
|
+
gem 'bark'
|
17
|
+
|
18
|
+
And then execute:
|
19
|
+
|
20
|
+
$ bundle
|
21
|
+
|
22
|
+
Or install it yourself as:
|
23
|
+
|
24
|
+
$ gem install bark
|
25
|
+
|
26
|
+
## Usage
|
27
|
+
|
28
|
+
Bark is broken down into Request and Response objects. These are additionally wrapped with a set of helper methods that map 1:1 with the [Open Tree URLs][3]. Binding method names [follow a convention][10] adopted by the related Python and R frameworks.
|
29
|
+
|
30
|
+
In your script:
|
31
|
+
|
32
|
+
```
|
33
|
+
require 'bark' # => true
|
34
|
+
```
|
35
|
+
|
36
|
+
### Simple usage
|
37
|
+
|
38
|
+
```ruby
|
39
|
+
Bark.tol_about # => { big hash }
|
40
|
+
```
|
41
|
+
|
42
|
+
Pass parameters like so:
|
43
|
+
|
44
|
+
```ruby
|
45
|
+
Bark.get_study(params: {:study_id => '2113'}) # => {big json response}
|
46
|
+
```
|
47
|
+
|
48
|
+
Parameter keys can be symbols or strings. Available methods [are listed here][10].
|
49
|
+
|
50
|
+
### Request/Response style
|
51
|
+
|
52
|
+
```ruby
|
53
|
+
request = Bark::Request::Studies.new(method: :get_study, params: {study_id: '2113'}) # => #<Bark::Request::Studies:0x0000010310d340 @method=:get_study, @params={:study_id=>"2113"}, @uri=#<URI::HTTP:0x0000010310c508 URL:http://devapi.opentreeoflife.org/v2/study/2113>>
|
54
|
+
```
|
55
|
+
|
56
|
+
Pre-check the validity of the requst (NOTE: mapping/checking is in development)
|
57
|
+
|
58
|
+
```ruby
|
59
|
+
request.valid? # => true
|
60
|
+
```
|
61
|
+
|
62
|
+
Get a response:
|
63
|
+
|
64
|
+
```ruby
|
65
|
+
response = Bark::Response.new(request: request) # => #<Bark::Response:0x0000010334c138 @json={ ... big response ... }
|
66
|
+
response.json # => { ... big response ... }
|
67
|
+
```
|
68
|
+
|
69
|
+
## Documentation
|
70
|
+
|
71
|
+
Documentation is autogenerated at [RubyDoc.info][1]
|
72
|
+
|
73
|
+
## Contributing
|
74
|
+
|
75
|
+
1. Fork it ( http://github.com/SpeciesFileGroup/bark/fork )
|
76
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
77
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
78
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
79
|
+
5. Create new Pull Request
|
80
|
+
|
81
|
+
## Licence
|
82
|
+
|
83
|
+
Bark is open source, it is available under the BSD licence.
|
84
|
+
|
85
|
+
[1]: http://rubydoc.info/github/SpeciesFileGroup/bark/frames
|
86
|
+
[2]: https://github.com/OpenTreeOfLife/hackathon
|
87
|
+
[3]: https://github.com/OpenTreeOfLife/opentree/wiki/Open-Tree-of-Life-APIs
|
88
|
+
[4]: https://github.com/fmichonneau/rotl
|
89
|
+
[5]: https://github.com/OpenTreeOfLife/opentree-interfaces
|
90
|
+
[6]: https://secure.travis-ci.org/SpeciesFileGroup/bark.png?branch=master
|
91
|
+
[7]: http://travis-ci.org/SpeciesFileGroup/bark?branch=master
|
92
|
+
[8]: https://gemnasium.com/SpeciesFileGroup/bark.png?branch=master
|
93
|
+
[9]: https://gemnasium.com/SpeciesFileGroup/bark?branch=master
|
94
|
+
[10]: https://github.com/OpenTreeOfLife/opentree/wiki/Libraries-for-working-with-opentree-in-various-languages-%28service-bindings-and-wrappers,-etc.%29
|
95
|
+
|
96
|
+
|
data/Rakefile
ADDED
data/bark.gemspec
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
#
|
3
|
+
# Notes for deploying
|
4
|
+
# gem build bark.gemspec
|
5
|
+
# gem install ./bark-0.0.1.gem
|
6
|
+
# gem yank bark -v 0.0.1
|
7
|
+
# gem push bark-0.0.1.gem
|
8
|
+
|
9
|
+
lib = File.expand_path('../lib', __FILE__)
|
10
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
11
|
+
require 'bark/version'
|
12
|
+
|
13
|
+
Gem::Specification.new do |spec|
|
14
|
+
spec.name = "bark"
|
15
|
+
spec.version = Bark::VERSION
|
16
|
+
spec.authors = ["Matt Yoder"]
|
17
|
+
spec.email = ["diapriid@gmail.com"]
|
18
|
+
spec.summary = %q{A Ruby wrapper on the Open Tree API.}
|
19
|
+
spec.description = %q{A wrapper on the Open Tree API, developed during the open tree hackathon in September, 2014.}
|
20
|
+
spec.homepage = "https://github.com/SpeciesFileGroup/bark"
|
21
|
+
spec.license = "BSD"
|
22
|
+
|
23
|
+
spec.files = `git ls-files -z`.split("\x0")
|
24
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
25
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
26
|
+
spec.require_paths = ["lib"]
|
27
|
+
|
28
|
+
spec.required_ruby_version = '~> 2.1'
|
29
|
+
|
30
|
+
spec.add_runtime_dependency 'json', '~> 1.8'
|
31
|
+
spec.add_runtime_dependency 'hashie', '~> 3.3'
|
32
|
+
|
33
|
+
spec.add_development_dependency "bundler", "~> 1.5"
|
34
|
+
spec.add_development_dependency "rake", "~> 10.3"
|
35
|
+
spec.add_development_dependency "byebug", "~> 3.4"
|
36
|
+
spec.add_development_dependency "rspec", '~> 3.1'
|
37
|
+
spec.add_development_dependency "awesome_print", '~> 1.2'
|
38
|
+
|
39
|
+
end
|
data/lib/bark.rb
ADDED
@@ -0,0 +1,109 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
recent_ruby = RUBY_VERSION >= '2.1.0'
|
4
|
+
raise "IMPORTANT: gem requires ruby >= 2.1.0" unless recent_ruby
|
5
|
+
|
6
|
+
require "bark/version"
|
7
|
+
|
8
|
+
require "json"
|
9
|
+
require "net/http"
|
10
|
+
|
11
|
+
require_relative 'bark/request'
|
12
|
+
require_relative 'bark/request/studies'
|
13
|
+
require_relative 'bark/request/tree_of_life'
|
14
|
+
require_relative 'bark/request/graph_of_life'
|
15
|
+
require_relative 'bark/request/tnrs'
|
16
|
+
require_relative 'bark/request/taxonomy'
|
17
|
+
|
18
|
+
require_relative 'bark/response'
|
19
|
+
|
20
|
+
class Bark
|
21
|
+
|
22
|
+
def self.request_class(method)
|
23
|
+
method = method.to_s
|
24
|
+
return Bark::Request::TreeOfLife if method =~ /^tol_/
|
25
|
+
return Bark::Request::Tnrs if method =~ /^tnrs_/
|
26
|
+
return Bark::Request::GraphOfLife if method =~ /^gol_/
|
27
|
+
return Bark::Request::Taxonomy if method =~ /^taxonomy_/
|
28
|
+
return Bark::Request::Studies if method =~ /^studies_|^get_study/
|
29
|
+
return false
|
30
|
+
end
|
31
|
+
|
32
|
+
# TODO: this needs more stress testing
|
33
|
+
def self.method_missing(meth, *args, &block)
|
34
|
+
if klass = self.request_class(meth)
|
35
|
+
if args[0].nil?
|
36
|
+
params = {}
|
37
|
+
else
|
38
|
+
params = args[0][:params]
|
39
|
+
end
|
40
|
+
params = {} if params.nil?
|
41
|
+
request = klass.new(method: meth, params: params, &block)
|
42
|
+
Bark::Response.new(request: request).result
|
43
|
+
else
|
44
|
+
super
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
#def self.tol_about(params: {})
|
49
|
+
#end
|
50
|
+
|
51
|
+
#def self.tol_mrca(params: {})
|
52
|
+
#end
|
53
|
+
|
54
|
+
#def self.tol_subtree(params: {})
|
55
|
+
#end
|
56
|
+
|
57
|
+
#def self.tol_induced_tree(params: {})
|
58
|
+
#end
|
59
|
+
|
60
|
+
#def self.gol_about(params: {})
|
61
|
+
#end
|
62
|
+
|
63
|
+
#def self.gol_source_tree(params: {})
|
64
|
+
#end
|
65
|
+
|
66
|
+
#def self.gol_node_info(params: {})
|
67
|
+
#end
|
68
|
+
|
69
|
+
#def self.tnrs_match_names(params: {})
|
70
|
+
#end
|
71
|
+
|
72
|
+
#def self.tnrs_contexts(params: {})
|
73
|
+
#end
|
74
|
+
|
75
|
+
#def self.tnrs_infer_context(params: {})
|
76
|
+
#end
|
77
|
+
|
78
|
+
#def self.taxonomy_about(params: {})
|
79
|
+
#end
|
80
|
+
|
81
|
+
#def self.taxonomy_lica(params: {})
|
82
|
+
#end
|
83
|
+
|
84
|
+
#def self.taxonomy_subtree(params: {})
|
85
|
+
#end
|
86
|
+
|
87
|
+
#def self.taxonomy_taxon(params: {})
|
88
|
+
#end
|
89
|
+
|
90
|
+
#def self.studies_find_studies(params: {})
|
91
|
+
#end
|
92
|
+
|
93
|
+
#def self.studies_find_trees(params: {})
|
94
|
+
#end
|
95
|
+
|
96
|
+
#def self.studies_properties(params: {})
|
97
|
+
#end
|
98
|
+
|
99
|
+
#def self.get_study(params: {})
|
100
|
+
#end
|
101
|
+
|
102
|
+
#def self.get_study_tree(params: {})
|
103
|
+
#end
|
104
|
+
|
105
|
+
end
|
106
|
+
|
107
|
+
class Bark::Error < StandardError
|
108
|
+
|
109
|
+
end
|
data/lib/bark/request.rb
ADDED
@@ -0,0 +1,77 @@
|
|
1
|
+
class Bark
|
2
|
+
class Request
|
3
|
+
|
4
|
+
# Target API https://github.com/OpenTreeOfLife/opentree/wiki/Open-Tree-of-Life-APIs
|
5
|
+
|
6
|
+
BASE_URL = 'http://devapi.opentreeoflife.org'
|
7
|
+
attr_accessor :params, :method
|
8
|
+
attr_accessor :payload
|
9
|
+
attr_reader :uri
|
10
|
+
|
11
|
+
# TODO: super this
|
12
|
+
def initialize(options = {})
|
13
|
+
opts = {
|
14
|
+
format: 'foo', # Bark::Request::FORMAT,
|
15
|
+
method: :getSyntheticTree,
|
16
|
+
params: { }
|
17
|
+
}.merge!(options)
|
18
|
+
|
19
|
+
assign_options(opts)
|
20
|
+
build_uri if valid?
|
21
|
+
end
|
22
|
+
|
23
|
+
def assign_options(opts)
|
24
|
+
@method = opts[:method]
|
25
|
+
@format = opts[:format]
|
26
|
+
@params = opts[:params]
|
27
|
+
|
28
|
+
end
|
29
|
+
|
30
|
+
def uri
|
31
|
+
build_uri
|
32
|
+
@uri
|
33
|
+
end
|
34
|
+
|
35
|
+
def response
|
36
|
+
build_uri
|
37
|
+
if valid?
|
38
|
+
Response.new(request: self)
|
39
|
+
else
|
40
|
+
false # raise?
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
def params_are_supported?
|
45
|
+
return false if @method.nil?
|
46
|
+
return true if self.class::METHODS[@method] == []
|
47
|
+
@params.keys.map(&:to_sym) - self.class::METHODS[@method] == []
|
48
|
+
end
|
49
|
+
|
50
|
+
def has_required_params?
|
51
|
+
return false if @method.nil?
|
52
|
+
return true if self.class::METHODS_REQUIRED_PARAMS[@method].nil?
|
53
|
+
self.class::METHODS_REQUIRED_PARAMS[@method].select{|v| !@params.keys.include?(v)} == []
|
54
|
+
end
|
55
|
+
|
56
|
+
# Stub for subclasses
|
57
|
+
def valid?
|
58
|
+
end
|
59
|
+
|
60
|
+
# stub for uri
|
61
|
+
def uri
|
62
|
+
build_uri
|
63
|
+
@uri
|
64
|
+
end
|
65
|
+
|
66
|
+
def json_payload
|
67
|
+
end
|
68
|
+
|
69
|
+
private
|
70
|
+
|
71
|
+
# Stub for subclasses
|
72
|
+
def build_uri
|
73
|
+
false
|
74
|
+
end
|
75
|
+
|
76
|
+
end
|
77
|
+
end
|