/** * Fetch and parse results as though they were a json string. * * @param String $url API URL * @param Array $params Array of parameters for the API request * * @return Array $parts Array of return values */ protected function get_json_results($url, $params = []) { $this->curl->set_option('CURLOPT_FAILONERROR', FALSE); $response = $this->curl->get_request($url . '?' . http_build_query($params)); $result = json_decode($response->get_result(), TRUE); if ($response->http_code !== 200) { $context = ['message' => $result['message'], 'request' => $url, 'id' => $result['sys']['id']]; $this->logger->warning('Contentful API Request ({request}) failed with id "{id}": {message}', $context); $result['total'] = 0; } unset($response); return $result; }
/** * Fetch and parse results as though they were a query string. * * @param String $url API URL * @param Array $params Array of parameters for the API request * @param String $method Request method to use, either 'get' or 'post' * * @return Array $result Array of return values */ protected function get_json_results($url, $params = [], $method = 'get') { if (strtolower($method) === 'get') { $response = $this->curl->get_request($url . '?' . http_build_query($params)); } else { $response = $this->curl->post_request($url, $params); } $result = json_decode($response->get_result(), TRUE); if ($response->http_code !== 200) { $error = $result['errors'][0]; $context = ['message' => $error['message'], 'code' => $error['code'], 'request' => $url]; $this->logger->error('Twitter API Request ({request}) failed, ({code}): {message}', $context); $result = ''; } unset($response); return $result; }
/** * Fetch and parse results as though they were a query string. * * @param String $url API URL * @param Array $params Array of parameters for the API request * @param String $method Request method to use, either 'get' or 'post' * * @return Array $parts Array of return values */ protected function get_json_results($url, $params = [], $method = 'get') { $this->curl->set_option('CURLOPT_FAILONERROR', FALSE); if (strtolower($method) === 'get') { $response = $this->curl->get_request($url . '?' . http_build_query($params)); } else { $response = $this->curl->post_request($url, $params); } $result = json_decode($response->get_result(), TRUE); if ($response->http_code !== 200) { $error = $result['error']; $result = []; $context = ['message' => $error['message'], 'code' => $error['code'], 'type' => $error['type'], 'request' => $url]; $this->logger->error('Facebook API Request ({request}) failed, {type} ({code}): {message}', $context); } unset($response); return $result; }
# limitations under the License. */ require_once dirname(__DIR__) . "/classes/Requires.php"; //Get settings $result = MySQLQueries::get_settings(); $row = MySQLConnection::fetch_object($result); $instance_key = null; if (isset($row->data)) { $row->data = json_decode($row->data); if (isset($row->data->instance_key) && !empty($row->data->instance_key)) { $instance_key = $row->data->instance_key; } else { $instance_key = Functions::generate_random(9) . uniqid() . Functions::generate_random(8); $data = array("instance_key" => $instance_key, "default_ssh_username" => $row->data->default_ssh_username, "default_ssh_port" => $row->data->default_ssh_port, "default_interpreter" => $row->data->default_interpreter, "timezone_offset" => $row->data->timezone_offset, "timezone_daylight_savings" => $row->data->timezone_daylight_savings); MySQLQueries::edit_settings(json_encode((object) $data)); } } else { $instance_key = Functions::generate_random(9) . uniqid() . Functions::generate_random(8); $data = array("instance_key" => $instance_key); MySQLQueries::edit_settings(json_encode((object) $data)); } $servers = array(); $result = MySQLQueries::get_servers(); while ($row = MySQLConnection::fetch_object($result)) { $servers[] = $row; } $payload = '{"event":"' . $instance_key . '","properties":{"token":"678f0669ff58d890eeb50633c91a633d","distinct_id":"' . $instance_key . '","ip":"' . Functions::get_remote_ip() . '","servers":"' . count($servers) . '","version":"' . Version::app . '","ip-address":"' . Functions::get_remote_ip() . '","mp_name_tag":"' . $instance_key . '","time":"' . time() . '"}}'; $curl = new Curl(); $curl->get_request("https://api.mixpanel.com/track/?data=" . base64_encode($payload)); $curl->close(); echo '{"instance_key":"' . $instance_key . '"}';