Skip to content

Commit dc64f1f

Browse files
committed
Loads of new files added
1 parent 741b21d commit dc64f1f

File tree

198 files changed

+19247
-1139
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

198 files changed

+19247
-1139
lines changed

01-diffbot.rst

+42-42
Large diffs are not rendered by default.

_build/doctrees/01-diffbot.doctree

6.84 KB
Binary file not shown.

_build/doctrees/abstract-api.doctree

22.7 KB
Binary file not shown.
21.1 KB
Binary file not shown.

_build/doctrees/api-analyze.doctree

15.2 KB
Binary file not shown.

_build/doctrees/api-article.doctree

89.5 KB
Binary file not shown.

_build/doctrees/api-crawl.doctree

4.36 KB
Binary file not shown.

_build/doctrees/api-custom.doctree

18 KB
Binary file not shown.
1.72 KB
Binary file not shown.

_build/doctrees/api-image.doctree

1.68 KB
Binary file not shown.

_build/doctrees/api-product.doctree

1.7 KB
Binary file not shown.

_build/doctrees/api-search.doctree

1.69 KB
Binary file not shown.
2.3 KB
Binary file not shown.
4.57 KB
Binary file not shown.
2.28 KB
Binary file not shown.
27.9 KB
Binary file not shown.

_build/doctrees/class-traits.doctree

51.2 KB
Binary file not shown.

_build/doctrees/environment.pickle

41.8 KB
Binary file not shown.

_build/doctrees/index.doctree

552 Bytes
Binary file not shown.

_build/doctrees/overview.doctree

3.6 KB
Binary file not shown.

_build/html/en/01-diffbot.html

+172-58
Large diffs are not rendered by default.

_build/html/en/_sources/01-diffbot.txt

+42-42
Large diffs are not rendered by default.
+68
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
.. API Abstract class
2+
Added: September 8th, 2015
3+
Author: Bruno Skvorc <[email protected]>
4+
5+
============
6+
API Abstract
7+
============
8+
9+
This page will describe the API Abstract class - the one which all the API classes extend to get some common functionality. Use this to build your own API class for custom APIs you defined in the Diffbot UI.
10+
11+
.. php:namespace:: Swader\Diffbot\Abstracts
12+
13+
.. php:class:: Api
14+
15+
:hidden:`__construct`
16+
"""""""""""""""""""""""
17+
18+
.. php:method:: __construct($url)
19+
20+
This class takes a single argument during construction, the URL of the page to process. Alternatively, the argument can be "crawl", if the API is to be used in conjunction with the :php:class:`Swader\\Diffbot\\Api\\Crawl` API.
21+
22+
:param string $url: The URL of the page to process
23+
:throws: InvalidArgumentException if the URL is invalid AND not the word "crawl"
24+
25+
:hidden:`setTimeout`
26+
""""""""""""""""""""
27+
28+
.. php:method:: setTimeout($timeout = 30000)
29+
30+
Setting the timeout will define how long Diffbot will keep trying to fetch the API results. A timeout can happen for various reasons, from Diffbot's failure, to the site being crawled being exceptionally slow, and more.
31+
32+
:param int $timeout: Optional. The timeout, in milliseconds. Defaults to 30,000, a.k.a. 30 seconds
33+
:returns: $this
34+
:throws: InvalidArgumentException if the timeout value is invalid (negative or not an integer)
35+
36+
Usage::
37+
38+
$api->setTimeout(40000);
39+
40+
:hidden:`call`
41+
""""""""""""""
42+
43+
.. php:method:: call()
44+
45+
When the API instance has been fully configured, this method executes the call.
46+
47+
:returns: \\Swader\\Diffbot\\Entity\\EntityIterator The return value will be an iterable collection of appropriate entities. Refer to each API's documentation for details on entites returned from each API call.
48+
49+
Usage::
50+
51+
$result = $api->call();
52+
foreach ($result as $entity) { /* ... */ }
53+
54+
55+
:hidden:`buildUrl`
56+
""""""""""""""""""
57+
58+
.. php:method:: buildUrl()
59+
60+
This method is called automatically when :php:meth:`Swader\\Diffbot\\Abstracts\\Api::call` is called. It builds the URL which is to be called by the HTTPClient in :php:meth:`Swader\\Diffbot\\Diffbot::setHttpClient`, and returns it. This method can be used to get the URL for the purposes of testing in third party API clients like `Postman <https://www.getpostman.com/>`_.
61+
62+
:returns: string
63+
64+
Usage::
65+
66+
$api-> // ... set up API
67+
$myUrl = $api->buildUrl();
68+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
.. Entity Abstract class
2+
Added: September 20th, 2015
3+
Author: Bruno Skvorc <[email protected]>
4+
5+
===============
6+
Entity Abstract
7+
===============
8+
9+
This page will describe the Entity Abstract class. This class is the root of all Entity classes. Entity classes are used as containers for return values from various API endpoints. For example, the Article API will return an Article Entity, the Discussion API will return a Discussion Entity, and so on.
10+
11+
It is important to note that an API class will *never* return an Entity class directly. Rather, it will return an :php:class:`Swader\\Diffbot\\Entity\\EntityIterator`, an iterable container with all the Entities inside. The container, however, is configured in such a way that executing *get* methods on it directly will forward those calls to the first Entity in its dataset. Thus, in instances where
12+
13+
.. php:namespace:: Swader\Diffbot\Abstracts
14+
15+
.. php:class:: Entity
16+
17+
:hidden:`__construct`
18+
"""""""""""""""""""""
19+
20+
.. php:method:: __construct(array $data)
21+
22+
This class takes a single argument during construction, an array of data. This data is then turned into gettable information by means of getters, both direct and magic. Some getters do additional processing of the data in order to make it more useful to the user.
23+
24+
:param array $data: The data
25+
26+
:hidden:`getData`
27+
"""""""""""""""""
28+
29+
.. php:method:: getData()
30+
31+
Returns the raw data passed into the Entity by the parent API class. This will be an associative array (see Usage below).
32+
33+
:returns: array
34+
35+
Usage::
36+
37+
// ...
38+
39+
$data = $article->getData();
40+
41+
echo $data['title'];
42+
echo $data['author'];
43+
44+
// etc.
45+
46+
:hidden:`__call`
47+
""""""""""""""""
48+
49+
.. php:method:: __call()
50+
51+
Magic method for resolving undefined getters and only getters. If the method being called starts with ``get``, the remainder of its name will be turned into a key to search inside the `$data` property (see ``getData``). Once the call is identified as a *getter* call, ``__get`` is invoked (see below).
52+
53+
:returns: mixed
54+
:throws: BadMethodCallException if the prefix of the method is not ``get``
55+
56+
:hidden:`__get`
57+
"""""""""""""""
58+
59+
.. php:method:: __get()
60+
61+
This method is called automatically when ``__call`` is called. It looks for the property being asked for inside the ``$data`` property of the current class, or returns null if not found.
62+
63+
:returns: string
64+
65+
Usage::
66+
67+
$api-> // ... set up API
68+
$myUrl = $api->buildUrl();
69+
+82-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,88 @@
1-
.. Stub file
2-
Added: September 7th, 2015
1+
.. Documentation of Analyze API
2+
Added: September 25th, 2015
33
Author: Bruno Skvorc <[email protected]>
44

55
===========
66
Analyze API
77
===========
88

9-
Description goes here.
9+
This API is a sort of "catch all" for all other API types in that it automatically determines the type of content being processed, and applies the appropriate API call to it.
10+
11+
This API will return entities matching the determined content type. For example, if you run Analyze API on a URL like ``www.sitepoint.com/quick-tip-get-homestead-vagrant-vm-running/``, the content type will be determined as "article" and it'll be exactly as if you had called the Article API (:php:class:`Swader\\Diffbot\\Api\\Article`) on it.
12+
13+
Analyze API Class
14+
=================
15+
16+
.. php:namespace:: Swader\Diffbot\Api
17+
18+
.. php:class:: Analyze
19+
20+
:hidden:`setDiscussion`
21+
"""""""""""""""""""""""
22+
23+
.. php:method:: setDiscussion($bool = true)
24+
25+
:param bool $bool: Either ``true`` or ``false``
26+
:returns: $this
27+
28+
If set to false, will not extract article comments in a Discussion entity embedded in the Article / Product entity. By default, it will.
29+
30+
:hidden:`setMode`
31+
"""""""""""""""""
32+
33+
.. php:method:: setMode($mode)
34+
35+
:param string $mode: "article", "product", "image" or "auto"
36+
:returns: $this
37+
38+
By default the Analyze API will fully extract all pages that match an existing Automatic API -- articles, products or image pages. Set mode to a specific page-type (e.g., mode=article) to extract content only from that specific page-type. All other pages will simply return the default Analyze fields.
39+
40+
Usage with defaults::
41+
42+
use Swader\Diffbot\Diffbot;
43+
44+
$url = "www.sitepoint.com/quick-tip-get-homestead-vagrant-vm-running/";
45+
46+
$diffbot = new Diffbot("my_token");
47+
$api = $diffbot->createAnalyzeApi($url);
48+
49+
$result = $api->call();
50+
51+
echo $result->getAuthorUrl(); // "http://www.sitepoint.com/author/bskvorc/"
52+
53+
echo $result->getDiscussion()->getNumPosts(); // 7
54+
echo $result->getDiscussion()->getProvider(); // Disqus
55+
56+
Usage with discussion off::
57+
58+
use Swader\Diffbot\Diffbot;
59+
60+
$url = "www.sitepoint.com/quick-tip-get-homestead-vagrant-vm-running/";
61+
62+
$diffbot = new Diffbot("my_token");
63+
$api = $diffbot->createAnalyzeApi($url);
64+
65+
$api->setDiscussion(false);
66+
$result = $api->call();
67+
68+
echo $result->getAuthorUrl(); // "http://www.sitepoint.com/author/bskvorc/"
69+
70+
var_dump($result->getDiscussion()); // null
71+
72+
Usage with non-matching mode::
73+
74+
use Swader\Diffbot\Diffbot;
75+
76+
$url = "www.sitepoint.com/quick-tip-get-homestead-vagrant-vm-running/";
77+
78+
$diffbot = new Diffbot("my_token");
79+
$api = $diffbot->createAnalyzeApi($url);
80+
81+
$api->setMode("image");
82+
$result = $api->call();
83+
84+
echo $result->getAuthorUrl(); // null
85+
var_dump($result->getDiscussion()); // null
86+
87+
88+
In the last example above, no data is available due to a mismatch in mode - using image parsing on an article entity does not produce any useful information.

0 commit comments

Comments
 (0)