-
Notifications
You must be signed in to change notification settings - Fork 81
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #29 from dannyweeks/implement-cryptonator-service
Implement cryptonator service
- Loading branch information
Showing
8 changed files
with
171 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
<?php | ||
|
||
namespace Exchanger\Service; | ||
|
||
use Exchanger\Contract\ExchangeRate; | ||
use Exchanger\Contract\ExchangeRateQuery; | ||
use Exchanger\Contract\HistoricalExchangeRateQuery; | ||
use Exchanger\Exception\Exception; | ||
use Exchanger\StringUtil; | ||
|
||
class Cryptonator extends Service | ||
{ | ||
const LATEST_URL = 'https://api.cryptonator.com/api/ticker/%s-%s'; | ||
|
||
/** | ||
* Gets the exchange rate. | ||
* | ||
* @param ExchangeRateQuery $exchangeQuery | ||
* | ||
* @return ExchangeRate | ||
* | ||
* @throws Exception | ||
*/ | ||
public function getExchangeRate(ExchangeRateQuery $exchangeQuery) | ||
{ | ||
$currencyPair = $exchangeQuery->getCurrencyPair(); | ||
|
||
$response = $this->request( | ||
sprintf( | ||
self::LATEST_URL, | ||
strtolower($currencyPair->getBaseCurrency()), | ||
strtolower($currencyPair->getQuoteCurrency()) | ||
) | ||
); | ||
|
||
$data = StringUtil::jsonToArray($response); | ||
|
||
if (!$data['success']) { | ||
$message = !empty($data['error']) ? $data['error'] : 'Unknown error'; | ||
throw new Exception($message); | ||
} | ||
|
||
$date = (new \DateTime())->setTimestamp($data['timestamp']); | ||
|
||
return new \Exchanger\ExchangeRate($data['ticker']['price'], $date); | ||
} | ||
|
||
/** | ||
* Tells if the service supports the exchange rate query. | ||
* | ||
* @param ExchangeRateQuery $exchangeQuery | ||
* | ||
* @return bool | ||
*/ | ||
public function supportQuery(ExchangeRateQuery $exchangeQuery) | ||
{ | ||
return !$exchangeQuery instanceof HistoricalExchangeRateQuery | ||
&& in_array($exchangeQuery->getCurrencyPair()->getBaseCurrency(), $this->getSupportedCodes()) | ||
&& in_array($exchangeQuery->getCurrencyPair()->getQuoteCurrency(), $this->getSupportedCodes()); | ||
} | ||
|
||
/** | ||
* Array of codes supported according to | ||
* @url https://www.cryptonator.com/api/currencies | ||
* | ||
* @return array | ||
*/ | ||
private function getSupportedCodes() | ||
{ | ||
return require __DIR__ . '/resources/cryptonator-codes.php'; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
<?php | ||
|
||
return ['007', '1337', '1ST', '2GIVE', '32BIT', '404', '611', '8BIT', '8BT', '9COIN', 'ABC', 'ABN', 'ACES', 'ACLR', 'ACN', 'ACOIN', 'ACP', 'ADAM', 'ADC', 'ADL', 'ADT', 'ADX', 'ADZ', 'AEB', 'AEO', 'AEON', 'AGRS', 'AGRI', 'AIB', 'AIR', 'AL', 'ALIEN', 'ALL', 'ALT', 'ALTC', 'AMB', 'AMBER', 'AMS', 'ANI', 'ANTI', 'APC', 'APW', 'APX', 'ANT', 'ARB', 'ARC', 'ARCO', 'ARD', 'ARDR', 'ARE', 'ARK', 'ARM', 'ARTA', 'ABY', 'ASAFE', 'ADCN', 'AST', 'ATB', 'ATM', 'ATOM', 'ATU', 'ATX', 'REP', 'AUM', 'AUR', 'AURS', 'AUS', 'AUD', 'AV', 'AVT', 'AXIOM', 'B2', 'B3', 'BAB', 'BAC', 'BAN', 'BAS', 'BASH', 'BAT', 'BTA', 'BATL', 'BAY', 'BBH', 'BBP', 'BCM', 'BCU', 'BDC', 'BDL', 'BEE', 'BEEP', 'BEEZ', 'BELA', 'BENJI', 'BERN', 'BEST', 'BET', 'BHC', 'BIGUP', 'BIOS', 'BIT', 'BIT16', 'BITB', 'BITCF', 'BTC', 'BCH', 'XBC', 'BTCD', 'BCY', 'BTM', 'BITOK', 'BITON', 'BPC', 'BTQ', 'BSD', 'BTS', 'PTS', 'SWIFT', 'BIZ', 'BLK', 'BLC', 'BLAZR', 'BLITZ', 'BLOCK', 'BLU', 'BMC', 'BNT', 'BOLI', 'BON', 'BOST', 'BOS', 'BOSS', 'BPOK', 'BQ', 'BQX', 'BRDD', 'BRE', 'BRIT', 'GBP', 'BRK', 'BRONZ', 'BRX', 'BS', 'BSC', 'BSDB', 'BSH', 'BST', 'BSTK', 'BTCHC', 'BTCO', 'BTCS', 'BTCU', 'BTD', 'BTLC', 'BTP', 'BTTF', 'BTXC', 'BTZ', 'BUB', 'BUCKS', 'BURST', 'BUS', 'BUZZ', 'BVC', 'BXT', 'GBYTE', 'BYC', 'BCN', 'C0C0', 'CAB', 'CAID', 'CALC', 'CAD', 'CANN', 'CPC', 'CAT', 'CB', 'CBD', 'CCB', 'CCC', 'CCRB', 'CCX', 'CD', 'CDN', 'CDT', 'CF', 'CFI', 'CH', 'CHEMX', 'CHESS', 'CHILL', 'CNY', 'CHIP', 'CHOOF', 'CIRC', 'CJ', 'CJC', 'CKS', 'CLAM', 'CLICK', 'CLOAK', 'CLR', 'CLUB', 'CLUD', 'CME', 'CMT', 'CNB', 'CNC', 'CND', 'CNNC', 'CNT', 'CNX', 'COB', 'COC', 'COIN', 'C2', 'CV2', 'CON', 'CONX', 'COS', 'XCP', 'COV', 'COVAL', 'COX', 'CRAB', 'CRAFT', 'CRC', 'CRE', 'CRB', 'CREVA', 'CRM', 'CRNK', 'CROC', 'CRPC', 'CRS', 'CRT', 'CRW', 'CRX', 'CESC', 'XCN', 'CS', 'CSMIC', 'CSN', 'CTIC', 'CTIC2', 'CTK', 'CTL', 'CTO', 'CTR', 'CURE', 'CVC', 'CYG', 'CYT', 'DANC', 'DAR', 'DGD', 'DAS', 'DASH', 'DSH', 'DASHS', 'DBG', 'DBIX', 'DBLK', 'DBT', 'DBTC', 'DC', 'DCC', 'DCK', 'DCN', 'DCT', 'DCYP', 'DDC', 'DDF', 'DEA', 'DCR', 'DEEP', 'DEN', 'DESH', 'DES', 'DETH', 'DEUS', 'DEM', 'DFT', 'DGCS', 'DGMS', 'DGORE', 'DMD', 'DIBC', 'DIC', 'DGB', 'CUBE', 'DGC', 'XDN', 'DP', 'DIME', 'DIRT', 'DKC', 'DLC', 'DLT', 'DMC', 'NOTE', 'DNT', 'DOGE', 'DOPE', 'DOTA', 'DOX', 'DP2', 'DPAY', 'DPY', 'DRACO', 'DRM', 'DRM8', 'DRZ', 'DTB', 'DTT', 'DBIC', 'DUO', 'DUR', 'DUS', 'DUST', 'DUX', 'DXO', 'DYN', 'EAGS', 'EBH', 'EBST', 'EBT', 'EC', 'ECA', 'ECCHI', 'ECN', 'ECO', 'ECOB', 'EDG', 'EDIT', 'EDR2', 'EDR', 'EET', 'EGO', 'EMC2', 'EKO', 'EL', 'ELE', 'EFL', 'ELI', 'EMB', 'EME', 'EMC', 'EMG', 'EMP', 'EMPC', 'ENRG', 'ENT', 'ENTER', 'EOS', 'EPC', 'EPY', 'EQM', 'EQT', 'EQUAL', 'ERC', 'ESB', 'ESC', 'ETH', 'ETC', 'ETHS', 'ETP', 'ETT', 'ETX', 'EUC', 'EURC', 'EUR', 'EVA', 'EGC', 'EVIL', 'EVO', 'EVX', 'EXCL', 'EXIT', 'EXP', 'FCT', 'FADE', 'FAIR', 'FAZZ', 'FCASH', 'FCH', 'FCN', 'FTC', 'TIPS', 'FFC', 'FIDEL', 'FIND', 'FIRST', 'FJC', 'FLO', 'FLVR', 'FLX', 'FLY', 'FNC', 'FLDC', 'FOREX', 'FRK', 'FRDC', 'FRE', 'FRN', 'FRST', 'FRWC', 'FSN', 'FST', 'FU', 'FUE', 'FUN', 'FUNC', 'FUNK', 'FUTC', 'FUZZ', 'FX', 'FYN', 'FYP', 'GAC', 'GAIN', 'GAKH', 'GAM', 'GBT', 'GAME', 'GARY', 'GAS', 'GB', 'GBC', 'GBG', 'GBIT', 'GBRC', 'GCC', 'GEO', 'GER', 'GHS', 'GIG', 'GLC', 'GLO', 'BSTY', 'GLTC', 'GML', 'GMX', 'GNO', 'GOAT', 'GCR', 'GOL', 'GLD', 'GNT', 'GOLOS', 'GOON', 'GP', 'GPU', 'GRF', 'GRAM', 'GRAV', 'GRC', 'GRS', 'GRP', 'GRWI', 'GSB', 'GSR', 'GSX', 'GSY', 'GT', 'GUC', 'NLG', 'GUM', 'GUP', 'GYC', 'HAC', 'HALLO', 'HBT', 'HCC', 'HEAT', 'THC', 'HET', 'XHI', 'HIFUN', 'HIRE', 'HKG', 'HMQ', 'HNC', 'HODL', 'HOP', 'HOPE', 'HPC', 'HSP', 'HSR', 'HTC', 'HTML5', 'HUC', 'HUS', 'HVCO', 'HVN', 'HZT', 'IBANK', 'IBITS', 'IBT', 'ICO', 'ICOBI', 'ICN', 'ICX', 'IET', 'IFLT', 'IFT', 'IGN', 'ILC', 'IML', 'IMPS', 'INC', 'INCNT', 'INCP', 'IND', 'IDR', 'INF', 'IFC', 'INFX', 'INGT', 'INPAY', 'INSN', 'INV', 'IOC', 'ION', 'IONX', 'IOP', 'IOT', 'ISE', 'ISL', 'ITI', 'IUS', 'IVZ', 'IXT', 'JPY', 'JIF', 'JIO', 'JNS', 'JOBS', 'JPC', 'JW', 'JWL', 'KARMC', 'KAT', 'KGB', 'KGC', 'KGDC', 'KIDS', 'KLC', 'KMD', 'KOBO', 'KORE', 'KPL', 'KRAK', 'KRB', 'KRONE', 'KRS', 'KR', 'KUBO', 'KUSH', 'L7S', 'LANA', 'LAT', 'LAZ', 'LBC', 'LBT', 'LC', 'LDC', 'LDCN', 'LEA', 'LEAF', 'LEO', 'LET', 'LGBTQ', 'LGD', 'LINDA', 'LIR', 'LSK', 'LITE', 'LTC', 'LTCR', 'LIV', 'LKC', 'LMC', 'LOYAL', 'LRC', 'LSB', 'LSD', 'LTCU', 'LTD', 'LTH', 'LTS', 'LUCKY', 'LUNA', 'LUNYR', 'LUN', 'LUS', 'LUX', 'LVG', 'M1', 'MAD', 'XMG', 'MAI', 'MAID', 'MALC', 'MAN', 'MAPC', 'MXT', 'MARV', 'OMNI', 'MAY', 'MAZE', 'MBL', 'MCA', 'MCAP', 'MCAR', 'MCO', 'MCR', 'MEME', 'MEN', 'MET', 'MG', 'MGC', 'MGO', 'MHC', 'MND', 'MIP', 'MIS', 'MLN', 'MM', 'MMXVI', 'MNE', 'MNM', 'MOIN', 'MOJO', 'MONA', 'XMR', 'MUE', 'MOON', 'MOOND', 'MPK', 'MPRO', 'MRB', 'MRV', 'MSCN', 'MSP', 'MST', 'MTH', 'MTL', 'MUSIC', 'MUU', 'MVR', 'MYB', 'MYST', 'N2O', 'NMC', 'NANOX', 'NAT', 'NAUT', 'NAV', 'NBIT', 'NCS', 'NDC', 'XEM', 'NEO', 'NEOS', 'NETC', 'NET', 'NETKO', 'NTRN', 'NEVA', 'NEWB', 'NXS', 'NIC', 'NICE', 'NKA', 'NKC', 'NKT', 'NLC2', 'NMR', 'NO', 'NODES', 'NOO', 'NVC', 'NPC', 'NRC', 'NTM', 'NTO', 'NUBIS', 'NBT', 'NXC', 'NXT', 'NZC', 'OAX', 'OBITS', 'OBS', 'OBT', 'OCOW', 'OD', 'ODNT', 'OK', 'OLIT', 'OLYMP', 'OMG', 'OPAL', 'OPES', 'OPNC', 'OPT', 'ORM', 'OS', 'OS76', 'OTC', 'OTX', 'OUS', 'OWB', 'OZC', 'P7C', 'PAC', 'PAK', 'PAL', 'PND', 'PARA', 'PART', 'PARTY', 'PASC', 'PAY', 'XPY', 'PAYP', 'PBK', 'PBT', 'PCS', 'PDC', 'PPC', 'PEO', 'PGUC', 'PHR', 'PHX', 'PIE', 'PIN', 'PING', 'PC', 'PIO', 'PIPL', 'PIVX', 'PIX', 'PIZZA', 'PKB', 'PLAY', 'PLB', 'PLBT', 'PLN', 'PLNC', 'PLR', 'PLU', 'PNK', 'POE', 'POKE', 'POLY', 'POM', 'PONZ2', 'POPPY', 'POST', 'POSW', 'POT', 'POWER', 'PPT', 'PPY', 'PQT', 'PRC', 'PRE', 'PRES', 'PRG', 'PXI', 'XPM', 'PRIMU', 'PRM', 'PRO', 'PROC', 'PROPY', 'PSB', 'PSI', 'PST', 'PTC', 'PTO', 'PTOY', 'PUPA', 'PURE', 'PUT', 'PUTIN', 'PWR', 'PX', 'QAU', 'QBC', 'QCN', 'QRL', 'QTU', 'QTUM', 'QTZ', 'QWARK', 'RADI', 'RADS', 'RAI', 'RATIO', 'RBIT', 'RCN', 'RDD', 'REE', 'RET', 'REV', 'RHFC', 'RICE', 'RICHX', 'RID', 'RIC', 'RBT', 'RING', 'RIO', 'XRP', 'RISE', 'RIYA', 'RKC', 'RLC', 'RLT', 'RNC', 'ROBO', 'ROLC', 'RONIN', 'ROO', 'ROYAL', 'RPC', 'RRT', 'RSGP', 'RBIES', 'RUBIT', 'RUR', 'RBY', 'RUC', 'RUP', 'RUPX', 'RUST', 'RVT', 'SAFEX', 'SAK', 'SAN', 'SBD', 'SBIT', 'SBT', 'SCAN', 'SCB', 'SCITW', 'SCL', 'SCRPT', 'SCRT', 'SCS', 'SCT', 'SDT', 'SED', 'SEL', 'SEQ', 'SET', 'SEV', 'SXC', 'SFE', 'SGC', 'SH', 'SDC', 'SHDW', 'SHIFT', 'SHREK', 'SC', 'SIB', 'SIGT', 'SIKKA', 'SIX', 'SKB', 'SKI', 'SLEEP', 'SLING', 'SLS', 'SMC', 'SMLY', 'SNC', 'SNG', 'SNGLS', 'SNM', 'SNRG', 'SOAR', 'SLR', 'SOLO', 'SOUL', 'SP', 'SPACE', 'SPC', 'SPEX', 'SPHR', 'SPM', 'SPORT', 'SPR', 'SPT', 'SQC', 'SRND', 'SSC', 'SSTC', 'STA', 'STAR', 'START', 'SNT', 'STE', 'XST', 'STEEM', 'STR', 'XLM', 'STEPS', 'SLG', 'STHR', 'STK', 'STO', 'STONK', 'STORJ', 'SJCX', 'STRAT', 'STRB', 'STS', 'STV', 'STX', 'SUPER', 'SUR', 'SUS', 'SVC', 'SWEET', 'SWING', 'SWT', 'SDP', 'AMP', 'SYNX', 'SYS', 'TAA', 'TAAS', 'TAJ', 'TAKE', 'TALK', 'TAM', 'TAO', 'TAP', 'TB', 'TBT', 'TC', 'TCASH', 'TCOIN', 'TDFB', 'TEAM', 'TEK', 'TELL', 'TERA', 'TERI', 'TERRA', 'TRC', 'TESLA', 'TES', 'TET', 'TFL', 'THOM', 'THS', 'TIA', 'TIX', 'TIDE', 'XTC', 'TIM', 'TIME', 'TIT', 'TTC', 'TKN', 'TKR', 'TKS', 'TLAC', 'TLE', 'TMC', 'TMRW', 'TNG', 'TNT', 'TOA', 'TODAY', 'TOKEN', 'TOT', 'TP1', 'TPG', 'TRA', 'TX', 'TRIG', 'TROLL', 'TRS', 'TRST', 'TRUMP', 'TRUST', 'TSE', 'TWERK', 'TWO', 'UAE', 'UBIQ', 'UBQ', 'UET', 'UIS', 'UAH', 'UNB', 'UNC', 'UNI', 'UNIT', 'UNO', 'UNRC', 'UNY', 'URO', 'USD', 'USC', 'USDE', 'UTA', 'UTLE', 'UXC', 'VAK', 'VAL', 'VASH', 'XVC', 'VEC2', 'VEG', 'VENE', 'VER', 'XVG', 'VRC', 'VTC', 'VIA', 'VIP', 'VK', 'VLT', 'VLTC', 'VNTX', 'VOISE', 'VOL', 'VOX', 'VPN', 'VPRC', 'VRM', 'VRP', 'VRS', 'VSL', 'VSX', 'VTL', 'VTN', 'VTR', 'VTY', 'VUC', 'WA', 'WARP', 'WASH', 'WAV', 'WAVES', 'WAY', 'WCASH', 'WCN', 'WEA', 'WEX', 'WGO', 'WGR', 'XWC', 'WHO', 'WIC', 'WBB', 'WIN', 'WINE', 'WINGS', 'WINK', 'WMC', 'WMG', 'LOG', 'WOP', 'WDC', 'WRT', 'WTT', 'X2', 'XAUR', 'XAU', 'XB', 'XBG', 'XBP', 'XBS', 'XBTS', 'XBY', 'XCXT', 'XDE', 'XDE2', 'XEL', 'XET', 'XFC', 'XFCX', 'XGB', 'XGTC', 'XID', 'XIN', 'XJO', 'XLC', 'XLTCG', 'XMINE', 'XMS', 'XMT', 'XMY', 'XNC', 'XNX', 'XOC', 'XODUS', 'XOM', 'XOT', 'XPC', 'XPD', 'XPO', 'XPS', 'XQN', 'XRC', 'XRL', 'XSP', 'XSPEC', 'XSY', 'XT', 'XTO', 'XTP', 'XTZ', 'XVE', 'XVP', 'XVS', 'XZA', 'YAY', 'YBT', 'YET', 'YMC', 'YOC', 'YOVI', 'YOY', 'ZYD', 'ZBCN', 'ZEC', 'ZCL', 'ZCC', 'XZC', 'ZECD', 'ZEIT', 'ZEN', 'ZENI', 'ZET2', 'ZET', 'ZRC', 'ZBC', 'ZLQ', 'ZNE', 'ZNY', 'ZRX', 'ZSC', 'ZUR',]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"success": false, | ||
"error": "Pair not found" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{"ticker":{"base":"BTC","target":"USD","price":"4194.86340277","volume":"29792.40032422","change":"0.85865006"},"timestamp":1506719641,"success":true,"error":""} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of Exchanger. | ||
* | ||
* (c) Florian Voutzinos <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Exchanger\Tests\Service; | ||
|
||
use Exchanger\HistoricalExchangeRateQuery; | ||
use Exchanger\CurrencyPair; | ||
use Exchanger\ExchangeRateQuery; | ||
use Exchanger\Service\Cryptonator; | ||
|
||
class CryptonatorTest extends ServiceTestCase | ||
{ | ||
/** | ||
* @test | ||
*/ | ||
public function it_does_not_support_all_codes() | ||
{ | ||
$service = new Cryptonator($this->getMock('Http\Client\HttpClient')); | ||
$this->assertFalse($service->supportQuery(new ExchangeRateQuery(CurrencyPair::createFromString('NONCODE/NONCODE')))); | ||
$this->assertTrue($service->supportQuery(new ExchangeRateQuery(CurrencyPair::createFromString('BTC/USD')))); | ||
} | ||
|
||
/** | ||
* @test | ||
*/ | ||
public function it_does_not_support_all_queries() | ||
{ | ||
$service = new Cryptonator($this->getMock('Http\Client\HttpClient')); | ||
|
||
$this->assertTrue($service->supportQuery(new ExchangeRateQuery(CurrencyPair::createFromString('BTC/USD')))); | ||
$this->assertFalse($service->supportQuery(new HistoricalExchangeRateQuery(CurrencyPair::createFromString('BTC/USD'), new \DateTime()))); | ||
} | ||
|
||
/** | ||
* @test | ||
* @expectedException \Exchanger\Exception\Exception | ||
*/ | ||
public function it_throws_an_exception_when_rate_not_supported() | ||
{ | ||
$uri = 'https://api.cryptonator.com/api/ticker/btc-isk'; | ||
$content = file_get_contents(__DIR__.'/../../Fixtures/Service/Cryptonator/error.json'); | ||
|
||
$service = new Cryptonator($this->getHttpAdapterMock($uri, $content)); | ||
$service->getExchangeRate(new ExchangeRateQuery(CurrencyPair::createFromString('BTC/ISK'))); | ||
} | ||
|
||
/** | ||
* @test | ||
*/ | ||
public function it_fetches_a_rate() | ||
{ | ||
$url = 'https://api.cryptonator.com/api/ticker/btc-usd'; | ||
$content = file_get_contents(__DIR__.'/../../Fixtures/Service/Cryptonator/success.json'); | ||
|
||
$service = new Cryptonator($this->getHttpAdapterMock($url, $content)); | ||
$rate = $service->getExchangeRate(new ExchangeRateQuery(CurrencyPair::createFromString('BTC/USD'))); | ||
|
||
$this->assertSame('4194.86340277', $rate->getValue()); | ||
$this->assertInstanceOf('\DateTime', $rate->getDate()); | ||
} | ||
|
||
/** | ||
* @test | ||
*/ | ||
public function it_has_no_php_errors() | ||
{ | ||
$url = 'https://api.cryptonator.com/api/ticker/btc-usd'; | ||
$content = file_get_contents(__DIR__.'/../../Fixtures/Service/Cryptonator/success.json'); | ||
|
||
$service = new Cryptonator($this->getHttpAdapterMock($url, $content)); | ||
$service->getExchangeRate(new ExchangeRateQuery(CurrencyPair::createFromString('BTC/USD'))); | ||
|
||
$this->assertNull(error_get_last()); | ||
} | ||
} |