Class: Wit::REST::Result
- Inherits:
-
Object
- Object
- Wit::REST::Result
- Defined in:
- lib/wit_ruby/rest/result.rb
Overview
Wrapper for all results that is returned by the session and API calls.
Direct Known Subclasses
Entity, Expression, Intent, Message, MultiEntity, MultiIntent
Instance Method Summary collapse
-
#empty? ⇒ Boolean
Checks to see if the data in the Result object is empty (empty array or hash).
-
#entities ⇒ Array
Returns the list of entities from the given results.
-
#initialize(resultData, requestRest = nil, requestPath = nil, requestBody = nil) ⇒ Wit::REST::Result
constructor
Instantiates with a given hash and its REST parameters.
-
#method_missing(possible_key, *args, &block) ⇒ Class
Checks if the method is one of the keys in the hash.
-
#raw_data ⇒ Hash
Returns the orginalHash instance variable.
-
#refreshable? ⇒ Boolean
Method to check if this current object is refreshable.
-
#restBody ⇒ String
Returns the request’s body.
-
#restCode ⇒ String
Returns the REST code from the given request.
-
#restPath ⇒ String
Returns the request’s path.
Constructor Details
#initialize(resultData, requestRest = nil, requestPath = nil, requestBody = nil) ⇒ Wit::REST::Result
Instantiates with a given hash and its REST parameters.
19 20 21 22 23 24 25 26 27 28 |
# File 'lib/wit_ruby/rest/result.rb', line 19 def initialize(resultData, requestRest=nil, requestPath=nil, requestBody=nil) @rawdata = resultData @requestRest = requestRest @requestPath = requestPath @requestBody = requestBody ## Sets self class to be the last index of the split class name. @selfClass = self.class.name.split("::")[-1] ## Setup lists / instance variables given the current class that is inheriting setup_entities if ["Intent", "Expression"].include?(@selfClass) end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(possible_key, *args, &block) ⇒ Class
Checks if the method is one of the keys in the hash. If it is then we can return the given value. If not, then raise a NoMethodError.
79 80 81 |
# File 'lib/wit_ruby/rest/result.rb', line 79 def method_missing(possible_key, *args, &block) @rawdata.has_key?(possible_key.to_s) ? @rawdata[possible_key.to_s] : super end |
Instance Method Details
#empty? ⇒ Boolean
Checks to see if the data in the Result object is empty (empty array or hash).
94 95 96 |
# File 'lib/wit_ruby/rest/result.rb', line 94 def empty? @rawdata.empty? end |
#entities ⇒ Array
Returns the list of entities from the given results. Only applicable to a few objects. If the current class is not applicable, then raise an error.
64 65 66 67 68 69 70 71 |
# File 'lib/wit_ruby/rest/result.rb', line 64 def entities unless ["Intent", "Expression"].include?(@selfClass) raise NoMethodError.new(%(The current class "#{@selfClass}' does not incorporate the '#{__method__}' method.)) end ## Included so return it. return @entities end |
#raw_data ⇒ Hash
Returns the orginalHash instance variable.
33 34 35 |
# File 'lib/wit_ruby/rest/result.rb', line 33 def raw_data return @rawdata end |
#refreshable? ⇒ Boolean
Method to check if this current object is refreshable. It is refresahble if the request parameters for checking is not nil;
87 88 89 |
# File 'lib/wit_ruby/rest/result.rb', line 87 def refreshable? !@requestRest.nil? end |
#restBody ⇒ String
Returns the request’s body.
47 48 49 |
# File 'lib/wit_ruby/rest/result.rb', line 47 def restBody return @requestBody end |
#restCode ⇒ String
Returns the REST code from the given request.
40 41 42 |
# File 'lib/wit_ruby/rest/result.rb', line 40 def restCode return @requestRest end |
#restPath ⇒ String
Returns the request’s path.
54 55 56 |
# File 'lib/wit_ruby/rest/result.rb', line 54 def restPath return @requestPath end |