jeudi 10 septembre 2015

Best design pattern to access external API

Our company has a big code base with classes for different entities like Porduct, Customer, Order, OrderItem etc. We need to access AliExpress API to be able to upload our products, edit info and their status, track orders etc.

The problem is our entities and AliExpress entities are not always the same. For example, their products all consist of one of several SKUs while our products don't have any but instead they can be "parent" products for other ones. We implemented an "Access" layer to access the API and a "API Function" layer to do some pre-validation and to form requests. It that approach right? What is unclear is how many other layers do we need?

Our Product class has methods update(), create(), createEmpty() to handle the Product and getters for different product property types (not individually), all of these deal with PostgreSQL through service classes.

While working with different properties is more or less standardized, say, we need to update a Product, we do something like

Product->update(array('field'=>'value'))

However, AliExpress has several methods to update different properties of the product. Updating the price is not the same as updating the stock which is not the same as group updating of other fields.

What architecture would you recommend to handle this? How many layers do we need between the layer handling a request to the API and our "Item" classes like Product?

Aucun commentaire:

Enregistrer un commentaire