Class: RTransmission::Response

Inherits:
Object
  • Object
show all
Defined in:
lib/rtransmission/response.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(body, prefix, block) ⇒ Response

Returns a new instance of Response.



13
14
15
16
17
# File 'lib/rtransmission/response.rb', line 13

def initialize(body, prefix, block)
  @body = body
  @prefix = prefix
  @block = block
end

Instance Attribute Details

#blockObject

Returns the value of attribute block.



11
12
13
# File 'lib/rtransmission/response.rb', line 11

def block
  @block
end

#bodyObject

Returns the value of attribute body.



9
10
11
# File 'lib/rtransmission/response.rb', line 9

def body
  @body
end

#prefixObject

Returns the value of attribute prefix.



10
11
12
# File 'lib/rtransmission/response.rb', line 10

def prefix
  @prefix
end

Instance Method Details

#parseObject



19
20
21
22
23
24
# File 'lib/rtransmission/response.rb', line 19

def parse
  body = JSON.parse(@body)
  raise RTransmission::Exception.new((@prefix ? @prefix + ': ' : '') + body['result']) if body['result'] != 'success'
  return @block.call(body['arguments']) if @block
  body['arguments']
end