Forums / General / Some progress with Amazon E-Commerce Service

Some progress with Amazon E-Commerce Service

Author Message

Geraint Edwards

Wednesday 18 May 2005 3:18:24 am

You can perform a simple search with the following code:

// Require the necessary libraries
require_once('lib/ezsoap/classes/ezsoapclient.php');
require_once('lib/ezsoap/classes/ezsoaprequest.php');

// Create a SOAP request
$client=new eZSOAPClient("soap.amazon.co.uk","/onca/soap?Service=AWSECommerceService");
$request=new eZSOAPRequest("ItemSearch","http://webservices.amazon.com/AWSECommerceService/2005-03-23");

$request->addParameter('SearchIndex','Books');
$request->addParameter('Keywords',"data on the web");
$request->addParameter("SubscriptionId","PUT YOUR ID HERE");

// look at the payload for test purposes
print $request->payload();

// Send the request to get back a response object
$response = $client->send($request);

if( $response->isFault() ) {
    trigger_error($response->faultString());
    return false;
}
else print ($response->DOMDocument->toString())

Looking at the WDSL the keywords and searchindex paramaters should be part of a complex type. This doesn't appear to be supported in ezsoap at present but is easily accomodated.

If we add a "type" variable to ezsoapparameter.php

    /*!
      Sets the complextype name.
    */
    function setType($type)
    {
        $this->Type = $type;
    }
    /*!
      Returns the parameter complextype.
    */
    function &type()
    {
        return $this->Type;
    }

...
     /// The type of parameter is its complex
    var $Type;
  
}

We can use this in the encoding step of ezsoaprequest.

...

    /*!
      Adds a new parameter to the request. You have to provide a prameter name
      and value - also a complex-type name
    */
    function addComplexParameter( $name, $complextype, $value )
    {
	$param =& new eZSOAPParameter( $name, $value );
	$param->setType($complextype);
	$this->Parameters[] = $param;
    }

...


encodeValue gets a new parameter (type) so I change the call to it in payload() to:

$param =& $this->encodeValue( $parameter->name(), $parameter->value(), $parameter->type() );

I then add a new case to the encodeValue function

	    // probably a complextype - needs more error checking!
            case "object" :
            {
                $node =& eZDOMDocument::createElementNode( $name );
                $attr =& eZDOMDocument::createAttributeNode( "type", "tns:".$type );
                $attr->setPrefix( EZ_SOAP_XSI_PREFIX );
                $node->appendAttribute( $attr );

	        // add the request parameters
		foreach ($value->Parameters as $prm)
	        {
	           unset( $subNode );
                   $subNode =& $this->encodeValue( $prm->name(), $prm->value(), $prm->type() );
                   $node->appendChild( $subNode );
		}	   
	        $returnValue =& $node;
            } break;

I don't know much PHP so don't know how to do the error checking here - any suggestions welcome. Also note that the "tns" is hard coded here - not sure is this is important (I'm at the edges of my understanding at this stage)?

Our original function call now changes to

// Require the necessary libraries
require_once('lib/ezsoap/classes/ezsoapclient.php');
require_once('lib/ezsoap/classes/ezsoaprequest.php');

$client=new eZSOAPClient("soap.amazon.co.uk","/onca/soap?Service=AWSECommerceService");

$SubscriptionId="PUT YOUR ID HERE";

$SearchIndex="Books";
$Keywords="data on the web";

$complexRequest=&new eZSOAPRequest("ItemSearchRequest","http://webservices.amazon.com/AWSECommerceService/2005-03-23");
$complexRequest->addParameter('SearchIndex',$SearchIndex);
$complexRequest->addParameter('Keywords',$Keywords);

$request=new eZSOAPRequest("ItemSearch","http://webservices.amazon.com/AWSECommerceService/2005-03-23");
$request->addParameter("SubscriptionId",$SubscriptionId);
$request->addComplexParameter("Request","ItemSearchRequest",$complexRequest);	

print $request->payload();

// Send the request to get back a response object
$response =  $client->send($request);

if( $response==false) {
    print "error";
} 
else print ($response->DOMDocument->toString())

Both versions of the code produce the same results but thesecond is more inline with the WDSL's suggestions in my opinion.

On a separate note:

I took a look at the useful article on phpPatterns (http://www.phppatterns.com/index.php/article/articleview/40/1/2/) about using the WDSL.

The generated functions don't appear to work since ezsoaprequest doesn't take SOAP_Value type parameters. Maybe something to incorporate at a future date - also the complex type issue arises again.

Geraint

Andrew Vorobyov

Saturday 28 May 2005 10:37:06 pm

cool

kracker (the)

Sunday 29 May 2005 1:07:04 pm

More than cool, <i>kickin'</i>

Where is Geraint now? We need more people like him in the community!

Wow, Wow...Wow!

//kracker

<i>sole : theme</i>

Member since: 2001.07.13 || http://ezpedia.se7enx.com/

eZ debug

Timing: Jan 18 2025 19:10:41
Script start
Timing: Jan 18 2025 19:10:41
Module start 'content'
Timing: Jan 18 2025 19:10:42
Module end 'content'
Timing: Jan 18 2025 19:10:42
Script end

Main resources:

Total runtime0.8191 sec
Peak memory usage4,096.0000 KB
Database Queries196

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0076 589.2656180.8203
Module start 'content' 0.00760.6683 770.0859595.6250
Module end 'content' 0.67590.1431 1,365.7109336.7500
Script end 0.8190  1,702.4609 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00430.5241210.0002
Check MTime0.00160.1999210.0001
Mysql Total
Database connection0.00080.098310.0008
Mysqli_queries0.742490.63671960.0038
Looping result0.00180.22401940.0000
Template Total0.785395.920.3927
Template load0.00220.269320.0011
Template processing0.783195.610020.3916
Template load and register function0.00020.018310.0002
states
state_id_array0.00140.166510.0014
state_identifier_array0.00110.134920.0006
Override
Cache load0.00180.2173310.0001
Sytem overhead
Fetch class attribute can translate value0.00150.177040.0004
Fetch class attribute name0.00100.118540.0002
XML
Image XML parsing0.00120.142040.0003
class_abstraction
Instantiating content class attribute0.00000.001140.0000
General
dbfile0.00540.6571290.0002
String conversion0.00000.000630.0000
Note: percentages do not add up to 100% because some accumulators overlap

CSS/JS files loaded with "ezjscPacker" during request:

CacheTypePacklevelSourceFiles
CSS0extension/community/design/community/stylesheets/ext/jquery.autocomplete.css
extension/community_design/design/suncana/stylesheets/scrollbars.css
extension/community_design/design/suncana/stylesheets/tabs.css
extension/community_design/design/suncana/stylesheets/roadmap.css
extension/community_design/design/suncana/stylesheets/content.css
extension/community_design/design/suncana/stylesheets/star-rating.css
extension/community_design/design/suncana/stylesheets/syntax_and_custom_tags.css
extension/community_design/design/suncana/stylesheets/buttons.css
extension/community_design/design/suncana/stylesheets/tweetbox.css
extension/community_design/design/suncana/stylesheets/jquery.fancybox-1.3.4.css
extension/bcsmoothgallery/design/standard/stylesheets/magnific-popup.css
extension/sevenx/design/simple/stylesheets/star_rating.css
extension/sevenx/design/simple/stylesheets/libs/fontawesome/css/all.min.css
extension/sevenx/design/simple/stylesheets/main.v02.css
extension/sevenx/design/simple/stylesheets/main.v02.res.css
JS0extension/ezjscore/design/standard/lib/yui/3.17.2/build/yui/yui-min.js
extension/ezjscore/design/standard/javascript/jquery-3.7.0.min.js
extension/community_design/design/suncana/javascript/jquery.ui.core.min.js
extension/community_design/design/suncana/javascript/jquery.ui.widget.min.js
extension/community_design/design/suncana/javascript/jquery.easing.1.3.js
extension/community_design/design/suncana/javascript/jquery.ui.tabs.js
extension/community_design/design/suncana/javascript/jquery.hoverIntent.min.js
extension/community_design/design/suncana/javascript/jquery.popmenu.js
extension/community_design/design/suncana/javascript/jScrollPane.js
extension/community_design/design/suncana/javascript/jquery.mousewheel.js
extension/community_design/design/suncana/javascript/jquery.cycle.all.js
extension/sevenx/design/simple/javascript/jquery.scrollTo.js
extension/community_design/design/suncana/javascript/jquery.cookie.js
extension/community_design/design/suncana/javascript/ezstarrating_jquery.js
extension/community_design/design/suncana/javascript/jquery.initboxes.js
extension/community_design/design/suncana/javascript/app.js
extension/community_design/design/suncana/javascript/twitterwidget.js
extension/community_design/design/suncana/javascript/community.js
extension/community_design/design/suncana/javascript/roadmap.js
extension/community_design/design/suncana/javascript/ez.js
extension/community_design/design/suncana/javascript/ezshareevents.js
extension/sevenx/design/simple/javascript/main.js

Templates used to render the page:

UsageRequested templateTemplateTemplate loadedEditOverride
1node/view/full.tplfull/forum_topic.tplextension/sevenx/design/simple/override/templates/full/forum_topic.tplEdit templateOverride template
3content/datatype/view/ezxmltext.tpl<No override>extension/community_design/design/suncana/templates/content/datatype/view/ezxmltext.tplEdit templateOverride template
9content/datatype/view/ezxmltags/paragraph.tpl<No override>extension/ezwebin/design/ezwebin/templates/content/datatype/view/ezxmltags/paragraph.tplEdit templateOverride template
6content/datatype/view/ezxmltags/literal.tpl<No override>extension/community/design/standard/templates/content/datatype/view/ezxmltags/literal.tplEdit templateOverride template
1content/datatype/view/ezimage.tpl<No override>extension/sevenx/design/simple/templates/content/datatype/view/ezimage.tplEdit templateOverride template
1pagelayout.tpl<No override>extension/sevenx/design/simple/templates/pagelayout.tplEdit templateOverride template
 Number of times templates used: 21
 Number of unique templates used: 6

Time used to render debug report: 0.0002 secs