webeweb/curl-library

Integrate web API with your projects

v1.1.7 2018-08-30 17:58 UTC

README

Build Status Coverage Status Scrutinizer Code Quality Latest Stable Version Latest Unstable Version License composer.lock

Integrate web API with your projects.

IMPORTANT NOTICE: This package is no longer maintained and its classes have been migrated into package "core-library" (available into version up to 4.3.0 and more) Core library

Compatibility

PHP HHVM

Requires:

ext-curl

Installation

Open a command console, enter your project directory and execute the following command to download the latest stable version of this package:

$ composer require webeweb/curl-library "^1.0"

This command requires you to have Composer installed globally, as explained in the installation chapter of the Composer documentation.

Usage

     // Initialize the POST request.
     $request = new CURLPostRequest(new CURLConfiguration(), "/resource-path");
     $request->getConfiguration()->setHost("http://domain.tld");
     $request->addQueryData("id", 1);
     $request->addPostData("firstname", "John");
     $request->addPostData("lastname", "DOE");
     // ...

     // Call the POST request.
     $response = $request->call();

     // Make something with the response.
     // ...

Requests available :

  • CURLDeleteRequest
  • CURLGetRequest
  • CURLHeadRequest
  • CURLOptionsRequest
  • CURLPatchRequest
  • CURLPostRequest
  • CURLPutRequest

Customize

class MyCustomRequest extends AbstractCURLRequest {

	/**
	 * Constructor.
	 *
	 * @param CURLConfiguration $configuration The configuration.
	 * @param string $resourcePath The resource path.
	 * @throws InvalidHTTPMethodException Throws an invalid HTTP method exception if the method is not implemented.
	 */
	public function __construct(CURLConfiguration $configuration, $resourcePath) {
		parent::__construct(self::METHOD_GET, $configuration, $resourcePath); //
	}

	...
}

Testing

To test the package, is better to clone this repository on your computer. Open a command console and execute the following commands to download the latest stable version of this package:

$ mkdir curl-library
$ cd curl-library
$ git clone git@github.com:webeweb/curl-library.git .
$ composer install

Once all required libraries are installed then do:

$ vendor/bin/phpunit

License

curl-library is released under the LGPL License. See the bundled LICENSE file for details.