Skip to content

Commit

Permalink
Fixed error messages and ensures all requests go via api.grabz.it
Browse files Browse the repository at this point in the history
  • Loading branch information
GrabzIt committed Feb 14, 2020
1 parent 4323697 commit 8f4e3c1
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 31 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"homepage": "https://grabz.it/",
"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.",
"license": "MIT",
"version":"3.3.7.2",
"version":"3.4.5",
"autoload": {
"psr-4": {
"GrabzIt\\": "lib/"
Expand Down
53 changes: 24 additions & 29 deletions lib/GrabzItClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@

class GrabzItClient
{
const WebServicesBaseURL_GET = "://api.grabz.it/services/";
const WebServicesBaseURL_POST = "://grabz.it/services/";
const WebServicesBaseURL = "://api.grabz.it/services/";
const TakePicture = "takepicture.ashx";
const TakeTable = "taketable.ashx";
const TakePDF = "takepdf.ashx";
Expand Down Expand Up @@ -167,7 +166,7 @@ public function URLToAnimation($url, GrabzItAnimationOptions $options = null)
$options = new GrabzItAnimationOptions();
}

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

/*
Expand All @@ -183,7 +182,7 @@ public function URLToImage($url, GrabzItImageOptions $options = null)
$options = new GrabzItImageOptions();
}

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

/*
Expand All @@ -199,7 +198,7 @@ public function HTMLToImage($html, GrabzItImageOptions $options = null)
$options = new GrabzItImageOptions();
}

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

/*
Expand Down Expand Up @@ -231,7 +230,7 @@ public function URLToRenderedHTML($url, GrabzItHTMLOptions $options = null)
$options = new GrabzItHTMLOptions();
}

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

/*
Expand All @@ -247,7 +246,7 @@ public function HTMLToRenderedHTML($html, GrabzItHTMLOptions $options = null)
$options = new GrabzItHTMLOptions();
}

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

/*
Expand Down Expand Up @@ -279,7 +278,7 @@ public function URLToTable($url, GrabzItTableOptions $options = null)
$options = new GrabzItTableOptions();
}

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

/*
Expand All @@ -295,7 +294,7 @@ public function HTMLToTable($html, GrabzItTableOptions $options = null)
$options = new GrabzItTableOptions();
}

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

/*
Expand Down Expand Up @@ -327,7 +326,7 @@ public function URLToPDF($url, GrabzItPDFOptions $options = null)
$options = new GrabzItPDFOptions();
}

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

/*
Expand All @@ -343,7 +342,7 @@ public function HTMLToPDF($html, GrabzItPDFOptions $options = null)
$options = new GrabzItPDFOptions();
}

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

/*
Expand Down Expand Up @@ -375,7 +374,7 @@ public function URLToDOCX($url, GrabzItDOCXOptions $options = null)
$options = new GrabzItDOCXOptions();
}

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

/*
Expand All @@ -391,7 +390,7 @@ public function HTMLToDOCX($html, GrabzItDOCXOptions $options = null)
$options = new GrabzItDOCXOptions();
}

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

/*
Expand Down Expand Up @@ -522,7 +521,7 @@ public function GetStatus($id)
return null;
}

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

$obj = simplexml_load_string($result);

Expand All @@ -549,7 +548,7 @@ public function GetResult($id)
return null;
}

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

if (empty($result))
{
Expand All @@ -572,7 +571,7 @@ public function GetCookies($domain)

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

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

$result = array();

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

$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;

return $this->isSuccessful($this->Get($this->getRootUrl(false) . "setcookie.ashx?" . $qs));
return $this->isSuccessful($this->Get($this->getRootUrl() . "setcookie.ashx?" . $qs));
}

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

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

return $this->isSuccessful($this->Get($this->getRootUrl(false) . "setcookie.ashx?" . $qs));
return $this->isSuccessful($this->Get($this->getRootUrl() . "setcookie.ashx?" . $qs));
}

/*
Expand Down Expand Up @@ -693,7 +692,7 @@ public function AddWaterMark($identifier, $path, $xpos, $ypos)

$context = stream_context_create($opts);

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

if (isset($http_response_header))
{
Expand Down Expand Up @@ -721,7 +720,7 @@ public function DeleteWaterMark($identifier)

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

return $this->isSuccessful($this->Get($this->getRootUrl(false) . "deletewatermark.ashx?" . $qs));
return $this->isSuccessful($this->Get($this->getRootUrl() . "deletewatermark.ashx?" . $qs));
}

/*
Expand Down Expand Up @@ -759,7 +758,7 @@ private function _getWaterMarks($identifier = null)

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

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

$result = array();

Expand Down Expand Up @@ -962,21 +961,17 @@ private function checkHttpCode($httpCode)
{
if ($httpCode == 403)
{
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);
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);
}
else if ($httpCode >= 400)
{
throw new GrabzItException("A network error occured when connecting to the GrabzIt servers.", GrabzItException::NETWORK_GENERAL_ERROR);
throw new GrabzItException("A network error occurred when connecting to GrabzIt.", GrabzItException::NETWORK_GENERAL_ERROR);
}
}

private function getRootUrl($isPost)
private function getRootUrl()
{
if ($isPost)
{
return $this->protocol . GrabzItClient::WebServicesBaseURL_POST;
}
return $this->protocol . GrabzItClient::WebServicesBaseURL_GET;
return $this->protocol . GrabzItClient::WebServicesBaseURL;
}

private function checkResponseHeader($header)
Expand Down
2 changes: 1 addition & 1 deletion readme.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
GrabzIt 3.3
GrabzIt 3.4
===========

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.
Expand Down

0 comments on commit 8f4e3c1

Please sign in to comment.