cvs: peardoc /en/package/webservices services-ebay.xml /en/package/webservices/services-ebay encoding.xml error-handling.xml
| From: | Stephan Schmidt | Date: | Sun, 05 Jun 2005 15:18:39 +0000 |
| Subject: | cvs: peardoc /en/package/webservices services-ebay.xml /en/package/webservices/services-ebay encoding.xml error-handling.xml | ||
| Groups: | php.pear.doc | ||
| Request: | Send a blank email to pear-doc+get-6232@lists.php.net to get a copy of this message | ||
schst Sun Jun 5 11:18:39 2005 EDT
Added files:
/peardoc/en/package/webservices/services-ebay encoding.xml
error-handling.xml
Modified files:
/peardoc/en/package/webservices services-ebay.xml
Log:
added information on error handling and encoding
http://cvs.php.net/diff.php/peardoc/en/package/webservices/services-ebay.xml?r1=1.2&r2=1.3&ty=u Index: peardoc/en/package/webservices/services-ebay.xml diff -u peardoc/en/package/webservices/services-ebay.xml:1.2 peardoc/en/package/webservices/services-ebay.xml:1.3 --- peardoc/en/package/webservices/services-ebay.xml:1.2 Sun Dec 19 07:35:26 2004 +++ peardoc/en/package/webservices/services-ebay.xml Sun Jun 5 11:18:38 2005 @@ -1,4 +1,4 @@ -<!-- $Revision: 1.2 $ --> +<!-- $Revision: 1.3 $ --> <sect1 id="package.webservices.services-ebay"> <title>Services_Ebay</title> @@ -7,6 +7,8 @@ </para> &package.webservices.services-ebay.intro; &package.webservices.services-ebay.getting-started; + &package.webservices.services-ebay.encoding; + &package.webservices.services-ebay.error-handling; &package.webservices.services-ebay.architecture; &package.webservices.services-ebay.example; </sect1> http://cvs.php.net/co.php/peardoc/en/package/webservices/services-ebay/encoding.xml?r=1.1&p=1 Index: peardoc/en/package/webservices/services-ebay/encoding.xml +++ peardoc/en/package/webservices/services-ebay/encoding.xml <!-- $Revision: 1.1 $ --> <refentry id="package.webservices.services-ebay.encoding"> <refnamediv> <refname>XML encoding</refname> <refpurpose>XML encoding in Services_Ebay</refpurpose> </refnamediv> <refsect1 id="package.webservices.services-ebay.encoding.refsect1"> <title>XML encoding in Services_Ebay</title> <para> Since mid-2005, the eBay API will only accept UTF-8 encoded XML-documents. As encoding all data to UTF-8 is tedious, Services_Ebay will take care of this for you. All you need to do is specify the encoding you want to use in your script when creating a session object. </para> <example> <title>Using ISO-8859-1 in your script</title> <programlisting role="php"> <![CDATA[require_once 'Services/Ebay.php'; // pass some authentication data $session = Services_Ebay::getSession($devId, $appId, $certId, 'ISO-8859-1'); $session->setToken($token); // create new proxy object $ebay = new Services_Ebay($session); $item = Services_Ebay::loadModel('Item', null, $session); $item->Category = 57882; $item->Title = 'International Item'; $item->Description = 'This description contains Umlaut characters like Ä, ü and ß'; $item->Location = 'At my home'; $item->MinimumBid = '532.0'; $item->VisaMaster = 1; $item->ShippingType = 1; $item->CheckoutDetailsSpecified = 1; $item->Country = 'US'; $item->SetShipToLocations(array('US', 'DE', 'GB')); $item->addShippingServiceOption(1, 1, 3, 1, array('US')); $result = $ebay->AddItem($item); ]]> </programlisting> </example> <para> The umlaut characters contained in the description of the item will be automatically converted to UTF-8 when the XML-document is created. Furthermore the result document which is returned by the eBay API will be decoded again to ISO-8859-1 so you do not have to worry about UTF-8 at all. </para> <para> Of course, it is also possible to supply UTF-8 encoded data to <classname>Services_Ebay</classname>. All you have to do is change the encoding type, when creating the session object. </para> <example> <title>Using UTF-8 in your script</title> <programlisting role="php"> <![CDATA[require_once 'Services/Ebay.php'; // pass some authentication data $session = Services_Ebay::getSession($devId, $appId, $certId, 'UTF-8'); $session->setToken($token); // create new proxy object $ebay = new Services_Ebay($session); $item = Services_Ebay::loadModel('Item', null, $session); $item->Category = 57882; $item->Title = 'International Item'; $item->Description = utf8_encode('This description contains Umlaut characters like Ä, ü and ß'); $item->Location = 'At my home'; $item->MinimumBid = '532.0'; $item->VisaMaster = 1; $item->ShippingType = 1; $item->CheckoutDetailsSpecified = 1; $item->Country = 'US'; $item->SetShipToLocations(array('US', 'DE', 'GB')); $item->addShippingServiceOption(1, 1, 3, 1, array('US')); $result = $ebay->AddItem($item); ]]> </programlisting> </example> <para> In this example you are using <function>utf8_encode</function> to encode the data prior to passing it to <classname>Services_Ebay</classname>. To avoid duplicated encoding, you need to set the encoding to UTF-8. </para> </refsect1> </refentry> <!-- Keep this comment at the end of the file Local variables: mode: sgml sgml-omittag:t sgml-shorttag:t sgml-minimize-attributes:nil sgml-always-quote-attributes:t sgml-indent-step:1 sgml-indent-data:t sgml-parent-document:nil sgml-default-dtd-file:"../../../../manual.ced" sgml-exposed-tags:nil sgml-local-catalogs:nil sgml-local-ecat-files:nil End: vim600: syn=webservices fen fdm=syntax fdl=2 si vim: et tw=78 syn=sgml vi: ts=1 sw=1 --> http://cvs.php.net/co.php/peardoc/en/package/webservices/services-ebay/error-handling.xml?r=1.1&p=1 Index: peardoc/en/package/webservices/services-ebay/error-handling.xml +++ peardoc/en/package/webservices/services-ebay/error-handling.xml <!-- $Revision: 1.1 $ --> <refentry id="package.webservices.services-ebay.error-handling"> <refnamediv> <refname>Error Handling</refname> <refpurpose>Error Handling in Services_Ebay</refpurpose> </refnamediv> <refsect1 id="package.webservices.services-ebay.error-handling.refsect1"> <title>Exceptions in Services_Ebay</title> <para> As Services_Ebay is a PHP 5 only package, it uses exception handling and the PEAR_Exception class as base class for all exceptions. Exceptions can be thrown, whenever you try to call any of the API calls provided by Services_Ebay, which means you should always nest those in a try/catch-block: </para> <example> <title>Exception handling</title> <programlisting role="php"> <![CDATA[require_once 'Services/Ebay.php'; // pass some authentication data $session = Services_Ebay::getSession($devId, $appId, $certId); $session->setToken($token); // create new proxy object $ebay = new Services_Ebay($session); try { // call a method echo $ebay->GeteBayOfficialTime(); } catch (Exceptio $e) { echo "Something went wrong."; echo $e; }]]> </programlisting> </example> <para> When calling a non-existent API call or passing the wrong parameters to the API, eBay will abort the API call and return an XML-document that contains error information. Services_Ebay will automatically convert this into an exception that can be easily handled by your PHP application. </para> </refsect1> <refsect1 id="package.webservices.services-ebay.error-handling.refsect2"> <title>Warnings in Services_Ebay</title> <para> In some cases, the eBay API will still process your request, even if you passed invalid parameters and include error information in the resulting XML-document alongside the actual response of your request. </para> <para> In this case, the errors will be tagged as warnings, as they were not serious errors. Services_Ebay will not convert these errors to exceptions, but only to instances of <classname>Services_Ebay_Error</classname>. These objects will be stored in the <classname>Services_Ebay_Session</classname> and can be retrieved by your application at a later point. </para> <example> <title>Handling warnings</title> <programlisting role="php"> <![CDATA[require_once 'Services/Ebay.php'; // pass some authentication data $session = Services_Ebay::getSession($devId, $appId, $certId); $session->setToken($token); // create new proxy object $ebay = new Services_Ebay($session); try { // call a method echo $ebay->GeteBayOfficialTime(); } catch (Exceptio $e) { // Just ignore the exception and handle them // with any warnings, that might have occured. } $errors = $session->getErrors(); if (count($errors) == 0) { echo "No errors or warnings.\n"; } else { foreach ($errors as $error) { printf("%s: %s (%d))\n", $error->getSeverity(), $error->getLongMessage(), $error->getCode()); } } ]]> </programlisting> </example> </refsect1> </refentry> <!-- Keep this comment at the end of the file Local variables: mode: sgml sgml-omittag:t sgml-shorttag:t sgml-minimize-attributes:nil sgml-always-quote-attributes:t sgml-indent-step:1 sgml-indent-data:t sgml-parent-document:nil sgml-default-dtd-file:"../../../../manual.ced" sgml-exposed-tags:nil sgml-local-catalogs:nil sgml-local-ecat-files:nil End: vim600: syn=webservices fen fdm=syntax fdl=2 si vim: et tw=78 syn=sgml vi: ts=1 sw=1 -->
http://cvs.php.net/diff.php/peardoc/en/package/webservices/services-ebay.xml?r1=1.2&r2=1.3&ty=u Index: peardoc/en/package/webservices/services-ebay.xml diff -u peardoc/en/package/webservices/services-ebay.xml:1.2 peardoc/en/package/webservices/services-ebay.xml:1.3 --- peardoc/en/package/webservices/services-ebay.xml:1.2 Sun Dec 19 07:35:26 2004 +++ peardoc/en/package/webservices/services-ebay.xml Sun Jun 5 11:18:38 2005 @@ -1,4 +1,4 @@ -<!-- $Revision: 1.2 $ --> +<!-- $Revision: 1.3 $ --> <sect1 id="package.webservices.services-ebay"> <title>Services_Ebay</title> @@ -7,6 +7,8 @@ </para> &package.webservices.services-ebay.intro; &package.webservices.services-ebay.getting-started; + &package.webservices.services-ebay.encoding; + &package.webservices.services-ebay.error-handling; &package.webservices.services-ebay.architecture; &package.webservices.services-ebay.example; </sect1> http://cvs.php.net/co.php/peardoc/en/package/webservices/services-ebay/encoding.xml?r=1.1&p=1 Index: peardoc/en/package/webservices/services-ebay/encoding.xml +++ peardoc/en/package/webservices/services-ebay/encoding.xml <!-- $Revision: 1.1 $ --> <refentry id="package.webservices.services-ebay.encoding"> <refnamediv> <refname>XML encoding</refname> <refpurpose>XML encoding in Services_Ebay</refpurpose> </refnamediv> <refsect1 id="package.webservices.services-ebay.encoding.refsect1"> <title>XML encoding in Services_Ebay</title> <para> Since mid-2005, the eBay API will only accept UTF-8 encoded XML-documents. As encoding all data to UTF-8 is tedious, Services_Ebay will take care of this for you. All you need to do is specify the encoding you want to use in your script when creating a session object. </para> <example> <title>Using ISO-8859-1 in your script</title> <programlisting role="php"> <![CDATA[require_once 'Services/Ebay.php'; // pass some authentication data $session = Services_Ebay::getSession($devId, $appId, $certId, 'ISO-8859-1'); $session->setToken($token); // create new proxy object $ebay = new Services_Ebay($session); $item = Services_Ebay::loadModel('Item', null, $session); $item->Category = 57882; $item->Title = 'International Item'; $item->Description = 'This description contains Umlaut characters like Ä, ü and ß'; $item->Location = 'At my home'; $item->MinimumBid = '532.0'; $item->VisaMaster = 1; $item->ShippingType = 1; $item->CheckoutDetailsSpecified = 1; $item->Country = 'US'; $item->SetShipToLocations(array('US', 'DE', 'GB')); $item->addShippingServiceOption(1, 1, 3, 1, array('US')); $result = $ebay->AddItem($item); ]]> </programlisting> </example> <para> The umlaut characters contained in the description of the item will be automatically converted to UTF-8 when the XML-document is created. Furthermore the result document which is returned by the eBay API will be decoded again to ISO-8859-1 so you do not have to worry about UTF-8 at all. </para> <para> Of course, it is also possible to supply UTF-8 encoded data to <classname>Services_Ebay</classname>. All you have to do is change the encoding type, when creating the session object. </para> <example> <title>Using UTF-8 in your script</title> <programlisting role="php"> <![CDATA[require_once 'Services/Ebay.php'; // pass some authentication data $session = Services_Ebay::getSession($devId, $appId, $certId, 'UTF-8'); $session->setToken($token); // create new proxy object $ebay = new Services_Ebay($session); $item = Services_Ebay::loadModel('Item', null, $session); $item->Category = 57882; $item->Title = 'International Item'; $item->Description = utf8_encode('This description contains Umlaut characters like Ä, ü and ß'); $item->Location = 'At my home'; $item->MinimumBid = '532.0'; $item->VisaMaster = 1; $item->ShippingType = 1; $item->CheckoutDetailsSpecified = 1; $item->Country = 'US'; $item->SetShipToLocations(array('US', 'DE', 'GB')); $item->addShippingServiceOption(1, 1, 3, 1, array('US')); $result = $ebay->AddItem($item); ]]> </programlisting> </example> <para> In this example you are using <function>utf8_encode</function> to encode the data prior to passing it to <classname>Services_Ebay</classname>. To avoid duplicated encoding, you need to set the encoding to UTF-8. </para> </refsect1> </refentry> <!-- Keep this comment at the end of the file Local variables: mode: sgml sgml-omittag:t sgml-shorttag:t sgml-minimize-attributes:nil sgml-always-quote-attributes:t sgml-indent-step:1 sgml-indent-data:t sgml-parent-document:nil sgml-default-dtd-file:"../../../../manual.ced" sgml-exposed-tags:nil sgml-local-catalogs:nil sgml-local-ecat-files:nil End: vim600: syn=webservices fen fdm=syntax fdl=2 si vim: et tw=78 syn=sgml vi: ts=1 sw=1 --> http://cvs.php.net/co.php/peardoc/en/package/webservices/services-ebay/error-handling.xml?r=1.1&p=1 Index: peardoc/en/package/webservices/services-ebay/error-handling.xml +++ peardoc/en/package/webservices/services-ebay/error-handling.xml <!-- $Revision: 1.1 $ --> <refentry id="package.webservices.services-ebay.error-handling"> <refnamediv> <refname>Error Handling</refname> <refpurpose>Error Handling in Services_Ebay</refpurpose> </refnamediv> <refsect1 id="package.webservices.services-ebay.error-handling.refsect1"> <title>Exceptions in Services_Ebay</title> <para> As Services_Ebay is a PHP 5 only package, it uses exception handling and the PEAR_Exception class as base class for all exceptions. Exceptions can be thrown, whenever you try to call any of the API calls provided by Services_Ebay, which means you should always nest those in a try/catch-block: </para> <example> <title>Exception handling</title> <programlisting role="php"> <![CDATA[require_once 'Services/Ebay.php'; // pass some authentication data $session = Services_Ebay::getSession($devId, $appId, $certId); $session->setToken($token); // create new proxy object $ebay = new Services_Ebay($session); try { // call a method echo $ebay->GeteBayOfficialTime(); } catch (Exceptio $e) { echo "Something went wrong."; echo $e; }]]> </programlisting> </example> <para> When calling a non-existent API call or passing the wrong parameters to the API, eBay will abort the API call and return an XML-document that contains error information. Services_Ebay will automatically convert this into an exception that can be easily handled by your PHP application. </para> </refsect1> <refsect1 id="package.webservices.services-ebay.error-handling.refsect2"> <title>Warnings in Services_Ebay</title> <para> In some cases, the eBay API will still process your request, even if you passed invalid parameters and include error information in the resulting XML-document alongside the actual response of your request. </para> <para> In this case, the errors will be tagged as warnings, as they were not serious errors. Services_Ebay will not convert these errors to exceptions, but only to instances of <classname>Services_Ebay_Error</classname>. These objects will be stored in the <classname>Services_Ebay_Session</classname> and can be retrieved by your application at a later point. </para> <example> <title>Handling warnings</title> <programlisting role="php"> <![CDATA[require_once 'Services/Ebay.php'; // pass some authentication data $session = Services_Ebay::getSession($devId, $appId, $certId); $session->setToken($token); // create new proxy object $ebay = new Services_Ebay($session); try { // call a method echo $ebay->GeteBayOfficialTime(); } catch (Exceptio $e) { // Just ignore the exception and handle them // with any warnings, that might have occured. } $errors = $session->getErrors(); if (count($errors) == 0) { echo "No errors or warnings.\n"; } else { foreach ($errors as $error) { printf("%s: %s (%d))\n", $error->getSeverity(), $error->getLongMessage(), $error->getCode()); } } ]]> </programlisting> </example> </refsect1> </refentry> <!-- Keep this comment at the end of the file Local variables: mode: sgml sgml-omittag:t sgml-shorttag:t sgml-minimize-attributes:nil sgml-always-quote-attributes:t sgml-indent-step:1 sgml-indent-data:t sgml-parent-document:nil sgml-default-dtd-file:"../../../../manual.ced" sgml-exposed-tags:nil sgml-local-catalogs:nil sgml-local-ecat-files:nil End: vim600: syn=webservices fen fdm=syntax fdl=2 si vim: et tw=78 syn=sgml vi: ts=1 sw=1 -->