Class: OpenGraphy::Url

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

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(uri) ⇒ Url

Returns a new instance of Url.



3
4
5
# File 'lib/open_graphy/url.rb', line 3

def initialize(uri)
  @uri = uri
end

Class Method Details

.fetch(uri) ⇒ Object



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

def self.fetch(uri)
  new(uri).fetch
end

Instance Method Details

#fetchObject



11
12
13
14
15
16
17
18
19
20
# File 'lib/open_graphy/url.rb', line 11

def fetch
  data.add('url', @uri)
  begin
    valid_meta_tags.each { |tag| data.add(tag.name, tag.value, namespace: tag.namespace) }
    data.add('__html_title_tag',  doc.css('title').text)
  rescue SocketError, Net::HTTPServerException, Uri::RedirectLoopError, Uri::BadUriError
  end

  data
end