Class: Diffbot::Article
- Inherits:
-
Hashie::Trash
- Object
- Hashie::Trash
- Diffbot::Article
- Includes:
- Hashie::Extensions::Coercion, Hashie::Extensions::IndifferentAccess
- Defined in:
- lib/diffbot/article.rb
Overview
Representation of an article (ie a blog post or similar). This class offers a single entry point: the ‘.fetch` method, that, given a URL, will return the article as analyzed by Diffbot.
Defined Under Namespace
Classes: ImageItem, MediaItem, RequestParams, Stats, VideoItem
Class Method Summary collapse
-
.endpoint ⇒ Object
The API endpoint where requests should be made.
-
.fetch(url, token = Diffbot.token, parser = Yajl::Parser.method(:parse), defaults = Diffbot.article_defaults) {|params| ... } ⇒ Object
Public: Fetch an article from a URL.
Class Method Details
.endpoint ⇒ Object
The API endpoint where requests should be made.
Returns a URL.
52 53 54 |
# File 'lib/diffbot/article.rb', line 52 def self.endpoint "http://www.diffbot.com/api/article" end |
.fetch(url, token = Diffbot.token, parser = Yajl::Parser.method(:parse), defaults = Diffbot.article_defaults) {|params| ... } ⇒ Object
Public: Fetch an article from a URL.
url - The article URL. token - The API token for Diffbot. parser - The callable object that will parse the raw output from the
API. Defaults to Yajl::Parser.method(:parse).
defaults - The default request options. See Diffbot.article_defaults.
Yields the request configuration.
Examples
# Request an article with the default options.
article = Diffbot::Article.fetch(url, api_token)
# Pass options to the request. See Diffbot::Article::RequestParams to
# see the available configuration options.
article = Diffbot::Article.fetch(url, api_token) do |req|
req.html = true
end
Returns a Diffbot::Article.
37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/diffbot/article.rb', line 37 def self.fetch(url, token=Diffbot.token, parser=Yajl::Parser.method(:parse), defaults=Diffbot.article_defaults) params = defaults.dup yield params if block_given? request = Diffbot::Request.new(token) response = request.perform(:get, endpoint, params) do |req| req[:query][:url] = url end new(parser.call(response.body)) end |