Zend_Service_StrikeIron-Overview.xml 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!-- Reviewed: no -->
  3. <sect1 id="zend.service.strikeiron">
  4. <title>Zend_Service_StrikeIron</title>
  5. <para>
  6. <classname>Zend_Service_StrikeIron</classname> provides a <acronym>PHP</acronym> 5 client to StrikeIron
  7. web services. See the following sections:
  8. </para>
  9. <para>
  10. <itemizedlist>
  11. <listitem><para><xref linkend="zend.service.strikeiron" /></para></listitem>
  12. </itemizedlist>
  13. <itemizedlist>
  14. <listitem><para><xref linkend="zend.service.strikeiron.bundled-services" /></para></listitem>
  15. </itemizedlist>
  16. <itemizedlist>
  17. <listitem><para><xref linkend="zend.service.strikeiron.advanced-uses" /></para></listitem>
  18. </itemizedlist>
  19. </para>
  20. <sect2 id="zend.service.strikeiron.overview">
  21. <title>Overview</title>
  22. <para>
  23. <ulink url="http://www.strikeiron.com">StrikeIron</ulink>
  24. offers hundreds of commercial data services ("Data as a Service")
  25. such as Online Sales Tax, Currency Rates, Stock Quotes, Geocodes, Global
  26. Address Verification, Yellow/White Pages, MapQuest Driving Directions,
  27. Dun &amp; Bradstreet Business Credit Checks, and much, much more.
  28. </para>
  29. <para>
  30. Each StrikeIron web service shares a standard <acronym>SOAP</acronym> (and REST)
  31. <acronym>API</acronym>, making it easy to integrate and manage multiple services.
  32. StrikeIron also manages customer billing for all services in a single
  33. account, making it perfect for solution providers. Get
  34. started with free web services at
  35. <ulink url="http://www.strikeiron.com/sdp">http://www.strikeiron.com/sdp</ulink>.
  36. </para>
  37. <para>
  38. StrikeIron's services may be used through the
  39. <ulink url="http://us.php.net/soap">PHP 5 <acronym>SOAP</acronym> extension</ulink> alone.
  40. However, using StrikeIron this way does not give an ideal <acronym>PHP</acronym>-like interface.
  41. The <classname>Zend_Service_StrikeIron</classname> component provides a lightweight layer on
  42. top of the <acronym>SOAP</acronym> extension for working with StrikeIron services in a
  43. more convenient, <acronym>PHP</acronym>-like manner.
  44. </para>
  45. <note>
  46. <para>
  47. The <acronym>PHP</acronym> 5 <acronym>SOAP</acronym> extension must be installed and enabled to use
  48. <classname>Zend_Service_StrikeIron</classname>.
  49. </para>
  50. </note>
  51. <para>
  52. The <classname>Zend_Service_StrikeIron</classname> component provides:
  53. <itemizedlist>
  54. <listitem>
  55. <para>
  56. A single point for configuring your StrikeIron authentication credentials
  57. that can be used across many StrikeIron services.
  58. </para>
  59. </listitem>
  60. <listitem>
  61. <para>
  62. A standard way of retrieving your StrikeIron subscription information
  63. such as license status and the number of hits remaining to a service.
  64. </para>
  65. </listitem>
  66. <listitem>
  67. <para>
  68. The ability to use any StrikeIron service from its WSDL without
  69. creating a <acronym>PHP</acronym> wrapper class, and the option of creating a wrapper for
  70. a more convenient interface.
  71. </para>
  72. </listitem>
  73. <listitem>
  74. <para>
  75. Wrappers for three popular StrikeIron services.
  76. </para>
  77. </listitem>
  78. </itemizedlist>
  79. </para>
  80. </sect2>
  81. <sect2 id="zend.service.strikeiron.registering">
  82. <title>Registering with StrikeIron</title>
  83. <para>
  84. Before you can get started with <classname>Zend_Service_StrikeIron</classname>, you must first
  85. <ulink url="http://strikeiron.com/Register.aspx">register</ulink> for a
  86. StrikeIron developer account.
  87. </para>
  88. <para>
  89. After registering, you will receive a StrikeIron username and password.
  90. These will be used when connecting to StrikeIron using <classname>Zend_Service_StrikeIron</classname>.
  91. </para>
  92. <para>
  93. You will also need to <ulink url="http://www.strikeiron.com/ProductDetail.aspx?p=257">sign up</ulink>
  94. for StrikeIron's Super Data Pack Web Service.
  95. </para>
  96. <para>
  97. Both registration steps are free and can be done relatively quickly through
  98. the StrikeIron website.
  99. </para>
  100. </sect2>
  101. <sect2 id="zend.service.strikeiron.getting-started">
  102. <title>Getting Started</title>
  103. <para>
  104. Once you have <ulink url="http://strikeiron.com/Register.aspx">registered</ulink>
  105. for a StrikeIron account and signed up for the
  106. <ulink url="http://www.strikeiron.com/ProductDetail.aspx?p=257">Super Data Pack</ulink>,
  107. you're ready to start using <classname>Zend_Service_StrikeIron</classname>.
  108. </para>
  109. <para>
  110. StrikeIron consists of hundreds of different web services.
  111. <classname>Zend_Service_StrikeIron</classname> can be used with many of these services but provides supported
  112. wrappers for three of them:
  113. </para>
  114. <itemizedlist>
  115. <listitem>
  116. <para><link linkend="zend.service.strikeiron.bundled-services.zip-code-information">ZIP Code Information</link></para>
  117. </listitem>
  118. <listitem>
  119. <para><link linkend="zend.service.strikeiron.bundled-services.us-address-verification">US Address Verification</link></para>
  120. </listitem>
  121. <listitem>
  122. <para><link linkend="zend.service.strikeiron.bundled-services.sales-use-tax-basic">Sales &amp; Use Tax Basic</link></para>
  123. </listitem>
  124. </itemizedlist>
  125. <para>
  126. The class <classname>Zend_Service_StrikeIron</classname> provides a simple way
  127. of specifying your StrikeIron account information and other options in
  128. its constructor. It also has a factory method that will return clients
  129. for StrikeIron services:
  130. <programlisting language="php"><![CDATA[
  131. $strikeIron = new Zend_Service_StrikeIron(array('username' => 'your-username',
  132. 'password' => 'your-password'));
  133. $taxBasic = $strikeIron->getService(array('class' => 'SalesUseTaxBasic'));
  134. ]]></programlisting>
  135. </para>
  136. <para>
  137. The <methodname>getService()</methodname> method will return a client for any
  138. StrikeIron service by the name of its <acronym>PHP</acronym> wrapper class. In this case,
  139. the name <code>SalesUseTaxBasic</code> refers to the wrapper class
  140. <classname>Zend_Service_StrikeIron_SalesUseTaxBasic</classname>. Wrappers are
  141. included for three services and described in
  142. <link linkend="zend.service.strikeiron.bundled-services">Bundled Services</link>.
  143. </para>
  144. <para>
  145. The <methodname>getService()</methodname> method can also return a client for
  146. a StrikeIron service that does not yet have a <acronym>PHP</acronym> wrapper. This is
  147. explained in
  148. <link linkend="zend.service.strikeiron.advanced-uses.services-by-wsdl">Using Services by WSDL</link>.
  149. </para>
  150. </sect2>
  151. <sect2 id="zend.service.strikeiron.making-first-query">
  152. <title>Making Your First Query</title>
  153. <para>
  154. Once you have used the <methodname>getService()</methodname> method to get a client
  155. for a particular StrikeIron service, you can utilize that client
  156. by calling methods on it just like any other PHP object.
  157. <programlisting language="php"><![CDATA[
  158. $strikeIron = new Zend_Service_StrikeIron(array('username' => 'your-username',
  159. 'password' => 'your-password'));
  160. // Get a client for the Sales & Use Tax Basic service
  161. $taxBasic = $strikeIron->getService(array('class' => 'SalesUseTaxBasic'));
  162. // Query tax rate for Ontario, Canada
  163. $rateInfo = $taxBasic->getTaxRateCanada(array('province' => 'ontario'));
  164. echo $rateInfo->province;
  165. echo $rateInfo->abbreviation;
  166. echo $rateInfo->GST;
  167. ]]></programlisting>
  168. In the example above, the <methodname>getService()</methodname> method is used
  169. to return a client to the
  170. <link linkend="zend.service.strikeiron.bundled-services.sales-use-tax-basic">Sales &amp; Use Tax Basic</link> service.
  171. The client object is stored in <varname>$taxBasic</varname>.
  172. </para>
  173. <para>
  174. The <methodname>getTaxRateCanada()</methodname> method is then called on the
  175. service. An associative array is used to supply keyword parameters to
  176. the method. This is the way that all StrikeIron methods are called.
  177. </para>
  178. <para>
  179. The result from <methodname>getTaxRateCanada()</methodname> is stored in
  180. <varname>$rateInfo</varname> and has properties like <code>province</code>
  181. and <constant>GST</constant>.
  182. </para>
  183. <para>
  184. Many of the StrikeIron services are as simple to use as the example above. See
  185. <link linkend="zend.service.strikeiron.bundled-services">Bundled Services</link>
  186. for detailed information on three StrikeIron services.
  187. </para>
  188. </sect2>
  189. <sect2 id="zend.service.strikeiron.examining-results">
  190. <title>Examining Results</title>
  191. <para>
  192. When learning or debugging the StrikeIron services, it's often useful to dump the
  193. result returned from a method call. The result will always be an object that is an
  194. instance of <classname>Zend_Service_StrikeIron_Decorator</classname>. This is a
  195. small <ulink url="http://en.wikipedia.org/wiki/Decorator_pattern">decorator</ulink>
  196. object that wraps the results from the method call.
  197. </para>
  198. <para>
  199. The simplest way to examine a result from the service is to use the built-in
  200. PHP functions like <ulink url="http://www.php.net/print_r">print_r()</ulink>:
  201. <programlisting language="php"><![CDATA[
  202. <?php
  203. $strikeIron = new Zend_Service_StrikeIron(array('username' => 'your-username',
  204. 'password' => 'your-password'));
  205. $taxBasic = $strikeIron->getService(array('class' => 'SalesUseTaxBasic'));
  206. $rateInfo = $taxBasic->getTaxRateCanada(array('province' => 'ontario'));
  207. print_r($rateInfo);
  208. ?>
  209. Zend_Service_StrikeIron_Decorator Object
  210. (
  211. [_name:protected] => GetTaxRateCanadaResult
  212. [_object:protected] => stdClass Object
  213. (
  214. [abbreviation] => ON
  215. [province] => ONTARIO
  216. [GST] => 0.06
  217. [PST] => 0.08
  218. [total] => 0.14
  219. [HST] => Y
  220. )
  221. )
  222. ]]></programlisting>
  223. </para>
  224. <para>
  225. In the output above, we see that the decorator (<varname>$rateInfo</varname>) wraps an object
  226. named <code>GetTaxRateCanadaResult</code>, the result of the call to <methodname>getTaxRateCanada()</methodname>.
  227. </para>
  228. <para>
  229. This means that <varname>$rateInfo</varname> has public properties like <code>abbreviation</code>,
  230. <code>province</code>, and <constant>GST</constant>. These are accessed like <code>$rateInfo->province</code>.
  231. </para>
  232. <tip>
  233. <para>
  234. StrikeIron result properties sometimes start with an uppercase
  235. letter such as <code>Foo</code> or <code>Bar</code> where most <acronym>PHP</acronym> object
  236. properties normally start with a lowercase letter as in <code>foo</code> or
  237. <code>bar</code>. The decorator will automatically do this inflection so you
  238. may read a property <code>Foo</code> as <code>foo</code>.
  239. </para>
  240. </tip>
  241. <para>
  242. If you ever need to get the original object or its name out of the decorator, use the
  243. respective methods <methodname>getDecoratedObject()</methodname> and <methodname>getDecoratedObjectName()</methodname>.
  244. </para>
  245. </sect2>
  246. <sect2 id="zend.service.strikeiron.handling-errors">
  247. <title>Handling Errors</title>
  248. <para>
  249. The previous examples are naive, i.e. no error handling was shown.
  250. It's possible that StrikeIron will return a fault during a method
  251. call. Events like bad account credentials or an expired subscription
  252. can cause StrikeIron to raise a fault.
  253. </para>
  254. <para>
  255. An exception will be thrown when such a fault occurs. You should
  256. anticipate and catch these exceptions when making method calls to the
  257. service:
  258. <programlisting language="php"><![CDATA[
  259. $strikeIron = new Zend_Service_StrikeIron(array('username' => 'your-username',
  260. 'password' => 'your-password'));
  261. $taxBasic = $strikeIron->getService(array('class' => 'SalesUseTaxBasic'));
  262. try {
  263. $taxBasic->getTaxRateCanada(array('province' => 'ontario'));
  264. } catch (Zend_Service_StrikeIron_Exception $e) {
  265. // error handling for events like connection
  266. // problems or subscription errors
  267. }
  268. ]]></programlisting>
  269. The exceptions thrown will always be <classname>Zend_Service_StrikeIron_Exception</classname>.
  270. </para>
  271. <para>
  272. It's important to understand the difference between exceptions and
  273. normal failed method calls. Exceptions occur for
  274. <emphasis>exceptional</emphasis> conditions, such as
  275. the network going down or your subscription expiring.
  276. Failed method calls that are a common occurrence,
  277. such as <methodname>getTaxRateCanada()</methodname> not finding the
  278. <code>province</code> you supplied, will not result an in exception.
  279. </para>
  280. <note>
  281. <para>
  282. Every time you make a method call to a StrikeIron service, you
  283. should check the response object for validity and also be
  284. prepared to catch an exception.
  285. </para>
  286. </note>
  287. <para><!-- included for whitespace --></para>
  288. </sect2>
  289. <sect2 id="zend.service.strikeiron.checking-subscription">
  290. <title>Checking Your Subscription</title>
  291. <para>
  292. StrikeIron provides many different services. Some of these are
  293. free, some are available on a trial basis, and some are pay subscription only.
  294. When using StrikeIron, it's important to be aware of your subscription
  295. status for the services you are using and check it regularly.
  296. </para>
  297. <para>
  298. Each StrikeIron client returned by the <code>getService</code> method
  299. has the ability to check the subscription status for that service using
  300. the <methodname>getSubscriptionInfo()</methodname> method of the client:
  301. <programlisting language="php"><![CDATA[
  302. // Get a client for the Sales & Use Tax Basic service
  303. $strikeIron = new Zend_Service_StrikeIron(array('username' => 'your-username',
  304. 'password' => 'your-password'));
  305. $taxBasic = $strikeIron->getService(array('class => 'SalesUseTaxBasic'));
  306. // Check remaining hits for the Sales & Use Tax Basic service
  307. $subscription = $taxBasic->getSubscriptionInfo();
  308. echo $subscription->remainingHits;
  309. ]]></programlisting>
  310. </para>
  311. <para>
  312. The <methodname>getSubscriptionInfo()</methodname> method will return an object
  313. that typically has a <code>remainingHits</code> property. It's
  314. important to check the status on each service that you are using. If
  315. a method call is made to StrikeIron after the remaining hits have been
  316. used up, an exception will occur.
  317. </para>
  318. <para>
  319. Checking your subscription to a service does not use any remaining
  320. hits to the service. Each time any method call to the service is made,
  321. the number of hits remaining will be cached and this cached value will
  322. be returned by <methodname>getSubscriptionInfo()</methodname> without connecting
  323. to the service again. To force <methodname>getSubscriptionInfo()</methodname>
  324. to override its cache and query the subscription information again, use
  325. <methodname>getSubscriptionInfo(true)</methodname>.
  326. </para>
  327. </sect2>
  328. </sect1>