Git Product home page Git Product logo

bol-retailer-php-client's Introduction

Bol.com Retailer API client for PHP

This is an open source PHP client for the Bol.com Retailer API version 4.

Installation

This project can easily be installed through Composer:

composer require picqer/bol-retailer-php-client "^4"

Usage

Create an instance of the client and authenticate

$client = new \Picqer\BolRetailer\Client();
$client->authenticate('your-client-id', 'your-client-secret');

Then you can get the first page of open orders by calling the getOrders() method on the client

$reducedOrders = $client->getOrders();

foreach ($reducedOrders as $reducedOrder) {
    echo 'hello, I am order ' . $reducedOrder->orderId . PHP_EOL;
}

Exceptions

Methods on the Client may throw Exceptions. All Exceptions have the parent class Picqer\BolRetailer\Exception\Exception:

  • ConnectException is thrown when a problem occurred in the connection (e.g. API server is down or a network issue). You may retry later.
  • ServerException (extends ConnectException) is thrown when a problem occurred on the Server (e.g. 500 Internal Server Error). You may retry later.
  • ResponseException is thrown when the received response could not be handled (e.g. not of proper format or unexpected type). Retrying will not help, investigation is needed.
  • UnauthorizedException is thrown when the server responded with 400 Unauthorized (e.g. invalid credentials).
  • RateLimitException is thrown when the throttling limit has been reached for the API user.
  • Exception is thrown when an error occurred in the HTTP library that is not covered by the cases above. We aim to map as much as possible to either ConnectionException or ResponseException.

Generated Models and Client

All the Models and Client are generated by the supplied API specifications by Bol. By generating these this ensures no typos are made, not every operation needs a test and future (minor) updates to the specifications can easily be applied.

The generated classes contain all data to properly map method arguments and response data to the models: the specifications are only used to generate them.

Client

The Client contains all operations specified in the specifications. The 'operationId' is converted to camelCase and used as method name for each operation.

The specifications define types for each request and response (if it needs to send data). If a model for such a type encapsulates just one field, that model is abstracted from the operation have a smoother development experience:

  • A method in the Client accepts that field as argument instead of the model
  • A method in the Client returns the field from that model instead of the model itself

To generate the Client, the following composer script may be used:

# Generates Picqer\BolRetailer\Client
composer run-script generate-client

Models

The class names for models are equal to the keys of the array 'definitions' in the specifications.

To generate the Models, the following composer script may be used:

# Generates all Picqer\BolRetailer\Model\* models
composer run-script generate-models

Quirks

  • Some type definitions in de specifications are sentences, for example 'Delivery windows for inbound shipments.'. These are converted to CamelCase and dots are removed.
  • Some operations in the specifications have no response type specified, while there is a response. Currently, this is only the case for operations that return CSV.
  • There a type 'Return' defined in the specifications. As this is a reserved keyword in PHP, it can't be used as class name for the model (in PHP <= 7), so for now it's replaced with 'ReturnObject'.
  • If an array field in a response is empty, the field is (sometimes?) omitted from the response. E.g. the raw JSON response for getOrders is
    { }
    
    where you might expect
    {
      "orders": [ ]
    }
    
  • Operation 'Get all invoices' is specified to have a string as response, while there is clearly some data model returned in JSON or XML.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.