Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Helper class for converting
- */
- class XmlElement {
- var $name;
- var $attributes;
- var $content;
- var $children;
- };
- /**
- * General class for web services
- */
- class SoapWebServices {
- private $url; //url for web services
- private $client; // Soap global(class) object
- function __construct($url) {
- $this->url = $url;
- $this->client = new SoapClient($this->url, array("trace" => 1, "exception" => 0));
- }
- /**
- * Add Soap Header
- * @param stdClass object
- * @param string
- */
- public function add_header($header, $name) {
- $header = new SoapHeader($this->url, $name, $header, false);
- $this->client->__setSoapHeaders(array($header));
- }
- /**
- * @param string API Method that you want to call
- * @param array Arguments to pass into API
- * @param string Parent array for arguments
- * @return array of objects generated from XML
- */
- public function call($func, $args, $parent_arg=NULL) {
- if (!parent_arg) $parent_arg = $func;
- $args = array($parent_arg => $args);
- try {
- $result = $this->client->__soapCall($func, $args, NULL);
- } catch (SoapFault $soap_fault) {
- return $soap_fault;
- }
- $result_func = $func.'Result';
- return $this->xml_to_object($result->$result_func->any);
- }
- /**
- * Get Last Request's XML
- * @return XML
- */
- public function __getLastRequest(){
- if (isset($this->client))
- return $this->client->__getLastRequest();
- else
- return NULL;
- }
- /**
- * Convert XML to PHP array of objects
- * @param XML
- * @return array of objects
- */
- public function xml_to_object($xml) {
- $parser = xml_parser_create();
- xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, 0);
- xml_parser_set_option($parser, XML_OPTION_SKIP_WHITE, 1);
- xml_parse_into_struct($parser, $xml, $tags);
- xml_parser_free($parser);
- $elements = array(); // the currently filling [child] XmlElement array
- $stack = array();
- foreach ($tags as $tag) {
- $index = count($elements);
- if ($tag['type'] == "complete" || $tag['type'] == "open") {
- $elements[$index] = new XmlElement;
- $elements[$index]->name = $tag['tag'];
- $elements[$index]->attributes = isset($tag['attributes'])?$tag['attributes']:NULL;
- $elements[$index]->content = isset($tag['value'])?$tag['value']:NULL;
- if ($tag['type'] == "open") { // push
- $elements[$index]->children = array();
- $stack[count($stack)] = &$elements;
- $elements = &$elements[$index]->children;
- }
- }
- if ($tag['type'] == "close") { // pop
- $elements = &$stack[count($stack) - 1];
- unset($stack[count($stack) - 1]);
- }
- }
- return $elements[0]; // the single top-level element
- }
- }
- /**
- * High level web services class for "Travel Security Web Services"
- */
- class TravelSecurityWebServices extends SoapWebServices {
- private $ts_url = "https://webservices.travelsecurity.com/Default.asmx?WSDL";
- private $username = "asd";
- private $password = "asd";
- private $membership = "asd";
- function __construct(){
- parent::__construct($this->ts_url);
- // TODO:
- // 1. create configuration page in drupal CMS
- // 2. Remove hardcoded credentials and pull them from DB here
- }
- public function GetCountryRiskRatings(){
- $args = array(
- "Username" => $this->username,
- "Password" => $this->password,
- );
- return $this->call('GetCountryRiskRatings', $args);
- }
- public function GetCountryMedicalRiskRatings($language = 1){
- $args = array(
- "Username" => $this->username,
- "Password" => $this->password,
- "LanguageId" => $language,
- );
- return $this->call('GetCountryMedicalRiskRatings', $args);
- }
- public function GetArticles($language = 1, $country = 30, $tabname = "risk summary"){
- $args = array(
- "Username" => $this->username,
- "Password" => $this->password,
- "languageID" => $language,
- "CountryID" => $country,
- "tabname" => $tabname,
- );
- return $this->call('GetArticles', $args);
- }
- }
- /**
- * High level class for "International SOS Web Services"
- */
- class InternationalSOSWebServices extends SoapWebServices {
- private $isos_url = "https://www.internationalsos.com/ISOS.ServiceCluster.Location.CountryData.WebServices2/CountryGuidesWebService.asmx?WSDL";
- private $username = "asd";
- private $password = "asd";
- private $membership = "asd";
- function __construct(){
- parent::__construct($this->isos_url);
- // TODO:
- // 1. create configuration page in drupal CMS
- // 2. Remove hardcoded credentials and pull them from DB here
- }
- public function addHeader(){
- $header = new stdClass();
- $header->MembershipNumber = $this->membership;
- $header->UserName = $this->username;
- $header->Password = $this->password;
- parent::add_header($header, "ISOSAuthenticationHeader");
- }
- public function GetCountryGeneralSiteContent($language, $country){
- $this->addHeader();
- $args = new stdClass();
- $args->GeneralSiteContentParam = new stdClass();
- $args->GeneralSiteContentParam->LanguageID = $language;
- $args->GeneralSiteContentParam->CountryID = $country;
- return $this->call('GetCountryGeneralSiteContent', $args, "GeneralSiteContentParam");
- }
- public function GetCountryMedicalSummary($language, $country){
- $this->addHeader();
- $args = new stdClass();
- $args->MedicalSummaryParam = new stdClass();
- $args->MedicalSummaryParam->LanguageID = $language;
- $args->MedicalSummaryParam->CountryID = $country;
- return $this->call('GetCountryMedicalSummary', $args, "MedicalSummaryParam");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement