當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript node-rest-client.Client類代碼示例

本文整理匯總了TypeScript中node-rest-client.Client的典型用法代碼示例。如果您正苦於以下問題:TypeScript Client類的具體用法?TypeScript Client怎麽用?TypeScript Client使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了Client類的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1: function

    function (session, results) {
        session.userData.countryCode = results.response;
        var stateInfo = "";
        var Client = require('node-rest-client').Client;
        var client = new Client();
        // set content-type header and data as json in args parameter 
        var args = {
            data: { test: "hello" },
            headers: { "Content-Type": "application/json" }
        };
        client.get("http://services.groupkt.com/state/get/" + session.userData.countryCode + "/all", args, function (data, response) {
            // parsed response body as js object 
            var result = data["RestResponse"]["result"];
            for (var idx = 0; idx < result.length; idx++) {
                var info = result[idx];
                stateInfo = stateInfo + info["country"] + "-" + info["name"] + ",";
                console.log(info["country"] + "-" + info["name"]);	
                //console.log(stateInfo);
            }
            session.send("Hello " + session.userData.name + "! I am going to check the " + session.userData.product +
                " availability for the address:" + session.userData.address + ", ZipCode:" + session.userData.zipCode +
                "\nList of States for your country code:" + session.userData.countryCode + "\n" + stateInfo);

        });
    }
開發者ID:giriganapathy,項目名稱:CheckServiceAvailabilityApp,代碼行數:25,代碼來源:server.ts

示例2: Promise

 return new Promise( ( resolve: (collectionInfo:{collectionId:string, postmanId:string} ) => void, reject: ( err?: any ) => void ) => {
   try {
     console.info("Update postman collection: ", collectionInfo.collectionId);
     let client = new Client();
     client.on( 'error', reject);
     let args: any = {
       headers: {
         "Content-Type": "application/json",
         "X-Api-Key": apiKey
       },
       data: { collection: collection }
     };
     collection.info._postman_id = collectionInfo.postmanId;
     let url = `https://api.getpostman.com/collections/${collectionInfo.collectionId}`;
     client.put( 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 " + JSON.stringify(data);
         reject( message );
       }
     } ).on( 'error', ( error: any ) => {
       let message = "Failed to POST to " + url + " (" + error + ")";
       reject( message );
     } );
   } catch ( e ) {
     reject(e);
   }
 });
開發者ID:MaxxtonGroup,項目名稱:microdocs,代碼行數:29,代碼來源:postman.client.ts

示例3: getSomethig

 getSomethig() : Q.Promise<string> {
   let deferred = Q.defer<string>();
   let client = new Client();
   client.on('error', function (err) {
     log.error(err);
     deferred.reject(err);
   });
   client.get(config.env.rest.url + '/something', function (data, response) {
     log.debug({data:data});
     deferred.resolve(data);
   }).on('error', function (err) {
     log.error(err);
     deferred.reject(err);
   });
   return deferred.promise;
 }
開發者ID:FranzZemen,項目名稱:nodets-scaffolding,代碼行數:16,代碼來源:someThing.service.ts

示例4: function

    function (session, args, next) {
        var entity = builder.EntityRecognizer.findEntity(args.entities, 'pnr-number');
        if (null != entity) {
            var pnrNumber = entity.entity;
            if (null != pnrNumber) {
                session.userData.pnrNumber = pnrNumber;
                var Client = require('node-rest-client').Client;
                var client = new Client();
                // set content-type header and data as json in args parameter 
                var options = {
                    headers: { "Content-Type": "application/json" }
                };

                client.get("http://api.railwayapi.com/pnr_status/pnr/" + session.userData.pnrNumber + "/apikey/" + key, options, function (data, response) {
                    // parsed response body as js object 
                    if (data) {
                        var resultInfo = "\nTrain Name: " + data["train_name"] +
                            "\nFrom Station: " + data["from_station"]["name"] +
                            "\To Station: " + data["to_station"]["name"] +
                            "\Date Of Journey: " + data["doj"];

                        session.send(resultInfo);
                        //var msg = "Wow.. That’s a FiOS available location...\n\nLet me ask you few usage questions to help you select suitable Fios package.\n\n" +
                        //    "How many devices does your family connect to the Internet such as: cell phone, tablet, laptop, Smart TV, etc.? Also, do you do any gaming or stream any videos?"

                        //builder.Prompts.text(session, msg);
                    }
                    else {                    
                        session.send("Sorry! Information not available...");
                        delete session.userData.pnrNumber
                    }
                });
            }
            else {
                session.send("Please provide your PNR Number...");
            }
        }
        else {
            session.send("Please provide your PNR Number...");
        }
    }
開發者ID:giriganapathy,項目名稱:TrainStatusApp,代碼行數:41,代碼來源:server.ts

示例5: function

    function (session, results, next) {
        if (results.response && !session.userData.zipCode) {
            var zipAndState = "";
            var zipCode = "";

            var userResponse = results.response;

            var zipAndStatePattern = "\\w{2}\\s\\d{5}";
            var regExpZipAndStatePattern = new RegExp(zipAndStatePattern);
            if (regExpZipAndStatePattern.test(userResponse)) {
                var zipAndStateArr = regExpZipAndStatePattern.exec(userResponse);
                if (null != zipAndStateArr) {
                    zipAndState = zipAndStateArr[0];

                    var zipCodePattern = new RegExp("\\d{5}");
                    var zipCodeArr = zipCodePattern.exec(zipAndState);
                    if (null != zipCodeArr) {
                        zipCode = zipCodeArr[0];
                    }
                }
                if (null != zipCode && zipCode.trim().length > 0) {
                    session.userData.zipCode = zipCode;
                    builder.DialogAction.send("Please wait while checking the service availability...");
                    var Client = require('node-rest-client').Client;
                    var client = new Client();
                    // set content-type header and data as json in args parameter 
                    var args = {
                        headers: { "Content-Type": "application/json" }
                    };
                    client.get("http://fiosserviceavailabilityapp.azurewebsites.net/zipcode/" + zipCode, args, function (data, response) {
                        // parsed response body as js object 
                        var result = data["status"];
                        if (result) {
                            session.userData.serviceAvailable = true;
                            var msg = "Great! " + session.userData.selectedOffer + " is available in your address with the zip code:" + zipCode + "\n\n" +
                                "To recommend best plan, can u tell me your usage..like do u use internet more or tv...etc.";
                            builder.Prompts.text(session, msg);
                        }
                        else {
                            session.userData.serviceAvailable = false;
                            session.send("Sorry! " + session.userData.selectedOffer + " is unavailable in your address with the zip code:" + zipCode);
                        }
                    });
                }
            }
            else {
                //Pl. provide the valid zip code.
                //session.userData.zipCode = null;
                session.send("Sorry! " + "I dont see the zip code in the address you provided...\nPlease provide me the address with zip code.");
                //session.replaceDialog("/showOffer");
            }
        }
        else {
            if (!session.userData.serviceAvailable) {
                session.send("Sorry! " + session.userData.selectedOffer + " is unavailable in your address with the zip code:" + session.userData.zipCode);
            }
            else {
                next({ response: session.message.text });
            }            
        }
    },
開發者ID:giriganapathy,項目名稱:VZChatBotApp,代碼行數:61,代碼來源:server.ts

示例6: 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"]);
  });
}
開發者ID:Aljaffa,項目名稱:DetrackSample,代碼行數:15,代碼來源:ViewAllDeliveries.ts

示例7: 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
  });
}
開發者ID:Aljaffa,項目名稱:DetrackSample,代碼行數:48,代碼來源:EditDelivery.ts

示例8: 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
  });
}
開發者ID:Aljaffa,項目名稱:DetrackSample,代碼行數:16,代碼來源:ViewAllVehicles.ts

示例9: 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
  });
}
開發者ID:Aljaffa,項目名稱:DetrackSample,代碼行數:21,代碼來源:DownloadDeliveryPodSignatureFile.ts

示例10: 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"]);
  });
}
開發者ID:Aljaffa,項目名稱:DetrackSample,代碼行數:22,代碼來源:DeleteDelivery.ts


注:本文中的node-rest-client.Client類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。