Ejemplo n.º 1
0
 public function call($method, $arguments)
 {
     $params = array("method" => $method, "functionOptions" => $arguments, "type" => "json");
     $response = wp_remote_get(add_query_arg($params, 'http://api.e-goi.com/v2/rest.php'));
     if (is_wp_error($response) || $response['response']['code'] != 200) {
         $this->logger->error('Response: ' . print_r($response, true));
         return;
     }
     $json = json_decode($response['body'], true);
     $map = $json['Egoi_Api'][$method];
     $this->logger->debug('Response: ' . print_r($map, true));
     $status = $map['status'];
     unset($map['status']);
     return $this->setMap($map);
 }
Ejemplo n.º 2
0
 /**
  * Do actual HTTP request.
  *
  * @param  string $method
  * @param  string $url
  * @param  string $body
  * @param  array  $headers
  * @return mixed
  */
 protected function request($method, $url, $body = null, $headers = array())
 {
     // Append URL to URL
     $url = add_query_arg(array('api_key' => $this->apiKey), $url);
     // Add authorization token to request headers
     $headers['Authorization'] = "Bearer " . $this->token;
     // Log method params
     $this->logger->info("URL: {$url}\n");
     $this->logger->info("Method: {$method}\n");
     $this->logger->info("Headers: " . print_r($headers, true) . "\n");
     $this->logger->info("Body: " . print_r($body, true) . "\n");
     switch ($method) {
         case 'put':
             $headers['Content-Type'] = 'application/json';
             $response = wp_remote_request($url, array('method' => 'PUT', 'headers' => $headers, 'body' => $body));
             break;
         case 'post':
             $headers['Content-Type'] = 'application/json';
             $response = wp_remote_post($url, array('headers' => $headers, 'body' => $body));
             break;
         default:
             $response = wp_remote_get($url, array('headers' => $headers, 'body' => $body));
             break;
     }
     // Log error and throw exception
     if (is_wp_error($response)) {
         $this->logger->error("WP ERR: " . print_r($response, true) . "\n");
         throw new Exception("Error when trying to connect to ConstantContact API");
     }
     // Check if status 200 was received
     if (200 !== (int) wp_remote_retrieve_response_code($response)) {
         $this->logger->info("HTTP status error: " . print_r($response, true) . "\n");
     }
     return $response;
 }
Ejemplo n.º 3
0
 /**
  * @see OptimizePress_Modules_Email_ProviderInterface::register()
  */
 public function register($list, $email, $fname, $lname)
 {
     $this->logger->info('Registering user: '******' ' . $lname, $email, 'standard', 0, null);
         $this->logger->notice('Registration status: ' . print_r($status, true));
     } catch (Exception $e) {
         $this->logger->error('Error ' . $e->getCode() . ': ' . $e->getMessage());
     }
     return true;
 }
Ejemplo n.º 4
0
 /**
  * @see OptimizePress_Modules_Email_ProviderInterface::register()
  */
 public function register($list, $email, $fname, $lname)
 {
     $this->logger->info('Registering user: '******'email' => $email, 'name' => $fname . ' ' . $lname));
         $this->logger->notice('Registration status: ' . print_r($status, true));
     } catch (OP_AWeberAPIException $e) {
         $this->logger->error('Error ' . $e->type . ': ' . $e->message);
     }
     return true;
 }
Ejemplo n.º 5
0
 /**
  * @see OptimizePress_Modules_Email_ProviderInterface::register()
  */
 public function register($list, $email, $fname, $lname)
 {
     $this->logger->info('Registering user: '******'fname' => $fname, 'lname' => $lname));
     $this->logger->notice('Registration status: ' . print_r($status, true));
     /*
      * Displays error
      */
     if (false === $status) {
         $this->logger->error('Error ' . $this->getClient()->errorCode . ': ' . $this->getClient()->errorMessage);
     }
     return true;
 }
Ejemplo n.º 6
0
 /**
  * @see OptimizePress_Modules_Email_ProviderInterface::register()
  */
 public function register($list, $email, $fname, $lname)
 {
     $this->logger->info('Registering user: '******'normal', $mergeVars['prefix'], $fname, $lname);
         $this->logger->notice('Adding contact status: ' . print_r($contact, true));
         $status = $this->getClient()->subscribeContactToList($contact->contactId, $list);
         $this->logger->notice('Registration status: ' . print_r($status, true));
         return true;
     } catch (Exception $e) {
         $this->logger->error('Error ' . $e->getCode() . ': ' . $e->getMessage());
         return true;
     }
 }
Ejemplo n.º 7
0
 /**
  * @see OptimizePress_Modules_Email_ProviderInterface::register()
  */
 public function register($list, $email, $fname, $lname)
 {
     $this->logger->info('Registering user: '******'EmailAddress' => $email, 'Name' => $fname . ' ' . $lname, 'CustomFields' => array(), 'Resubscribe' => true, 'RestartSubscriptionBasedAutoresponders' => true);
     $status = $this->getSubscribersClient($list)->add($subscriber);
     $this->logger->notice('Registration status: ' . print_r($status, true));
     /*
      * Displays error
      */
     if (!$status->was_successful()) {
         $this->logger->error('Error ' . $status->response->Code . ': ' . $status->response->Message);
     }
     return true;
 }
Ejemplo n.º 8
0
 /**
  * @see OptimizePress_Modules_Email_ProviderInterface::register()
  */
 public function register($list, $email, $fname, $lname)
 {
     $this->logger->info('Registering user: '******'fields']['First Name'] = $fname;
     $params['fields']['Last Name'] = $lname;
     $params['fields']['E-Mail'] = $email;
     if (!empty($list)) {
         $params['sequences'] = array($list);
     }
     try {
         $status = $this->getClient()->add_contact($params);
         $this->logger->notice('Registration status: ' . print_r($status, true));
     } catch (Exception $e) {
         $this->logger->error('Error ' . $e->getCode() . ': ' . $e->getMessage());
     }
     return true;
 }
Ejemplo n.º 9
0
 /**
  * @see OptimizePress_Modules_Email_ProviderInterface::subscribe()
  */
 public function subscribe($data)
 {
     $this->logger->info('Subscribing user: '******'list']) && isset($data['email'])) {
         $webinarKey = substr($data['list'], 1);
         unset($data['list']);
         try {
             $status = $this->getClient()->createRegistrant($webinarKey, $data);
             $this->logger->notice('Subscription status: ' . print_r($status, true));
         } catch (Exception $e) {
             $this->logger->error('Error ' . $e->getCode() . ': ' . $e->getMessage());
         }
         return true;
     } else {
         $this->logger->alert('Mandatory information not present [list and/or email address]');
         wp_die('Mandatory information not present [webinar and/or email address].');
     }
 }
Ejemplo n.º 10
0
 /**
  * HTTP request wrapped with wp_remote_get
  * @param  string $action [description]
  * @param  array  $params [description]
  * @return mixed
  */
 protected function request($action, array $params)
 {
     $this->logger->info("arpReach Request\n");
     $this->logger->info("Action: {$action}\n");
     $this->logger->info("Params: " . print_r($params, true) . "\n");
     // Add API key to params stack
     $params['api_key'] = $this->apiKey;
     // Lets create request URL
     $url = add_query_arg($this->urlEncodeParams($params), trailingslashit($this->apiEndpoint) . 'api/' . $action);
     $this->logger->info("URL: {$url}\n");
     $response = wp_remote_get($url);
     // Log error and throw exception
     if (is_wp_error($response)) {
         $this->logger->error("WP ERR: " . print_r($response, true) . "\n");
         throw new Exception("Error when trying to connect to arpReach API");
     }
     // Check if status 200 was received
     if (200 !== (int) wp_remote_retrieve_response_code($response)) {
         $this->logger->info("HTTP status error: " . print_r($response, true) . "\n");
     }
     return $response;
 }