Skip to content

Commit

Permalink
Fixes for erroring SaveTo and empty id for GetStatus
Browse files Browse the repository at this point in the history
  • Loading branch information
oi.u.sms@gmail.com committed Aug 2, 2013
1 parent cd3e808 commit f551f30
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 12 deletions.
10 changes: 10 additions & 0 deletions java/grabzit/src/it/grabz/grabzit/GrabzItClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,12 @@ public String Save() throws Exception
public boolean SaveTo(String saveToFile) throws Exception
{
String id = Save();

if (isNullOrEmpty(id))
{
return false;
}

//Wait for it to be ready.
while (true)
{
Expand Down Expand Up @@ -355,6 +361,10 @@ public boolean SaveTo(String saveToFile) throws Exception
*/
public Status GetStatus(String id) throws IOException, JAXBException, Exception
{
if (isNullOrEmpty(id))
{
return null;
}
return get(BASE_URL + "getstatus.ashx?id=" + id, Status.class);
}

Expand Down
4 changes: 2 additions & 2 deletions java/grabzit/test/it/grabz/grabzit/GrabzItClientTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ public class GrabzItClientTest {
private GrabzItClient client;

public GrabzItClientTest() {
applicationKey = "c3VwcG9ydEBncmFiei5pdA==";
applicationSecret = "AD8/aT8/Pz8/Tz8/PwJ3Pz9sVSs/Pz8/Pz9DOzJodoi=";
applicationKey = "YOUR APPLICATION KEY";
applicationSecret = "YOUR APPLICATION SECRET";
isSubscribedAccount = true;
client = new GrabzItClient(applicationKey, applicationSecret);
}
Expand Down
7 changes: 6 additions & 1 deletion perl/GrabzIt/GrabzItClient.pm
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,11 @@ sub SaveTo($)

my $id = self->Save();

if ($id eq '')
{
return 0;
}

#Wait for it to be ready.
while(1)
{
Expand Down Expand Up @@ -246,7 +251,7 @@ sub GetResult($)
#
sub GetStatus($)
{
my ($self, $id) = @_;
my ($self, $id) = @_;

my $url = GrabzItClient::WebServicesBaseURL . "getstatus.ashx?id=" . $id;

Expand Down
24 changes: 17 additions & 7 deletions php/lib/GrabzItClient.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,11 @@ public function SaveTo($saveToFile)
{
$id = $this->Save();

if (empty($id))
{
return false;
}

//Wait for it to be ready.
while(true)
{
Expand Down Expand Up @@ -180,6 +185,11 @@ public function SaveTo($saveToFile)
*/
public function GetStatus($id)
{
if (empty($id))
{
return null;
}

$result = $this->Get(GrabzItClient::WebServicesBaseURL . "getstatus.ashx?id=" . $id);

$obj = simplexml_load_string($result);
Expand Down Expand Up @@ -468,7 +478,7 @@ private function Get($url)
{
$response = @file_get_contents($url);
$this->checkResponseHeader($http_response_header);

return $response;
}
else
Expand All @@ -480,15 +490,15 @@ private function Get($url)
curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,$timeout);
$data = curl_exec($ch);
$httpCode = curl_getinfo($handle, CURLINFO_HTTP_CODE);
if($httpCode == 403)
{
if($httpCode == 403)
{
throw new Exception('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.');
}
}
curl_close($ch);
return $data;
}
}

private function checkResponseHeader($header)
{
list($version,$httpCode,$msg) = explode(' ',$header[0], 3);
Expand All @@ -499,7 +509,7 @@ private function checkResponseHeader($header)
else if ($httpCode >= 400)
{
throw new Exception("A network error occured when connecting to the GrabzIt servers.");
}
}
}
}
}
?>
9 changes: 8 additions & 1 deletion python/GrabzIt/GrabzItClient.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,9 @@ def Save(self, callBackURL = ''):
def SaveTo(self, saveToFile):
id = self.Save()

if (id == None or id == ""):
return False;

#Wait for it to be ready.
while(1):
status = self.GetStatus(id)
Expand Down Expand Up @@ -175,6 +178,10 @@ def GetResult(self, id):
#This function returns a Status object representing the screenshot
#
def GetStatus(self, id):

if (id == "" or id == None):
return None

result = self.HTTPGet(self.WebServicesBaseURL + "getstatus.ashx?id=" + id)

dom = minidom.parseString(result)
Expand Down Expand Up @@ -371,7 +378,7 @@ def GetWaterMark(self, identifier):
watermarks = self.getWaterMarks(identifier)
if watermarks.Length == 1:
return watermarks.get(0)
return nil
return None

def getWaterMarks(self, identifier = ""):
sig = self.CreateSignature(str(self.applicationSecret)+"|"+str(identifier))
Expand Down
11 changes: 10 additions & 1 deletion ruby/GrabzIt/lib/grabzit/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -152,13 +152,17 @@ def save(callBackURL = nil)
def save_to(saveToFile)
id = save()

if id == nil || id == ""
return false
end

#Wait for it to be ready.
while true do
status = get_status(id)

if !status.cached && !status.processing
raise "The screenshot did not complete with the error: " + status.Message
break;
break
elsif status.cached
result = get_result(id)
if !result
Expand All @@ -184,6 +188,11 @@ def save_to(saveToFile)
# @param id [String] the id of the screenshot
# @return [ScreenShotStatus] a object representing the status of the screenshot
def get_status(id)

if id == nil || id == ""
return nil
end

result = get(WebServicesBaseURL + "getstatus.ashx?id=" + nil_check(id))

doc = REXML::Document.new(result)
Expand Down

0 comments on commit f551f30

Please sign in to comment.