diffbot 0.1.2 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +1 -1
- data/Gemfile.lock +2 -1
- data/README.md +1 -1
- data/Rakefile +1 -0
- data/diffbot.gemspec +2 -2
- data/lib/diffbot.rb +20 -0
- data/lib/diffbot/items/product.rb +63 -0
- data/lib/diffbot/product.rb +67 -0
- metadata +18 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 35d6b7f9cfea3baed8bce0a8f4c858ecd9aa6329
|
4
|
+
data.tar.gz: a9276c70d867748eb8be81cb9dd14d6ef30bddd6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 19a67f552b510e4d3774c1594a8bb2a4712b4ffa996390a6d52d57ca84cd3b09fb6ac30847cddd05767ab910f05fde909d18bc5ec5454930ae05ac4d792623c2
|
7
|
+
data.tar.gz: 178401466e3697b83295c08773a583075592bc9bb75d5e701d7e3bd5a49f3536091ff2dd528614389797d11bca9d6c0ce7a03afd022d8308d3e7f14ad2f06b02
|
data/.travis.yml
CHANGED
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# Diffbot
|
2
2
|
|
3
|
-
This is a ruby client for the [Diffbot](http://diffbot.com) API.
|
3
|
+
This is a ruby client for the [Diffbot](http://diffbot.com) API. [![Build Status](https://travis-ci.org/greshny/diffbot.png?branch=master)](https://travis-ci.org/greshny/diffbot)
|
4
4
|
|
5
5
|
## Install
|
6
6
|
|
data/Rakefile
CHANGED
data/diffbot.gemspec
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
s.name = "diffbot"
|
3
|
-
s.version = "0.1.
|
3
|
+
s.version = "0.1.3"
|
4
4
|
s.description = "Diffbot provides a concise API for analyzing and extracting semantic information from web pages using Diffbot (http://www.diffbot.com)."
|
5
5
|
s.summary = "Ruby interface to the Diffbot API "
|
6
6
|
s.authors = ["Nicolas Sanguinetti", "Roman Greshny"]
|
@@ -14,6 +14,6 @@ Gem::Specification.new do |s|
|
|
14
14
|
s.add_dependency("yajl-ruby")
|
15
15
|
s.add_dependency("nokogiri", "~> 1.5.0")
|
16
16
|
s.add_dependency("hashie")
|
17
|
-
|
17
|
+
s.add_development_dependency("bundler", "~> 1.3")
|
18
18
|
s.add_development_dependency("minitest")
|
19
19
|
end
|
data/lib/diffbot.rb
CHANGED
@@ -3,6 +3,7 @@ require "diffbot/coercible_hash"
|
|
3
3
|
require "diffbot/request"
|
4
4
|
require "diffbot/article"
|
5
5
|
require "diffbot/frontpage"
|
6
|
+
require "diffbot/product"
|
6
7
|
|
7
8
|
module Diffbot
|
8
9
|
# Public: Set global options. This is a nice API to group calls to the Diffbot
|
@@ -34,10 +35,29 @@ module Diffbot
|
|
34
35
|
@article_defaults
|
35
36
|
end
|
36
37
|
|
38
|
+
# Public: Configure the default request parameters for Product requests. See
|
39
|
+
# Product::RequestParams documentation for the specific configuration values
|
40
|
+
# you can set.
|
41
|
+
#
|
42
|
+
# Yields the default Product::RequestParams object.
|
43
|
+
#
|
44
|
+
# Returns the default Product::RequestParams object.
|
45
|
+
def self.product_defaults
|
46
|
+
if block_given?
|
47
|
+
@product_defaults = Product::RequestParams.new
|
48
|
+
yield @product_defaults
|
49
|
+
else
|
50
|
+
@product_defaults ||= Product::RequestParams.new
|
51
|
+
end
|
52
|
+
|
53
|
+
@product_defaults
|
54
|
+
end
|
55
|
+
|
37
56
|
# Public: Reset the configuration to the defaults. Useful for testing.
|
38
57
|
#
|
39
58
|
# Returns nil.
|
40
59
|
def self.reset!
|
60
|
+
@product_defaults = nil
|
41
61
|
@article_defaults = nil
|
42
62
|
@token = nil
|
43
63
|
@instrumentor = nil
|
@@ -0,0 +1,63 @@
|
|
1
|
+
module Diffbot
|
2
|
+
module Items
|
3
|
+
class Product < Hashie::Trash
|
4
|
+
extend CoercibleHash
|
5
|
+
|
6
|
+
# Name of the product. Returned by default.
|
7
|
+
property :title
|
8
|
+
|
9
|
+
# Description, if available, of the product. Returned by default.
|
10
|
+
property :description
|
11
|
+
|
12
|
+
# Identified offer or actual/'final' price of the product. Returned by default.
|
13
|
+
property :offer_price, from: :offerPrice
|
14
|
+
|
15
|
+
# A Diffbot-determined unique product ID.
|
16
|
+
# If upc, isbn, mpn or sku are identified on the page,
|
17
|
+
# productId will select from these values in the above order.
|
18
|
+
# Otherwise Diffbot will attempt to derive the best unique value for the product.
|
19
|
+
# Returned by default.
|
20
|
+
property :product_id, from: :productId
|
21
|
+
|
22
|
+
# Item's availability, either true or false. Returned by default.
|
23
|
+
property :availability
|
24
|
+
|
25
|
+
class Details < Hashie::Trash
|
26
|
+
property :amount
|
27
|
+
property :text
|
28
|
+
property :symbol
|
29
|
+
end
|
30
|
+
|
31
|
+
property :offer_price_details, from: :offerPriceDetails
|
32
|
+
coerce_property :offer_price_details, class: Details
|
33
|
+
|
34
|
+
class Media < Hashie::Trash
|
35
|
+
# Only images. Returns "True" if image is identified as primary in terms of size
|
36
|
+
# or positioning.
|
37
|
+
property :primary
|
38
|
+
|
39
|
+
# Direct (fully resolved) link to image or video content.
|
40
|
+
property :link
|
41
|
+
|
42
|
+
# Diffbot-determined best caption for the image.
|
43
|
+
property :caption
|
44
|
+
|
45
|
+
# Type of media identified (image or video).
|
46
|
+
property :type
|
47
|
+
|
48
|
+
# Image height, in pixels.
|
49
|
+
property :height
|
50
|
+
|
51
|
+
# Image width, in pixels.
|
52
|
+
property :width
|
53
|
+
|
54
|
+
# Full document Xpath to the media item.
|
55
|
+
property :xpath
|
56
|
+
end
|
57
|
+
|
58
|
+
# Array of media items (images or videos) of the product. Returned by default.
|
59
|
+
property :media
|
60
|
+
coerce_property :media, collection: Media
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
@@ -0,0 +1,67 @@
|
|
1
|
+
require 'yajl'
|
2
|
+
require 'diffbot/items/product'
|
3
|
+
|
4
|
+
module Diffbot
|
5
|
+
# Representation of a product. This class offers a single entry point: the
|
6
|
+
# `.fetch` method, that, given a URL, will return the front page as analyzed
|
7
|
+
# by Diffbot.
|
8
|
+
class Product < Hashie::Trash
|
9
|
+
extend CoercibleHash
|
10
|
+
# Public: The Product API analyzes a shopping or e-commerce product page
|
11
|
+
# and returns information on the product.
|
12
|
+
#
|
13
|
+
# url - Product URL to process (URL encoded).
|
14
|
+
# token - The API token for Diffbot.
|
15
|
+
# parser - The callable object that will parse the raw output from the
|
16
|
+
# API. Defaults to Yajl::Parser.method(:parse).
|
17
|
+
# defaults - The default request options. See Diffbot.product_defaults.
|
18
|
+
#
|
19
|
+
# Yields the request configuration.
|
20
|
+
#
|
21
|
+
# Examples
|
22
|
+
#
|
23
|
+
# # Request a product with the default options.
|
24
|
+
# product = Diffbot::Product.fetch(url, api_token)
|
25
|
+
#
|
26
|
+
# Returns a Diffbot::Product
|
27
|
+
def self.fetch url, token=Diffbot.token, parser=Yajl::Parser.method(:parse), defaults=Diffbot.product_defaults
|
28
|
+
request = Diffbot::Request.new(token)
|
29
|
+
response = request.perform(:get, endpoint,{url: url, token: token})
|
30
|
+
new(parser.call(response.body))
|
31
|
+
end
|
32
|
+
|
33
|
+
def self.endpoint
|
34
|
+
'http://api.diffbot.com/v2/product'
|
35
|
+
end
|
36
|
+
|
37
|
+
class Breadcrumb < Hashie::Trash
|
38
|
+
property :name
|
39
|
+
property :link
|
40
|
+
end
|
41
|
+
|
42
|
+
# If available, an array of link URLs and link text from page breadcrumbs.
|
43
|
+
# Returned by default.
|
44
|
+
property :breadcrumb
|
45
|
+
coerce_property :breadcrumb, collection: Breadcrumb
|
46
|
+
|
47
|
+
property :date_created
|
48
|
+
|
49
|
+
property :leaf_page, from: :leafPage
|
50
|
+
|
51
|
+
property :error
|
52
|
+
property :error_code, from: :errorCode
|
53
|
+
|
54
|
+
property :type
|
55
|
+
|
56
|
+
property :offer_price_details, from: :offerPriceDetails
|
57
|
+
|
58
|
+
|
59
|
+
# Products array
|
60
|
+
property :products
|
61
|
+
coerce_property :products, collection: Items::Product
|
62
|
+
|
63
|
+
# URL submitted. Returned by default.
|
64
|
+
property :url
|
65
|
+
class RequestParams < Hashie::Trash; end
|
66
|
+
end
|
67
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: diffbot
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nicolas Sanguinetti
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2014-
|
12
|
+
date: 2014-02-06 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: excon
|
@@ -67,6 +67,20 @@ dependencies:
|
|
67
67
|
- - '>='
|
68
68
|
- !ruby/object:Gem::Version
|
69
69
|
version: '0'
|
70
|
+
- !ruby/object:Gem::Dependency
|
71
|
+
name: bundler
|
72
|
+
requirement: !ruby/object:Gem::Requirement
|
73
|
+
requirements:
|
74
|
+
- - ~>
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: '1.3'
|
77
|
+
type: :development
|
78
|
+
prerelease: false
|
79
|
+
version_requirements: !ruby/object:Gem::Requirement
|
80
|
+
requirements:
|
81
|
+
- - ~>
|
82
|
+
- !ruby/object:Gem::Version
|
83
|
+
version: '1.3'
|
70
84
|
- !ruby/object:Gem::Dependency
|
71
85
|
name: minitest
|
72
86
|
requirement: !ruby/object:Gem::Requirement
|
@@ -104,6 +118,8 @@ files:
|
|
104
118
|
- lib/diffbot/frontpage.rb
|
105
119
|
- lib/diffbot/frontpage/dml_parser.rb
|
106
120
|
- lib/diffbot/item.rb
|
121
|
+
- lib/diffbot/items/product.rb
|
122
|
+
- lib/diffbot/product.rb
|
107
123
|
- lib/diffbot/request.rb
|
108
124
|
- test/article_test.rb
|
109
125
|
- test/coercible_hash_test.rb
|