Skip to content

Commit dd86b91

Browse files
authored
Merge pull request #60 from shinoshi/fix-crawl-post
Changed crawl api's call method from GET to POST
2 parents 5b29fc5 + 95ac967 commit dd86b91

File tree

1 file changed

+28
-8
lines changed

1 file changed

+28
-8
lines changed

src/Api/Crawl.php

+28-8
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,7 @@ public function setObeyRobots($bool = true)
365365

366366
return $this;
367367
}
368-
368+
369369
/**
370370
* Set value to 1 to force the use of proxy IPs for the crawl.
371371
*
@@ -450,10 +450,31 @@ public function delete($commit = true)
450450

451451
return ($commit) ? $this->call() : $this;
452452
}
453+
public function getCrawl()
454+
{
455+
$theUrl = $this->apiUrl ."?token=" . $this->diffbot->getToken() . "&name=" . $this->name;
456+
$response = $this->diffbot->getHttpClient()->get($theUrl);
457+
458+
$array = json_decode($response->getBody(), true);
459+
460+
if (isset($array['jobs'])) {
461+
$jobs = [];
462+
foreach ($array['jobs'] as $job) {
463+
$jobs[] = new JobCrawl($job);
464+
}
465+
return new EntityIterator($jobs, $response);
466+
} elseif (!isset($array['jobs']) && isset($array['response'])) {
467+
return $array['response'];
468+
} else {
469+
throw new DiffbotException($array["error"]);
470+
}
471+
}
453472

454473
public function call()
455474
{
456-
$response = $this->diffbot->getHttpClient()->get($this->buildUrl());
475+
$theHeader=["content-type"=>"application/x-www-form-urlencoded; charset=UTF-8"];
476+
$response = $this->diffbot->getHttpClient()->post($this->apiUrl, $theHeader, $this->buildUrl());
477+
457478

458479
$array = json_decode($response->getBody(), true);
459480

@@ -491,10 +512,9 @@ public function buildUrl()
491512
unset($this->otherOptions['urlCrawlPattern']);
492513
}
493514

494-
$url = rtrim($this->apiUrl, '/') . '?';
495515

496516
// Add token
497-
$url .= 'token=' . $this->diffbot->getToken();
517+
$url = 'token=' . $this->diffbot->getToken();
498518

499519
if ($this->getName()) {
500520
// Add name
@@ -503,8 +523,8 @@ public function buildUrl()
503523
// Add seeds
504524
if (!empty($this->seeds)) {
505525
$url .= '&seeds=' . implode('%20', array_map(function ($item) {
506-
return urlencode($item);
507-
}, $this->seeds));
526+
return urlencode($item);
527+
}, $this->seeds));
508528
}
509529

510530
// Add other options
@@ -523,7 +543,7 @@ public function buildUrl()
523543

524544
/**
525545
* Sets the request type to "urls" to retrieve the URL Report
526-
* URL for understanding diagnostic data of URLs
546+
* URL for understanding diagnostic data of URLs
527547
*
528548
* @return $this
529549
*/
@@ -532,7 +552,7 @@ public function getUrlReportUrl($num = null)
532552
$this->otherOptions['type'] = 'urls';
533553

534554
if (!empty($num) && is_numeric($num)) {
535-
$this->otherOptions['num'] = $num;
555+
$this->otherOptions['num'] = $num;
536556
}
537557

538558
// Setup data endpoint

0 commit comments

Comments
 (0)