Class: Radiant::Helper::Response

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(url, status, body = "") ⇒ Response

Returns a new instance of Response.



10
11
12
13
14
# File 'lib/radiant_helper_response.rb', line 10

def initialize(url, status, body = "")
  self.url = url
  self.status = status.to_i
  self.body = body
end

Instance Attribute Details

#bodyObject

Returns the value of attribute body.



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

def body
  @body
end

#statusObject

Returns the value of attribute status.



6
7
8
# File 'lib/radiant_helper_response.rb', line 6

def status
  @status
end

#urlObject

Returns the value of attribute url.



8
9
10
# File 'lib/radiant_helper_response.rb', line 8

def url
  @url
end

Instance Method Details

#exceptionObject



38
39
40
# File 'lib/radiant_helper_response.rb', line 38

def exception
  Radiant::Helper::InvalidResponseError.new("URL: #{self.url} did not return a valid response! Status: #{self.status}") unless self.success?
end

#has_layout?Boolean

Returns:

  • (Boolean)


28
29
30
31
32
33
34
35
36
# File 'lib/radiant_helper_response.rb', line 28

def has_layout?
  ivar_cache("has_layout") do
    unless self.body.nil?
      b = self.body.downcase
      return ((b.match("<html>") ? true : false) && (b.match("</html>") ? true : false))
    end
    return false
  end
end

#success?Boolean

Returns:

  • (Boolean)


16
17
18
# File 'lib/radiant_helper_response.rb', line 16

def success?
  self.status == 200
end

#to_sObject



20
21
22
# File 'lib/radiant_helper_response.rb', line 20

def to_s
  self.success? ? self.body : ""
end

#to_strObject



24
25
26
# File 'lib/radiant_helper_response.rb', line 24

def to_str
  self.to_s
end