Skip to content

Commit 8f4e3c1

Browse files
committed
Fixed error messages and ensures all requests go via api.grabz.it
1 parent 4323697 commit 8f4e3c1

File tree

3 files changed

+26
-31
lines changed

3 files changed

+26
-31
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"homepage": "https://grabz.it/",
66
"description": "Use our API to allow your app to create images, DOCX documents, rendered HTML and PDF's from URL's or raw HTML. Additionally GrabzIt allows you to convert online videos into animated GIF's or HTML tables into CSV's.",
77
"license": "MIT",
8-
"version":"3.3.7.2",
8+
"version":"3.4.5",
99
"autoload": {
1010
"psr-4": {
1111
"GrabzIt\\": "lib/"

lib/GrabzItClient.php

Lines changed: 24 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@
1010

1111
class GrabzItClient
1212
{
13-
const WebServicesBaseURL_GET = "://api.grabz.it/services/";
14-
const WebServicesBaseURL_POST = "://grabz.it/services/";
13+
const WebServicesBaseURL = "://api.grabz.it/services/";
1514
const TakePicture = "takepicture.ashx";
1615
const TakeTable = "taketable.ashx";
1716
const TakePDF = "takepdf.ashx";
@@ -167,7 +166,7 @@ public function URLToAnimation($url, GrabzItAnimationOptions $options = null)
167166
$options = new GrabzItAnimationOptions();
168167
}
169168

170-
$this->request = new GrabzItRequest($this->getRootUrl(false) . "takeanimation.ashx", false, $options, $url);
169+
$this->request = new GrabzItRequest($this->getRootUrl() . "takeanimation.ashx", false, $options, $url);
171170
}
172171

173172
/*
@@ -183,7 +182,7 @@ public function URLToImage($url, GrabzItImageOptions $options = null)
183182
$options = new GrabzItImageOptions();
184183
}
185184

186-
$this->request = new GrabzItRequest($this->getRootUrl(false) . GrabzItClient::TakePicture, false, $options, $url);
185+
$this->request = new GrabzItRequest($this->getRootUrl() . GrabzItClient::TakePicture, false, $options, $url);
187186
}
188187

189188
/*
@@ -199,7 +198,7 @@ public function HTMLToImage($html, GrabzItImageOptions $options = null)
199198
$options = new GrabzItImageOptions();
200199
}
201200

202-
$this->request = new GrabzItRequest($this->getRootUrl(true) . GrabzItClient::TakePicture, true, $options, $html);
201+
$this->request = new GrabzItRequest($this->getRootUrl() . GrabzItClient::TakePicture, true, $options, $html);
203202
}
204203

205204
/*
@@ -231,7 +230,7 @@ public function URLToRenderedHTML($url, GrabzItHTMLOptions $options = null)
231230
$options = new GrabzItHTMLOptions();
232231
}
233232

234-
$this->request = new GrabzItRequest($this->getRootUrl(false) . GrabzItClient::TakeHTML, false, $options, $url);
233+
$this->request = new GrabzItRequest($this->getRootUrl() . GrabzItClient::TakeHTML, false, $options, $url);
235234
}
236235

237236
/*
@@ -247,7 +246,7 @@ public function HTMLToRenderedHTML($html, GrabzItHTMLOptions $options = null)
247246
$options = new GrabzItHTMLOptions();
248247
}
249248

250-
$this->request = new GrabzItRequest($this->getRootUrl(true) . GrabzItClient::TakeHTML, true, $options, $html);
249+
$this->request = new GrabzItRequest($this->getRootUrl() . GrabzItClient::TakeHTML, true, $options, $html);
251250
}
252251

253252
/*
@@ -279,7 +278,7 @@ public function URLToTable($url, GrabzItTableOptions $options = null)
279278
$options = new GrabzItTableOptions();
280279
}
281280

282-
$this->request = new GrabzItRequest($this->getRootUrl(false) . GrabzItClient::TakeTable, false, $options, $url);
281+
$this->request = new GrabzItRequest($this->getRootUrl() . GrabzItClient::TakeTable, false, $options, $url);
283282
}
284283

285284
/*
@@ -295,7 +294,7 @@ public function HTMLToTable($html, GrabzItTableOptions $options = null)
295294
$options = new GrabzItTableOptions();
296295
}
297296

298-
$this->request = new GrabzItRequest($this->getRootUrl(true) . GrabzItClient::TakeTable, true, $options, $html);
297+
$this->request = new GrabzItRequest($this->getRootUrl() . GrabzItClient::TakeTable, true, $options, $html);
299298
}
300299

301300
/*
@@ -327,7 +326,7 @@ public function URLToPDF($url, GrabzItPDFOptions $options = null)
327326
$options = new GrabzItPDFOptions();
328327
}
329328

330-
$this->request = new GrabzItRequest($this->getRootUrl(false) . GrabzItClient::TakePDF, false, $options, $url);
329+
$this->request = new GrabzItRequest($this->getRootUrl() . GrabzItClient::TakePDF, false, $options, $url);
331330
}
332331

333332
/*
@@ -343,7 +342,7 @@ public function HTMLToPDF($html, GrabzItPDFOptions $options = null)
343342
$options = new GrabzItPDFOptions();
344343
}
345344

346-
$this->request = new GrabzItRequest($this->getRootUrl(true) . GrabzItClient::TakePDF, true, $options, $html);
345+
$this->request = new GrabzItRequest($this->getRootUrl() . GrabzItClient::TakePDF, true, $options, $html);
347346
}
348347

349348
/*
@@ -375,7 +374,7 @@ public function URLToDOCX($url, GrabzItDOCXOptions $options = null)
375374
$options = new GrabzItDOCXOptions();
376375
}
377376

378-
$this->request = new GrabzItRequest($this->getRootUrl(false) . GrabzItClient::TakeDOCX, false, $options, $url);
377+
$this->request = new GrabzItRequest($this->getRootUrl() . GrabzItClient::TakeDOCX, false, $options, $url);
379378
}
380379

381380
/*
@@ -391,7 +390,7 @@ public function HTMLToDOCX($html, GrabzItDOCXOptions $options = null)
391390
$options = new GrabzItDOCXOptions();
392391
}
393392

394-
$this->request = new GrabzItRequest($this->getRootUrl(true) . GrabzItClient::TakeDOCX, true, $options, $html);
393+
$this->request = new GrabzItRequest($this->getRootUrl() . GrabzItClient::TakeDOCX, true, $options, $html);
395394
}
396395

397396
/*
@@ -522,7 +521,7 @@ public function GetStatus($id)
522521
return null;
523522
}
524523

525-
$result = $this->Get($this->getRootUrl(false) . "getstatus.ashx?id=" . $id);
524+
$result = $this->Get($this->getRootUrl() . "getstatus.ashx?id=" . $id);
526525

527526
$obj = simplexml_load_string($result);
528527

@@ -549,7 +548,7 @@ public function GetResult($id)
549548
return null;
550549
}
551550

552-
$result = $this->Get($this->getRootUrl(false) . "getfile.ashx?id=" . $id);
551+
$result = $this->Get($this->getRootUrl() . "getfile.ashx?id=" . $id);
553552

554553
if (empty($result))
555554
{
@@ -572,7 +571,7 @@ public function GetCookies($domain)
572571

573572
$qs = "key=" .urlencode($this->applicationKey)."&domain=".urlencode($domain)."&sig=".$sig;
574573

575-
$obj = $this->getResultObject($this->Get($this->getRootUrl(false) . "getcookies.ashx?" . $qs));
574+
$obj = $this->getResultObject($this->Get($this->getRootUrl() . "getcookies.ashx?" . $qs));
576575

577576
$result = array();
578577

@@ -614,7 +613,7 @@ public function SetCookie($name, $domain, $value = "", $path = "/", $httponly =
614613

615614
$qs = "key=" .urlencode($this->applicationKey)."&domain=".urlencode($domain)."&name=".urlencode($name)."&value=".urlencode($value)."&path=".urlencode($path)."&httponly=".intval($httponly)."&expires=".urlencode($expires)."&sig=".$sig;
616615

617-
return $this->isSuccessful($this->Get($this->getRootUrl(false) . "setcookie.ashx?" . $qs));
616+
return $this->isSuccessful($this->Get($this->getRootUrl() . "setcookie.ashx?" . $qs));
618617
}
619618

620619
/*
@@ -631,7 +630,7 @@ public function DeleteCookie($name, $domain)
631630

632631
$qs = "key=" .urlencode($this->applicationKey)."&domain=".urlencode($domain)."&name=".urlencode($name)."&delete=1&sig=".$sig;
633632

634-
return $this->isSuccessful($this->Get($this->getRootUrl(false) . "setcookie.ashx?" . $qs));
633+
return $this->isSuccessful($this->Get($this->getRootUrl() . "setcookie.ashx?" . $qs));
635634
}
636635

637636
/*
@@ -693,7 +692,7 @@ public function AddWaterMark($identifier, $path, $xpos, $ypos)
693692

694693
$context = stream_context_create($opts);
695694

696-
$response = @file_get_contents('http://grabz.it/services/addwatermark.ashx', false, $context);
695+
$response = @file_get_contents($this->getRootUrl() . 'addwatermark.ashx', false, $context);
697696

698697
if (isset($http_response_header))
699698
{
@@ -721,7 +720,7 @@ public function DeleteWaterMark($identifier)
721720

722721
$qs = "key=" .urlencode($this->applicationKey)."&identifier=".urlencode($identifier)."&sig=".$sig;
723722

724-
return $this->isSuccessful($this->Get($this->getRootUrl(false) . "deletewatermark.ashx?" . $qs));
723+
return $this->isSuccessful($this->Get($this->getRootUrl() . "deletewatermark.ashx?" . $qs));
725724
}
726725

727726
/*
@@ -759,7 +758,7 @@ private function _getWaterMarks($identifier = null)
759758

760759
$qs = "key=" .urlencode($this->applicationKey)."&identifier=".urlencode($identifier)."&sig=".$sig;
761760

762-
$obj = $this->getResultObject($this->Get($this->getRootUrl(false) . "getwatermarks.ashx?" . $qs));
761+
$obj = $this->getResultObject($this->Get($this->getRootUrl() . "getwatermarks.ashx?" . $qs));
763762

764763
$result = array();
765764

@@ -962,21 +961,17 @@ private function checkHttpCode($httpCode)
962961
{
963962
if ($httpCode == 403)
964963
{
965-
throw new GrabzItException('Potential DDOS Attack Detected. Please wait for your service to resume shortly. Also please slow the rate of requests you are sending to GrabzIt to ensure this does not happen in the future.', GrabzItException::NETWORK_DDOS_ATTACK);
964+
throw new GrabzItException('Rate limit reached. Please wait for your service to resume shortly. Also please slow the rate of requests you are sending to GrabzIt to ensure this does not happen in the future.', GrabzItException::NETWORK_DDOS_ATTACK);
966965
}
967966
else if ($httpCode >= 400)
968967
{
969-
throw new GrabzItException("A network error occured when connecting to the GrabzIt servers.", GrabzItException::NETWORK_GENERAL_ERROR);
968+
throw new GrabzItException("A network error occurred when connecting to GrabzIt.", GrabzItException::NETWORK_GENERAL_ERROR);
970969
}
971970
}
972971

973-
private function getRootUrl($isPost)
972+
private function getRootUrl()
974973
{
975-
if ($isPost)
976-
{
977-
return $this->protocol . GrabzItClient::WebServicesBaseURL_POST;
978-
}
979-
return $this->protocol . GrabzItClient::WebServicesBaseURL_GET;
974+
return $this->protocol . GrabzItClient::WebServicesBaseURL;
980975
}
981976

982977
private function checkResponseHeader($header)

readme.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
GrabzIt 3.3
1+
GrabzIt 3.4
22
===========
33

44
This library allows you to programmatically convert HTML and URL's into images, DOCX documents, rendered HTML, PDF's, CSV's, spreadsheets and JSON. Additionally GrabzIt allows you to convert online videos into animated GIF's.

0 commit comments

Comments
 (0)