General Information - celdotro/marketplace GitHub Wiki

About

CEL.ro's API Wrapper uses the namespace "celmarket".
It contains 3 main scripts: Auth.php, Config.php, and Dispatcher.php. Alongside these, there are specific scripts for each action and method grouped in different folders.

Access information and use methods

In this section relevant information about the site, the API and the connection to the marketplace are presented. Please read this section in order to avoid misunderstandings.

Marketplace access

  • In order to prevent unauthorized access and limit its consequences in case it occurs, each client is granted 10 simultaneous connections to the marketplace. You can choose to use them either by accessing the site or by connecting to the API.

Methods to use the marketplace

Site

  • The site's advantage is that it provides you with a complete set of tools in order to manage your marketplace page.
  • Its disadvantage is the fact that you'll have to manually process data or upload them in standard format files where it's applicable.

API

  • The API's advantage is the ability to send data directly from your system. Also, by using the API on a server that you own, can make it possible to manage employees' access so that they can share the same authentication token. On a more general note, the API wrapper's main reason to exist is so that you can integrate it into your own software in order to facilitate the automation of processes.
  • Its disadvantage is that it needs a programmer to write a software that will connect your business's processes and databases to the marketplace.

Demo

  • In order to make the testing process easier, every minute (server time) all products imported through a testing account will be automatically approved/rejected. The approval rule is the following:
    • price <= 5000 = approve
    • price > 5000 = reject

Project's structure

Namespaces and classes

Main namespace: celmarket

Config

Contains constants pointing to the server's address and a method to easily switch to the demo server.

Link: https://github.com/celdotro/marketplace/blob/master/src/Config.php

Auth

A singleton for authentication with built-in token generation and regeneration methods.

Link: https://github.com/celdotro/marketplace/blob/master/src/Auth.php

Dispatcher

This is the main part of the API wrapper.

  • getGuzzleClient = enforces the use of a single connection
  • whitelistMethod = check if method is correct, otherwise don't contact the API unnecessarily
  • send ($method, $action, $data) = main function that does the following
    1. Validates method, action and data, then builds URL based on method and action
    2. Authenticates user
    3. Instantiates a guzzleClient object and makes a POST request to the API server with
      1. Data received via the 3rd parameter as the request's body
      2. Token used for bearer type authorization header
    4. Processes the response in order to throw relevant exception messages or return the correctly formed response

Link: https://github.com/celdotro/marketplace/blob/master/src/Dispatcher.php

Action and method namespaces

Actions are sub-namespaces and folders in the project's structure that contain multiple files, each one describing a class that groups relevant methods.

Actions

  1. AWB
  2. Campaigns
  3. Invoices
  4. Orders
  5. Pages
  6. Products
  7. Admin (administrative information)

Methods

Usually methods contain:

  • data sanity check
  • API's action and method names
  • data array setting and sometimes processing
  • dispatcher call
  • result returning statement

For more information regarding a method, check the accompanying comments for each method.

⚠️ **GitHub.com Fallback** ⚠️