Class: Linkser::Object

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

Direct Known Subclasses

Linkser::Objects::HTML

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(url, last_url, head, options = {}) ⇒ Object

Returns a new instance of Object.


8
9
10
11
12
13
# File 'lib/linkser/object.rb', line 8

def initialize url, last_url, head, options={}
  @url = url
  @last_url = last_url
  @head = head
  @options = options
end

Instance Attribute Details

#headObject (readonly)

Returns the value of attribute head


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

def head
  @head
end

#last_urlObject (readonly)

Returns the value of attribute last_url


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

def last_url
  @last_url
end

#urlObject (readonly)

Returns the value of attribute url


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

def url
  @url
end

Instance Method Details

#bodyObject


15
16
17
# File 'lib/linkser/object.rb', line 15

def body
  @body ||= build_body
end

#build_bodyObject


19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/linkser/object.rb', line 19

def build_body
  uri = URI.parse last_url
  if uri.scheme and (uri.scheme.eql? "http" or uri.scheme.eql? "https")
    http = Net::HTTP.new uri.host, uri.port
    if uri.scheme.eql? "https"
      unless @options[:ssl_verify]==true
       http.verify_mode = OpenSSL::SSL::VERIFY_NONE
      end
      http.use_ssl = true
    end
  else
  raise 'URI ' + uri.to_s + ' is not supported by Linkser'
  end
  http.start do |agent|
    request = Net::HTTP::Get.new uri.request_uri
    response = http.request request
    return response.body
  end
end