Example #1
0
 private function call($action, DefensioParams $params)
 {
     $client = new RemoteRequest($this->build_url($action), 'POST');
     $client->set_postdata($params->get_post_data());
     if ($client->execute()) {
         if (self::get_http_status($client->get_response_headers()) == '401') {
             throw new Exception('Invalid/Unauthorized API Key');
         }
         $response = new DefensioResponse($client->get_response_body());
         unset($client);
         return $response;
     } else {
         throw new Exception('Server Not Responding');
     }
 }
Example #2
0
 function call($method, $args = array())
 {
     $args = array_merge(array('method' => $method, 'api_key' => $this->key), $args);
     ksort($args);
     $args = array_merge($args, array('api_sig' => $this->sign($args)));
     ksort($args);
     $call = new RemoteRequest($this->endpoint, 'POST');
     $args['api_key'] = $this->key;
     if ($method == 'upload') {
         $call = new RemoteRequest($this->uploadendpoint, 'POST');
         if (is_file($args['photo'])) {
             // we have a valid file and filename
             $call->set_file('photo', $args['photo']);
             unset($args['photo']);
         }
     }
     $call->set_timeout($this->conntimeout);
     $call->set_postdata($args);
     try {
         $result = $call->execute();
     } catch (RemoteRequest_Timeout $t) {
         Session::error('Currently unable to connect to Flickr.', 'flickr API');
         return false;
     } catch (Exception $e) {
         // at the moment we're using the same error message, though this is more catastrophic
         Session::error('Currently unable to connect to Flickr.', 'flickr API');
         return false;
     }
     $response = $call->get_response_body();
     try {
         $xml = new SimpleXMLElement($response);
         return $xml;
     } catch (Exception $e) {
         Session::error('Unable to process Flickr response.', 'flickr API');
         return false;
     }
 }
 function __call($name, $inputs)
 {
     if (isset($this->api_calls[$name])) {
         list($fn, $params) = $this->api_calls[$name];
         foreach ($params as $param) {
             switch ($param) {
                 case '#private_key':
                     $outputs['private_key'] = $this->privatekey;
                     break;
                 case '#blog_url':
                     $outputs['blog_url'] = Site::get_url('habari');
                     break;
                 default:
                     $outputs[$param] = array_shift($inputs);
                     break;
             }
         }
         //Utils::debug(self::BASE_URL . $fn, $outputs);
         $rr = new RemoteRequest(self::BASE_URL . $fn, 'POST', 180);
         $rr->set_postdata($outputs);
         $rr->execute();
         $headers = $rr->get_response_headers();
         $response = json_decode($rr->get_response_body());
         $response->_status = $headers['Status'];
         return $response;
     }
 }