Class: Proxtopus::Response

Inherits:
Object
  • Object
show all
Defined in:
lib/proxtopus/response.rb,
lib/proxtopus/response_parser.rb

Defined Under Namespace

Modules: Parser

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(page, resource) ⇒ Response

Returns a new instance of Response.



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/proxtopus/response.rb', line 6

def initialize(page, resource)
  #puts "to response"
  #raise ArgumentError, "Response.new() expects page to be of type Mechanize::Page!" if !page.is_a?(Mechanize::Page)
  #raise ArgumentError, "Response.new() expects format to be of type Symbol!" if !format.is_a?(Symbol)
  #raise ArgumentError, "Response.new() expects elements to be of type Symbol!" if !format.is_a?(Symbol)
  
  @page = page
  @resource = resource
  #@body = page
  #@format = format
  #@elements = elements
  
  if resource.format == :json
    @proxies = Parser.json(page.body, resource.elements)
  elsif resource.format == :xml
    @proxies = Parser.xml(page.body, resource.elements)
  #elsif format == :rss
  #  @parsed = Parser.rss(@body, @elements)
  else
    raise ArgumentError, "Format #{resource.format} is currenly unsupported... consider adding it =]"
  end
  
  #puts "[@proxies in Response]"
  #puts @proxies.inspect
  #puts
  #puts
  #gets
  @proxies
end

Instance Attribute Details

#pageObject (readonly)

Returns the value of attribute page.



4
5
6
# File 'lib/proxtopus/response.rb', line 4

def page
  @page
end

#proxiesObject (readonly)

Returns the value of attribute proxies.



4
5
6
# File 'lib/proxtopus/response.rb', line 4

def proxies
  @proxies
end

#resourceObject (readonly)

Returns the value of attribute resource.



4
5
6
# File 'lib/proxtopus/response.rb', line 4

def resource
  @resource
end