You are here

class WebServiceUtility in Smart IP 8.4

Same name in this branch
  1. 8.4 modules/smart_ip_ipinfodb_web_service/src/WebServiceUtility.php \Drupal\smart_ip_ipinfodb_web_service\WebServiceUtility
  2. 8.4 modules/smart_ip_abstract_web_service/src/WebServiceUtility.php \Drupal\smart_ip_abstract_web_service\WebServiceUtility
  3. 8.4 modules/smart_ip_maxmind_geoip2_web_service/src/WebServiceUtility.php \Drupal\smart_ip_maxmind_geoip2_web_service\WebServiceUtility
Same name and namespace in other branches
  1. 8.2 modules/smart_ip_ipinfodb_web_service/src/WebServiceUtility.php \Drupal\smart_ip_ipinfodb_web_service\WebServiceUtility
  2. 8.3 modules/smart_ip_ipinfodb_web_service/src/WebServiceUtility.php \Drupal\smart_ip_ipinfodb_web_service\WebServiceUtility

Utility methods class wrapper.

@package Drupal\smart_ip_ipinfodb_web_service

Hierarchy

Expanded class hierarchy of WebServiceUtility

1 file declares its use of WebServiceUtility
SmartIpEventSubscriber.php in modules/smart_ip_ipinfodb_web_service/src/EventSubscriber/SmartIpEventSubscriber.php
Contains \Drupal\smart_ip_ipinfodb_web_service\EventSubscriber\SmartIpEventSubscriber.

File

modules/smart_ip_ipinfodb_web_service/src/WebServiceUtility.php, line 20
Contains \Drupal\smart_ip_ipinfodb_web_service\WebServiceUtility.

Namespace

Drupal\smart_ip_ipinfodb_web_service
View source
class WebServiceUtility extends WebServiceUtilityBase {

  /**
   * {@inheritdoc}
   */
  public static function getUrl($ipAddress = NULL) {
    if (!empty($ipAddress)) {
      $config = \Drupal::config(SmartIpEventSubscriber::configName());
      $apiKey = $config
        ->get('api_key');
      $version = $config
        ->get('version');
      if ($version == 2) {
        return IpinfodbWebService::V2_URL . "?key={$apiKey}&ip={$ipAddress}&output=json&timezone=false";
      }
      elseif ($version == 3) {
        return IpinfodbWebService::V3_URL . "?key={$apiKey}&ip={$ipAddress}&format=json";
      }
    }
    return '';
  }

  /**
   * {@inheritdoc}
   */
  public static function getGeolocation($ipAddress = NULL) {
    $url = self::getUrl($ipAddress);
    $json = self::sendRequest($url);
    $data = Json::decode($json);
    return $data;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
WebServiceUtility::getGeolocation public static function Perform HTTP request and decoding the raw Geolocation data returned by Smart IP's data source module web service. Overrides WebServiceUtilityInterface::getGeolocation
WebServiceUtility::getUrl public static function Get Smart IP's data source module's web service URL. Overrides WebServiceUtilityInterface::getUrl
WebServiceUtilityBase::sendRequest public static function Perform HTTP request to the Smart IP's data source module web service. Overrides WebServiceUtilityInterface::sendRequest