function setCurlOpts($ch) { parent::setCurlOpts($ch); if ($this->get_location == true) { curl_setopt($ch, CURLOPT_HEADERFUNCTION, array(&$this, 'getLocation')); } }
/** * Store a newly created resource in storage. * * @return Response */ public function store() { $imageurl = ''; if (Request::get('image') != '') { $imageurl = "/images/report/trafficjam_" . time() . ".jpg"; $base = Request::get('image'); $binary = base64_decode($base); $ifp = fopen($imageurl, "wb"); fwrite($ifp, $binary); fclose($ifp); $imageurl = 'http://125.62.200.54/traffic/' . $imageurl; } $trafficJam = TrafficJam::create(array('user' => Request::get('user'), 'latitude' => Request::get('lat'), 'longitude' => Request::get('lng'), 'clear_by' => RestApi::clearBy(Request::get('status')), 'time' => date('g:iA', time()), 'date' => date('M j', time()), 'status' => Request::get('status'), 'reason' => Request::get('reason'), 'image_url' => $imageurl)); $report = new Report(); $report->traffic_jam_id = $trafficJam->id; $report->user = Request::get('user'); $report->latitude = Request::get('lat'); $report->longitude = Request::get('lng'); $report->time = date('g:i A', time()); $report->date = date('M j', time()); $report->clear_by = RestApi::clearBy(Request::get('status')); $report->description = "There is a " . Request::get('status') . " traffic jam at " . RestApi::getaddress(Request::get('lat'), Request::get('lng')) . " due to " . Request::get('reason'); $report->image_url = $imageurl; $report->type = 'Traffic Jam'; $report->title = RestApi::getaddress(Request::get('lat'), Request::get('lng')); $report->save(); $values = array(Request::get('lat'), Request::get('lng'), '12'); return RestApi::sendNotification('TJ', $values); /*return Response::json(array( 'error' => false), 200 ); */ }
/** * Store a newly created resource in storage. * * @return Response */ public function store() { $imageurl = ''; if (Request::get('image') != '') { $imageurl = "/images/report/accident_" . time() . ".jpg"; $base = Request::get('image'); $binary = base64_decode($base); $ifp = fopen($imageurl, "wb"); fwrite($ifp, $binary); fclose($ifp); $imageurl = 'http://125.62.200.54/traffic/' . $imageurl; } $accident = Accident::create(array('user' => Request::get('user'), 'latitude' => Request::get('lat'), 'longitude' => Request::get('lng'), 'time' => date('g:i A', time()), 'date' => date('M j', time()), 'details' => Request::get('details'), 'image_url' => $imageurl)); $report = new Report(); $report->traffic_jam_id = $accident->id; $report->user = Request::get('user'); $report->latitude = Request::get('lat'); $report->longitude = Request::get('lng'); $report->time = date('g:i A', time()); $report->date = date('M j', time()); $report->description = "There has been an accident. " . Request::get('details'); $report->image_url = $imageurl; $report->type = 'Accident'; $report->title = RestApi::getaddress(Request::get('lat'), Request::get('lng')); $report->save(); //RestApi::sendNotification() return Response::json(array('error' => false), 200); }
/** * Store a newly created resource in storage. * * @return Response */ public function store() { $imageurl = ''; if (Request::get('image') != '') { $imageurl = "public/images/report/trafficjam_" . time() . ".jpg"; $base = Request::get('image'); $binary = base64_decode($base); $ifp = fopen($imageurl, "wb"); fwrite($ifp, $binary); fclose($ifp); $imageurl = 'http://125.62.200.54/traffic/' . $imageurl; } $roadblock = RoadBlock::create(array('user' => Request::get('user'), 'latitude' => Request::get('lat'), 'longitude' => Request::get('lng'), 'time' => date('g:iA', time()), 'date' => date('M j', time()), 'status' => Request::get('status'), 'reason' => Request::get('reason'), 'image_url' => $imageurl)); $report = new Report(); $report->user = Request::get('user'); $report->latitude = Request::get('lat'); $report->longitude = Request::get('lng'); $report->time = date('g:i A', time()); $report->date = date('M j', time()); $report->description = "The road is blocked at " . RestApi::getaddress(Request::get('lat'), Request::get('lng')) . " due to " . Request::get('reason'); $report->image_url = $imageurl; $report->type = 'Road Block'; $report->title = RestApi::getaddress(Request::get('lat'), Request::get('lng')); $report->save(); return RestApi::sendNotification('RB', Request::get('lat'), Request::get('lng'), RestApi::getaddress(Request::get('lat'), Request::get('lng')), '12'); }
function __construct($username = false, $password = false) { if ($username && $password) { $this->login($username, $password); } parent::__construct(); }
function objectify($response) { if ($this->format == 'json') { $response = preg_replace('/^var [^\\{]*/', '', $response); $response = preg_replace('/;$/', '', $response); } return parent::objectify($response); }
function requestFeed($method, $extra = array()) { $url = "http://api.flickr.com/services/feeds/{$method}.gne"; $get = array('lang' => 'en-us', 'format' => $this->format); if ($this->format == 'json') { $get['nojsoncallback'] = 1; } if (isset($extra['get']) && is_array($extra['get'])) { $extra['get'] = array_merge($extra['get'], $get); } return parent::request($url, $extra); }
function request($method, $request_type = 'get', $extra = array()) { $params = array('api_key' => $this->api_key, 'method' => $method, 'format' => $this->format); if ($request_type != 'post') { $request_type = 'get'; } if (isset($extra[$request_type]) && is_array($extra[$request_type])) { $extra[$request_type] = array_merge($extra[$request_type], $params); } else { $extra[$request_type] = $params; } return parent::request($this->endpoint, $extra); }
/** * Create RestApiResponse from curl result. * * Overridden parent functionality so we throw exceptions for errors. * * @returns RestApiResponse */ protected function createResponse($result, $curl_info) { $response = parent::createResponse($result, $curl_info); switch ($response->status) { case 200: case 204: return $response; default: // Useful for debugging // print "\ndebug\n\tRequest: $this->method $this->url\n\tStatus: $response->status: {$response->body->title}\n\t{$response->body->detail}\n\t{$response->body->type}\n"; return $response; } }
function request($url, $extra = array(), $force_post = false) { if ($this->token) { if (is_array($extra['post'])) { $extra['post']['oauth_token'] = $this->token; } elseif ($extra['post']) { $extra['post'] .= "&oauth_token={$this->token}"; } elseif ($force_post) { $extra['post']['oauth_token'] = $this->token; } else { $extra['get']['oauth_token'] = $this->token; } } return parent::request($url, $extra, $force_post); }
/** * Store a newly created resource in storage. * * @return Response */ public function store() { $tracker_ids = Request::get('tracker_ids'); $tracker_id = explode(',', $tracker_ids); $usernameArray = []; $response = null; foreach ($tracker_id as $id) { if (trim($id) != 'null') { $username = null; if (is_numeric($id)) { $user = User::where('mobile', '=', $id)->get(array('username')); foreach ($user as $name) { $username = $name->username; array_push($usernameArray, $username); } } $validate = TrackAssign::where('user_id', '=', Request::get('user_id'))->where('tracker_id', '=', $username)->first(); if ($username != null) { if ($validate == null) { $assign = new TrackAssign(); $assign->user_id = Request::get('user_id'); $assign->tracker_id = $username; $assign->status = 1; $assign->save(); return $response = RestApi::trackNotification($username, Request::get('user_id')); } else { $validate->status = 1; $validate->save(); return $response = RestApi::trackNotification($username, Request::get('user_id')); } } } } //return $response; /*return Response::json(array( "status" => "OK", "users" => $usernameArray), 200);*/ }
// Build the data structure for the REST API call. $params = array('url' => $base_url . 'parcels', 'token' => $api_key, 'methodType' => 'POST', 'params' => array('description' => $line[0], 'receiver' => array('email' => $line[1], 'phone' => $line[2]), 'size' => $line[3], 'tmp_id' => RestApi::generate(4, 15), 'target_machine' => $line[4])); if ($num >= 10) { $params['sender_address'] = array('first_name' => $line[5], 'last_name' => $line[6], 'post_code' => $line[7], 'town' => $line[8], 'street' => $line[9]); } if ($num >= 11) { $params['sender_address']['company_name'] = $line[10]; } if ($num >= 12) { $params['sender_address']['building_number'] = $line[11]; } if ($num == 13) { $params['sender_address']['flat_number'] = $line[12]; } //echo print_r($params) . '<br>'; $ret = new RestApi($params); $info_arr = $ret->getInfo(); if ($info_arr['http_code'] != 201) { $err = $ret->getResponse(); $message[] = "Parcel Create failed for line {$row} <br>Error Code: " . $info_arr["http_code"] . " " . $err; $error_rows++; $row++; continue; } $response = json_decode($ret->getResponse()); $parcel_id = $response->id; // Add the parcel to the log table. $params['parcel_id'] = $parcel_id; add_parcel($params, $num); $processed_rows++; $row++;
function __construct($api_key) { $this->api_key = $api_key; parent::__construct(); }
} } } function safe_int($value) { return is_null($value) ? null : (int) $value; } function safe_float($value) { return is_null($value) ? null : (double) $value; } function safe_bool($value) { return is_null($value) ? null : (bool) $value; } $api = new RestApi(); /** * API information */ function info() { return array('api_version' => DOMJUDGE_API_VERSION, 'domjudge_version' => DOMJUDGE_VERSION); } $doc = "Get general API information."; $api->provideFunction('GET', 'info', $doc); /** * Contest information */ function contest() { global $cids, $cdatas, $userdata;
$params['methodType'] = 'GET'; $params['params']['date_before'] = date('Y-m-d'); $params['params']['date_after'] = date('Y-m-d'); $rest_api = new RestApi($params); $reply = $rest_api->getResponse(); $returns_today = json_decode($reply); // Get the count for the previous month $params['params']['date_after'] = date('Y-m-d', mktime(0, 0, 0, date('m') - 1, date('d'), date('Y'))); $params['params']['date_before'] = date('Y-m-d'); $rest_api = new RestApi($params); $reply = $rest_api->getResponse(); $returns_month = json_decode($reply); // Get the count for the previous year $params['params']['date_after'] = date('Y-m-d', mktime(0, 0, 0, date('m'), date('d'), date('Y') - 1)); $params['params']['date_before'] = date('Y-m-d'); $rest_api = new RestApi($params); $reply = $rest_api->getResponse(); $returns_year = json_decode($reply); ?> <!DOCTYPE HTML> <html> <head profile="http://www.w3.org/2005/10/profile"> <link rel="icon" type="image/png" href="images/favicon.ico" /> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <meta name="author" content="InPost UK Ltd"> <meta name="dcterms.rightsHolder" content="InPost UK Ltd"> <meta name="dcterms.dateCopyrighted" content="2014"> <title>InPost 24/7 - User Portal</title> <link rel="stylesheet" type="text/css" href="css/main_ss.css"> </head>
} //echo $count; if (count($to_print_array) == 0) { // Simply return. We have no labels to print header('Location: c_orders.php'); return; } $parcels_st = implode(";", $to_print_array); //echo $parcels_st; // Get the user's label format $ret = tep_db_query("SELECT label_format from " . $table_prefix . "users where username='******'"); $result = tep_db_fetch_array($ret); $label_format = $result['label_format']; $dispatch_date = date('Y-m-d H:i:s'); foreach ($parcels as $pid) { $query = tep_db_query("UPDATE imported_orders SET status='DISPATCHED', dispatch_date='{$dispatch_date}' WHERE parcel_id='{$pid}' AND perm_token='{$api_key}'"); } //retrieve stickers $restApi = new RestApi(array('url' => $base_url . 'stickers/' . $parcels_st, 'token' => $api_key, 'methodType' => 'GET', 'params' => array('format' => $label_format, 'type' => 'normal'))); date_default_timezone_set('Europe/London'); $timestamp = date('dmy_His', time()); if ($label_format == 'Pdf') { $file_name = "InPost_Labels_" . $timestamp . ".pdf"; } else { $file_name = "InPost_Labels_" . $timestamp . ".epl"; } $pdf = $restApi->getResponse(); $binary = base64_decode($pdf); header('Content-type: application/pdf'); header("Content-Disposition:attachment; filename={$file_name}"); echo $binary;
$params['params']['additional_description_1'] = $line[13]; } if ($num >= 15) { $params['params']['additional_description_2'] = $line[14]; } if ($num >= 16) { $params['params']['additional_description_3'] = $line[15]; } if ($num == 17) { $params['params']['company_name'] = $line[16]; } if ($num == 18) { $params['params']['address']['flat_number'] = $line[17]; } //echo print_r($params) . '<br>'; $ret = new RestApi($params); $info_arr = $ret->getInfo(); $response = $ret->getResponse(); if ($info_arr['http_code'] != 200) { $message[] = "Parcel Create failed for line {$row} <br>Error Code: " . $info_arr["http_code"] . " " . $response; $error_rows++; $row++; continue; } $response = json_decode($response, true); //echo "Response = " . print_r($response) . '<br>'; //echo "<br>info = " . print_r($info_arr) . '<br>'; $ex_date = $response['expire_at']; $exp_date = substr($ex_date, 0, 10); //extract expiry date if (array_key_exists("is_active", $response)) {
/** static shortcut method */ public static function api($verb, $url, $data = null) { $rest = new RestApi(); if (!$rest->verbIsValid($verb)) { throw new \Exception("Verb '{$verb}' is invalid"); } return $rest->{$verb}($url, $data); }
$params = array('url' => $base_url . 'parcels', 'token' => $api_key, 'methodType' => 'POST', 'params' => array('description' => $refe, 'receiver' => array('phone' => $mobile, 'email' => $email), 'size' => $size, 'tmp_id' => $temp_parcel_id, 'target_machine' => $locker)); $restApi1 = new RestApi($params); //echo '<pre>'; //print_r($restApi1->getInfo()); //echo '</pre><br>'; //echo '<pre>'; //print_r($restApi1->getResponse()); //echo '</pre>'; //returned header info $info_arr1 = $restApi1->getInfo(); //if parcel creation successful if ($info_arr1["http_code"] == 201) { $response = json_decode($restApi1->getResponse()); $parcel_id = $response->id; //pay for the parcel $restApi2 = new RestApi(array('url' => $base_url . 'parcels/' . $parcel_id . '/pay', 'token' => $api_key, 'methodType' => 'POST', 'params' => array())); //returned header info $info_arr2 = $restApi2->getInfo(); // if payment successful if ($info_arr2["http_code"] == 204) { //update payment status in db $creation_date = date('Y-m-d H:i:s'); $query = tep_db_query("UPDATE " . $table_prefix . $parcel_table . " SET status='PAID', rl_code='{$rl_code}', parcel_id='{$parcel_id}', creation_date='{$creation_date}' WHERE id={$new_id}"); echo "<td><div style='text-align: center'>CREATED & PAID</div></td>"; echo "<td><div style='text-align: center'>NONE</div></td>"; //header("Location: u_orders.php"); } else { //if not, display the error code, error description $error_cr = $info_arr2["http_code"]; echo "<td><div style='text-align: center'>UNPAID</div></td>"; echo "<td><div style='text-align: center'>" . $error_cr . "</div></td>";
</head> <body> <div class="wrapper"> <?php include_once 'includes/menu.php'; ?> <div align="center" style="position: relative; top:75px; margin-left:auto; margin-right:auto;"> <?php //Generate an active return code $params = array('url' => $base_url . 'reverselogistics.json', 'token' => $api_key, 'methodType' => 'POST', 'params' => array('rma' => $rma_code, 'parcel_size' => $size, 'expire_at' => $expiry_date, 'sender_phone' => $mobile, 'sender_email' => $email, 'with_label' => 'TRUE', 'additional_description_1' => $add_desc1, 'additional_description_2' => $add_desc2, 'additional_description_3' => $add_desc3, 'address' => array('first_name' => $fname, 'last_name' => $lname, 'company_name' => $cname, 'post_code' => $postcode, 'town' => $town, 'street' => $street, 'building_number' => $building, 'flat_number' => '', 'province' => $county, 'phone' => $rmobile))); //echo 'sent paramsters ' . json_encode($params) . '<br>'; $restApi = new RestApi($params); $request = $restApi->getInfo(); //echo 'request ' . print_r($request) . '<br>'; $response = json_decode($restApi->getResponse(), true); $info_arr = $restApi->getInfo(); //echo '<pre>'; //echo '<br>response ' . print_r($response); //echo '</pre>'; //echo '<pre>'; //echo '<br>info_arr ' . print_r($info_arr); //echo '</pre>'; //echo 'getErrno ' . $restApi->getErrno() . '<br>'; //echo 'getError ' . $restApi->getError() . '<br>'; if ($info_arr["http_code"] == 200) { $ex_date = $response['expire_at']; $exp_date = substr($ex_date, 0, 10);
$session_life = time() - $_SESSION['start']; if ($session_life > $inactive) { header("Location: logout.php"); } $_SESSION['start'] = time(); } else { header("Location: 404_error.php"); } // Set the timezone // Europe/London date_default_timezone_set('Europe/London'); // Get a list of the machines for use on the form. $params['url'] = $base_url . 'machines'; $params['token'] = $api_key; $params['methodType'] = 'GET'; $rest_api = new RestApi($params); $info = $rest_api->getInfo(); $reply = $rest_api->getResponse(); $parcelTargetMachinesId = array(); $parcelTargetMachinesDetail = array(); $defaultSelect = 'Select Machine..'; if ($info['http_code'] == 200) { $machines = json_decode($reply); if (is_array(@$machines) && !empty($machines)) { foreach ($machines as $key => $machine) { $parcelTargetMachinesId[$machine->id] = $machine->id . ', ' . @$machine->address->city . ', ' . @$machine->address->street; $parcelTargetMachinesDetail[$machine->id] = array('id' => $machine->id, 'address' => array('building_number' => @$machine->address->building_number, 'flat_number' => @$machine->address->flat_number, 'post_code' => @$machine->address->post_code, 'province' => @$machine->address->province, 'street' => @$machine->address->street, 'city' => @$machine->address->city)); } } } else { echo 'Failed to get the machines.<br>';
$ret = preg_match("/^(?=.*\\d)(?=.*[a-z])(?=.*[A-Z])(?=.*[^a-zA-Z0-9])(?!.*\\s).{8,20}\$/", $_POST['password']); if ($ret != true) { $_SESSION['error_message'] = "The password must contain:<br>one lower case letter, one upper case letter,<br>one digit, one special character,<br>be 8-20 in length, and have no spaces."; session_write_close(); header("Location: register.php"); return; } $username = test_input($_POST["email"]); $api_key = test_input($_POST["api_key"]); $answer = test_input($_POST["answer"]); $label_format = $_POST['label_format']; $question = $_POST['question']; $password = $_POST['password']; $password_hash = better_crypt($password); // Check if the API Key is valid $restApi = new RestApi(array('url' => $base_url . 'machines', 'token' => $api_key, 'methodType' => 'GET', 'params' => array())); $info_arr = $restApi->getInfo(); //echo $info_arr["http_code"]; if ($info_arr["http_code"] != 200) { $_SESSION['error_message'] = 'Your API Key does not seem to be valid<br>Error Code: ' . $info_arr["http_code"]; header("Location: register.php"); return; } // check if the username or API already exists in the DB if (checkRedundantVal($username) || checkRedundantVal($api_key)) { header("Location: check_user_false.php"); } else { // Connect to the DB $con = tep_db_connect(); if (!$con) { die('Could not connect: ' . mysqli_error());
function print_many_labels(&$params, &$parcels, $username) { require "config.php"; $return = array(); $zipname = "test_" . $username . '_' . session_id() . ".zip"; $zip = new ZipArchive(); $res = $zip->open($zipname, ZipArchive::CREATE); if ($res === TRUE) { $timestamp = date('dmy_His', time()); foreach ($parcels as $key => $parcel) { $params['url'] = $base_url . 'reverselogistics/' . $parcel . '/label.json'; //echo json_encode($params); $restApi2 = new RestApi($params); $file_name = "InPost_Return_Label" . $timestamp . $key . ".pdf"; $pdf = $restApi2->getResponse(); $info = $restApi2->getInfo(); if ($info['http_code'] != 200) { $_SESSION['error_message'] = 'Failed to create your labels ' . $info["http_code"]; continue; } $binary = base64_decode($pdf); // Add to the list of parcels that need their status // updated. $return[] = $parcel; // Add the PDF to the main ZIP file. $zip->addFromString($file_name, $binary); } $zip->close(); } else { $_SESSION['error_message'] = 'Failed to create ZIP file for your labels.'; header("Location: r_orders.php"); return $return; } return $return; }
function request($url, $extra = array(), $force_post = false) { $oauth = array('oauth_version' => OAuthRequest::$version, 'oauth_nonce' => OAuthRequest::generate_nonce(), 'oauth_timestamp' => OAuthRequest::generate_timestamp(), 'oauth_consumer_key' => $this->consumer->key, 'oauth_token' => $this->access_token->key, 'oauth_signature_method' => $this->oa_method->get_name()); if (isset($extra['post'])) { $params = $extra['post']; } elseif (isset($extra['get'])) { $params = $extra['get']; } else { $params = array(); } if (isset($extra['post']) || $force_post) { $method = 'POST'; } else { $method = 'GET'; } $params = array_merge($params, $oauth); $request = new OAuthRequest($method, $url, $params); $params['oauth_signature'] = $request->build_signature($this->oa_method, $this->consumer, $this->access_token); $extra[strtolower($method)] = $params; return parent::request($url, $extra, $force_post); }
public function stop() { $track_id = Request::get('trackid'); $username = TrackId::where('track_id', $track_id)->first(); $trackers = TrackAssign::where('username', $username->username)->get(array('tracker_id')); foreach ($trackers as $tracker) { $values = array($tracker->tracker_id, $username->username); RestApi::sendNotification('ST', $values); } $username->status = 0; $username->save(); $query = "INSERT INTO track_user_backup (track_id, latitude, longitude, created_at, updated_at) SELECT track_id, latitude, longitude, created_at, updated_at FROM track_user WHERE track_id = '{$track_id}'"; DB::insert(DB::raw($query)); TrackUser::where('track_id', $track_id)->delete(); }
/** * Tests a GET request using the httpbin service. */ public function xtestGetWithTemplating() { $rest = new RestApi('http://httpbin.org'); $rest->setJson(false, true); $response = $rest->get(array('/%something', array('%something' => 'get')), array('foo' => 'bar')); $this->assertEquals(200, $response->status); $this->assertObjectHasAttribute('args', $response->body); $this->assertInternalType('object', $response->body->args); $this->assertEquals('bar', $response->body->args->foo); }