Example #1
0
 /**
  * Get the raw GeoIP info using Maxmind.
  * 
  * @param  string $ip
  * 
  * @return mixed
  */
 public function getRaw($ip)
 {
     try {
         return $this->maxmind->city($ip);
     } catch (AddressNotFoundException $e) {
         // ignore
     }
     return [];
 }
Example #2
0
 /**
  * Set the client IP to analyse
  *
  * @param $ip
  *
  * @return IVisitorInfo
  */
 public function setClientIp($ip)
 {
     $this->_ip = $ip;
     try {
         $this->_record = $this->_reader->city($ip);
     } catch (\Exception $e) {
         $this->_record = null;
     }
 }
Example #3
0
 public function city($ip)
 {
     $method = get_option('geoip-detect-precision_api_type', 'city');
     $ret = null;
     $callback = array($this, $method);
     if (!is_callable($callback)) {
         throw new \RuntimeException('Precision API: Unsupported method ' . $method);
     }
     if ($method == 'city') {
         $ret = parent::city($ip);
     } else {
         $ret = call_user_func_array($callback, array($ip));
     }
     /* Web-API-specific exceptions:
     			} catch (AuthenticationException $e) {
     			} catch (OutOfQueriesException $e) {
     			}
     			*/
     if ($ret) {
         $credits = $ret->maxmind->queriesRemaining;
         // This seems to be approximate.
         update_option('geoip-detect-precision-remaining_credits', $credits);
     }
     return $ret;
 }
 /**
  * @group external-http
  * @expectedException \GeoIp2\Exception\AuthenticationException
  */
 function testMaxmindApiPasswordWrong2()
 {
     $client = new Client('', '');
     $client->city('8.8.8.8');
 }