Skip to content

Commit b3bb3b4

Browse files
author
Michael Christopher
committed
Added additional error reporting, minor formatting fixes
1 parent 756c7ca commit b3bb3b4

File tree

5 files changed

+81
-19
lines changed

5 files changed

+81
-19
lines changed

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Copyright (c) 2011 Zencoder
1+
Copyright (c) 2012 Zencoder
22

33
Permission is hereby granted, free of charge, to any person obtaining
44
a copy of this software and associated documentation files (the

README.md

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ Zencoder API PHP Library
33

44
Author: [Michael Christopher] (m (a) zencoder (.) com)
55
Company: [Zencoder - Online Video Encoder](http://www.zencoder.com)
6-
Version: 2.0
7-
Date: 2012-01-02
6+
Version: 2.0.1
7+
Date: 2012-01-10
88
Repository: <http://github.com/zencoder/zencoder-php/>
99

1010
Parts of this library are based on <http://github.com/twilio/twilio-php>
@@ -31,6 +31,9 @@ called:
3131
$zencoder->outputs->details($output_id);
3232
$zencoder->notifications->parseIncoming();
3333

34+
Any errors will throw a Services_Zencoder_Exception. You can call getErrors() on an exception
35+
and it will return any errors received from the Zencoder API.
36+
3437

3538
ENCODING JOB
3639
------------
@@ -175,10 +178,11 @@ Your [notifications page](https://app.zencoder.com/notifications) will come in h
175178

176179
VERSIONS
177180
---------
178-
Version 2.0 - 2012-01-02 Complete refactoring of library
179-
Version 1.6 - 2011-10-24 Fixed issue with user agents in cURL
180-
Version 1.4 - 2011-10-06 Fixed error with adding api_key to URL
181-
Version 1.3 - 2011-09-21 Fixed bundled SSL certification chain and made catch_and_parse() static
182-
Version 1.2 - 2011-08-06 Added fixes for PHP Notices and SSL handling
183-
Version 1.1 - 2010-06-04 Added General API Requests
184-
Version 1.0 - 2010-04-02 Jobs and Notifications.
181+
Version 2.0.1 - 2012-01-10 Added ability to get error info from API
182+
Version 2.0 - 2012-01-02 Complete refactoring of library
183+
Version 1.6 - 2011-10-24 Fixed issue with user agents in cURL
184+
Version 1.4 - 2011-10-06 Fixed error with adding api_key to URL
185+
Version 1.3 - 2011-09-21 Fixed bundled SSL certification chain and made catch_and_parse() static
186+
Version 1.2 - 2011-08-06 Added fixes for PHP Notices and SSL handling
187+
Version 1.1 - 2010-06-04 Added General API Requests
188+
Version 1.0 - 2010-04-02 Jobs and Notifications.

Services/Zencoder.php

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,9 @@ function Services_Zencoder_autoload($className) {
3030
* @link http://github.com/zencoder/zencoder-php
3131
*/
3232

33-
class Services_Zencoder_Exception extends ErrorException {}
34-
3533
class Services_Zencoder extends Services_Zencoder_Base
3634
{
37-
const USER_AGENT = 'ZencoderPHP v2.0';
35+
const USER_AGENT = 'ZencoderPHP v2.0.1';
3836

3937
/**
4038
* Contains the HTTP communication class
@@ -171,8 +169,7 @@ private function _getApiPath($opts = array())
171169
isset($opts['api_version'])
172170
? $opts['api_version']
173171
: $this->version
174-
)
175-
. "/";
172+
) . "/";
176173
}
177174

178175
private function _processResponse($response)
@@ -182,7 +179,7 @@ private function _processResponse($response)
182179
return TRUE;
183180
}
184181
if (empty($headers['Content-Type'])) {
185-
throw new Services_Zencoder_Exception('Response header is missing Content-Type');
182+
throw new Services_Zencoder_Exception('Response header is missing Content-Type', $body);
186183
}
187184
switch ($headers['Content-Type']) {
188185
case 'application/json':
@@ -191,7 +188,7 @@ private function _processResponse($response)
191188
break;
192189
}
193190
throw new Services_Zencoder_Exception(
194-
'Unexpected content type: ' . $headers['Content-Type']);
191+
'Unexpected content type: ' . $headers['Content-Type'], $body);
195192
}
196193

197194
private function _processJsonResponse($status, $headers, $body)
@@ -201,8 +198,7 @@ private function _processJsonResponse($status, $headers, $body)
201198
return $decoded;
202199
}
203200
throw new Services_Zencoder_Exception(
204-
"Invalid HTTP status code: " . $status
205-
. ", body: " . $body
201+
"Invalid HTTP status code: " . $status, $body
206202
);
207203
}
208204
}

Services/Zencoder/Error.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?php
2+
/**
3+
* Zencoder API client interface.
4+
*
5+
* @category Services
6+
* @package Services_Zencoder
7+
* @author Michael Christopher <m@zencoder.com>
8+
* @version 2.0
9+
* @license http://creativecommons.org/licenses/MIT/MIT
10+
* @link http://github.com/zencoder/zencoder-php
11+
*/
12+
13+
class Services_Zencoder_Error extends Services_Zencoder_Object
14+
{
15+
}

Services/Zencoder/Exception.php

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
<?php
2+
/**
3+
* Zencoder API client interface.
4+
*
5+
* @category Services
6+
* @package Services_Zencoder
7+
* @author Michael Christopher <m@zencoder.com>
8+
* @version 2.0
9+
* @license http://creativecommons.org/licenses/MIT/MIT
10+
* @link http://github.com/zencoder/zencoder-php
11+
*/
12+
13+
class Services_Zencoder_Exception extends ErrorException
14+
{
15+
protected $context;
16+
protected $errors;
17+
18+
function __construct($message, $errors = null, $code = null, $severity = E_ERROR, $filename = null,
19+
$lineno = null, array $context = array()) {
20+
parent::__construct($message, $code, $severity, $filename, $lineno);
21+
$this->errors = ($decode = json_decode($errors)) ? new Services_Zencoder_Error($decode->errors) : $errors;
22+
$this->context = $context;
23+
}
24+
25+
/**
26+
* Return array that points to the active symbol table at the point the error
27+
* occurred. In other words, it will contain an array of every variable that
28+
* existed in the scope the error was triggered in.
29+
*
30+
* @return array
31+
*/
32+
public function getContext()
33+
{
34+
return $this->context;
35+
}
36+
37+
/**
38+
* Return array containing any errors returned from the code that threw the
39+
* exception.
40+
*
41+
* @return array
42+
*/
43+
public function getErrors()
44+
{
45+
return $this->errors;
46+
}
47+
}

0 commit comments

Comments
 (0)