Skip to content

Commit

Permalink
Updates byebug (development) to latest version. Stubs all remaining s…
Browse files Browse the repository at this point in the history
…hared test frameworks (and they run!).
  • Loading branch information
mjy committed Sep 18, 2014
1 parent 4baf64b commit 638935b
Show file tree
Hide file tree
Showing 11 changed files with 374 additions and 6 deletions.
6 changes: 4 additions & 2 deletions Gemfile.lock
Expand Up @@ -9,9 +9,10 @@ GEM
remote: https://rubygems.org/
specs:
awesome_print (1.2.0)
byebug (3.1.2)
byebug (3.4.0)
columnize (~> 0.8)
debugger-linecache (~> 1.2)
slop (~> 3.6)
columnize (0.8.9)
debugger-linecache (1.2.0)
diff-lcs (1.2.5)
Expand All @@ -30,6 +31,7 @@ GEM
rspec-mocks (3.1.0)
rspec-support (~> 3.1.0)
rspec-support (3.1.0)
slop (3.6.0)

PLATFORMS
ruby
Expand All @@ -38,6 +40,6 @@ DEPENDENCIES
awesome_print
bark!
bundler (~> 1.5)
byebug
byebug (~> 3.4)
rake
rspec (~> 3.1)
4 changes: 3 additions & 1 deletion README.md
Expand Up @@ -4,12 +4,14 @@ bark
[![Continuous Integration Status][6]][7]
[![Dependency Status][8]][9]

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 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 unity tests shared by related wrappers in [Python][5] and [R][4].
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 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].

## Installation

_Bark has not yet been published to a gem repo!_

Bark is written targetting Ruby 2.1.x.

Add this line to your application's Gemfile:

gem 'bark'
Expand Down
2 changes: 1 addition & 1 deletion bark.gemspec
Expand Up @@ -25,7 +25,7 @@ Gem::Specification.new do |spec|

spec.add_development_dependency "bundler", "~> 1.5"
spec.add_development_dependency "rake"
spec.add_development_dependency "byebug"
spec.add_development_dependency "byebug", "~> 3.4"
spec.add_development_dependency "rspec", '~> 3.1'
spec.add_development_dependency "awesome_print"

Expand Down
4 changes: 4 additions & 0 deletions lib/bark.rb
Expand Up @@ -11,6 +11,10 @@
require_relative 'bark/request'
require_relative 'bark/request/studies'
require_relative 'bark/request/tree_of_life'
require_relative 'bark/request/graph_of_life'
require_relative 'bark/request/tnrs'
require_relative 'bark/request/taxonomy'

require_relative 'bark/response'

class Bark
Expand Down
76 changes: 76 additions & 0 deletions lib/bark/request/graph_of_life.rb
@@ -0,0 +1,76 @@
class Bark::Request::GraphOfLife < Bark::Request

API_VERSION = 'v2'
SEARCH_BASE = [Bark::Request::BASE_URL, API_VERSION, 'graph'].join("/")

# Method: {parameters}
METHODS = {
gol_about: %i{},
gol_source_tree: %i{},
gol_node_info: %i{}, # tree_id "is superflous and can be ignored"
}

# node_ids or ott_ids are required in some cases, so this
# will have to be cased
REQUIRED_PARAMS = {
}

mrp = {}

REQUIRED_PARAMS.each do |k,v|
v.each do |m|
mrp[m].push(k) if mrp[m]
mrp[m] ||= [k]
end
end

METHODS_REQUIRED_PARAMS = mrp

def initialize(method: :tol_about, params: {})
assign_options(method: method, params: params)
build_uri if valid?
end

def assign_options(method: method, params: params)
@method = method
@params = params
@params ||= {}
end

def valid?
raise "Method #{@method} not recognized." if @method && !self.class::METHODS.keys.include?(@method)
!@method.nil? && params_are_supported? && has_required_params?
end

def has_required_params?
case @method
when :gol_of_life
end
return true
end

def json_payload
JSON.generate(@params)
end

private

# TODO: this doesn't feel right (or could be generalized out to superclass)
def build_uri
@uri = URI( SEARCH_BASE + '/' + send("#{@method}_url") )
end

def gol_about_url
'about'
end

def gol_source_tree_url
'source_tree'
end

def gol_node_info_url
'node_info'
end


end
78 changes: 78 additions & 0 deletions lib/bark/request/taxonomy.rb
@@ -0,0 +1,78 @@
class Bark::Request::Taxonomy < Bark::Request

API_VERSION = 'v2'
SEARCH_BASE = [Bark::Request::BASE_URL, API_VERSION, 'taxonomy'].join("/")

# Method: {parameters}
METHODS = {
taxonomy_about: %i{},
taxonomy_lica: %i{},
taxonomy_subtree: %i{},
taxonomy_taxon: %i{},
}

REQUIRED_PARAMS = {
}

mrp = {}

REQUIRED_PARAMS.each do |k,v|
v.each do |m|
mrp[m].push(k) if mrp[m]
mrp[m] ||= [k]
end
end

METHODS_REQUIRED_PARAMS = mrp

def initialize(method: :tol_about, params: {})
assign_options(method: method, params: params)
build_uri if valid?
end

def assign_options(method: method, params: params)
@method = method
@params = params
@params ||= {}
end

def valid?
raise "Method #{@method} not recognized." if @method && !self.class::METHODS.keys.include?(@method)
!@method.nil? && params_are_supported? && has_required_params?
end

def has_required_params?
case @method
when :taxonomy_about
end
return true
end

def json_payload
JSON.generate(@params)
end

private

# TODO: this doesn't feel right (or could be generalized out to superclass)
def build_uri
@uri = URI( SEARCH_BASE + '/' + send("#{@method}_url") )
end

def taxonomy_about_url
'about'
end

def taxonomy_lica_url
'lica'
end

def taxonomy_subtree_url
'subtree'
end

def taxonomy_taxon_url
'taxon'
end

end
75 changes: 75 additions & 0 deletions lib/bark/request/tnrs.rb
@@ -0,0 +1,75 @@
class Bark::Request::Tnrs < Bark::Request

API_VERSION = 'v2'
SEARCH_BASE = [Bark::Request::BASE_URL, API_VERSION, 'tnrs'].join("/")

# Method: {parameters}
METHODS = {
tnrs_match_names: %i{},
tnrs_contexts: %i{},
tnrs_infer_context: %i{},
}

# node_ids or ott_ids are required in some cases, so this
# will have to be cased
REQUIRED_PARAMS = {
}

mrp = {}

REQUIRED_PARAMS.each do |k,v|
v.each do |m|
mrp[m].push(k) if mrp[m]
mrp[m] ||= [k]
end
end

METHODS_REQUIRED_PARAMS = mrp

def initialize(method: :tol_about, params: {})
assign_options(method: method, params: params)
build_uri if valid?
end

def assign_options(method: method, params: params)
@method = method
@params = params
@params ||= {}
end

def valid?
raise "Method #{@method} not recognized." if @method && !self.class::METHODS.keys.include?(@method)
!@method.nil? && params_are_supported? && has_required_params?
end

def has_required_params?
#case @method
#when :foo
#end
return true
end

def json_payload
JSON.generate(@params)
end

private

# TODO: this doesn't feel right (or could be generalized out to superclass)
def build_uri
@uri = URI( SEARCH_BASE + '/' + send("#{@method}_url") )
end

def tnrs_match_names_url
'match_names'
end

def tnrs_contexts_url
'contexts'
end

def tnrs_infer_context_url
'infer_context'
end

end
44 changes: 44 additions & 0 deletions spec/lib/request/graph_of_life_spec.rb
@@ -0,0 +1,44 @@
require 'spec_helper'

describe Bark::Request::GraphOfLife do

#context 'Ruby/Bark specific implementation' do
# specify 'is written for an API_VERSION' do
# expect( Bark::Request::TreeOfLife::API_VERSION).to eq('v2')
# end

# specify 'has an SEARCH_BASE' do
# expect( Bark::Request::TreeOfLife::SEARCH_BASE).to eq('http://devapi.opentreeoflife.org/v2/tree_of_life')
# end

# specify 'reference methods by ot API wrapper shared name in METHODS' do
# expect( Bark::Request::TreeOfLife::METHODS.keys.sort).to eq(%i{tol_about tol_mrca tol_subtree tol_induced_tree}.sort)
# end

# context 'building a request URI' do
# specify 'for find_tree_of_life' do
# a = Bark::Request::TreeOfLife.new(method: :tol_about)
# expect(a.uri.to_s).to eq('http://devapi.opentreeoflife.org/v2/tree_of_life/about')
# end

# specify 'for matched_tree_of_life' do
# a = Bark::Request::TreeOfLife.new(method: :tol_mrca)
# expect(a.uri.to_s).to eq('http://devapi.opentreeoflife.org/v2/tree_of_life/mrca')
# end
# end

# context 'basic use, for :about, in a response' do
# specify 'works' do
# a = Bark::Request::TreeOfLife.new(method: :tol_about, params: {})
# b = Bark::Response.new(request: a)
# expect(b.request_succeeded?).to be(true)
# expect(b.json.keys.include?('root_node_id')).to be(true)
# end
# end

context 'shared tests' do
run_tests(Bark::Request::GraphOfLife, SharedTestsHelper::SHARED_TESTS['graph_of_life'])
end

# end
end
44 changes: 44 additions & 0 deletions spec/lib/request/taxonomy_spec.rb
@@ -0,0 +1,44 @@
require 'spec_helper'

describe Bark::Request::Taxonomy do

#context 'Ruby/Bark specific implementation' do
# specify 'is written for an API_VERSION' do
# expect( Bark::Request::TreeOfLife::API_VERSION).to eq('v2')
# end

# specify 'has an SEARCH_BASE' do
# expect( Bark::Request::TreeOfLife::SEARCH_BASE).to eq('http://devapi.opentreeoflife.org/v2/tree_of_life')
# end

# specify 'reference methods by ot API wrapper shared name in METHODS' do
# expect( Bark::Request::TreeOfLife::METHODS.keys.sort).to eq(%i{tol_about tol_mrca tol_subtree tol_induced_tree}.sort)
# end

# context 'building a request URI' do
# specify 'for find_tree_of_life' do
# a = Bark::Request::TreeOfLife.new(method: :tol_about)
# expect(a.uri.to_s).to eq('http://devapi.opentreeoflife.org/v2/tree_of_life/about')
# end

# specify 'for matched_tree_of_life' do
# a = Bark::Request::TreeOfLife.new(method: :tol_mrca)
# expect(a.uri.to_s).to eq('http://devapi.opentreeoflife.org/v2/tree_of_life/mrca')
# end
# end

# context 'basic use, for :about, in a response' do
# specify 'works' do
# a = Bark::Request::TreeOfLife.new(method: :tol_about, params: {})
# b = Bark::Response.new(request: a)
# expect(b.request_succeeded?).to be(true)
# expect(b.json.keys.include?('root_node_id')).to be(true)
# end
# end

context 'shared tests' do
run_tests(Bark::Request::Taxonomy, SharedTestsHelper::SHARED_TESTS['taxonomy'])
end

# end
end

0 comments on commit 638935b

Please sign in to comment.