Zend_Service_StrikeIron-Overview.xml 17 KB

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