2011/02/28

Manifest - update

mainfest 幾時先用update 呢~?
係得原本個manifest file 的content 有變

試過用touch 改個timestamp ... 唔得
改左cache 的嗰d file ...唔得
改manifest 的名... 唔得 (因為那版 cache 了)

manifest syntax

MANIFEST

CACHE MANIFEST
 
CACHE: 
#要cahce的file 放在下面, relative path 同實path 都ok
#但一定要有file 名, 唔可以用* 
img/cat.jpg
img/dog.jpg
img/bird.jpg
img/rabbit.jpg
img/mouse.jpg
img/ant.jpg
 
NETWORK: 
#要從network 拎的file 放呢度 (e.g api)
#用 * 就即係除左cache下面的file 都從network 拎
* 
 
FALLBACK:
#拎唔到file 時的替代方案
api/ api/index.html 

Manifest - cache page

manifest 會自動cache 了有 <html mani....> tag 的那版, 有人會用iframe 的方法避了它...
firefox 同chrome 同 pc safari 都ok gei (cache 到d file, 唔會每次次再d/l)
但去到手機就...... x_x

iphone 的safari ok, 好正常, 但用add to home screen 開就唔得了 (用唔到cache 的file, 每次要上網拎)
android 2.0 以下唔支援html5, 所以唔會cache 到
android 2.1 同android 2.2 都用唔到cache 的file

所以手機 + iframe 是廢的, 加上iframe 是不鼓勵用的

Make HTTP / XML request in API and Parse result (PHP)

for美國郵政局,using simple XML request, include the XML within the url with the registered userID,
it will then return XML result in similar format
http://www.usps.com/webtools/htm/Track-Confirm.htm

Test Request #1

http://SERVERNAME/ShippingAPITest.dll?API=TrackV2&XML=

<TrackRequest USERID="xxxxxxxx">
<TrackID ID="EJ958083578US">
</TrackID>
</TrackRequest>

Example
$xml ='http://testing.shippingapis.com/ShippingAPITest.dll?API=TrackV2&XML=';
$xml.= '<TrackRequest USERID="'.$usps_id.'">';
$xml.= '<TrackID ID="'.$usps_track_id.'">';
$xml.= '</TrackID></TrackRequest>';

$xml_file = urlencode($xml);

    if( ! $xml = simplexml_load_file($xml_file) )
    { 
        echo 'unable to load XML file';
    }
    else
    { 
        foreach( $xml as $user )
        {
            echo 'TrackSummary: '.$user->TrackSummary.'<br />';
for ($i=0;$i<count($user->TrackDetail);$i++){
echo 'TrackDetail: '.$user->TrackDetail[$i].'<br />';
}
        }
    }


EBay
SOAP API  request can be posted by CURL which is an extension in PHP.
E.g. ebay api, using CURL,data in xml and header can be make into HTTP request to the specific URL

 $endpoint = 'https://api.ebay.com/ws/api.dll';
    // create the xml request that will be POSTed
    $xmlRequest  = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n";
    $xmlRequest .= ".........";


    $session  = curl_init($endpoint);                       // create a curl session
    curl_setopt($session, CURLOPT_POST, true);              // POST request type
    curl_setopt($session, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt($session, CURLOPT_POSTFIELDS, $xmlRequest); // set the body of the POST
    curl_setopt($session, CURLOPT_RETURNTRANSFER, true);    // return values as a string - not to std out
    $headers = array(
      'X-EBAY-API-COMPATIBILITY-LEVEL: 643',
      'X-EBAY-API-DEV-NAME: ...........
//input your required a/c info
      'X-EBAY-API-SITEID: 0',                                 // Site 0 is for US
      'Content-Type: text/xml;charset=utf-8'
    );
    curl_setopt($session, CURLOPT_HTTPHEADER, $headers);    //set headers using the above array of headers

    $responseXML = curl_exec($session);                     // send the request
    curl_close($session);

//    print_r($responseXML);

ebay (Alternative)

但以上的CODE太麻煩, 次次都要人手對番那串極長的xml request, 再insert對應不同api的parameter太費時了,  所以ebay 有sdk for php 給人下載, 名為PHP Toolkit with 527 Support
file名係EbatNs_1_0_527_0, 內置了所有api, 只要在config 輸入appid 等info便可即時調用

 $session = new EbatNs_Session('../EbatNsSamples/config/ebay.config.php');
 $cs = new EbatNs_ServiceProxy($session);
 // Set the Request type
 //#type $req GetSellerListRequestType
 $req = new GetSellerListRequestType();



PHP Toolkit Samples 有齊各api的sample code, copy & paste 改variable數值就可以了