Class: Bark::Request::TreeOfLife
- Inherits:
-
Bark::Request
- Object
- Bark::Request
- Bark::Request::TreeOfLife
- Defined in:
- lib/bark/request/tree_of_life.rb
Constant Summary collapse
- API_VERSION =
'v2'- SEARCH_BASE =
[Bark::Request::BASE_URL, API_VERSION, 'tree_of_life'].join("/")
- METHODS =
Method: parameters
{ tol_about: i{}, tol_mrca: i{node_ids ott_ids}, tol_subtree: i{node_id ott_id}, # tree_id "is superflous and can be ignored" tol_induced_subtree: i{node_ids ott_ids}, }
- REQUIRED_PARAMS =
node_ids or ott_ids are required in some cases, so this will have to be cased
{ }
- METHODS_REQUIRED_PARAMS =
mrp
Constants inherited from Bark::Request
Instance Attribute Summary
Attributes inherited from Bark::Request
#method, #params, #payload, #uri
Instance Method Summary collapse
- #assign_options(method: method, params: params) ⇒ Object
- #has_required_params? ⇒ Boolean
-
#initialize(method: :tol_about, params: {}) ⇒ TreeOfLife
constructor
A new instance of TreeOfLife.
- #json_payload ⇒ Object
- #valid? ⇒ Boolean
Methods inherited from Bark::Request
#params_are_supported?, #response
Constructor Details
#initialize(method: :tol_about, params: {}) ⇒ TreeOfLife
Returns a new instance of TreeOfLife.
30 31 32 33 |
# File 'lib/bark/request/tree_of_life.rb', line 30 def initialize(method: :tol_about, params: {}) (method: method, params: params) build_uri if valid? end |
Instance Method Details
#assign_options(method: method, params: params) ⇒ Object
35 36 37 38 39 |
# File 'lib/bark/request/tree_of_life.rb', line 35 def (method: method, params: params) @method = method @params = params @params ||= {} end |
#has_required_params? ⇒ Boolean
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/bark/request/tree_of_life.rb', line 46 def has_required_params? case @method when :tol_mrca, :tol_induced_subtree return false if @params == {} # Both empty return false if ((@params[:node_ids] == []) || @params[:node_ids].nil?) && ((@params[:ott_ids] == []) || @params[:ott_ids].nil?) when :tol_subtree # Both provided return false if !@params[:node_id].nil? && !@params[:ott_id].nil? # Neither provided return false unless !@params[:node_id].nil? || !@params[:ott_id].nil? when :tol_about else raise "Curious, #{@method} is not a method." end return true end |
#json_payload ⇒ Object
64 65 66 |
# File 'lib/bark/request/tree_of_life.rb', line 64 def json_payload JSON.generate(@params) end |
#valid? ⇒ Boolean
41 42 43 44 |
# File 'lib/bark/request/tree_of_life.rb', line 41 def valid? raise "Method #{@method} not recognized." if @method && !self.class::METHODS.keys.include?(@method) !@method.nil? && params_are_supported? && has_required_params? end |