| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438 |
- <?xml version="1.0" encoding="UTF-8"?>
- <!-- Reviewed: no -->
- <sect1 id="zend.service.strikeiron">
- <title>Zend_Service_StrikeIron</title>
- <para>
- <classname>Zend_Service_StrikeIron</classname> provides a <acronym>PHP</acronym> 5 client to
- StrikeIron web services. See the following sections:
- </para>
- <para>
- <itemizedlist>
- <listitem>
- <para><link linkend="zend.service.strikeiron">Zend_Service_StrikeIron</link></para>
- </listitem>
- </itemizedlist>
- <itemizedlist>
- <listitem>
- <para>
- <link linkend="zend.service.strikeiron.bundled-services">Bundled Services</link>
- </para>
- </listitem>
- </itemizedlist>
- <itemizedlist>
- <listitem>
- <para>
- <link linkend="zend.service.strikeiron.advanced-uses">Advanced Use</link>
- </para>
- </listitem>
- </itemizedlist>
- </para>
- <sect2 id="zend.service.strikeiron.overview">
- <title>Overview</title>
- <para>
- <ulink url="http://www.strikeiron.com">StrikeIron</ulink>
- offers hundreds of commercial data services ("Data as a Service")
- such as Online Sales Tax, Currency Rates, Stock Quotes, Geocodes, Global
- Address Verification, Yellow/White Pages, MapQuest Driving Directions,
- Dun & Bradstreet Business Credit Checks, and much, much more.
- </para>
- <para>
- Each StrikeIron web service shares a standard <acronym>SOAP</acronym> (and REST)
- <acronym>API</acronym>, making it easy to integrate and manage multiple services.
- StrikeIron also manages customer billing for all services in a single
- account, making it perfect for solution providers. Get
- started with free web services at
- <ulink url="http://www.strikeiron.com/sdp">http://www.strikeiron.com/sdp</ulink>.
- </para>
- <para>
- StrikeIron's services may be used through the
- <ulink url="http://us.php.net/soap">PHP 5 <acronym>SOAP</acronym> extension</ulink>
- alone. However, using StrikeIron this way does not give an ideal
- <acronym>PHP</acronym>-like interface. The
- <classname>Zend_Service_StrikeIron</classname> component provides a lightweight layer on
- top of the <acronym>SOAP</acronym> extension for working with StrikeIron services in a
- more convenient, <acronym>PHP</acronym>-like manner.
- </para>
- <note>
- <para>
- The <acronym>PHP</acronym> 5 <acronym>SOAP</acronym> extension must be installed and
- enabled to use <classname>Zend_Service_StrikeIron</classname>.
- </para>
- </note>
- <para>
- The <classname>Zend_Service_StrikeIron</classname> component provides:
- <itemizedlist>
- <listitem>
- <para>
- A single point for configuring your StrikeIron authentication credentials
- that can be used across many StrikeIron services.
- </para>
- </listitem>
- <listitem>
- <para>
- A standard way of retrieving your StrikeIron subscription information
- such as license status and the number of hits remaining to a service.
- </para>
- </listitem>
- <listitem>
- <para>
- The ability to use any StrikeIron service from its WSDL without
- creating a <acronym>PHP</acronym> wrapper class, and the option of creating
- a wrapper for a more convenient interface.
- </para>
- </listitem>
- <listitem>
- <para>
- Wrappers for three popular StrikeIron services.
- </para>
- </listitem>
- </itemizedlist>
- </para>
- </sect2>
- <sect2 id="zend.service.strikeiron.registering">
- <title>Registering with StrikeIron</title>
- <para>
- Before you can get started with <classname>Zend_Service_StrikeIron</classname>, you must
- first <ulink url="http://strikeiron.com/Register.aspx">register</ulink> for a
- StrikeIron developer account.
- </para>
- <para>
- After registering, you will receive a StrikeIron username and password.
- These will be used when connecting to StrikeIron using
- <classname>Zend_Service_StrikeIron</classname>.
- </para>
- <para>
- You will also need to <ulink
- url="http://www.strikeiron.com/ProductDetail.aspx?p=257">sign up</ulink>
- for StrikeIron's Super Data Pack Web Service.
- </para>
- <para>
- Both registration steps are free and can be done relatively quickly through
- the StrikeIron website.
- </para>
- </sect2>
- <sect2 id="zend.service.strikeiron.getting-started">
- <title>Getting Started</title>
- <para>
- Once you have <ulink url="http://strikeiron.com/Register.aspx">registered</ulink>
- for a StrikeIron account and signed up for the
- <ulink url="http://www.strikeiron.com/ProductDetail.aspx?p=257">Super Data Pack</ulink>,
- you're ready to start using <classname>Zend_Service_StrikeIron</classname>.
- </para>
- <para>
- StrikeIron consists of hundreds of different web services.
- <classname>Zend_Service_StrikeIron</classname> can be used with many of these services
- but provides supported wrappers for three of them:
- </para>
- <itemizedlist>
- <listitem>
- <para>
- <link
- linkend="zend.service.strikeiron.bundled-services.zip-code-information">ZIP
- Code Information</link>
- </para>
- </listitem>
- <listitem>
- <para>
- <link
- linkend="zend.service.strikeiron.bundled-services.us-address-verification">US
- Address Verification</link>
- </para>
- </listitem>
- <listitem>
- <para>
- <link
- linkend="zend.service.strikeiron.bundled-services.sales-use-tax-basic">Sales
- & Use Tax Basic</link>
- </para>
- </listitem>
- </itemizedlist>
- <para>
- The class <classname>Zend_Service_StrikeIron</classname> provides a simple way
- of specifying your StrikeIron account information and other options in
- its constructor. It also has a factory method that will return clients
- for StrikeIron services:
- </para>
- <programlisting language="php"><![CDATA[
- $strikeIron = new Zend_Service_StrikeIron(array('username' => 'your-username',
- 'password' => 'your-password'));
- $taxBasic = $strikeIron->getService(array('class' => 'SalesUseTaxBasic'));
- ]]></programlisting>
- <para>
- The <methodname>getService()</methodname> method will return a client for any
- StrikeIron service by the name of its <acronym>PHP</acronym> wrapper class. In this
- case, the name 'SalesUseTaxBasic' refers to the wrapper class
- <classname>Zend_Service_StrikeIron_SalesUseTaxBasic</classname>. Wrappers are
- included for three services and described in
- <link linkend="zend.service.strikeiron.bundled-services">Bundled Services</link>.
- </para>
- <para>
- The <methodname>getService()</methodname> method can also return a client for
- a StrikeIron service that does not yet have a <acronym>PHP</acronym> wrapper. This is
- explained in
- <link linkend="zend.service.strikeiron.advanced-uses.services-by-wsdl">Using Services by
- WSDL</link>.
- </para>
- </sect2>
- <sect2 id="zend.service.strikeiron.making-first-query">
- <title>Making Your First Query</title>
- <para>
- Once you have used the <methodname>getService()</methodname> method to get a client
- for a particular StrikeIron service, you can utilize that client
- by calling methods on it just like any other <acronym>PHP</acronym> object.
- </para>
- <programlisting language="php"><![CDATA[
- $strikeIron = new Zend_Service_StrikeIron(array('username' => 'your-username',
- 'password' => 'your-password'));
- // Get a client for the Sales & Use Tax Basic service
- $taxBasic = $strikeIron->getService(array('class' => 'SalesUseTaxBasic'));
- // Query tax rate for Ontario, Canada
- $rateInfo = $taxBasic->getTaxRateCanada(array('province' => 'ontario'));
- echo $rateInfo->province;
- echo $rateInfo->abbreviation;
- echo $rateInfo->GST;
- ]]></programlisting>
- <para>
- In the example above, the <methodname>getService()</methodname> method is used
- to return a client to the <link
- linkend="zend.service.strikeiron.bundled-services.sales-use-tax-basic">Sales &
- Use Tax Basic</link> service. The client object is stored in
- <varname>$taxBasic</varname>.
- </para>
- <para>
- The <methodname>getTaxRateCanada()</methodname> method is then called on the
- service. An associative array is used to supply keyword parameters to
- the method. This is the way that all StrikeIron methods are called.
- </para>
- <para>
- The result from <methodname>getTaxRateCanada()</methodname> is stored in
- <varname>$rateInfo</varname> and has properties like <property>province</property>
- and <constant>GST</constant>.
- </para>
- <para>
- Many of the StrikeIron services are as simple to use as the example above. See
- <link linkend="zend.service.strikeiron.bundled-services">Bundled Services</link>
- for detailed information on three StrikeIron services.
- </para>
- </sect2>
- <sect2 id="zend.service.strikeiron.examining-results">
- <title>Examining Results</title>
- <para>
- When learning or debugging the StrikeIron services, it's often useful to dump the
- result returned from a method call. The result will always be an object that is an
- instance of <classname>Zend_Service_StrikeIron_Decorator</classname>. This is a
- small <ulink url="http://en.wikipedia.org/wiki/Decorator_pattern">decorator</ulink>
- object that wraps the results from the method call.
- </para>
- <para>
- The simplest way to examine a result from the service is to use the built-in
- <acronym>PHP</acronym> functions like <ulink
- url="http://www.php.net/print_r">print_r()</ulink>:
- </para>
- <programlisting language="php"><![CDATA[
- <?php
- $strikeIron = new Zend_Service_StrikeIron(array('username' => 'your-username',
- 'password' => 'your-password'));
- $taxBasic = $strikeIron->getService(array('class' => 'SalesUseTaxBasic'));
- $rateInfo = $taxBasic->getTaxRateCanada(array('province' => 'ontario'));
- print_r($rateInfo);
- ?>
- Zend_Service_StrikeIron_Decorator Object
- (
- [_name:protected] => GetTaxRateCanadaResult
- [_object:protected] => stdClass Object
- (
- [abbreviation] => ON
- [province] => ONTARIO
- [GST] => 0.06
- [PST] => 0.08
- [total] => 0.14
- [HST] => Y
- )
- )
- ]]></programlisting>
- <para>
- In the output above, we see that the decorator (<varname>$rateInfo</varname>) wraps an
- object named <classname>GetTaxRateCanadaResult</classname>, the result of the call to
- <methodname>getTaxRateCanada()</methodname>.
- </para>
- <para>
- This means that <varname>$rateInfo</varname> has public properties like
- <property>abbreviation</property>, <property>province</property>, and
- <constant>GST</constant>. These are accessed like
- <command>$rateInfo->province</command>.
- </para>
- <tip>
- <para>
- StrikeIron result properties sometimes start with an uppercase letter such as
- <property>Foo</property> or <property>Bar</property> where most
- <acronym>PHP</acronym> object properties normally start with a lowercase letter as
- in <property>foo</property> or <property>bar</property>. The decorator will
- automatically do this inflection so you may read a property <property>Foo</property>
- as <property>foo</property>.
- </para>
- </tip>
- <para>
- If you ever need to get the original object or its name out of the decorator, use the
- respective methods <methodname>getDecoratedObject()</methodname> and
- <methodname>getDecoratedObjectName()</methodname>.
- </para>
- </sect2>
- <sect2 id="zend.service.strikeiron.handling-errors">
- <title>Handling Errors</title>
- <para>
- The previous examples are naive, i.e. no error handling was shown.
- It's possible that StrikeIron will return a fault during a method
- call. Events like bad account credentials or an expired subscription
- can cause StrikeIron to raise a fault.
- </para>
- <para>
- An exception will be thrown when such a fault occurs. You should
- anticipate and catch these exceptions when making method calls to the
- service:
- </para>
- <programlisting language="php"><![CDATA[
- $strikeIron = new Zend_Service_StrikeIron(array('username' => 'your-username',
- 'password' => 'your-password'));
- $taxBasic = $strikeIron->getService(array('class' => 'SalesUseTaxBasic'));
- try {
- $taxBasic->getTaxRateCanada(array('province' => 'ontario'));
- } catch (Zend_Service_StrikeIron_Exception $e) {
- // error handling for events like connection
- // problems or subscription errors
- }
- ]]></programlisting>
- <para>
- The exceptions thrown will always be
- <classname>Zend_Service_StrikeIron_Exception</classname>.
- </para>
- <para>
- It's important to understand the difference between exceptions and
- normal failed method calls. Exceptions occur for
- <emphasis>exceptional</emphasis> conditions, such as
- the network going down or your subscription expiring.
- Failed method calls that are a common occurrence,
- such as <methodname>getTaxRateCanada()</methodname> not finding the
- <property>province</property> you supplied, will not result an in exception.
- </para>
- <note>
- <para>
- Every time you make a method call to a StrikeIron service, you
- should check the response object for validity and also be
- prepared to catch an exception.
- </para>
- </note>
- <para><!-- included for whitespace --></para>
- </sect2>
- <sect2 id="zend.service.strikeiron.checking-subscription">
- <title>Checking Your Subscription</title>
- <para>
- StrikeIron provides many different services. Some of these are
- free, some are available on a trial basis, and some are pay subscription only.
- When using StrikeIron, it's important to be aware of your subscription
- status for the services you are using and check it regularly.
- </para>
- <para>
- Each StrikeIron client returned by the <methodname>getService()</methodname> method
- has the ability to check the subscription status for that service using
- the <methodname>getSubscriptionInfo()</methodname> method of the client:
- </para>
- <programlisting language="php"><![CDATA[
- // Get a client for the Sales & Use Tax Basic service
- $strikeIron = new Zend_Service_StrikeIron(array('username' => 'your-username',
- 'password' => 'your-password'));
- $taxBasic = $strikeIron->getService(array('class => 'SalesUseTaxBasic'));
- // Check remaining hits for the Sales & Use Tax Basic service
- $subscription = $taxBasic->getSubscriptionInfo();
- echo $subscription->remainingHits;
- ]]></programlisting>
- <para>
- The <methodname>getSubscriptionInfo()</methodname> method will return an object
- that typically has a <property>remainingHits</property> property. It's
- important to check the status on each service that you are using. If
- a method call is made to StrikeIron after the remaining hits have been
- used up, an exception will occur.
- </para>
- <para>
- Checking your subscription to a service does not use any remaining
- hits to the service. Each time any method call to the service is made,
- the number of hits remaining will be cached and this cached value will
- be returned by <methodname>getSubscriptionInfo()</methodname> without connecting
- to the service again. To force <methodname>getSubscriptionInfo()</methodname>
- to override its cache and query the subscription information again, use
- <methodname>getSubscriptionInfo(true)</methodname>.
- </para>
- </sect2>
- </sect1>
|