Using the Google currency converter

For a project I’m working, I needed to get shipping rates from the UPS API (a blog post about this will follow soon).

The problem I ran into was that the UPS API returns the shipping rates with the currency of the country where the rates for are asked, so you can’t force it to always return the rates in EUR.

One solution to convert the prices is to make a very big array with all currency rates in it. I then would maintain the array every day at 9’o clock to check if the rates weren’t changed. Right, that’s not an option.

Like you might know you can easily convert currencies by using the Google search engine. For example searching on “1 Euro to dollar” will retrieve the Euro in dollar.

Below the class I wrote to convert currencies using the Google currency converter.

sConvertorUrl, $this->fPrice, $this->sFrom, $this->sTo);

		$sResponse = file_get_contents($sUrl);
		if(!$sResponse) {
			throw new Exception('Google currency convertor is not available at the moment');
		}

		$oResult = json_decode($sResponse);
		if($oResult->error != '') {
			throw new Exception('The following error occurred: '.$oResult->error);
		}

		// Isolate the price
		return (float)$oResult->rhs;
	}

	/**
	 * Get, retrieve the foreign currency
	 *
	 * @param float $fPrice
	 * @param string $sFrom, currency code (EUR, USD,...)
	 * @param string $sTo, currency code (EUR, USD,...)
	 */
	public function get($fPrice, $sFrom, $sTo)
	{
		if(!is_float($fPrice)) {
			throw new Exception('The price to convert should be a float, "'.gettype($fPrice). '" given while calling: '.__FUNCTION__);
		}

		$this->fPrice	= $fPrice;
		$this->sFrom	= strtoupper($sFrom);
		$this->sTo		= strtoupper($sTo);

		return $this->exec();
	}

}
?>

Pretty straightforward as you see.

Comments

740 responses to “Using the Google currency converter”

  1. https://git.hanumanit.co.th/jermainefunkho Avatar

    References:

    Risks of using anabolic steroids and other performance-enhancing drugs

    References:
    http://www.tm-jikayo.com/jaituggle27316

  2. git.mana-web.com Avatar

    References:

    Body building without steroids

    References:
    http://180.163.77.12:3000/denicehansell9

  3. http://118.178.172.49 Avatar

    References:

    Diseases that cause long-term or permanent damage are called

    References:
    https://code.tczkiot.com/brookeshoebrid

  4. https://videowala.xyz Avatar

    References:

    Winstrol results before and after

    References:
    https://aeterna.cim.mcgill.ca/jaquelinerichm

  5. gitea.scivigi.com Avatar

    References:

    Female bodybuilders before and after steroids

    References:
    https://git.genowisdom.cn/jeannettebrook

  6. https://abadeez.com/ Avatar

    References:

    Where do you get anabolic steroids

    References:
    https://bv.bcia.agency/@felicitasomay?page=about

  7. git.p1.bitstorm.co.nz Avatar

    References:

    Anabolic steroids are which of the following

    References:
    http://jinhon-info.com.tw:3000/florhotham198

  8. https://inmessage.site Avatar

    References:

    Synthetic anabolic steroids

    References:
    https://tcodpractice.com/lloydwofford43

  9. 62.234.194.66 Avatar

    References:

    People on steroids before and after pictures

    References:
    https://lasigal.com/mirandamcdowal

  10. gitea.wgqcd.com Avatar

    References:

    Creatine vs steroids

    References:
    https://www.musicsound.ca/deneenord29143

  11. 66.179.208.56 Avatar

    References:

    Best steroid for fat loss and muscle gain

    References:
    http://47.93.252.243:3000/mosescolmenero

  12. http://55x.top/ Avatar

    References:

    Where to order testosterone online

    References:
    http://47.97.50.232:3000/florianinman10

  13. git.game-dev.space Avatar

    References:

    Anabolic steroids pill

    References:
    https://worldclassdjs.com/lenoraoqa6652

  14. http://git.ibossay.com:3000/dinah647354867 Avatar

    References:

    Why are steroids illegal in the us

    References:
    https://www.fepp.org.ec/miriamstockwel

  15. aladin.tube Avatar

    References:

    Which of the following conditions is commonly associated with the abuse of
    anabolic steroids?

    References:
    https://blackvision.co.uk/@vernitabutts06?page=about

  16. https://gitea.ww3.tw Avatar

    References:

    Best natural anabolic

    References:
    http://14.103.239.131:3000/federicomcgrew

  17. git.yinbonet.cn Avatar

    References:

    Testosterone bodybuilding before and after

    References:
    https://tiktub.com/@tiffinyshah472?page=about

  18. fancybox.qa Avatar

    References:

    Safe steroids for muscle building

    References:
    http://111.230.98.74/silasmintz2801

  19. git.rmarl.in Avatar

    References:

    Cheap steroids pills for sale

    References:
    http://61.190.74.90:9900/fawnarmfield6

  20. https://music.drepic.com/caren85259668 Avatar

    References:

    Describe the clinical appearance of the following variations in stature

    References:
    https://git.secretserver.club/izettapedigo86

  21. gitea.syn-assist.fr Avatar

    References:

    Testosterone cream bodybuilding

    References:
    https://liverights.org//@jbpaurora2241?page=about

  22. realhire.co Avatar

    References:

    Anadrol steroids

    References:
    https://git.dotb.cloud/jaydenbozeman6

  23. hearty.rip Avatar

    References:

    How many types of steroids are there

    References:
    https://conspiracytheoristdating.com/@brooks12068061

  24. http://rejobbing.com/ Avatar

    References:

    How long does it take to get big on steroids

    References:
    https://freehaitianmovies.com/@shelleytrainor?page=about

  25. moxxtv.com Avatar

    References:

    How many bodybuilders use steroids

    References:
    https://megastream.pl/@juliannebavist?page=about

Leave a Reply

Your email address will not be published. Required fields are marked *