Skip to content

Commit

Permalink
Merge pull request #5 from jr-cologne/bugsnag
Browse files Browse the repository at this point in the history
Implement Error Handling with Bugsnag
  • Loading branch information
jr-cologne authored Mar 10, 2018
2 parents b32bab7 + 248a003 commit 4653c73
Show file tree
Hide file tree
Showing 15 changed files with 448 additions and 13 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ Twitter Account: [@status_crypto](https://twitter.com/status_crypto)
## Dependencies
- [PHP](http://php.net/) (version 7.0 or higher)
- [Codebird Twitter API library](https://github.com/jublonet/codebird-php) (version ^3.1)
- [Bugsnag PHP library](https://github.com/bugsnag/bugsnag-php) (version ^3.12)

## Contributing and Support
Feel free to contribute to or support this project. Any sort of help is much appreciated.
Expand Down
6 changes: 5 additions & 1 deletion app/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
* @author JR Cologne <[email protected]>
* @copyright 2018 JR Cologne
* @license https://github.com/jr-cologne/CryptoStatus/blob/master/LICENSE MIT
* @version v0.1.3
* @version v0.2.0
* @link https://github.com/jr-cologne/CryptoStatus GitHub Repository
*
* ________________________________________________________________________________
Expand All @@ -23,8 +23,12 @@

require_once 'vendor/autoload.php';

use CryptoStatus\BugsnagClient;
use CryptoStatus\CryptoStatus;

// initialize error handling
$bugsnag_client = new BugsnagClient;

$app = new CryptoStatus;

// initialize app
Expand Down
52 changes: 52 additions & 0 deletions app/classes/BugsnagClient.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?php

/**
* A simple Twitter bot application which posts hourly status updates for the top 10 cryptocurrencies.
*
* PHP version >= 7.0
*
* LICENSE: MIT, see LICENSE file for more information
*
* @author JR Cologne <[email protected]>
* @copyright 2018 JR Cologne
* @license https://github.com/jr-cologne/CryptoStatus/blob/master/LICENSE MIT
* @version v0.2.0
* @link https://github.com/jr-cologne/CryptoStatus GitHub Repository
*
* ________________________________________________________________________________
*
* BugsnagClient.php
*
* The client for handling errors with Bugsnag.
*
*/

namespace CryptoStatus;

class BugsnagClient {

/**
* Constructor, initialization of Bugsnag's error handler
*/
public function __construct() {
$bugsnag = Bugsnag\Client::make($this->getApiKey());
Bugsnag\Handler::register($bugsnag);
}

/**
* Get API key from environment variables
*
* @return string
* @throws BugsnagClientException if Bugsnag API key could not be retrieved
*/
protected function getApiKey() : string {
$api_key = getenv(BUGSNAG_API_KEY);

if (empty($api_key)) {
throw new BugsnagClientException("Could not get Bugsnag API Key", 1);
}

return $api_key;
}

}
2 changes: 1 addition & 1 deletion app/classes/CryptoClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
* @author JR Cologne <[email protected]>
* @copyright 2018 JR Cologne
* @license https://github.com/jr-cologne/CryptoStatus/blob/master/LICENSE MIT
* @version v0.1.3
* @version v0.2.0
* @link https://github.com/jr-cologne/CryptoStatus GitHub Repository
*
* ________________________________________________________________________________
Expand Down
2 changes: 1 addition & 1 deletion app/classes/CryptoStatus.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
* @author JR Cologne <[email protected]>
* @copyright 2018 JR Cologne
* @license https://github.com/jr-cologne/CryptoStatus/blob/master/LICENSE MIT
* @version v0.1.3
* @version v0.2.0
* @link https://github.com/jr-cologne/CryptoStatus GitHub Repository
*
* ________________________________________________________________________________
Expand Down
2 changes: 1 addition & 1 deletion app/classes/CurlClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
* @author JR Cologne <[email protected]>
* @copyright 2018 JR Cologne
* @license https://github.com/jr-cologne/CryptoStatus/blob/master/LICENSE MIT
* @version v0.1.3
* @version v0.2.0
* @link https://github.com/jr-cologne/CryptoStatus GitHub Repository
*
* ________________________________________________________________________________
Expand Down
30 changes: 30 additions & 0 deletions app/classes/Exceptions/BugsnagClientException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

/**
* A simple Twitter bot application which posts hourly status updates for the top 10 cryptocurrencies.
*
* PHP version >= 7.0
*
* LICENSE: MIT, see LICENSE file for more information
*
* @author JR Cologne <[email protected]>
* @copyright 2018 JR Cologne
* @license https://github.com/jr-cologne/CryptoStatus/blob/master/LICENSE MIT
* @version v0.2.0
* @link https://github.com/jr-cologne/CryptoStatus GitHub Repository
*
* ________________________________________________________________________________
*
* BugsnagClientException.php
*
* The Exception of the Bugsnag client
*
*/

namespace CryptoStatus\Exceptions;

use \Exception;

class BugsnagClientException extends Exception {

}
2 changes: 1 addition & 1 deletion app/classes/Exceptions/CryptoClientException.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
* @author JR Cologne <[email protected]>
* @copyright 2018 JR Cologne
* @license https://github.com/jr-cologne/CryptoStatus/blob/master/LICENSE MIT
* @version v0.1.3
* @version v0.2.0
* @link https://github.com/jr-cologne/CryptoStatus GitHub Repository
*
* ________________________________________________________________________________
Expand Down
2 changes: 1 addition & 1 deletion app/classes/Exceptions/CryptoStatusException.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
* @author JR Cologne <[email protected]>
* @copyright 2018 JR Cologne
* @license https://github.com/jr-cologne/CryptoStatus/blob/master/LICENSE MIT
* @version v0.1.3
* @version v0.2.0
* @link https://github.com/jr-cologne/CryptoStatus GitHub Repository
*
* ________________________________________________________________________________
Expand Down
2 changes: 1 addition & 1 deletion app/classes/Exceptions/CurlClientException.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
* @author JR Cologne <[email protected]>
* @copyright 2018 JR Cologne
* @license https://github.com/jr-cologne/CryptoStatus/blob/master/LICENSE MIT
* @version v0.1.3
* @version v0.2.0
* @link https://github.com/jr-cologne/CryptoStatus GitHub Repository
*
* ________________________________________________________________________________
Expand Down
2 changes: 1 addition & 1 deletion app/classes/Exceptions/TwitterClientException.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
* @author JR Cologne <[email protected]>
* @copyright 2018 JR Cologne
* @license https://github.com/jr-cologne/CryptoStatus/blob/master/LICENSE MIT
* @version v0.1.3
* @version v0.2.0
* @link https://github.com/jr-cologne/CryptoStatus GitHub Repository
*
* ________________________________________________________________________________
Expand Down
3 changes: 1 addition & 2 deletions app/classes/TwitterClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
* @author JR Cologne <[email protected]>
* @copyright 2018 JR Cologne
* @license https://github.com/jr-cologne/CryptoStatus/blob/master/LICENSE MIT
* @version v0.1.3
* @version v0.2.0
* @link https://github.com/jr-cologne/CryptoStatus GitHub Repository
*
* ________________________________________________________________________________
Expand Down Expand Up @@ -47,7 +47,6 @@ class TwitterClient {
* Constructor, initialization and authentication with Twitter API
*
* @param Codebird $twitter_client A Cordbird instance
* @param string $twitter_api_credentials_file The Twitter API credentials file
* @throws TwitterClientException if authentication with Twitter API failed
*/
public function __construct(Codebird $twitter_client) {
Expand Down
4 changes: 3 additions & 1 deletion app/config/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
* @author JR Cologne <[email protected]>
* @copyright 2018 JR Cologne
* @license https://github.com/jr-cologne/CryptoStatus/blob/master/LICENSE MIT
* @version v0.1.3
* @version v0.2.0
* @link https://github.com/jr-cologne/CryptoStatus GitHub Repository
*
* ________________________________________________________________________________
Expand All @@ -31,3 +31,5 @@
const CRYPTO_API = 'https://api.coinmarketcap.com/v1/';
const CRYPTO_API_ENDPOINT = 'ticker/';
const CRYPTO_API_LIMIT = 10;

const BUGSNAG_API_KEY = 'BUGSNAG_API_KEY';
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
{
"require": {
"php": ">=7.0",
"jublonet/codebird-php": "^3.1"
"jublonet/codebird-php": "^3.1",
"bugsnag/bugsnag": "^3.12"
},
"autoload": {
"psr-4": {
Expand Down
Loading

0 comments on commit 4653c73

Please sign in to comment.