Skip to content

Instantly share code, notes, and snippets.

@rbocchinfuso
Last active March 22, 2017 21:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rbocchinfuso/36f8c58eb93c4932ec4d31b6818b82e8 to your computer and use it in GitHub Desktop.
Save rbocchinfuso/36f8c58eb93c4932ec4d31b6818b82e8 to your computer and use it in GitHub Desktop.
#!/usr/bin/php
<?php
/*
ssUpdate
MIT License
Copyright (c) [2017] [Richard J. Bocchinfuso]
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
* @package ssUpdate
* @author Richard Bocchinfuso <rbocchinfuso@gmail.com>
* @copyright 2017 Richard J. Bocchinfuso
* @license MIT License
* @version v1.20170322
* @link https://gist.github.com/36f8c58eb93c4932ec4d31b6818b82e8
*/
// break
// echo ""."\r\n";echo ""."\r\n";echo ""."\r\n";echo ""."\r\n";
require_once ('config.inc.php');
/* get */ {
$query_column = curl_init();
curl_setopt_array($query_column, array(
CURLOPT_URL => $columnURL,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "GET",
CURLOPT_HTTPHEADER => $header
));
$response = curl_exec($query_column);
$err = curl_error($query_column);
curl_close($query_column);
if ($err) {
echo "cURL Error #:" . $err;
} else {
// echo $response;
$query_column_decode = json_decode($response);
// print_r ($query_column_decode);
// echo $query_column_decode->data[0]->title."\r\n";
// echo $query_column_decode->data[0]->id."\r\n";
$column_array = $query_column_decode->data;
// print_r ($column_array);
foreach($column_array as $column_data){
$title = $column_data->title;
$column_id = $column_data->id;
// echo $title."\r\n";
// echo $column_id."\r\n";
// create column id lookup key value pair
$column_lookup[$title] = $column_id;
}
print_r ($column_lookup);
}
// assign column ID
$column_name = $milestone;
$column_value = $column_lookup[$column_name];
echo $column_value."\r\n";
$columnId = $column_value;
}
/* query */ {
$query_row = curl_init();
curl_setopt_array($query_row, array(
CURLOPT_URL => $queryURL.$query_text,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "GET",
CURLOPT_HTTPHEADER => $header
));
$response = curl_exec($query_row);
$err = curl_error($query_row);
curl_close($query_row);
if ($err) {
echo "cURL Error #:" . $err;
} else {
// echo $response;
$query_row_decode = json_decode($response);
// print_r ($query_row_decode);
// echo $query_row_decode->results[0]->objectId;
$ssRowID = $query_row_decode->results[0]->objectId;
// echo $ssRowID;
}
}
/* post */ {
$cput = curl_init();
curl_setopt_array($cput, array(
CURLOPT_URL => $rowURL,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "PUT",
CURLOPT_POSTFIELDS => "{\"id\": \"$ssRowID\", \"cells\": [{\"columnId\": $columnId,\"value\": $value}]}",
CURLOPT_HTTPHEADER => $header
));
$response = curl_exec($cput);
$err = curl_error($cput);
curl_close($cput);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment