Skip to content

Fixes #42 #43

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 8, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Full documentation available [here](http://diffbot-php-client-docs.readthedocs.o

## Requirements

Minimum PHP 5.6 is required.
Minimum PHP 5.6 is required. PHP 7.0 is recommended.

This package uses some non-stable packages, so you must set your project's minimum stability to something like beta or dev in `composer.json`:

Expand Down
13 changes: 13 additions & 0 deletions puli.json
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,10 @@
"installer": "composer",
"env": "dev"
},
"paragonie/random_compat": {
"install-path": "vendor/paragonie/random_compat",
"installer": "composer"
},
"php-http/client-common": {
"install-path": "vendor/php-http/client-common",
"installer": "composer"
Expand Down Expand Up @@ -220,6 +224,11 @@
"installer": "composer",
"env": "dev"
},
"sebastian/object-enumerator": {
"install-path": "vendor/sebastian/object-enumerator",
"installer": "composer",
"env": "dev"
},
"sebastian/recursion-context": {
"install-path": "vendor/sebastian/recursion-context",
"installer": "composer",
Expand Down Expand Up @@ -249,6 +258,10 @@
"installer": "composer",
"env": "dev"
},
"symfony/filesystem": {
"install-path": "vendor/symfony/filesystem",
"installer": "composer"
},
"symfony/polyfill-mbstring": {
"install-path": "vendor/symfony/polyfill-mbstring",
"installer": "composer",
Expand Down
2 changes: 2 additions & 0 deletions src/Abstracts/Api.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,8 @@ public function buildUrl()
$url .= '&url=' . urlencode($this->url);
}

$url .= '&timeout='.$this->timeout;

// Add Custom Fields
$fields = $this->fieldSettings;
$fieldString = '';
Expand Down
12 changes: 6 additions & 6 deletions tests/Api/AnalyzeApiTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public function testBuildUrlNoCustomFields()
$url = $this
->apiWithMock
->buildUrl();
$expectedUrl = 'https://api.diffbot.com/v3/analyze?token=demo&url=https%3A%2F%2Farticle-mock.com';
$expectedUrl = 'https://api.diffbot.com/v3/analyze?token=demo&url=https%3A%2F%2Farticle-mock.com&timeout=30000';
$this->assertEquals($expectedUrl, $url);
}

Expand All @@ -50,7 +50,7 @@ public function testBuildUrlOneCustomField()
->apiWithMock
->setMeta(true)
->buildUrl();
$expectedUrl = 'https://api.diffbot.com/v3/analyze?token=demo&url=https%3A%2F%2Farticle-mock.com&fields=meta';
$expectedUrl = 'https://api.diffbot.com/v3/analyze?token=demo&url=https%3A%2F%2Farticle-mock.com&timeout=30000&fields=meta';
$this->assertEquals($expectedUrl, $url);
}

Expand All @@ -61,7 +61,7 @@ public function testBuildUrlTwoCustomFields()
->setMeta(true)
->setLinks(true)
->buildUrl();
$expectedUrl = 'https://api.diffbot.com/v3/analyze?token=demo&url=https%3A%2F%2Farticle-mock.com&fields=meta,links';
$expectedUrl = 'https://api.diffbot.com/v3/analyze?token=demo&url=https%3A%2F%2Farticle-mock.com&timeout=30000&fields=meta,links';
$this->assertEquals($expectedUrl, $url);
}

Expand All @@ -74,7 +74,7 @@ public function testBuildUrlFourCustomFields()
->setBreadcrumb(true)
->setQuerystring(true)
->buildUrl();
$expectedUrl = 'https://api.diffbot.com/v3/analyze?token=demo&url=https%3A%2F%2Farticle-mock.com&fields=meta,links,breadcrumb,querystring';
$expectedUrl = 'https://api.diffbot.com/v3/analyze?token=demo&url=https%3A%2F%2Farticle-mock.com&timeout=30000&fields=meta,links,breadcrumb,querystring';
$this->assertEquals($expectedUrl, $url);
}

Expand All @@ -85,7 +85,7 @@ public function testBuildUrlOtherOptionsOnly()
->setMode('article')
->buildUrl();

$expectedUrl = 'https://api.diffbot.com/v3/analyze?token=demo&url=https%3A%2F%2Farticle-mock.com&discussion=false&mode=article';
$expectedUrl = 'https://api.diffbot.com/v3/analyze?token=demo&url=https%3A%2F%2Farticle-mock.com&timeout=30000&discussion=false&mode=article';
$this->assertEquals($expectedUrl, $url);
}

Expand All @@ -100,7 +100,7 @@ public function testBuildUrlOtherOptionsAndCustomFields()
->setDiscussion(false)
->setMode('product')
->buildUrl();
$expectedUrl = 'https://api.diffbot.com/v3/analyze?token=demo&url=https%3A%2F%2Farticle-mock.com&fields=meta,links,breadcrumb,querystring&discussion=false&mode=product';
$expectedUrl = 'https://api.diffbot.com/v3/analyze?token=demo&url=https%3A%2F%2Farticle-mock.com&timeout=30000&fields=meta,links,breadcrumb,querystring&discussion=false&mode=product';
$this->assertEquals($expectedUrl, $url);
}

Expand Down
12 changes: 6 additions & 6 deletions tests/Api/ArticleApiTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public function testBuildUrlNoCustomFields()
$url = $this
->apiWithMock
->buildUrl();
$expectedUrl = 'https://api.diffbot.com/v3/article?token=demo&url=https%3A%2F%2Farticle-mock.com';
$expectedUrl = 'https://api.diffbot.com/v3/article?token=demo&url=https%3A%2F%2Farticle-mock.com&timeout=30000';
$this->assertEquals($expectedUrl, $url);
}

Expand All @@ -57,7 +57,7 @@ public function testBuildUrlOneCustomField()
->apiWithMock
->setMeta(true)
->buildUrl();
$expectedUrl = 'https://api.diffbot.com/v3/article?token=demo&url=https%3A%2F%2Farticle-mock.com&fields=meta';
$expectedUrl = 'https://api.diffbot.com/v3/article?token=demo&url=https%3A%2F%2Farticle-mock.com&timeout=30000&fields=meta';
$this->assertEquals($expectedUrl, $url);
}

Expand All @@ -68,7 +68,7 @@ public function testBuildUrlTwoCustomFields()
->setMeta(true)
->setLinks(true)
->buildUrl();
$expectedUrl = 'https://api.diffbot.com/v3/article?token=demo&url=https%3A%2F%2Farticle-mock.com&fields=meta,links';
$expectedUrl = 'https://api.diffbot.com/v3/article?token=demo&url=https%3A%2F%2Farticle-mock.com&timeout=30000&fields=meta,links';
$this->assertEquals($expectedUrl, $url);
}

Expand All @@ -82,7 +82,7 @@ public function testBuildUrlFourCustomFields()
->setQuerystring(true)
->setSentiment(true)
->buildUrl();
$expectedUrl = 'https://api.diffbot.com/v3/article?token=demo&url=https%3A%2F%2Farticle-mock.com&fields=meta,links,breadcrumb,querystring,sentiment';
$expectedUrl = 'https://api.diffbot.com/v3/article?token=demo&url=https%3A%2F%2Farticle-mock.com&timeout=30000&fields=meta,links,breadcrumb,querystring,sentiment';
$this->assertEquals($expectedUrl, $url);
}

Expand All @@ -94,7 +94,7 @@ public function testBuildUrlOtherOptionsOnly()
->setDiscussion(false)
->buildUrl();

$expectedUrl = 'https://api.diffbot.com/v3/article?token=demo&url=https%3A%2F%2Farticle-mock.com&paging=false&maxTags=10&discussion=false';
$expectedUrl = 'https://api.diffbot.com/v3/article?token=demo&url=https%3A%2F%2Farticle-mock.com&timeout=30000&paging=false&maxTags=10&discussion=false';
$this->assertEquals($expectedUrl, $url);
}

Expand All @@ -109,7 +109,7 @@ public function testBuildUrlOtherOptionsAndCustomFields()
->setQuerystring(true)
->setMaxTags(10)
->buildUrl();
$expectedUrl = 'https://api.diffbot.com/v3/article?token=demo&url=https%3A%2F%2Farticle-mock.com&fields=meta,links,breadcrumb,querystring&paging=false&maxTags=10';
$expectedUrl = 'https://api.diffbot.com/v3/article?token=demo&url=https%3A%2F%2Farticle-mock.com&timeout=30000&fields=meta,links,breadcrumb,querystring&paging=false&maxTags=10';
$this->assertEquals($expectedUrl, $url);
}

Expand Down
28 changes: 14 additions & 14 deletions tests/Api/CrawlTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,15 @@ public function testBuildUrlArticleApi()
{
$api = $this->diffbot->createArticleAPI('crawl')->setDiscussion(false);

$expected = 'https://api.diffbot.com/v3/crawl?token=demo&name=sitepoint_01&seeds=http%3A%2F%2Fsitepoint.com&apiUrl=https%3A%2F%2Fapi.diffbot.com%2Fv3%2Farticle%3F%26discussion%3Dfalse';
$expected = 'https://api.diffbot.com/v3/crawl?token=demo&name=sitepoint_01&seeds=http%3A%2F%2Fsitepoint.com&apiUrl=https%3A%2F%2Fapi.diffbot.com%2Fv3%2Farticle%3F%26timeout%3D30000%26discussion%3Dfalse';
$c = $this->diffbot->crawl('sitepoint_01', $api);
$c->setSeeds(['http://sitepoint.com']);
$this->assertEquals($expected, $c->buildUrl());
}

public function testBuildUrlDefaultApi()
{
$expected = 'https://api.diffbot.com/v3/crawl?token=demo&name=sitepoint_01&seeds=http%3A%2F%2Fsitepoint.com&apiUrl=https%3A%2F%2Fapi.diffbot.com%2Fv3%2Fanalyze%3F%26mode%3Dauto';
$expected = 'https://api.diffbot.com/v3/crawl?token=demo&name=sitepoint_01&seeds=http%3A%2F%2Fsitepoint.com&apiUrl=https%3A%2F%2Fapi.diffbot.com%2Fv3%2Fanalyze%3F%26timeout%3D30000%26mode%3Dauto';
$c = $this->diffbot->crawl('sitepoint_01');
$c->setSeeds(['http://sitepoint.com']);
$this->assertEquals($expected, $c->buildUrl());
Expand All @@ -67,7 +67,7 @@ public function testInvalidSeeds()

public function testPatternSetters()
{
$expected = 'https://api.diffbot.com/v3/crawl?token=demo&name=sitepoint_01&seeds=http%3A%2F%2Fsitepoint.com&pageProcessPattern=class%3DarticleBody&urlCrawlPattern=%2Fcategory%2Fshoes||%21%2Fauthor%2F||%5Ehttp%3A%2F%2Fwww.diffbot.com||type%3Dproduct%24&urlProcessPattern=%2Fproduct%2Fdetail||%21%3Fcurrency%3Deuro&apiUrl=https%3A%2F%2Fapi.diffbot.com%2Fv3%2Fanalyze%3F%26mode%3Dauto';
$expected = 'https://api.diffbot.com/v3/crawl?token=demo&name=sitepoint_01&seeds=http%3A%2F%2Fsitepoint.com&pageProcessPattern=class%3DarticleBody&urlCrawlPattern=%2Fcategory%2Fshoes||%21%2Fauthor%2F||%5Ehttp%3A%2F%2Fwww.diffbot.com||type%3Dproduct%24&urlProcessPattern=%2Fproduct%2Fdetail||%21%3Fcurrency%3Deuro&apiUrl=https%3A%2F%2Fapi.diffbot.com%2Fv3%2Fanalyze%3F%26timeout%3D30000%26mode%3Dauto';
$c = $this->diffbot->crawl('sitepoint_01');
$c->setSeeds(['http://sitepoint.com']);

Expand All @@ -85,7 +85,7 @@ public function testPatternSetters()

public function testRegexSetters()
{
$expected = 'https://api.diffbot.com/v3/crawl?token=demo&name=sitepoint_01&seeds=http%3A%2F%2Fsitepoint.com&urlCrawlRegEx=/^[a-z0-9_-]{3,16}$/&urlProcessRegEx=/^#?([a-f0-9]{6}|[a-f0-9]{3})$/&apiUrl=https%3A%2F%2Fapi.diffbot.com%2Fv3%2Fanalyze%3F%26mode%3Dauto';
$expected = 'https://api.diffbot.com/v3/crawl?token=demo&name=sitepoint_01&seeds=http%3A%2F%2Fsitepoint.com&urlCrawlRegEx=/^[a-z0-9_-]{3,16}$/&urlProcessRegEx=/^#?([a-f0-9]{6}|[a-f0-9]{3})$/&apiUrl=https%3A%2F%2Fapi.diffbot.com%2Fv3%2Fanalyze%3F%26timeout%3D30000%26mode%3Dauto';
$c = $this->diffbot->crawl('sitepoint_01');
$c->setSeeds(['http://sitepoint.com']);

Expand Down Expand Up @@ -114,7 +114,7 @@ public function maxHopsProvider()
*/
public function testMaxHops($input, $urlFragment)
{
$expected = 'https://api.diffbot.com/v3/crawl?token=demo&name=sitepoint_01&seeds=http%3A%2F%2Fsitepoint.com&maxHops=' . $urlFragment . '&apiUrl=https%3A%2F%2Fapi.diffbot.com%2Fv3%2Fanalyze%3F%26mode%3Dauto';
$expected = 'https://api.diffbot.com/v3/crawl?token=demo&name=sitepoint_01&seeds=http%3A%2F%2Fsitepoint.com&maxHops=' . $urlFragment . '&apiUrl=https%3A%2F%2Fapi.diffbot.com%2Fv3%2Fanalyze%3F%26timeout%3D30000%26mode%3Dauto';
$c = $this->diffbot->crawl('sitepoint_01');
$c->setSeeds(['http://sitepoint.com']);

Expand Down Expand Up @@ -142,7 +142,7 @@ public function maxProvider()
*/
public function testMax($input, $urlFragment)
{
$expected = 'https://api.diffbot.com/v3/crawl?token=demo&name=sitepoint_01&seeds=http%3A%2F%2Fsitepoint.com&maxToCrawl=' . $urlFragment . '&maxToProcess=' . $urlFragment . '&apiUrl=https%3A%2F%2Fapi.diffbot.com%2Fv3%2Fanalyze%3F%26mode%3Dauto';
$expected = 'https://api.diffbot.com/v3/crawl?token=demo&name=sitepoint_01&seeds=http%3A%2F%2Fsitepoint.com&maxToCrawl=' . $urlFragment . '&maxToProcess=' . $urlFragment . '&apiUrl=https%3A%2F%2Fapi.diffbot.com%2Fv3%2Fanalyze%3F%26timeout%3D30000%26mode%3Dauto';
$c = $this->diffbot->crawl('sitepoint_01');
$c->setSeeds(['http://sitepoint.com']);

Expand Down Expand Up @@ -177,7 +177,7 @@ public function notifyProviderOk()
*/
public function testNotify($input, $urlFragment)
{
$expected = 'https://api.diffbot.com/v3/crawl?token=demo&name=sitepoint_01&seeds=http%3A%2F%2Fsitepoint.com&' . $urlFragment . '&apiUrl=https%3A%2F%2Fapi.diffbot.com%2Fv3%2Fanalyze%3F%26mode%3Dauto';
$expected = 'https://api.diffbot.com/v3/crawl?token=demo&name=sitepoint_01&seeds=http%3A%2F%2Fsitepoint.com&' . $urlFragment . '&apiUrl=https%3A%2F%2Fapi.diffbot.com%2Fv3%2Fanalyze%3F%26timeout%3D30000%26mode%3Dauto';
$c = $this->diffbot->crawl('sitepoint_01');
$c->setSeeds(['http://sitepoint.com']);

Expand Down Expand Up @@ -230,7 +230,7 @@ public function crawlDelayProviderOk()
*/
public function testCrawlOk($input, $urlFragment)
{
$expected = 'https://api.diffbot.com/v3/crawl?token=demo&name=sitepoint_01&seeds=http%3A%2F%2Fsitepoint.com&crawlDelay=' . $urlFragment . '&apiUrl=https%3A%2F%2Fapi.diffbot.com%2Fv3%2Fanalyze%3F%26mode%3Dauto';
$expected = 'https://api.diffbot.com/v3/crawl?token=demo&name=sitepoint_01&seeds=http%3A%2F%2Fsitepoint.com&crawlDelay=' . $urlFragment . '&apiUrl=https%3A%2F%2Fapi.diffbot.com%2Fv3%2Fanalyze%3F%26timeout%3D30000%26mode%3Dauto';
$c = $this->diffbot->crawl('sitepoint_01');
$c->setSeeds(['http://sitepoint.com']);

Expand Down Expand Up @@ -280,7 +280,7 @@ public function repeatProviderOk()
*/
public function testRepeatOk($input, $urlFragment)
{
$expected = 'https://api.diffbot.com/v3/crawl?token=demo&name=sitepoint_01&seeds=http%3A%2F%2Fsitepoint.com&repeat=' . $urlFragment . '&apiUrl=https%3A%2F%2Fapi.diffbot.com%2Fv3%2Fanalyze%3F%26mode%3Dauto';
$expected = 'https://api.diffbot.com/v3/crawl?token=demo&name=sitepoint_01&seeds=http%3A%2F%2Fsitepoint.com&repeat=' . $urlFragment . '&apiUrl=https%3A%2F%2Fapi.diffbot.com%2Fv3%2Fanalyze%3F%26timeout%3D30000%26mode%3Dauto';
$c = $this->diffbot->crawl('sitepoint_01');
$c->setSeeds(['http://sitepoint.com']);

Expand Down Expand Up @@ -314,8 +314,8 @@ public function testRepeatNotOk($input)

public function testOnlyProcessIfNew()
{
$expected1 = 'https://api.diffbot.com/v3/crawl?token=demo&name=sitepoint_01&seeds=http%3A%2F%2Fsitepoint.com&onlyProcessIfNew=1&apiUrl=https%3A%2F%2Fapi.diffbot.com%2Fv3%2Fanalyze%3F%26mode%3Dauto';
$expected2 = 'https://api.diffbot.com/v3/crawl?token=demo&name=sitepoint_01&seeds=http%3A%2F%2Fsitepoint.com&onlyProcessIfNew=0&apiUrl=https%3A%2F%2Fapi.diffbot.com%2Fv3%2Fanalyze%3F%26mode%3Dauto';
$expected1 = 'https://api.diffbot.com/v3/crawl?token=demo&name=sitepoint_01&seeds=http%3A%2F%2Fsitepoint.com&onlyProcessIfNew=1&apiUrl=https%3A%2F%2Fapi.diffbot.com%2Fv3%2Fanalyze%3F%26timeout%3D30000%26mode%3Dauto';
$expected2 = 'https://api.diffbot.com/v3/crawl?token=demo&name=sitepoint_01&seeds=http%3A%2F%2Fsitepoint.com&onlyProcessIfNew=0&apiUrl=https%3A%2F%2Fapi.diffbot.com%2Fv3%2Fanalyze%3F%26timeout%3D30000%26mode%3Dauto';

$c = $this->diffbot->crawl('sitepoint_01');
$c->setSeeds(['http://sitepoint.com']);
Expand Down Expand Up @@ -345,7 +345,7 @@ public function maxRoundsProvider()
*/
public function testMaxRounds($input, $urlFragment)
{
$expected = 'https://api.diffbot.com/v3/crawl?token=demo&name=sitepoint_01&seeds=http%3A%2F%2Fsitepoint.com&maxRounds=' . $urlFragment . '&apiUrl=https%3A%2F%2Fapi.diffbot.com%2Fv3%2Fanalyze%3F%26mode%3Dauto';
$expected = 'https://api.diffbot.com/v3/crawl?token=demo&name=sitepoint_01&seeds=http%3A%2F%2Fsitepoint.com&maxRounds=' . $urlFragment . '&apiUrl=https%3A%2F%2Fapi.diffbot.com%2Fv3%2Fanalyze%3F%26timeout%3D30000%26mode%3Dauto';
$c = $this->diffbot->crawl('sitepoint_01');
$c->setSeeds(['http://sitepoint.com']);

Expand All @@ -356,8 +356,8 @@ public function testMaxRounds($input, $urlFragment)

public function testObeyRobots()
{
$expected1 = 'https://api.diffbot.com/v3/crawl?token=demo&name=sitepoint_01&seeds=http%3A%2F%2Fsitepoint.com&obeyRobots=1&apiUrl=https%3A%2F%2Fapi.diffbot.com%2Fv3%2Fanalyze%3F%26mode%3Dauto';
$expected2 = 'https://api.diffbot.com/v3/crawl?token=demo&name=sitepoint_01&seeds=http%3A%2F%2Fsitepoint.com&obeyRobots=0&apiUrl=https%3A%2F%2Fapi.diffbot.com%2Fv3%2Fanalyze%3F%26mode%3Dauto';
$expected1 = 'https://api.diffbot.com/v3/crawl?token=demo&name=sitepoint_01&seeds=http%3A%2F%2Fsitepoint.com&obeyRobots=1&apiUrl=https%3A%2F%2Fapi.diffbot.com%2Fv3%2Fanalyze%3F%26timeout%3D30000%26mode%3Dauto';
$expected2 = 'https://api.diffbot.com/v3/crawl?token=demo&name=sitepoint_01&seeds=http%3A%2F%2Fsitepoint.com&obeyRobots=0&apiUrl=https%3A%2F%2Fapi.diffbot.com%2Fv3%2Fanalyze%3F%26timeout%3D30000%26mode%3Dauto';
$c = $this->diffbot->crawl('sitepoint_01');
$c->setSeeds(['http://sitepoint.com']);

Expand Down
10 changes: 5 additions & 5 deletions tests/Api/CustomApiTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,23 +37,23 @@ public function apiNameProvider()
return [
[
'custom',
'https://api.diffbot.com/v3/custom?token=demo&url=http%3A%2F%2Fsample-url.com'
'https://api.diffbot.com/v3/custom?token=demo&url=http%3A%2F%2Fsample-url.com&timeout=30000'
],
[
'authorFolioNew',
'https://api.diffbot.com/v3/authorFolioNew?token=demo&url=http%3A%2F%2Fsample-url.com'
'https://api.diffbot.com/v3/authorFolioNew?token=demo&url=http%3A%2F%2Fsample-url.com&timeout=30000'
],
[
'authorFolioNew/something',
'https://api.diffbot.com/v3/authorFolioNew/something?token=demo&url=http%3A%2F%2Fsample-url.com'
'https://api.diffbot.com/v3/authorFolioNew/something?token=demo&url=http%3A%2F%2Fsample-url.com&timeout=30000'
],
[
'my-api',
'https://api.diffbot.com/v3/my-api?token=demo&url=http%3A%2F%2Fsample-url.com'
'https://api.diffbot.com/v3/my-api?token=demo&url=http%3A%2F%2Fsample-url.com&timeout=30000'
],
[
'my-api?param=value',
'https://api.diffbot.com/v3/my-api?param=value?token=demo&url=http%3A%2F%2Fsample-url.com'
'https://api.diffbot.com/v3/my-api?param=value?token=demo&url=http%3A%2F%2Fsample-url.com&timeout=30000'
]
];
}
Expand Down
Loading