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:
176 <programlisting language="php"><![CDATA[
177 $strikeIron = new Zend_Service_StrikeIron(array('username' => 'your-username',
178 'password' => 'your-password'));
180 $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 PHP object.
210 <programlisting language="php"><![CDATA[
211 $strikeIron = new Zend_Service_StrikeIron(array('username' => 'your-username',
212 'password' => 'your-password'));
214 // Get a client for the Sales & Use Tax Basic service
215 $taxBasic = $strikeIron->getService(array('class' => 'SalesUseTaxBasic'));
217 // Query tax rate for Ontario, Canada
218 $rateInfo = $taxBasic->getTaxRateCanada(array('province' => 'ontario'));
219 echo $rateInfo->province;
220 echo $rateInfo->abbreviation;
224 In the example above, the <methodname>getService()</methodname> method is used
225 to return a client to the <link
226 linkend="zend.service.strikeiron.bundled-services.sales-use-tax-basic">Sales &
227 Use Tax Basic</link> service. The client object is stored in
228 <varname>$taxBasic</varname>.
232 The <methodname>getTaxRateCanada()</methodname> method is then called on the
233 service. An associative array is used to supply keyword parameters to
234 the method. This is the way that all StrikeIron methods are called.
238 The result from <methodname>getTaxRateCanada()</methodname> is stored in
239 <varname>$rateInfo</varname> and has properties like <code>province</code>
240 and <constant>GST</constant>.
244 Many of the StrikeIron services are as simple to use as the example above. See
245 <link linkend="zend.service.strikeiron.bundled-services">Bundled Services</link>
246 for detailed information on three StrikeIron services.
250 <sect2 id="zend.service.strikeiron.examining-results">
251 <title>Examining Results</title>
254 When learning or debugging the StrikeIron services, it's often useful to dump the
255 result returned from a method call. The result will always be an object that is an
256 instance of <classname>Zend_Service_StrikeIron_Decorator</classname>. This is a
257 small <ulink url="http://en.wikipedia.org/wiki/Decorator_pattern">decorator</ulink>
258 object that wraps the results from the method call.
262 The simplest way to examine a result from the service is to use the built-in
263 PHP functions like <ulink url="http://www.php.net/print_r">print_r()</ulink>:
265 <programlisting language="php"><![CDATA[
267 $strikeIron = new Zend_Service_StrikeIron(array('username' => 'your-username',
268 'password' => 'your-password'));
270 $taxBasic = $strikeIron->getService(array('class' => 'SalesUseTaxBasic'));
272 $rateInfo = $taxBasic->getTaxRateCanada(array('province' => 'ontario'));
276 Zend_Service_StrikeIron_Decorator Object
278 [_name:protected] => GetTaxRateCanadaResult
279 [_object:protected] => stdClass Object
282 [province] => ONTARIO
293 In the output above, we see that the decorator (<varname>$rateInfo</varname>) wraps an
294 object named <code>GetTaxRateCanadaResult</code>, the result of the call to
295 <methodname>getTaxRateCanada()</methodname>.
299 This means that <varname>$rateInfo</varname> has public properties like
300 <code>abbreviation</code>, <code>province</code>, and <constant>GST</constant>. These
301 are accessed like <code>$rateInfo->province</code>.
306 StrikeIron result properties sometimes start with an uppercase letter such as
307 <code>Foo</code> or <code>Bar</code> where most <acronym>PHP</acronym> object
308 properties normally start with a lowercase letter as in <code>foo</code> or
309 <code>bar</code>. The decorator will automatically do this inflection so you
310 may read a property <code>Foo</code> as <code>foo</code>.
315 If you ever need to get the original object or its name out of the decorator, use the
316 respective methods <methodname>getDecoratedObject()</methodname> and
317 <methodname>getDecoratedObjectName()</methodname>.
321 <sect2 id="zend.service.strikeiron.handling-errors">
322 <title>Handling Errors</title>
325 The previous examples are naive, i.e. no error handling was shown.
326 It's possible that StrikeIron will return a fault during a method
327 call. Events like bad account credentials or an expired subscription
328 can cause StrikeIron to raise a fault.
332 An exception will be thrown when such a fault occurs. You should
333 anticipate and catch these exceptions when making method calls to the
336 <programlisting language="php"><![CDATA[
337 $strikeIron = new Zend_Service_StrikeIron(array('username' => 'your-username',
338 'password' => 'your-password'));
340 $taxBasic = $strikeIron->getService(array('class' => 'SalesUseTaxBasic'));
344 $taxBasic->getTaxRateCanada(array('province' => 'ontario'));
346 } catch (Zend_Service_StrikeIron_Exception $e) {
348 // error handling for events like connection
349 // problems or subscription errors
354 The exceptions thrown will always be
355 <classname>Zend_Service_StrikeIron_Exception</classname>.
359 It's important to understand the difference between exceptions and
360 normal failed method calls. Exceptions occur for
361 <emphasis>exceptional</emphasis> conditions, such as
362 the network going down or your subscription expiring.
363 Failed method calls that are a common occurrence,
364 such as <methodname>getTaxRateCanada()</methodname> not finding the
365 <code>province</code> you supplied, will not result an in exception.
370 Every time you make a method call to a StrikeIron service, you
371 should check the response object for validity and also be
372 prepared to catch an exception.
376 <para><!-- included for whitespace --></para>
379 <sect2 id="zend.service.strikeiron.checking-subscription">
380 <title>Checking Your Subscription</title>
383 StrikeIron provides many different services. Some of these are
384 free, some are available on a trial basis, and some are pay subscription only.
385 When using StrikeIron, it's important to be aware of your subscription
386 status for the services you are using and check it regularly.
390 Each StrikeIron client returned by the <code>getService</code> method
391 has the ability to check the subscription status for that service using
392 the <methodname>getSubscriptionInfo()</methodname> method of the client:
394 <programlisting language="php"><![CDATA[
395 // Get a client for the Sales & Use Tax Basic service
396 $strikeIron = new Zend_Service_StrikeIron(array('username' => 'your-username',
397 'password' => 'your-password'));
399 $taxBasic = $strikeIron->getService(array('class => 'SalesUseTaxBasic'));
401 // Check remaining hits for the Sales & Use Tax Basic service
402 $subscription = $taxBasic->getSubscriptionInfo();
403 echo $subscription->remainingHits;
408 The <methodname>getSubscriptionInfo()</methodname> method will return an object
409 that typically has a <code>remainingHits</code> property. It's
410 important to check the status on each service that you are using. If
411 a method call is made to StrikeIron after the remaining hits have been
412 used up, an exception will occur.
416 Checking your subscription to a service does not use any remaining
417 hits to the service. Each time any method call to the service is made,
418 the number of hits remaining will be cached and this cached value will
419 be returned by <methodname>getSubscriptionInfo()</methodname> without connecting
420 to the service again. To force <methodname>getSubscriptionInfo()</methodname>
421 to override its cache and query the subscription information again, use
422 <methodname>getSubscriptionInfo(true)</methodname>.