Class: Diffbot::Product

Inherits:
Hashie::Trash
  • Object
show all
Extended by:
CoercibleHash
Includes:
Hashie::Extensions::Coercion, Hashie::Extensions::IndifferentAccess
Defined in:
lib/diffbot/product.rb

Overview

Representation of a product. This class offers a single entry point: the ‘.fetch` method, that, given a URL, will return the front page as analyzed by Diffbot.

Defined Under Namespace

Classes: Breadcrumb, RequestParams

Instance Attribute Summary

Attributes included from CoercibleHash

#coercions

Class Method Summary collapse

Methods included from CoercibleHash

coerce_property, extended

Class Method Details

.endpointObject



35
36
37
# File 'lib/diffbot/product.rb', line 35

def self.endpoint
  'http://api.diffbot.com/v2/product'
end

.fetch(url, token = Diffbot.token, parser = Yajl::Parser.method(:parse), defaults = Diffbot.product_defaults) ⇒ Object

Public: The Product API analyzes a shopping or e-commerce product page

and returns information on the product.

url - Product URL to process (URL encoded). 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.product_defaults.

Yields the request configuration.

Examples

# Request a product with the default options.
product = Diffbot::Product.fetch(url, api_token)

Returns a Diffbot::Product



29
30
31
32
33
# File 'lib/diffbot/product.rb', line 29

def self.fetch url, token=Diffbot.token, parser=Yajl::Parser.method(:parse), defaults=Diffbot.product_defaults
  request = Diffbot::Request.new(token)
  response = request.perform(:get, endpoint,{url: url, token: token})
  new(parser.call(response.body))
end