API PLAYGROUND

Build your POST here and send to the listener by clicking "POST to listener"

a0
b0
a1
b1
a2
b2
a3
b3
a4
b4
a5
b5
a6
b6
a7
b7
a8
b8
a9
b9
debug

example wrapper class

<?php


class Public_Holidays_API
{
    //illustrates communication with the webservery public holidays API.
    //provides a workable wrapper class, if you don't mind my shonky coding
    //email me if you want any help, or want to help me - scott@webservery.com

    private $authenticating_user_email;
    private $authenticating_user_password;

    public $unix_time;
    public $state;
    public $result;
    
    public $status;   //holds the status of the last executed command.  200 indicates succes.
    public $error_description;  // if status <> 200 there will probably be a clue in this variable

    public function __construct($email,$password)
    {
$this->authenticating_user_email = $email;
$this->authenticating_user_password = $password;
        
        
    }
    public function __destruct()
    {
//nothing to do really
    }

   

    private function _fetch_xml_response($post_array)
    {

        //The parameter $post_array is converted to a string of urlencoded name-value pairs and then       
        unset($url_encoded_post_array);
        foreach($post_array as $key => $value)
        { $url_encoded_post_array[$key] = urlencode($key)."=".urlencode($value);
        }
        $nvp_string = join("&",$url_encoded_post_array);

        //send to the API using curl
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_TIMEOUT, 30); 
        curl_setopt($ch, CURLOPT_URL, "https://www.webservery.com/services/public_holidays/listener.php");
        curl_setopt($ch, CURLOPT_POST, 1);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $nvp_string);
        $xml_string = curl_exec($ch);
        if(!$xml_string){
            $xml_string = "<?xml version='1.0' encoding='ISO-8859-1'?>
                            <response>
                                <b0>500</b0>
                                <b1>The API returned no data.  It shouldn't do that.  It's probably unwell.</b1>
                            </response>";
        } 
        
        $xml = simplexml_load_string($xml_string);

        return ($xml);
    }


public function check_date(){
            unset ($post);
            $post["a0"] = "check_by_unix_time";
            $post["a1"]         = $this->authenticating_user_email;
            $post["a2"] = $this->authenticating_user_password;   
            $post["a3"] = $this->unix_time;   
            $post["a4"] = $this->state;

            $response = $this->_fetch_xml_response($post);
            
            $this->status               = $response->b0;
            $this->error_description    = $response->b1;
            $this->result               = $response->b2;

}
    
    public function validation_table(){
            unset ($post);
            $post["a0"]     = "validation_table";
            $post["a1"]     = $this->authenticating_user_email;
            $post["a2"]     = $this->authenticating_user_password;   
            
            $response = $this->_fetch_xml_response($post);
            
            $this->status               = $response->b0;
            $this->error_description    = $response->b1;
            $this->result               = urldecode($response->b2);

    }
    
    public function big_table(){
            
            
            
            unset ($post);
            $post["a0"] = "big_table";
            $post["a1"] = $this->authenticating_user_email;
            $post["a2"] = $this->authenticating_user_password;   
            
            $response = $this->_fetch_xml_response($post);
            
            $this->status               = $response->b0;
            $this->error_description    = $response->b1;
            $this->result               = urldecode($response->b2);
            
           
    }
   
}