So I've just started working on an SDK for a client which will allow us to book vacation package by leveraging their SOAP based Web Service. The request data is obviously very complex since we need to account for numerous nested XML objects (packages, passengers, reservations, etc) and other optional parameters.
In addition to this, there's the distinct possible that they may scrap or replace their existing web service for a more Restful API. My initial approach to this problem involves creating a Service class which will accept an array of "descriptors" on exactly what resources are available then act as an interface between them.
Each SOAP operation will reference a specific class object which will be responsible for building the actual request and returning the appropriate response object. So something like this:
<?php
class BookPackage implements OperationInterface
{
private $service;
private $uri = '/';
public function __construct(ServiceInterface $service)
{
$this->service = $service;
}
public function operate(array $params = $params)
{
$nestedObj = new ($params..*);
$requestObj = new RQ($nestedObj);
$result = $this->service->postData($this->uri, $requestObj);
//create an object if this endpoint one day returns JSON?
$return $result;
}
}
The issue I'm still facing with this approach is how to actually map, or build these objects without it becoming too convoluted. Basically I want to hide the underlying complexity of the SOAP WS.
I was thinking that one approach might be to introduce additional models which leverage the existing OperationsInterface class implementations (which are mapped out by the service descriptors) in order to build these objects piece by piece.
Ultimately, I'm hoping for something that looks like this:
$service = ServiceBuilder(include_once('serviceDescript.php'))->get('servicename');
$service->login()->packages($params)
->get('package id')
->quote($params)
->book($params)
->finalize($params);
Is this a reasonable approach or should I consider another way of doing this?
Thanks.
Aucun commentaire:
Enregistrer un commentaire