Permalink
Browse files

Merge pull request #2 from robbrit/master

Added PDF support.
  • Loading branch information...
2 parents 48612ea + b3572f8 commit b8d58a9a5c5a65a3cba92f273b2f38b47ca3f8bb Jordan Boesch committed Sep 28, 2012
Showing with 17 additions and 6 deletions.
  1. +17 −6 lib/FreshBooksRequest.php
View
@@ -1,4 +1,4 @@
-<?
+<?php
require_once('XmlDomConstruct.php');
/**
* A simple PHP API wrapper for the FreshBooks API.
@@ -143,9 +143,10 @@ public function getGeneratedXML()
}
/*
- * Send the request over the wire
+ * Send the request over the wire. Return result will be binary data if the FreshBooks response is
+ * a PDF, array if it is a normal request.
*
- * @return array
+ * @return mixed
*/
public function request()
{
@@ -177,15 +178,25 @@ public function request()
curl_close($ch);
}
- $response = json_decode(json_encode(simplexml_load_string($result)), true);
+ // With the new invoice.getPDF request, we sometimes have non-XML come through here
+ if (substr($result, 0, 4) == "%PDF")
+ {
+ // it's a PDF file
+ $response = $result;
+ $this->_success = true;
+ }
+ else
+ {
+ $response = json_decode(json_encode(simplexml_load_string($result)), true);
+ $this->_success = ($response['@attributes']['status'] == 'ok');
+ }
$this->_response = $response;
- $this->_success = ($response['@attributes']['status'] == 'ok');
if(isset($response['error']))
{
$this->_error = $response['error'];
}
}
-}
+}

0 comments on commit b8d58a9

Please sign in to comment.