本文整理汇总了TypeScript中node-rest-client.Client.post方法的典型用法代码示例。如果您正苦于以下问题:TypeScript Client.post方法的具体用法?TypeScript Client.post怎么用?TypeScript Client.post使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类node-rest-client.Client
的用法示例。
在下文中一共展示了Client.post方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: Promise
return new Promise( ( resolve: (collectionInfo:{collectionId:string, postmanId:string} ) => void, reject: ( err?: any ) => void ) => {
try {
console.info("Create postman collection");
let client = new Client();
client.on( 'error', reject);
let args: any = {
headers: {
"Content-Type": "application/json",
"X-Api-Key": apiKey
},
data: { collection: collection }
};
let url = `https://api.getpostman.com/collections`;
client.post( url, args, ( data: any, response: any ) => {
if ( response.statusCode >= 200 && response.statusCode < 300 ) {
resolve( {collectionId: data.collection.uid, postmanId: data.collection.id} );
} else {
let message = "Wrong response status " + response.statusCode + ", expected 2xx -> body:\n " + data.toString();
reject( message );
}
} ).on( 'error', ( error: any ) => {
let message = "Failed to POST to " + url + " (" + error + ")";
reject( message );
} );
} catch ( e ) {
reject(e);
}
});
示例2: viewAllDeliveries
function viewAllDeliveries() {
var postData = { "date": "2016-03-02"};
var args = {
data: postData,
headers: {
'X-API-KEY': apiKey,
'Content-Type': 'application/json',
}
};
client.post("https://app.detrack.com/api/v1/deliveries/view/all.json", args, function (data, response) {
console.log(data);
console.log("Address: " + data["deliveries"][0]["address"]);
});
}
示例3: editDeliveries
function editDeliveries() {
//Data that needs to be updated
var postData = [
{
"date": new Date().toISOString().split('T')[0],
"do": "DO140211001",
"address": "63 Ubi Avenue 1 Singapore 408937",
"delivery_time": "12 : 00 PM - 03 : 00 PM",
"deliver_to": "John Tan",
"phone": "+6591234567",
"notify_email": "john.tan@example.com",
"notify_url": "http : //www.example.com/notify.php",
"assign_to": "1111",
"instructions": "Call customer upon arrival.",
"zone": "East",
"items": [
{
"sku": "T0201",
"desc": "Test Item #01",
"qty": 1
},
{
"sku": "T0202",
"desc": "Test Item #02",
"qty": 5
},
{
"sku": "T0203",
"desc": "Test Item #03",
"qty": 10
}
]
}
];
var args = {
data: postData,
headers: {
'X-API-KEY': apiKey,
'Content-Type': 'application/json',
}
};
//Initiate edit request
client.post("https://app.detrack.com/api/v1/deliveries/update.json", args, function (data, response) {
console.log(data);
console.log("Do: " + data["results"][0]["do"]); //Return data is in JSON array format. Access the individual Elements with index or iterate over it to access the individual property
});
}
示例4: viewAllVehicles
function viewAllVehicles() {
var postData = {}; // Prepare the rest data that will be used in the post request. In case of ViewAllVehicles, it will be empty body
// set content-type header and data as json in args parameter
var args = {
data: postData,
headers: {
'X-API-KEY': apiKey, // API of your account to access the API
'Content-Type': 'application/json' //How the Data will be returned from API. In case of Detrack API it will be JSON format
}
};
client.post("https://app.detrack.com/api/v1/vehicles/view/all.json", args, function (data, response) {
console.log(data);
console.log("vehicle name: " + data["vehicles"][0]["name"]); //Return data is in JSON array format. Access the individual Elements with index or iterate over it to access the individual property
});
}
示例5: downloadSignatureFile
function downloadSignatureFile() {
var postData = {
"date": "2016-03-02", //Date of the delivery job
"do": "DO140211001", //Unique job number for the date for which signature file will be downloaded if present
}
;
var file = fs.createWriteStream("signature.jpeg"); //Provide local file system path where file will be downloaded
var args = {
data: postData,
headers: {
'X-API-KEY': apiKey,
'Content-Type': 'application/json',
}
};
//Initiate file download
client.post("https://app.detrack.com/api/v1/deliveries/signature.json", args, function (data, response) {
file.write(data); //Write binary response data to file system.
file.close(); //Close the file stream
});
}
示例6: deleteDeliveries
function deleteDeliveries() {
// Prepare the rest data that will be used in the post request.
var postData = [
{
"date": new Date().toISOString().split('T')[0], //Date of the delivery job
"do": "DO140211001", //unique job number for the date specified
}
];
var args = {
data: postData,
headers: {
'X-API-KEY': apiKey,
'Content-Type': 'application/json',
}
};
//Initiate the post request
client.post("https://app.detrack.com/api/v1/deliveries/delete.json", args, function (data, response) {
console.log(data);
//console.log("Address: " + data["deliveries"][0]["address"]);
});
}