_apiKey = $apiKey; $this->_hashKey = $hashKey; $this->setApiUrl( $apiUrl ); } /** * Set Api url, always as https://domain.sendlane.com * * @param $apiUrl */ protected function setApiUrl( $apiUrl ) { $this->_apiUrl = $apiUrl . '/api/v1/'; if ( preg_match( '/http/', $this->_apiUrl ) ) { $this->_apiUrl = preg_replace( "/^http:/i", "https:", $this->_apiUrl ); } if ( ! preg_match( '/https/', $this->_apiUrl ) ) { $this->_apiUrl = 'https://' . $this->_apiUrl; } } /** * Do a call to an api endpoint * Sendlane requires all api requests to be made via POST method: https://help.sendlane.com/knowledgebase/api-docs * * @param $api_action * @param array $args * * @return array */ public function call( $api_action, $args = array() ) { $args['api'] = $this->_apiKey; $args['hash'] = $this->_hashKey; $url = $this->_apiUrl . $api_action . '?' . http_build_query( $args ); $result = tve_dash_api_remote_post( $url ); $body = trim( wp_remote_retrieve_body( $result ) ); return array( 'data' => json_decode( $body, true ), 'status' => trim( wp_remote_retrieve_response_code( $result ) ), ); } /** * Set connection status * * @param $status */ public function setConnectionStatus( $status ) { $this->connectionStatus = $status; } /** * Get connection status * * @return bool */ public function getConnectionStatus() { return $this->connectionStatus; } }