Class: WhatCounts::Response

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

Constant Summary collapse

SUCCESS =
true
FAILURE =
false

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(url, document) ⇒ Response

Returns a new instance of Response.



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/whatcounts/response.rb', line 12

def initialize(url,document)
  self.url = url
  if document =~ /^(SUCCESS|FAILURE):?(.*)/
    # simple response
    self.body = $2.strip
    case $1 
    when "SUCCESS"
      self.result = SUCCESS
    when "FAILURE"
      self.result = FAILURE
    end
  else
    # TODO data based response
    self.body = document
  end
end

Instance Attribute Details

#bodyObject

Returns the value of attribute body.



7
8
9
# File 'lib/whatcounts/response.rb', line 7

def body
  @body
end

#resultObject

Returns the value of attribute result.



7
8
9
# File 'lib/whatcounts/response.rb', line 7

def result
  @result
end

#urlObject

Returns the value of attribute url.



7
8
9
# File 'lib/whatcounts/response.rb', line 7

def url
  @url
end

Instance Method Details

#failure?Boolean

Returns:

  • (Boolean)


30
# File 'lib/whatcounts/response.rb', line 30

def failure?; !self.result end

#success?Boolean

Returns:

  • (Boolean)


29
# File 'lib/whatcounts/response.rb', line 29

def success?; !!self.result end