public function getRequestDetails(string $ip_address)
    {
      if (!$this->cache->has($ip_address)) {
        $url = self::API_URL;
        if ($ip_address) {
          $url .= "/$ip_address";
        }

        try {
          $response = $this->http_client->request(
            self::REQUEST_TYPE_GET,
            $url,
            $this->buildHeaders()
          );
        } catch (GuzzleException $e) {
          throw new IPinfoException($e->getMessage());
        } catch (Exception $e) {
          throw new IPinfoException($e->getMessage());
        }

        if ($response->getStatusCode() == self::STATUS_CODE_QUOTA_EXCEEDED) {
          throw new IPinfoException('IPinfo request quota exceeded.');
        } elseif ($response->getStatusCode() >= 400) {
          throw new IPinfoException('Exception: ' . json_encode([
            'status' => $response->getStatusCode(),
            'reason' => $response->getReasonPhrase(),
          ]));
        }

        $raw_details = json_decode($response->getBody(), true);
        $this->cache->set($ip_address, $raw_details);
      }

      return $this->cache->get($ip_address);
    }
public function getRequestDetails(string $ip_address)
    {
      if (!$this->cache->has($ip_address)) {
        $url = self::API_URL;
        if ($ip_address) {
          $url .= "/$ip_address";
        }

        try {
          $response = $this->http_client->request(
            self::REQUEST_TYPE_GET,
            $url,
            $this->buildHeaders()
          );
        } catch (GuzzleException $e) {
          throw new IPinfoException($e->getMessage());
        } catch (Exception $e) {
          throw new IPinfoException($e->getMessage());
        }

        if ($response->getStatusCode() == self::STATUS_CODE_QUOTA_EXCEEDED) {
          throw new IPinfoException('IPinfo request quota exceeded.');
        } elseif ($response->getStatusCode() >= 400) {
          throw new IPinfoException('Exception: ' . json_encode([
            'status' => $response->getStatusCode(),
            'reason' => $response->getReasonPhrase(),
          ]));
        }

        $raw_details = json_decode($response->getBody(), true);
        $this->cache->set($ip_address, $raw_details);
      }

      return $this->cache->get($ip_address);
    }
public function getRequestDetails ( string $ ip_address ) { if ( ! $ this -> cache -> has ( $ ip_address ) ) { $ url = self :: API_URL ; if ( $ ip_address ) { $ url .= "/$ip_address" ; } try { $ response = $ this -> http_client -> request ( self :: REQUEST_TYPE_GET , $ url , $ this -> buildHeaders ( ) ) ; } catch ( GuzzleException $ e ) { throw new IPinfoException ( $ e -> getMessage ( ) ) ; } catch ( Exception $ e ) { throw new IPinfoException ( $ e -> getMessage ( ) ) ; } if ( $ response -> getStatusCode ( ) == self :: STATUS_CODE_QUOTA_EXCEEDED ) { throw new IPinfoException ( 'IPinfo request quota exceeded.' ) ; } elseif ( $ response -> getStatusCode ( ) >= 400 ) { throw new IPinfoException ( 'Exception: ' . json_encode ( [ 'status' => $ response -> getStatusCode ( ) , 'reason' => $ response -> getReasonPhrase ( ) , ] ) ) ; } $ raw_details = json_decode ( $ response -> getBody ( ) , true ) ; $ this -> cache -> set ( $ ip_address , $ raw_details ) ; } return $ this -> cache -> get ( $ ip_address ) ; }
Get details for a specific IP address.
@param  string $ip_address IP address to query API for.
@return array IP response data.
@throws IPinfoException
Get details for a specific IP address .