Zend_Service_StrikeIron-Overview.xml 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426
  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. <programlisting language="php"><![CDATA[
  150. $strikeIron = new Zend_Service_StrikeIron(array('username' => 'your-username',
  151. 'password' => 'your-password'));
  152. $taxBasic = $strikeIron->getService(array('class' => 'SalesUseTaxBasic'));
  153. ]]></programlisting>
  154. </para>
  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. <programlisting language="php"><![CDATA[
  178. $strikeIron = new Zend_Service_StrikeIron(array('username' => 'your-username',
  179. 'password' => 'your-password'));
  180. // Get a client for the Sales & Use Tax Basic service
  181. $taxBasic = $strikeIron->getService(array('class' => 'SalesUseTaxBasic'));
  182. // Query tax rate for Ontario, Canada
  183. $rateInfo = $taxBasic->getTaxRateCanada(array('province' => 'ontario'));
  184. echo $rateInfo->province;
  185. echo $rateInfo->abbreviation;
  186. echo $rateInfo->GST;
  187. ]]></programlisting>
  188. In the example above, the <methodname>getService()</methodname> method is used
  189. to return a client to the <link
  190. linkend="zend.service.strikeiron.bundled-services.sales-use-tax-basic">Sales &amp;
  191. Use Tax Basic</link> service. The client object is stored in
  192. <varname>$taxBasic</varname>.
  193. </para>
  194. <para>
  195. The <methodname>getTaxRateCanada()</methodname> method is then called on the
  196. service. An associative array is used to supply keyword parameters to
  197. the method. This is the way that all StrikeIron methods are called.
  198. </para>
  199. <para>
  200. The result from <methodname>getTaxRateCanada()</methodname> is stored in
  201. <varname>$rateInfo</varname> and has properties like <code>province</code>
  202. and <constant>GST</constant>.
  203. </para>
  204. <para>
  205. Many of the StrikeIron services are as simple to use as the example above. See
  206. <link linkend="zend.service.strikeiron.bundled-services">Bundled Services</link>
  207. for detailed information on three StrikeIron services.
  208. </para>
  209. </sect2>
  210. <sect2 id="zend.service.strikeiron.examining-results">
  211. <title>Examining Results</title>
  212. <para>
  213. When learning or debugging the StrikeIron services, it's often useful to dump the
  214. result returned from a method call. The result will always be an object that is an
  215. instance of <classname>Zend_Service_StrikeIron_Decorator</classname>. This is a
  216. small <ulink url="http://en.wikipedia.org/wiki/Decorator_pattern">decorator</ulink>
  217. object that wraps the results from the method call.
  218. </para>
  219. <para>
  220. The simplest way to examine a result from the service is to use the built-in
  221. <acronym>PHP</acronym> functions like <ulink
  222. url="http://www.php.net/print_r">print_r()</ulink>:
  223. <programlisting language="php"><![CDATA[
  224. <?php
  225. $strikeIron = new Zend_Service_StrikeIron(array('username' => 'your-username',
  226. 'password' => 'your-password'));
  227. $taxBasic = $strikeIron->getService(array('class' => 'SalesUseTaxBasic'));
  228. $rateInfo = $taxBasic->getTaxRateCanada(array('province' => 'ontario'));
  229. print_r($rateInfo);
  230. ?>
  231. Zend_Service_StrikeIron_Decorator Object
  232. (
  233. [_name:protected] => GetTaxRateCanadaResult
  234. [_object:protected] => stdClass Object
  235. (
  236. [abbreviation] => ON
  237. [province] => ONTARIO
  238. [GST] => 0.06
  239. [PST] => 0.08
  240. [total] => 0.14
  241. [HST] => Y
  242. )
  243. )
  244. ]]></programlisting>
  245. </para>
  246. <para>
  247. In the output above, we see that the decorator (<varname>$rateInfo</varname>) wraps an
  248. object named <code>GetTaxRateCanadaResult</code>, the result of the call to
  249. <methodname>getTaxRateCanada()</methodname>.
  250. </para>
  251. <para>
  252. This means that <varname>$rateInfo</varname> has public properties like
  253. <code>abbreviation</code>, <code>province</code>, and <constant>GST</constant>. These
  254. are accessed like <code>$rateInfo->province</code>.
  255. </para>
  256. <tip>
  257. <para>
  258. StrikeIron result properties sometimes start with an uppercase letter such as
  259. <code>Foo</code> or <code>Bar</code> where most <acronym>PHP</acronym> object
  260. properties normally start with a lowercase letter as in <code>foo</code> or
  261. <code>bar</code>. The decorator will automatically do this inflection so you
  262. may read a property <code>Foo</code> as <code>foo</code>.
  263. </para>
  264. </tip>
  265. <para>
  266. If you ever need to get the original object or its name out of the decorator, use the
  267. respective methods <methodname>getDecoratedObject()</methodname> and
  268. <methodname>getDecoratedObjectName()</methodname>.
  269. </para>
  270. </sect2>
  271. <sect2 id="zend.service.strikeiron.handling-errors">
  272. <title>Handling Errors</title>
  273. <para>
  274. The previous examples are naive, i.e. no error handling was shown.
  275. It's possible that StrikeIron will return a fault during a method
  276. call. Events like bad account credentials or an expired subscription
  277. can cause StrikeIron to raise a fault.
  278. </para>
  279. <para>
  280. An exception will be thrown when such a fault occurs. You should
  281. anticipate and catch these exceptions when making method calls to the
  282. service:
  283. <programlisting language="php"><![CDATA[
  284. $strikeIron = new Zend_Service_StrikeIron(array('username' => 'your-username',
  285. 'password' => 'your-password'));
  286. $taxBasic = $strikeIron->getService(array('class' => 'SalesUseTaxBasic'));
  287. try {
  288. $taxBasic->getTaxRateCanada(array('province' => 'ontario'));
  289. } catch (Zend_Service_StrikeIron_Exception $e) {
  290. // error handling for events like connection
  291. // problems or subscription errors
  292. }
  293. ]]></programlisting>
  294. The exceptions thrown will always be
  295. <classname>Zend_Service_StrikeIron_Exception</classname>.
  296. </para>
  297. <para>
  298. It's important to understand the difference between exceptions and
  299. normal failed method calls. Exceptions occur for
  300. <emphasis>exceptional</emphasis> conditions, such as
  301. the network going down or your subscription expiring.
  302. Failed method calls that are a common occurrence,
  303. such as <methodname>getTaxRateCanada()</methodname> not finding the
  304. <code>province</code> you supplied, will not result an in exception.
  305. </para>
  306. <note>
  307. <para>
  308. Every time you make a method call to a StrikeIron service, you
  309. should check the response object for validity and also be
  310. prepared to catch an exception.
  311. </para>
  312. </note>
  313. <para><!-- included for whitespace --></para>
  314. </sect2>
  315. <sect2 id="zend.service.strikeiron.checking-subscription">
  316. <title>Checking Your Subscription</title>
  317. <para>
  318. StrikeIron provides many different services. Some of these are
  319. free, some are available on a trial basis, and some are pay subscription only.
  320. When using StrikeIron, it's important to be aware of your subscription
  321. status for the services you are using and check it regularly.
  322. </para>
  323. <para>
  324. Each StrikeIron client returned by the <code>getService</code> method
  325. has the ability to check the subscription status for that service using
  326. the <methodname>getSubscriptionInfo()</methodname> method of the client:
  327. <programlisting language="php"><![CDATA[
  328. // Get a client for the Sales & Use Tax Basic service
  329. $strikeIron = new Zend_Service_StrikeIron(array('username' => 'your-username',
  330. 'password' => 'your-password'));
  331. $taxBasic = $strikeIron->getService(array('class => 'SalesUseTaxBasic'));
  332. // Check remaining hits for the Sales & Use Tax Basic service
  333. $subscription = $taxBasic->getSubscriptionInfo();
  334. echo $subscription->remainingHits;
  335. ]]></programlisting>
  336. </para>
  337. <para>
  338. The <methodname>getSubscriptionInfo()</methodname> method will return an object
  339. that typically has a <code>remainingHits</code> property. It's
  340. important to check the status on each service that you are using. If
  341. a method call is made to StrikeIron after the remaining hits have been
  342. used up, an exception will occur.
  343. </para>
  344. <para>
  345. Checking your subscription to a service does not use any remaining
  346. hits to the service. Each time any method call to the service is made,
  347. the number of hits remaining will be cached and this cached value will
  348. be returned by <methodname>getSubscriptionInfo()</methodname> without connecting
  349. to the service again. To force <methodname>getSubscriptionInfo()</methodname>
  350. to override its cache and query the subscription information again, use
  351. <methodname>getSubscriptionInfo(true)</methodname>.
  352. </para>
  353. </sect2>
  354. </sect1>