Hello guys,
I am trying to learn working with Web services using PHP. I have found many methods to access and consume these services, but I've come to know Soap Client and cURL are the best way to do it. I decided to work on an API provided by a UK Money Saving Forum 'HUKD'
I used both (SOAP & cURL) and successfully retrieved data in XML format. which is pretty neat, so far. I get the following XML as a response. (don't be afraid its just a list of data)
file.xml
(I have attached the XML and not pasted here because of its really large text of 1000 something lines and its annoying to scroll down).
Now, this is a filtered response. My response can have many 'api_item' I found that a bit challenging to work with and handle.
So this is what I did.
<?php
include_once 'api_item.php';
$api_item[] = new api_item();
$file= 'file.xml';
$xml = simplexml_load_file($file);
$api_item[0]->put_title($xml->children()->children()->children()->__toString());
?>
and it gives me this
response.txt
the response is an array of all the xml data.
so I decided to create a class and I've planned to fetch the data and get the 'api_item' data from fetched data and dump it into the class array. (its just a theory. Is it something we can do?)
this is what I designed
<?php
class api_item{
private $title;
private $deal_link;
private $mobile_deal_link;
private $deal_image;
private $description;
private $submit_time;
private $hot_time;
private $poster_name;
private $temperature;
private $price;
private $timestamp;
private $expired;
private $deal_image_highres;
function get_title(){
return $title;
}
function get_deal_link(){
return $deal_link;
}
function get_mobile_deal_link(){
return $mobile_deal_link;
}
function get_deal_image(){
return $get_deal_image;
}
function get_description(){
return $description;
}
function get_submit_time(){
return $submit_time;
}
function get_hot_time(){
return $hot_time;
}
function get_poster_name(){
return $poster_name;
}
function get_temperature(){
return $temperature;
}
function get_price(){
return $price;
}
function get_timestamp(){
return $timestamp;
}
function get_expired(){
return $expired;
}
function get_deal_image_highres(){
return $deal_image_highres;
}
function put_title($var_title){
$title = $var_title;
}
function put_deal_link($var_deal_link){
$deal_link = $var_deal_link;
}
function put_mobile_deal_link($var_mobile_deal_link){
$mobile_deal_link = $var_mobile_deal_link;
}
function put_deal_image($put_deal_image){
$deal_image = $var_deal_image;
}
function put_description($var_description){
$description = $var_description;
}
function put_submit_time($var_submit_time){
$submit_time = $var_submit_time;
}
function put_hot_time($var_hot_time){
$hot_time = $var_hot_time;
}
function put_poster_name($var_poster_name){
$poster_name = $var_poster_name;
}
function put_temperature($var_temperature){
$temperature = $var_temperature;
}
function put_price($var_price){
$price = $var_price;
}
function put_timestamp($var_timestamp){
$timestamp = $var_timestamp;
}
function put_expired($var_expired){
$expired = $var_expired;
}
function put_deal_image_highres($var_deal_image_highres){
$deal_image_highres = $var_deal_image_highres;
}
}
?>
now how do I traverse through the result and dump my array data into the class??
weird ideas my brain gives me :S