Class: Diffbot::Frontpage
- Inherits:
-
Hashie::Trash
- Object
- Hashie::Trash
- Diffbot::Frontpage
- Extended by:
- CoercibleHash
- Includes:
- Hashie::Extensions::Coercion, Hashie::Extensions::IndifferentAccess
- Defined in:
- lib/diffbot/frontpage.rb
Overview
Representation of an front page. This class offers a single entry point: the ‘.fetch` method, that, given a URL, will return the front page as analyzed by Diffbot.
Instance Attribute Summary
Attributes included from CoercibleHash
Class Method Summary collapse
-
.endpoint ⇒ Object
The API endpoint where requests should be made.
-
.fetch(url, token = Diffbot.token, parser = Yajl::Parser.method(:parse)) ⇒ Object
Public: Fetch a frontpage’s information from a URL.
Methods included from CoercibleHash
Class Method Details
.endpoint ⇒ Object
The API endpoint where requests should be made.
Returns a URL.
38 39 40 |
# File 'lib/diffbot/frontpage.rb', line 38 def self.endpoint "http://www.diffbot.com/api/frontpage" end |
.fetch(url, token = Diffbot.token, parser = Yajl::Parser.method(:parse)) ⇒ Object
Public: Fetch a frontpage’s information from a URL.
url - The frontpage URL. token - The API token for Diffbot. parser - The callable object that will parse the raw output from the
API. Defaults to Diffbot::Frontpage::DmlParser.method(:parse).
Examples
# Request a frontpage with the default options.
frontpage = Diffbot::Frontpage.fetch(url, api_token)
Returns a Diffbot::Frontpage.
26 27 28 29 30 31 32 33 |
# File 'lib/diffbot/frontpage.rb', line 26 def self.fetch(url, token=Diffbot.token, parser=Yajl::Parser.method(:parse)) request = Diffbot::Request.new(token) response = request.perform(:get, endpoint) do |req| req[:query][:url] = url end new(parser.call(response.body)) end |