On April 1, 2021, we are moving all of our QuotaGuard Support Documentation to
https://quotaguard.github.io/qg-docs/
Please Update Your Support Bookmarks
Documentation for this article will be maintained at
https://quotaguard.github.io/qg-docs/quickstart-ruby
Please click on the above link to ensure you are reading
the most recent and updated documentation.
Installation
When you sign up with QuotaGuard, you will be provided with a unique username and password that you can use when configuring your proxy service in your application:
http://username:password@proxy.quotaguard.com:9292
We recommend you store the connection string in an environment variable QUOTAGUARD_URL to maintain compatibility with platforms like Heroku and CloudControl.
You can test your proxy setup using curl:
$ curl -x username:password@proxy.quotaguard.com:9292 http://www.google.com/
Integration
PHP cURL is the easiest way to make HTTP requests via a proxy. The below shows an example of making a geocoding request:
<?php function lookup($string){ $quotaguard_env = getenv("QUOTAGUARD_URL"); $quotaguard = parse_url($quotaguard_env); $proxyUrl = $quotaguard['host'].":".$quotaguard['port']; $proxyAuth = $quotaguard['user'].":".$quotaguard['pass']; $string = str_replace (" ", "+", urlencode($string)); $details_url = "http://maps.googleapis.com/maps/api/geocode/json?address=".$string."&sensor=false"; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $details_url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_PROXY, $proxyUrl); curl_setopt($ch, CURLOPT_PROXYAUTH, CURLAUTH_BASIC); curl_setopt($ch, CURLOPT_PROXYUSERPWD, $proxyAuth); $response = json_decode(curl_exec($ch), true); // If Status Code is ZERO_RESULTS, OVER_QUERY_LIMIT, REQUEST_DENIED or INVALID_REQUEST if ($response['status'] != 'OK') { return null; } print_r($response); $geometry = $response['results'][0]['geometry']; $longitude = $geometry['location']['lng']; $latitude = $geometry['location']['lat']; $array = array( 'latitude' => $latitude, 'longitude' => $longitude, 'location_type' => $geometry['location_type'], ); return $array; } $city = 'San Francisco, USA'; $array = lookup($city); print_r($array); ?>