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/configuration.rb,
lib/open_graph_reader/object/registry.rb,
lib/open_graph_reader/object/dsl/types.rb
Overview
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, Configuration, Fetcher, InvalidObjectError, Music, NoOpenGraphDataError, Og, Parser, Profile, UndefinedPropertyError, UnknownNamespaceError, Video
Constant Summary collapse
- VERSION =
Tbe library version
"0.7.2"
Class Method Summary collapse
-
.config ⇒ Configuration
private
Get the current Configuration instance.
-
.configure {|the| ... } ⇒ Object
Configure the library, see Configuration for the list of available options and their defaults.
-
.current_origin ⇒ String?
private
Thread local to retrieve the current origin if available.
- .current_origin=(value) ⇒ Object
-
.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
.config ⇒ Configuration
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Get the current Configuration instance
87 88 89 |
# File 'lib/open_graph_reader.rb', line 87 def self.config Configuration.instance end |
.configure {|the| ... } ⇒ Object
Configure the library, see Configuration for the list of available options and their defaults. Changing configuration at runtime is not thread safe.
79 80 81 |
# File 'lib/open_graph_reader.rb', line 79 def self.configure yield config end |
.current_origin ⇒ String?
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Thread local to retrieve the current origin if available. See OpenGraphReader::Base#origin if you want to know the origin of a parsed object.
96 97 98 |
# File 'lib/open_graph_reader.rb', line 96 def self.current_origin Thread.current[:_open_graph_reader_current_origin] end |
.current_origin=(value) ⇒ Object
100 101 102 |
# File 'lib/open_graph_reader.rb', line 100 def self.current_origin= value Thread.current[:_open_graph_reader_current_origin] = value end |
.fetch(url) ⇒ Base?
Convenience wrapper around fetch! that swallows the esceptions and returns nil instead.
56 57 58 59 |
# File 'lib/open_graph_reader.rb', line 56 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.
22 23 24 25 26 27 28 29 30 31 |
# File 'lib/open_graph_reader.rb', line 22 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.
68 69 70 71 |
# File 'lib/open_graph_reader.rb', line 68 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.
40 41 42 43 44 45 46 47 48 |
# File 'lib/open_graph_reader.rb', line 40 def self.parse! html, origin=nil self.current_origin = origin parser = Parser.new html raise NoOpenGraphDataError, "#{origin || html} does not contain any OpenGraph tags" unless parser. Builder.new(parser).base.tap {|base| base.origin = origin.to_s if origin self.current_origin = nil } end |