Directory structure refactoring.
[siap.git] / ws / nusoap / samples / wsdlclient12.php
CommitLineData
1c21f490
MS
1<?php
2/*
3 * $Id: wsdlclient12.php,v 1.4 2007/11/06 14:50:07 snichol Exp $
4 *
5 * WSDL client sample.
6 *
7 * Service: WSDL
8 * Payload: document/literal
9 * Transport: http
10 * Authentication: none
11 */
12require_once('../lib/nusoap.php');
13require_once('../lib/class.wsdlcache.php');
14$proxyhost = isset($_POST['proxyhost']) ? $_POST['proxyhost'] : '';
15$proxyport = isset($_POST['proxyport']) ? $_POST['proxyport'] : '';
16$proxyusername = isset($_POST['proxyusername']) ? $_POST['proxyusername'] : '';
17$proxypassword = isset($_POST['proxypassword']) ? $_POST['proxypassword'] : '';
18
19$method = isset($_GET['method']) ? $_GET['method'] : 'ItemSearch';
20
21$SubscriptionId = 'Your AWS subscription id';
22
23$wsdlurl = 'http://webservices.amazon.com/AWSECommerceService/US/AWSECommerceService.wsdl';
24$cache = new wsdlcache('.', 120);
25$wsdl = $cache->get($wsdlurl);
26if (is_null($wsdl)) {
27 $wsdl = new wsdl($wsdlurl,
28 $proxyhost, $proxyport, $proxyusername, $proxypassword);
29 $cache->put($wsdl);
30} else {
31 $wsdl->debug_str = '';
32 $wsdl->debug('Retrieved from cache');
33}
34$client = new nusoap_client($wsdl, true,
35 $proxyhost, $proxyport, $proxyusername, $proxypassword);
36$err = $client->getError();
37if ($err) {
38 echo '<h2>Constructor error</h2><pre>' . $err . '</pre>';
39}
40
41$client->soap_defencoding = 'UTF-8';
42
43function GetCartCreateParams() {
44 global $SubscriptionId;
45
46 // create items to be added to the cart
47 $item = array ();
48 $item[0] = array( "ASIN" => "0596004206",
49 "Quantity" => "1"
50 );
51 $item[1] = array( "ASIN" => "0596003277",
52 "Quantity" => "2"
53 );
54
55 // pack it to <Item> array
56 $items = array("Item" => $item);
57 // Construct request parameters
58 $request = array("Items" => $items, "ResponseGroup" => "CartSimilarities");
59
60 // Construct all parameters
61 $cartCreate = array( "SubscriptionId" => $SubscriptionId,
62 "Request" => $request
63 );
64
65 return $cartCreate;
66}
67
68function GetItemLookupParams() {
69 global $SubscriptionId;
70
71 $itemLookupRequest[] = array(
72 'ItemId' => 'B0002IQML6',
73 'IdType' => 'ASIN',
74 'Condition' => 'All',
75 'ResponseGroup' => 'Large'
76 );
77
78 $itemLookupRequest[] = array(
79 'ItemId' => '0486411214',
80 'IdType' => 'ASIN',
81 'Condition' => 'New',
82 'ResponseGroup' => 'Small'
83 );
84
85 $itemLookup = array(
86 'SubscriptionId' => $SubscriptionId,
87 // 'AssociateTag' => '',
88 'Request' => $itemLookupRequest,
89 );
90
91 return $itemLookup;
92}
93
94function GetItemSearchParams() {
95 global $SubscriptionId;
96
97 $itemSearchRequest = array(
98 'BrowseNode' => '53',
99 'ItemPage' => 1,
100 // 'ResponseGroup' => array('Request', 'Small'),
101 'SearchIndex' => 'Books',
102 'Sort' => 'salesrank'
103 );
104
105 $itemSearch = array(
106 'SubscriptionId' => $SubscriptionId,
107 // 'AssociateTag' => '',
108 // 'Validate' => '',
109 // 'XMLEscaping' => '',
110 // 'Shared' => $itemSearchRequest,
111 'Request' => array($itemSearchRequest)
112 );
113
114 return $itemSearch;
115}
116
117function GetItemSearchParams2() {
118 global $SubscriptionId;
119
120 $request = array(
121 "Keywords" => "postal stamps",
122 "SearchIndex" => "Books"
123 );
124
125 $itemSearch = array(
126 'SubscriptionId' => $SubscriptionId,
127 'Request' => $request
128 );
129
130 return $itemSearch;
131}
132
133function GetListLookupParams() {
134 global $SubscriptionId;
135
136 $listLookupRequest[] = array(
137 'ListId' => '1L0ZL7Y9FL4U0',
138 'ListType' => 'WishList',
139 'ProductPage' => 1,
140 'ResponseGroup' => 'ListFull',
141 'Sort' => 'LastUpdated'
142 );
143
144 $listLookupRequest[] = array(
145 'ListId' => '1L0ZL7Y9FL4U0',
146 'ListType' => 'WishList',
147 'ProductPage' => 2,
148 'ResponseGroup' => 'ListFull',
149 'Sort' => 'LastUpdated'
150 );
151/*
152// two lookup maximum
153 $listLookupRequest[] = array(
154 'ListId' => '1L0ZL7Y9FL4U0',
155 'ListType' => 'WishList',
156 'ProductPage' => 3,
157 'ResponseGroup' => 'ListFull',
158 'Sort' => 'LastUpdated'
159 );
160*/
161 $listLookup = array(
162 'SubscriptionId' => $SubscriptionId,
163 // 'AssociateTag' => '',
164 'Request' => $listLookupRequest,
165 );
166
167 return $listLookup;
168}
169
170function GetListSearchParams() {
171 global $SubscriptionId;
172
173 $listSearchRequest[] = array(
174 'FirstName' => 'Scott',
175 'LastName' => 'Nichol',
176 'ListType' => 'WishList'
177 );
178
179 $listSearch = array(
180 'SubscriptionId' => $SubscriptionId,
181 // 'AssociateTag' => '',
182 'Request' => $listSearchRequest,
183 );
184
185 return $listSearch;
186}
187
188if ($method == 'ItemLookup') {
189 $result = $client->call('ItemLookup', array('body' => GetItemLookupParams()));
190} elseif ($method == 'ItemSearch') {
191 $result = $client->call('ItemSearch', array('body' => GetItemSearchParams()));
192} elseif ($method == 'ItemSearch2') {
193 $result = $client->call('ItemSearch', array('body' => GetItemSearchParams2()));
194} elseif ($method == 'ListLookup') {
195 $result = $client->call('ListLookup', array('body' => GetListLookupParams()));
196} elseif ($method == 'ListSearch') {
197 $result = $client->call('ListSearch', array('body' => GetListSearchParams()));
198} elseif ($method == 'CartCreate') {
199 $result = $client->call('CartCreate', array('body' => GetCartCreateParams()));
200} else {
201 echo "Unsupported method $method";
202 exit;
203}
204// Check for a fault
205if ($client->fault) {
206 echo '<h2>Fault</h2><pre>';
207 print_r($result);
208 echo '</pre>';
209} else {
210 // Check for errors
211 $err = $client->getError();
212 if ($err) {
213 // Display the error
214 echo '<h2>Error</h2><pre>' . $err . '</pre>';
215 } else {
216 // Display the result
217 echo '<h2>Result</h2><pre>';
218 print_r($result);
219 echo '</pre>';
220 }
221}
222echo '<h2>Request</h2><pre>' . htmlspecialchars($client->request, ENT_QUOTES) . '</pre>';
223echo '<h2>Response</h2><pre>' . htmlspecialchars($client->response, ENT_QUOTES) . '</pre>';
224echo '<h2>Debug</h2><pre>' . htmlspecialchars($client->debug_str, ENT_QUOTES) . '</pre>';
225?>