resnext/spotoption-api-client

PHP Client for SpotOption platform

v0.1.1 2017-03-05 19:25 UTC

This package is not auto-updated.

Last update: 2024-11-09 20:39:36 UTC


README

API Client for binary options platform SpotOption.

Installation

Install using Composer, doubtless.

$ composer require resnext/spotoption-api-client

General API Client usage.

$apiClient = new SpotOption\ApiClient(<URL>, <USERNAME>, <PASSWORD>);

Error handling

Each method of \SpotOption\ApiClient can return response object (instance of \SpotOption\Response) or throws two kind of exceptions.

  1. \SpotOption\ServerException Server-side exception assigned with invalid data received of impossible operation is requested.
  2. \SpotOption\ClientException Client-side exception means API Client cannot connect to SpotOption servers or receive invalid response with any reasons.

Configuration and customization

Your can configure used HTTP client using $options param of ApiClient constructor.

Example:

$httpClient = new GuzzleHttp\Client([
   GuzzleHttp\RequestOptions::CONNECT_TIMEOUT => 2,
]);

$apiClient = new \SpotOption\ApiClient(<API_URL>, <API_USERNAME>, <API_PASSWORD>, [
    'httpClient' => $httpClient,
]);

Countries retrieving

/** @var \SpotOption\Responses\GetCountriesResponse $response */
$response = $this->apiClient->getCountries();
/** @var \SpotOption\Entities\Country[] $countries */
$countries = $response->getData();

Campaigns retrieving

This example retrieves all campaign with type CPA.

/** @var \SpotOption\Responses\GetCampaigns $response */
$response = $this->apiClient->getCampaigns(\SpotOption\Entities\Campaign::TYPE_CPA);
/** @var \SpotOption\Entities\Campaign[] $countries */
$countries = $response->getData();

Customer validation

/** @var \SpotOption\Responses\ValidateCustomerResponse
$response = $apiClient->validateCustomer('email@domain.com', 'password');