Test Connection Step 1: Create an HTTPS request to send to the Yahoo Finance API using the testConnection function.
function testConnection(context) {
// Step 1: Create a https request to send to Yahoo Finance API
var url = 'https://finance.yahoo.com/webservice...on&view=detail';
var method = 'GET';
var body = '';
var headers = {
'Content-Type': 'text/json'
};
Test Connection Step 2: Send HTTPS request and receive a response.
// Step 2: Send request and receive response
var response = ai.https.request(url, method, body, headers);
Test Connection Step 3: Interrogate the response to check if it succeeded and that HTTP communication was successful.
// Step 3: Interrogate response to see if it was successful. Return true or false depending on the result.
// Check that http communication was successful
if (response.getHttpCode() === 200) {
// Parse response body xml
var body = response.getBody();
var json = JSON.parse(body);
if (typeof(json.list.meta.count) != "undefined" && json.list.meta.count == 1) {
return true;
}
}
return false;
}