Class: Wit::REST::Result

Inherits:
Object
  • Object
show all
Defined in:
lib/wit_ruby/rest/result.rb

Instance Method Summary collapse

Constructor Details

#initialize(resultHash, requestRest = nil, requestPath = nil, requestBody = nil) ⇒ Result

Instantiates with a given hash.



11
12
13
14
15
16
# File 'lib/wit_ruby/rest/result.rb', line 11

def initialize(resultHash, requestRest=nil, requestPath=nil, requestBody=nil)
  @originalHash = resultHash
  @requestRest = requestRest
  @requestPath = requestPath
  @requestBody = requestBody
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(possible_key, *args, &block) ⇒ Object

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.



41
42
43
# File 'lib/wit_ruby/rest/result.rb', line 41

def method_missing(possible_key, *args, &block)
  @originalHash.has_key?(possible_key.to_s) ? @originalHash[possible_key.to_s] : super
end

Instance Method Details

#bodyObject

Returns the request’s body



28
29
30
# File 'lib/wit_ruby/rest/result.rb', line 28

def body
  return @requestBody
end

#hashObject

Returns the orginalHash instance variable.



19
20
21
# File 'lib/wit_ruby/rest/result.rb', line 19

def hash
  return @originalHash
end

#pathObject

Returns the request’s path



33
34
35
# File 'lib/wit_ruby/rest/result.rb', line 33

def path
  return @requestPath
end

#restCodeObject

Returns the REST code from the given request



24
25
26
# File 'lib/wit_ruby/rest/result.rb', line 24

def restCode
  return @requestRest
end