/** * 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; }
/** * @see OptimizePress_Modules_Email_ProviderInterface::register() */ public function register($list, $email, $fname, $lname) { $this->logger->info('Registering user: '******'first_name' => $fname, 'last_name' => $lname)); $this->logger->notice('Registration status: ' . print_r($status, true)); return true; }
/** * @see OptimizePress_Modules_Email_ProviderInterface::getItems() */ public function getItems() { $data = array('lists' => array()); $lists = $this->getLists(); foreach ($lists as $list) { $data['lists'][$list['listnum']] = array('name' => $list['title']); } $this->logger->info('Items: ' . print_r($data, true)); return $data; }
/** * @see OptimizePress_Modules_Email_ProviderInterface::getItems() */ public function getItems() { $data = array('lists' => array()); /* * List parsing */ $lists = $this->getLists(); foreach ($lists as $list) { $data['lists'][$list->id] = array('name' => $list->name); } $this->logger->info('Items: ' . print_r($data, true)); return $data; }
/** * @see OptimizePress_Modules_Email_ProviderInterface::getItems() */ public function getItems() { $data = array('lists' => array()); /* * List parsing */ $lists = $this->getLists(); if ($lists['total'] > 0) { foreach ($lists['data'] as $list) { $data['lists'][$list['id']] = array('name' => $list['name']); } } $this->logger->info('Items: ' . print_r($data, true)); return $data; }
/** * 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; }
/** * @see OptimizePress_Modules_Email_ProviderInterface::getItems() */ public function getItems() { $data = $this->getData(); $this->logger->info('Items: ' . print_r($data, true)); return $data; }
/** * @see OptimizePress_Modules_Email_ProviderInterface::getListFields() */ public function getListFields($listId) { $fields = $this->getFormFields($listId); $this->logger->info("Fields for list {$listId} (CampaignMonitor): " . print_r($fields, true)); return array('fields' => $fields); }
/** * @see OptimizePress_Modules_Email_ProviderInterface::getListFields() */ public function getListFields($listId) { $fields = $this->getCustomFields(); $this->logger->info("Fields for list {$listId}: " . print_r($fields, true)); return array('fields' => $fields); }