Skip to content

Commit

Permalink
fix invalid currency issue
Browse files Browse the repository at this point in the history
  • Loading branch information
JRSaunders committed Aug 30, 2017
1 parent e10dcb2 commit 6dcd2a0
Showing 1 changed file with 19 additions and 8 deletions.
27 changes: 19 additions & 8 deletions src/Query.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,12 @@ public function getToCurrency() {
* @param $currency
*/
public function setToCurrency( $currency ) {
if ( $this->codes->isValid( $currency ) ) {
$this->toCurrency = $currency;
if ( $currency ) {
if ( $this->codes->isValid( $currency ) ) {
$this->toCurrency = $currency;
} else {
throw new \Exception( "Not a valid currency for Diva!" );
}
}
}

Expand All @@ -88,10 +92,12 @@ public function getFromCurrency() {
* @param string $currency
*/
public function setFromCurrency( $currency ) {
if ( $this->codes->isValid( $currency ) ) {
$this->fromCurrency = $currency;
}else{
throw new \Exception("Not a valid currency for Diva!");
if ( $currency ) {
if ( $this->codes->isValid( $currency ) ) {
$this->fromCurrency = $currency;
} else {
throw new \Exception( "Not a valid currency for Diva!" );
}
}
}

Expand Down Expand Up @@ -125,7 +131,12 @@ protected function buildQuery( $fromCurrency = false, $toCurrency = false ) {


$this->url = $url;
$this->params = "apikey=" . Auth::getApiKey() . "&from=" . $finalFromCurrency . "&to=" . $finalToCurrency;
$this->params = array(
'apikey' => Auth::getApiKey(),
'from' => $finalFromCurrency,
'to' => $finalToCurrency
);


return $this;
}
Expand All @@ -138,7 +149,7 @@ public function execute( $fromCurrency = false, $toCurrency = false ) {
$this->buildQuery( $fromCurrency, $toCurrency );
$url = $this->getUrl();
$params = $this->getParams();
$rawData = $this->curl( $url, $params );
$rawData = $this->curl( $url, $params, null, 180, 1, 3, 'Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0)', false );
$this->rawData = $rawData;

return $this;
Expand Down

0 comments on commit 6dcd2a0

Please sign in to comment.