madmis/coingecko-api

Coingecko REST API php client

1.0.0 2017-08-31 07:33 UTC

This package is auto-updated.

Last update: 2024-04-05 18:13:44 UTC


README

SensioLabsInsight Build Status Coverage Status Latest Stable Version Total Downloads License

This API client will help you interact with Coingecko data.

License

MIT License

Contributing

To create new endpoint - create issue or create pull request

Install

composer require madmis/coingecko-api 1.0.*

Usage

$api = new CoingeckoApi();
$timestamp = $api->shared()->priceCharts(Api::BASE_ETH, Api::QUOTE_USD, Api::PERIOD_24HOURS, true));

Mapping

Each endpoint response can be received as array or as object.

To use mapping response to object set parameter $mapping to true.

$issue = $api->shared()->priceCharts(Api::BASE_ETH, Api::QUOTE_USD, Api::PERIOD_24HOURS, true));

// Result
[
    {
    class madmis\CoingeckoApi\Model\Price {
        protected $price => 379.62131925945
        protected $date => DateTime
      }
    
    },
    ...
] 

Error handling

Each client request errors wrapped to custom exception madmis\ExchangeApi\Exception\ClientException

class madmis\ExchangeApi\Exception\ClientException {
  private $request => class GuzzleHttp\Psr7\Request
  private $response => NULL
  protected $message => "cURL error 7: Failed to connect to 127.0.0.1 port 8080: Connection refused (see http://curl.haxx.se/libcurl/c/libcurl-errors.html)"
  ...
}

ClientException contains original request object and response object if response available

class madmis\ExchangeApi\Exception\ClientException {
  private $request => class GuzzleHttp\Psr7\Request 
  private $response => class GuzzleHttp\Psr7\Response {
    private $reasonPhrase => "Unauthorized"
    private $statusCode => 401
    ...
  }
  protected $message => "Client error: 401"
  ...  
}

Running the tests

To run the tests, you'll need to install phpunit. Easiest way to do this is through composer.

composer install

Running Unit tests

php vendor/bin/phpunit -c phpunit.xml.dist