1 <?xml version="1.0" encoding="UTF-8"?>
3 <sect1 id="zend.service.strikeiron">
4 <title>Zend_Service_StrikeIron</title>
7 <classname>Zend_Service_StrikeIron</classname> provides a <acronym>PHP</acronym> 5 client to
8 StrikeIron web services. See the following sections:
13 <listitem><para><xref linkend="zend.service.strikeiron" /></para></listitem>
18 <para><xref linkend="zend.service.strikeiron.bundled-services" /></para>
24 <para><xref linkend="zend.service.strikeiron.advanced-uses" /></para>
29 <sect2 id="zend.service.strikeiron.overview">
30 <title>Overview</title>
33 <ulink url="http://www.strikeiron.com">StrikeIron</ulink>
34 offers hundreds of commercial data services ("Data as a Service")
35 such as Online Sales Tax, Currency Rates, Stock Quotes, Geocodes, Global
36 Address Verification, Yellow/White Pages, MapQuest Driving Directions,
37 Dun & Bradstreet Business Credit Checks, and much, much more.
41 Each StrikeIron web service shares a standard <acronym>SOAP</acronym> (and REST)
42 <acronym>API</acronym>, making it easy to integrate and manage multiple services.
43 StrikeIron also manages customer billing for all services in a single
44 account, making it perfect for solution providers. Get
45 started with free web services at
46 <ulink url="http://www.strikeiron.com/sdp">http://www.strikeiron.com/sdp</ulink>.
50 StrikeIron's services may be used through the
51 <ulink url="http://us.php.net/soap">PHP 5 <acronym>SOAP</acronym> extension</ulink>
52 alone. However, using StrikeIron this way does not give an ideal
53 <acronym>PHP</acronym>-like interface. The
54 <classname>Zend_Service_StrikeIron</classname> component provides a lightweight layer on
55 top of the <acronym>SOAP</acronym> extension for working with StrikeIron services in a
56 more convenient, <acronym>PHP</acronym>-like manner.
61 The <acronym>PHP</acronym> 5 <acronym>SOAP</acronym> extension must be installed and
62 enabled to use <classname>Zend_Service_StrikeIron</classname>.
67 The <classname>Zend_Service_StrikeIron</classname> component provides:
72 A single point for configuring your StrikeIron authentication credentials
73 that can be used across many StrikeIron services.
79 A standard way of retrieving your StrikeIron subscription information
80 such as license status and the number of hits remaining to a service.
86 The ability to use any StrikeIron service from its WSDL without
87 creating a <acronym>PHP</acronym> wrapper class, and the option of creating
88 a wrapper for a more convenient interface.
94 Wrappers for three popular StrikeIron services.
101 <sect2 id="zend.service.strikeiron.registering">
102 <title>Registering with StrikeIron</title>
105 Before you can get started with <classname>Zend_Service_StrikeIron</classname>, you must
106 first <ulink url="http://strikeiron.com/Register.aspx">register</ulink> for a
107 StrikeIron developer account.
111 After registering, you will receive a StrikeIron username and password.
112 These will be used when connecting to StrikeIron using
113 <classname>Zend_Service_StrikeIron</classname>.
117 You will also need to <ulink
118 url="http://www.strikeiron.com/ProductDetail.aspx?p=257">sign up</ulink>
119 for StrikeIron's Super Data Pack Web Service.
123 Both registration steps are free and can be done relatively quickly through
124 the StrikeIron website.
128 <sect2 id="zend.service.strikeiron.getting-started">
129 <title>Getting Started</title>
132 Once you have <ulink url="http://strikeiron.com/Register.aspx">registered</ulink>
133 for a StrikeIron account and signed up for the
134 <ulink url="http://www.strikeiron.com/ProductDetail.aspx?p=257">Super Data Pack</ulink>,
135 you're ready to start using <classname>Zend_Service_StrikeIron</classname>.
139 StrikeIron consists of hundreds of different web services.
140 <classname>Zend_Service_StrikeIron</classname> can be used with many of these services
141 but provides supported wrappers for three of them:
148 linkend="zend.service.strikeiron.bundled-services.zip-code-information">ZIP
149 Code Information</link>
156 linkend="zend.service.strikeiron.bundled-services.us-address-verification">US
157 Address Verification</link>
164 linkend="zend.service.strikeiron.bundled-services.sales-use-tax-basic">Sales
165 & Use Tax Basic</link>
171 The class <classname>Zend_Service_StrikeIron</classname> provides a simple way
172 of specifying your StrikeIron account information and other options in
173 its constructor. It also has a factory method that will return clients
174 for StrikeIron services:
177 <programlisting language="php"><![CDATA[
178 $strikeIron = new Zend_Service_StrikeIron(array('username' => 'your-username',
179 'password' => 'your-password'));
181 $taxBasic = $strikeIron->getService(array('class' => 'SalesUseTaxBasic'));
185 The <methodname>getService()</methodname> method will return a client for any
186 StrikeIron service by the name of its <acronym>PHP</acronym> wrapper class. In this
187 case, the name <code>SalesUseTaxBasic</code> refers to the wrapper class
188 <classname>Zend_Service_StrikeIron_SalesUseTaxBasic</classname>. Wrappers are
189 included for three services and described in
190 <link linkend="zend.service.strikeiron.bundled-services">Bundled Services</link>.
194 The <methodname>getService()</methodname> method can also return a client for
195 a StrikeIron service that does not yet have a <acronym>PHP</acronym> wrapper. This is
197 <link linkend="zend.service.strikeiron.advanced-uses.services-by-wsdl">Using Services by
202 <sect2 id="zend.service.strikeiron.making-first-query">
203 <title>Making Your First Query</title>
206 Once you have used the <methodname>getService()</methodname> method to get a client
207 for a particular StrikeIron service, you can utilize that client
208 by calling methods on it just like any other <acronym>PHP</acronym> object.
211 <programlisting language="php"><![CDATA[
212 $strikeIron = new Zend_Service_StrikeIron(array('username' => 'your-username',
213 'password' => 'your-password'));
215 // Get a client for the Sales & Use Tax Basic service
216 $taxBasic = $strikeIron->getService(array('class' => 'SalesUseTaxBasic'));
218 // Query tax rate for Ontario, Canada
219 $rateInfo = $taxBasic->getTaxRateCanada(array('province' => 'ontario'));
220 echo $rateInfo->province;
221 echo $rateInfo->abbreviation;
226 In the example above, the <methodname>getService()</methodname> method is used
227 to return a client to the <link
228 linkend="zend.service.strikeiron.bundled-services.sales-use-tax-basic">Sales &
229 Use Tax Basic</link> service. The client object is stored in
230 <varname>$taxBasic</varname>.
234 The <methodname>getTaxRateCanada()</methodname> method is then called on the
235 service. An associative array is used to supply keyword parameters to
236 the method. This is the way that all StrikeIron methods are called.
240 The result from <methodname>getTaxRateCanada()</methodname> is stored in
241 <varname>$rateInfo</varname> and has properties like <code>province</code>
242 and <constant>GST</constant>.
246 Many of the StrikeIron services are as simple to use as the example above. See
247 <link linkend="zend.service.strikeiron.bundled-services">Bundled Services</link>
248 for detailed information on three StrikeIron services.
252 <sect2 id="zend.service.strikeiron.examining-results">
253 <title>Examining Results</title>
256 When learning or debugging the StrikeIron services, it's often useful to dump the
257 result returned from a method call. The result will always be an object that is an
258 instance of <classname>Zend_Service_StrikeIron_Decorator</classname>. This is a
259 small <ulink url="http://en.wikipedia.org/wiki/Decorator_pattern">decorator</ulink>
260 object that wraps the results from the method call.
264 The simplest way to examine a result from the service is to use the built-in
265 <acronym>PHP</acronym> functions like <ulink
266 url="http://www.php.net/print_r">print_r()</ulink>:
269 <programlisting language="php"><![CDATA[
271 $strikeIron = new Zend_Service_StrikeIron(array('username' => 'your-username',
272 'password' => 'your-password'));
274 $taxBasic = $strikeIron->getService(array('class' => 'SalesUseTaxBasic'));
276 $rateInfo = $taxBasic->getTaxRateCanada(array('province' => 'ontario'));
280 Zend_Service_StrikeIron_Decorator Object
282 [_name:protected] => GetTaxRateCanadaResult
283 [_object:protected] => stdClass Object
286 [province] => ONTARIO
296 In the output above, we see that the decorator (<varname>$rateInfo</varname>) wraps an
297 object named <code>GetTaxRateCanadaResult</code>, the result of the call to
298 <methodname>getTaxRateCanada()</methodname>.
302 This means that <varname>$rateInfo</varname> has public properties like
303 <code>abbreviation</code>, <code>province</code>, and <constant>GST</constant>. These
304 are accessed like <code>$rateInfo->province</code>.
309 StrikeIron result properties sometimes start with an uppercase letter such as
310 <code>Foo</code> or <code>Bar</code> where most <acronym>PHP</acronym> object
311 properties normally start with a lowercase letter as in <code>foo</code> or
312 <code>bar</code>. The decorator will automatically do this inflection so you
313 may read a property <code>Foo</code> as <code>foo</code>.
318 If you ever need to get the original object or its name out of the decorator, use the
319 respective methods <methodname>getDecoratedObject()</methodname> and
320 <methodname>getDecoratedObjectName()</methodname>.
324 <sect2 id="zend.service.strikeiron.handling-errors">
325 <title>Handling Errors</title>
328 The previous examples are naive, i.e. no error handling was shown.
329 It's possible that StrikeIron will return a fault during a method
330 call. Events like bad account credentials or an expired subscription
331 can cause StrikeIron to raise a fault.
335 An exception will be thrown when such a fault occurs. You should
336 anticipate and catch these exceptions when making method calls to the
340 <programlisting language="php"><![CDATA[
341 $strikeIron = new Zend_Service_StrikeIron(array('username' => 'your-username',
342 'password' => 'your-password'));
344 $taxBasic = $strikeIron->getService(array('class' => 'SalesUseTaxBasic'));
348 $taxBasic->getTaxRateCanada(array('province' => 'ontario'));
350 } catch (Zend_Service_StrikeIron_Exception $e) {
352 // error handling for events like connection
353 // problems or subscription errors
359 The exceptions thrown will always be
360 <classname>Zend_Service_StrikeIron_Exception</classname>.
364 It's important to understand the difference between exceptions and
365 normal failed method calls. Exceptions occur for
366 <emphasis>exceptional</emphasis> conditions, such as
367 the network going down or your subscription expiring.
368 Failed method calls that are a common occurrence,
369 such as <methodname>getTaxRateCanada()</methodname> not finding the
370 <code>province</code> you supplied, will not result an in exception.
375 Every time you make a method call to a StrikeIron service, you
376 should check the response object for validity and also be
377 prepared to catch an exception.
381 <para><!-- included for whitespace --></para>
384 <sect2 id="zend.service.strikeiron.checking-subscription">
385 <title>Checking Your Subscription</title>
388 StrikeIron provides many different services. Some of these are
389 free, some are available on a trial basis, and some are pay subscription only.
390 When using StrikeIron, it's important to be aware of your subscription
391 status for the services you are using and check it regularly.
395 Each StrikeIron client returned by the <code>getService</code> method
396 has the ability to check the subscription status for that service using
397 the <methodname>getSubscriptionInfo()</methodname> method of the client:
400 <programlisting language="php"><![CDATA[
401 // Get a client for the Sales & Use Tax Basic service
402 $strikeIron = new Zend_Service_StrikeIron(array('username' => 'your-username',
403 'password' => 'your-password'));
405 $taxBasic = $strikeIron->getService(array('class => 'SalesUseTaxBasic'));
407 // Check remaining hits for the Sales & Use Tax Basic service
408 $subscription = $taxBasic->getSubscriptionInfo();
409 echo $subscription->remainingHits;
413 The <methodname>getSubscriptionInfo()</methodname> method will return an object
414 that typically has a <code>remainingHits</code> property. It's
415 important to check the status on each service that you are using. If
416 a method call is made to StrikeIron after the remaining hits have been
417 used up, an exception will occur.
421 Checking your subscription to a service does not use any remaining
422 hits to the service. Each time any method call to the service is made,
423 the number of hits remaining will be cached and this cached value will
424 be returned by <methodname>getSubscriptionInfo()</methodname> without connecting
425 to the service again. To force <methodname>getSubscriptionInfo()</methodname>
426 to override its cache and query the subscription information again, use
427 <methodname>getSubscriptionInfo(true)</methodname>.