Giter Club home page Giter Club logo

collmex's Introduction

Collmex API PHP SDK

This library provides a wrapper for the Collmex API. It's not complete yet, some record types (and maybe some features) are missing.

Please create a Pull Request if you've implemented a new type/feature or create Issues for bugs/feature requests.

There is (or least should be…) a Type class for every Collmex record type ("Satzart"). Currently only the base types (MESSAGE, LOGIN, NEW_OBJECT_ID) and a few normal record types (CMXKND, CMXINV, CMXABO, CMXUMS) are implemented.

Installation

Using Composer, just add it to your composer.json by running:

composer require mjaschen/collmex

Compatibility

The Collmex PHP SDK requires PHP 5.5.9. If you're still using older PHP versions, you can install the 0.4 branch for PHP 5.4 compatibility or the 0.3 branch for PHP 5.3 compatibility. New features will only go into the current branch.

Usage/Examples

Request information from Collmex API

Load a Collmex Customer record:

<?php

use \MarcusJaschen\Collmex\Client\Curl as CurlClient;
use \MarcusJaschen\Collmex\Request;
use \MarcusJaschen\Collmex\Type\CustomerGet;

// initialize HTTP client
$collmexClient = new CurlClient("USER", "PASSWORD", "CUSTOMER_ID");

// create request object
$collmexRequest = new Request($collmexClient);

// create a record type; we're querying the API for customer with ID=12345
$getCustomerType = new CustomerGet(array('customer_id' => '12345'));

// send HTTP request and get response object
$collmexResponse = $collmexRequest->send($getCustomerType->getCsv());

if ($collmexResponse->isError()) {
    echo "Collmex error: " . $collmexResponse->getErrorMessage() . "; Code=" . $collmexResponse->getErrorCode() . PHP_EOL;
} else {
    $records = $collmexResponse->getRecords();

    foreach ($records as $record) {
        var_dump($record->getData()); // contains one Customer object and the Message object(s)
    }
}

Create a new Collmex customer record

Create a new Collmex Customer record and get the Collmex Customer-ID from the response data:

<?php

use \MarcusJaschen\Collmex\Client\Curl as CurlClient;
use \MarcusJaschen\Collmex\Request;
use \MarcusJaschen\Collmex\Type\Customer;

// initialize HTTP client
$collmexClient = new CurlClient("USER", "PASSWORD", "CUSTOMER_ID");

// create request object
$collmexRequest = new Request($collmexClient);

// create a record type; we create a customer with some basic fields
$customer = new Customer(
    array(
        'client_id'                      => "2",
        'salutation'                     => "Herr",
        'forename'                       => "Charly",
        'lastname'                       => "Cash",
        'street'                         => "Hauptstraße 12",
        'zipcode'                        => "12222",
        'city'                           => "Berlin",
        'inactive'                       => Customer::STATUS_ACTIVE,
        'country'                        => "DE",
        'phone'                          => "+49300000000",
        'email'                          => "[email protected]",
        'output_medium'                  => Customer::OUTPUT_MEDIUM_EMAIL,
    )
);

// send HTTP request and get response object
$collmexResponse = $collmexRequest->send($customer->getCsv());

if ($collmexResponse->isError()) {
    echo "Collmex error: " . $collmexResponse->getErrorMessage() . "; Code=" . $collmexResponse->getErrorCode() . PHP_EOL;
} else {
    $newObject = $collmexResponse->getFirstRecord();
    echo "New Collmex customer ID=" . $newObject->new_id . PHP_EOL;

    $records = $collmexResponse->getRecords();

    foreach ($records as $record) {
        var_dump($record->getData()); // contains one NewObject object and the Message object(s)
    }
}

Notes

Collmex expects all strings encoded in Codepage 1252 (Windows) while the Collmex PHP SDK expects all inputs as UTF-8 and outputs everything as UTF-8. The conversion of string encodings is done transparently before sending an request to the Collmex API and after receiving the response from the API.

Run Tests

  • Install with --dev option: php composer.phar install --dev or php composer.phar update --dev
  • run ./vendor/bin/phpunit

Collmex API Documentation

Contributions

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.