viddler / phpviddler

The PHP wrapper for Viddler's API

phpviddler / php5viddler.php
100644 43 lines (32 sloc) 1.152 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
<?php
include_once('phpviddler.php');
 
class Php5viddler extends Phpviddler {
  function sendRequest($method=null,$args=null,$postmethod='get',$tryagain=true) {
    $result = parent::sendRequest($method, $args, $postmethod);
    
    if($tryagain && is_null($result)) {
      $result = parent::sendRequest($method, $args, $postmethod, false);
    } elseif(is_null($result)) {
      throw new ViddlerException("No response", $method, 8888, 'n/a');
    }
    
    if(is_array($result) && isset($result['error'])) {
      throw new ViddlerException($result['error']['description'], $method, $result['error']['code'], $result['error']['details']);
    }
 
return $result;
  }
 
}
 
class ViddlerException extends Exception {
  var $details;
  var $method;
  
  public function __construct($message, $method, $code=0, $details='') {
    $this->details = $details;
    $this->method = $method;
    parent::__construct($message, $code);
  }
  
  public function getDetails() {
    return $this->details;
  }
  
  public function __toString() {
    return "{$this->method} exception [{$this->code}]: {$this->getMessage()} ({$this->details})\n";
  }
}
 
 
?>