"Price Spectre"
 All Data Structures Functions Pages
WS Class Reference

Public Member Functions

 setEndpoint ($endpoint)
 
 setHeaders ($headers)
 
 setRequestBody ($requestBody)
 
 get ()
 
 post ()
 

Detailed Description

A class that allows calling external webservices and APIs.

Member Function Documentation

get ( )

Performs a GET call to the external webservice.

Returns
A String with the output of the webservice call.
// Perform a GET request and store in XMLDocument
var response = ws.get();
var xmlResponse = new XMLDocument(response);
post ( )

Performs a POST call to the external webservice.

Returns
A String with the output of the webservice call.
// Perform a POST request and store in XMLDocument
var response = ws.post();
var xmlResponse = new XMLDocument(response);
setEndpoint (   $endpoint)

Sets the endpoint of the external webservice to contact.

Returns
The calling WS object.
Parameters
endpointSpecifies the endpoint of the external webservice. This should include any necessary GET parameters.
// sets up WS object to communicate with eBay's finding API.
var findingAPI = 'http://svcs.ebay.com/services/search/FindingService/v1';
ws.setEndpoint(findingAPI);
setHeaders (   $headers)

Sets the headers to include when calling the external webservice.

Returns
The calling WS object.
Parameters
headersAn array specifying the headers to include when calling the external webservice.
// sets up WS object to communicate with eBay's finding API.
var headers = new Array(
"X-EBAY-SOA-OPERATION-NAME: findItemsByProduct",
"X-EBAY-SOA-SECURITY-APPNAME: <YOUR APP ID>",
"X-EBAY-SOA-GLOBAL-ID: EBAY-US",
"X-EBAY-SOA-SERVICE-VERSION: 1.11.0"
);
ws.setHeaders(headers);
setRequestBody (   $requestBody)

Sets the request body to include when POSTing to the external webservice.

Returns
The calling WS object.
Parameters
requestBodyThe body to POST when making the exterenal webservice call. requestBody can be of type String or XMLDocument
// fetch UPC from keywords
var upc = ps.getSearchParameter('keywords');
// sets up WS object to communicate with eBay's finding API.
var xmlStr = "<?xml version='1.0'?>"
+ '<findItemsByProductRequest
+ "<productId type=\"UPC\">" + upc + "</productId>"
+ "<sortOrder>PricePlusShippingLowest</sortOrder>"
+ "</findItemsByProductRequest>";
);
ws.setRequestBody(xmlStr);