Zend_Service_StrikeIron-Overview.xml 17 KB

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