Zend_Service_StrikeIron-Overview.xml 18 KB

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