cert
8 years ago
Ga_Lib_Api_Client.php
6 years ago
Ga_Lib_Api_Request.php
6 years ago
Ga_Lib_Api_Response.php
9 years ago
Ga_Lib_Google_Api_Client.php
9 years ago
Ga_Lib_Sharethis_Api_Client.php
6 years ago
Ga_Lib_Api_Client.php
76 lines
| 1 | <?php |
| 2 | |
| 3 | abstract class Ga_Lib_Api_Client { |
| 4 | |
| 5 | /** |
| 6 | * Keeps error messages. |
| 7 | * @var array |
| 8 | */ |
| 9 | protected $errors = array(); |
| 10 | |
| 11 | /** |
| 12 | * Returns errors array. |
| 13 | * @return array |
| 14 | */ |
| 15 | public function get_errors() { |
| 16 | return $this->errors; |
| 17 | } |
| 18 | |
| 19 | /** |
| 20 | * Calls private API method from context client. |
| 21 | * |
| 22 | * @param $callback |
| 23 | * @param $args |
| 24 | * |
| 25 | * @return Ga_Lib_Api_Response |
| 26 | */ |
| 27 | abstract function call_api_method( $callback, $args ); |
| 28 | |
| 29 | /** |
| 30 | * Calls api methods. |
| 31 | * |
| 32 | * @param string $callback |
| 33 | * @param mixed $args |
| 34 | * |
| 35 | * @return mixed |
| 36 | */ |
| 37 | public function call( $callback, $args = null ) { |
| 38 | try { |
| 39 | update_option( 'googleanalytics_sherethis_error_log', false ); |
| 40 | return $this->call_api_method( $callback, $args ); |
| 41 | } catch ( Ga_Lib_Api_Client_Exception $e ) { |
| 42 | $this->add_error( $e ); |
| 43 | |
| 44 | return new Ga_Lib_Api_Response( Ga_Lib_Api_Response::$empty_response ); |
| 45 | } catch ( Ga_Lib_Api_Request_Exception $e ) { |
| 46 | $this->add_error( $e ); |
| 47 | |
| 48 | return new Ga_Lib_Api_Response( Ga_Lib_Api_Response::$empty_response ); |
| 49 | } catch ( Exception $e ) { |
| 50 | $this->add_error( $e ); |
| 51 | |
| 52 | return new Ga_Lib_Api_Response( Ga_Lib_Api_Response::$empty_response ); |
| 53 | } |
| 54 | } |
| 55 | |
| 56 | /** |
| 57 | * Prepares error data. |
| 58 | * |
| 59 | * @param Exception $e |
| 60 | * |
| 61 | */ |
| 62 | protected function add_error( Exception $e ) { |
| 63 | $this->errors[ $e->getCode() ] = array( 'class' => get_class( $e ), 'message' => $e->getMessage() ); |
| 64 | do_action( 'st_support_save_error', $e ); |
| 65 | } |
| 66 | |
| 67 | public function add_own_error( $code, $message, $class = '' ) { |
| 68 | $this->errors[ $code ] = array( 'class' => $class, 'message' => $message ); |
| 69 | } |
| 70 | |
| 71 | } |
| 72 | |
| 73 | class Ga_Lib_Api_Client_Exception extends Exception { |
| 74 | |
| 75 | } |
| 76 |