Module: OpenGraphReader
- Defined in:
- lib/open_graph_reader.rb,
lib/open_graph_reader/base.rb,
lib/open_graph_reader/object.rb,
lib/open_graph_reader/parser.rb,
lib/open_graph_reader/builder.rb,
lib/open_graph_reader/fetcher.rb,
lib/open_graph_reader/version.rb,
lib/open_graph_reader/object/dsl.rb,
lib/open_graph_reader/definitions.rb,
lib/open_graph_reader/parser/graph.rb,
lib/open_graph_reader/object/registry.rb,
lib/open_graph_reader/object/dsl/types.rb
Overview
quirks mode where invalid attributes don’t raise?
1.1 compatibility mode?
This module provides the main entry to the library. Please see the README for usage examples.
Defined Under Namespace
Modules: Object Classes: Article, Base, Book, Builder, Fetcher, InvalidObjectError, Music, NoOpenGraphDataError, Og, Parser, Profile, Video
Constant Summary collapse
- VERSION =
Tbe library version
"0.1.0"
Class Method Summary collapse
-
.fetch(url) ⇒ Base?
Convenience wrapper around OpenGraphReader.fetch! that swallows the esceptions and returns nil instead.
-
.fetch!(url) ⇒ Base
Fetch the OpenGraph object at the given URL.
-
.parse(html, origin = nil) ⇒ Base?
Convenience wrapper around OpenGraphReader.parse! that swallows the esceptions and returns nil instead.
-
.parse!(html, origin = nil) ⇒ Base
Parse the OpenGraph object in the given HTML document.
Class Method Details
.fetch(url) ⇒ Base?
Convenience wrapper around fetch! that swallows the esceptions and returns nil instead.
58 59 60 61 |
# File 'lib/open_graph_reader.rb', line 58 def self.fetch url fetch! url rescue NoOpenGraphDataError, InvalidObjectError end |
.fetch!(url) ⇒ Base
Fetch the OpenGraph object at the given URL. Raise if there are any issues.
26 27 28 29 30 31 32 33 34 35 |
# File 'lib/open_graph_reader.rb', line 26 def self.fetch! url case url when URI target = Fetcher.new(url) raise NoOpenGraphDataError, "#{url} doesn't contain any HTML" unless target.html? parse! target.body, target.url else fetch! URI.parse(url.to_s) end end |
.parse(html, origin = nil) ⇒ Base?
Convenience wrapper around parse! that swallows the esceptions and returns nil instead.
70 71 72 73 |
# File 'lib/open_graph_reader.rb', line 70 def self.parse html, origin=nil parse! html, origin rescue NoOpenGraphDataError, InvalidObjectError end |
.parse!(html, origin = nil) ⇒ Base
Parse the OpenGraph object in the given HTML document. Raise if there are any issues.
44 45 46 47 48 49 50 |
# File 'lib/open_graph_reader.rb', line 44 def self.parse! html, origin=nil parser = Parser.new html raise NoOpenGraphDataError, "#{origin || html} does not contain any OpenGraph tags" unless parser. Builder.new(parser.graph, parser.additional_namespaces).base.tap {|base| base.origin = origin.to_s if origin } end |