Class: HelloGoodbye::Request

Inherits:
Object
  • Object
show all
Defined in:
lib/hello_goodbye/json/request.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(str) ⇒ Request

Returns a new instance of Request.



6
7
8
# File 'lib/hello_goodbye/json/request.rb', line 6

def initialize(str)
  self.request_data=str
end

Instance Attribute Details

#commandObject (readonly)

Returns the value of attribute command.



4
5
6
# File 'lib/hello_goodbye/json/request.rb', line 4

def command
  @command
end

#request_hashObject

Returns the value of attribute request_hash.



3
4
5
# File 'lib/hello_goodbye/json/request.rb', line 3

def request_hash
  @request_hash
end

Instance Method Details

#request_data=(str) ⇒ Object



10
11
12
13
14
15
16
17
18
# File 'lib/hello_goodbye/json/request.rb', line 10

def request_data=(str)
  @request_data = JSON.parse(str)
  unless @request_data.include?("command")
    raise ArgumentError, 
      "The JSON string you supplied is invalid.  All requests must include a 'command' attribute."
  end
  @command = @request_data["command"]
  @request_data
end