Giter VIP home page Giter VIP logo

apigee-client-php's Introduction

Apigee Edge Client Library for PHP

Build Status Code Coverage Latest Stable Version Total Downloads Latest Unstable Version Minimum PHP Version License

The Apigee API Client Library for PHP makes it easy to develop PHP clients that call the Apigee Edge Management API. The Apigee API Client Library for PHP enables you to interact with the API using objects instead of coding to handle the HTTP request and response calls directly.

Specifically, the Apigee API Client Library for PHP provides access to Apigee Edge Management APIs in the following categories:

For more information about the Apigee Edge Management APIs, see Getting started with the API Edge Management APIs in the Apigee documentation.

The Apigee API Client Library for PHP, built using the HTTPlug library, provides an HTTP client implementation-independent library. You choose the client that best fits your project requirements.

If you need PHP < 7.1 or Monetization API support please install the older edge-php-sdk version. We are planning to add Monetization API support to this library in the near future.

Monetization API: Alpha Release

The Apigee Monetization APIs have been added to this library but are considered to be an alpha. If you run into any problems, add an issue to our GitHub issue queue.

Installing the client library

You must install an HTTP client or adapter before you install the Apigee API Client Library for PHP. For a complete list of available clients and adapters, see Clients & Adapters in the PHP-HTTP documentation.

To install the client library using Guzzle 6, enter the following commands:

$ composer require php-http/guzzle6-adapter:^1.1.1
$ composer require apigee/apigee-client-php

If you would like to use OAuth (SAML) authentication then you have to install this patch from this php-http/client-common pull request. If you use composer-patches plugin and you allowed dependencies to apply patches then this patch is automatically gets applied when this library is installed.

Usage examples

Basic API usage

<?php

use Apigee\Edge\Api\Management\Controller\DeveloperController;
use Apigee\Edge\Api\Management\Entity\Developer;
use Apigee\Edge\Exception\ApiException;
use Apigee\Edge\Exception\ClientErrorException;
use Apigee\Edge\Exception\ServerErrorException;
use Apigee\Edge\Client;
use Http\Message\Authentication\BasicAuth;

include_once 'vendor/autoload.php';

$username = '[email protected]';
$password = 'my-secure-password';
$organization = 'my-organization';

$auth = new BasicAuth($username, $password);
// Initialize a client and use basic authentication for all API calls.
$client = new Client($auth);

// Initialize a controller for making API calls, for example a developer controller to working with developer entities.
$ec = new DeveloperController($organization, $client);

try {
    /** @var \Apigee\Edge\Api\Management\Entity\Developer $entity */
    $entity = $ec->load('[email protected]');
    $entity->setEmail('[email protected]');
    $ec->update($entity);
    // Some setters on entities are intentionally marked as @internal because the underlying entity properties can not
    // be changed on the entity level. Those must be modified by using dedicated API calls.
    // So instead of this:
    $entity->setStatus(Developer::STATUS_INACTIVE);
    // You should use this:
    $ec->setStatus($entity->id(), Developer::STATUS_INACTIVE);
} catch (ClientErrorException $e) {
    // HTTP code >= 400 and < 500. Ex.: 401 Unauthorised.
    if ($e->getEdgeErrorCode()) {
        print $e->getEdgeErrorCode();
    } else {
        print $e;
    }
} catch (ServerErrorException $e) {
    // HTTP code >= 500 and < 600. Ex.: 500 Server error.
} catch (ApiException $e) {
    // Anything else, because this is the parent class of all the above.
}

Advanced examples

Unit Tests

Setup the test suite using Composer if it has not already done:

$ composer install --dev

Run it using PHPUnit:

$ composer test

Testing of new changes does not require Apigee Edge connection. By default, unit tests are using the content of the offline-test-data folder to make testing quicker and easier. If you would like to run units tests with a real Apigee Edge instance you have to specify the following environment variables (without brackets):

APIGEE_EDGE_PHP_CLIENT_API_CLIENT=\Apigee\Edge\Tests\Test\FileSystemMockClient
APIGEE_EDGE_PHP_CLIENT_HTTP_CLIENT=\Http\Adapter\Guzzle6\Client
APIGEE_EDGE_PHP_CLIENT_BASIC_AUTH_USER=[[email protected]]
APIGEE_EDGE_PHP_CLIENT_BASIC_AUTH_PASSWORD=[PASSWORD]
APIGEE_EDGE_PHP_CLIENT_ORGANIZATION=[ORGANIZATION]
APIGEE_EDGE_PHP_CLIENT_ENVIRONMENT=[ENVIRONMENT]

There are multiple ways to set these environment variables, but probably the easiest is creating a copy from the phpunit.xml.dist file as phpunit.xml and add these variables one-by-one inside the element with an element.

It is also possible to create and use your own data set. If you would like to use your own offline test data set then you just need to define the APIGEE_EDGE_PHP_CLIENT_OFFLINE_TEST_DATA_FOLDER environment variable set its value to the parent folder of your own test data set.

PS.: Some unit tests cannot be executed when the offline test data set is in use, those are automatically marked as skipped.

Support

This is not an officially supported Google product. Please file issues in our GitHub Issue Queue. We would love to accept contributions to this project, please see the contribution guidelines for this project for more details.

apigee-client-php's People

Contributors

cnovak avatar mxr576 avatar tamasd avatar

Watchers

 avatar  avatar  avatar

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.