Skip to content

Commit

Permalink
Init commit
Browse files Browse the repository at this point in the history
  • Loading branch information
jr-cologne committed Jan 20, 2018
0 parents commit 46cedb2
Show file tree
Hide file tree
Showing 17 changed files with 1,058 additions and 0 deletions.
7 changes: 7 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
root = true

[*]
charset = utf-8
indent_style = space
indent_size = 2
insert_final_newline = true
17 changes: 17 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Auto detect text files and perform LF normalization
* text=auto

# Custom for Visual Studio
*.cs diff=csharp

# Standard to msysgit
*.doc diff=astextplain
*.DOC diff=astextplain
*.docx diff=astextplain
*.DOCX diff=astextplain
*.dot diff=astextplain
*.DOT diff=astextplain
*.pdf diff=astextplain
*.PDF diff=astextplain
*.rtf diff=astextplain
*.RTF diff=astextplain
50 changes: 50 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# Windows image file caches
Thumbs.db
ehthumbs.db

# Folder config file
Desktop.ini

# Recycle Bin used on file shares
$RECYCLE.BIN/

# Windows Installer files
*.cab
*.msi
*.msm
*.msp

# Windows shortcuts
*.lnk

# =========================
# Operating System Files
# =========================

# OSX
# =========================

.DS_Store
.AppleDouble
.LSOverride

# Thumbnails
._*

# Files that might appear in the root of a volume
.DocumentRevisions-V100
.fseventsd
.Spotlight-V100
.TemporaryItems
.Trashes
.VolumeIcon.icns

# Directories potentially created on remote AFP share
.AppleDB
.AppleDesktop
Network Trash Folder
Temporary Items
.apdisk

# Exclude Composer stuff
vendor
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2018 JR Cologne

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# CryptoStatus
A simple Twitter bot application which posts hourly status updates for the top 10 cryptocurrencies.

Twitter Account: [@status_crypto](https://twitter.com/status_crypto)
34 changes: 34 additions & 0 deletions app/app.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?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.1
* @link https://github.com/jr-cologne/CryptoStatus GitHub Repository
*
* ________________________________________________________________________________
*
* app.php
*
* The main application file
*
*/

require_once 'vendor/autoload.php';

use CryptoStatus\CryptoStatus;

$app = new CryptoStatus;

// initialize app
$app->init();

// run app
$app->run();
109 changes: 109 additions & 0 deletions app/classes/CryptoClient.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
<?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.1
* @link https://github.com/jr-cologne/CryptoStatus GitHub Repository
*
* ________________________________________________________________________________
*
* CryptoClient.php
*
* The client for retrieving the Crypto data from an API.
*
*/

namespace CryptoStatus;

use CryptoStatus\CurlClient;
use CryptoStatus\Exceptions\CryptoClientException;

class CryptoClient {

/**
* The cURL client instance
*
* @var CurlClient $curl_client
*/
protected $curl_client;

/**
* The Crypto client options
*
* @var array $options
*/
protected $options = [
'api' => null,
'endpoint' => null,
'params' => []
];

/**
* Constructor, initialization
*
* @param CurlClient $curl_client
* @param array $options
* @throws CryptoClientException if no API and/or API Endpoint is specified in options
*/
public function __construct(CurlClient $curl_client, array $options = []) {
$this->curl_client = $curl_client;

$this->options = array_merge($this->options, $options);

if (empty($this->options['api']) || !isset($this->options['endpoint'])) {
throw new CryptoClientException('No API and/or API Endpoint specified', 1);
}
}

/**
* Get Crypto data
*
* @return array
*/
public function getData() : array {
return $this->curl_client->get($this->getRequestUrl())->json();
}

/**
* Get request URL for Crypto API call
*
* @return string
* @throws CryptoClientException if no API and/or API Endpoint is specified
*/
protected function getRequestUrl() : string {
if (empty($this->options['api']) || !isset($this->options['endpoint'])) {
throw new CryptoClientException('No API and/or API Endpoint specified', 1);
}

$url = $this->options['api'] . $this->options['endpoint'];

if (empty($this->options['params'])) {
return $url;
}

$first_param = true;

foreach ($this->options['params'] as $key => $value) {
if (isset($this->options['params'][$key])) {
if ($first_param) {
$first_param = false;
} else {
$url .= urlencode('&');
}

$url .= "?{$key}={$value}";
}
}

return $url;
}

}
Loading

0 comments on commit 46cedb2

Please sign in to comment.