You are here

class WebServiceUtility in Smart IP 8.3

Same name in this branch
  1. 8.3 modules/smart_ip_ipinfodb_web_service/src/WebServiceUtility.php \Drupal\smart_ip_ipinfodb_web_service\WebServiceUtility
  2. 8.3 modules/smart_ip_abstract_web_service/src/WebServiceUtility.php \Drupal\smart_ip_abstract_web_service\WebServiceUtility
  3. 8.3 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.4 modules/smart_ip_maxmind_geoip2_web_service/src/WebServiceUtility.php \Drupal\smart_ip_maxmind_geoip2_web_service\WebServiceUtility

Utility methods class wrapper.

@package Drupal\smart_ip_maxmind_geoip2_web_service

Hierarchy

Expanded class hierarchy of WebServiceUtility

See also

http://dev.maxmind.com/geoip/geoip2/web-services

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

File

modules/smart_ip_maxmind_geoip2_web_service/src/WebServiceUtility.php, line 21
Contains \Drupal\smart_ip_maxmind_geoip2_web_service\WebServiceUtility.

Namespace

Drupal\smart_ip_maxmind_geoip2_web_service
View source
class WebServiceUtility extends WebServiceUtilityBase {

  /**
   * {@inheritdoc}
   */
  public static function getUrl($ipAddress = NULL) {
    if (!empty($ipAddress)) {
      $config = \Drupal::config(SmartIpEventSubscriber::configName());
      $userId = $config
        ->get('user_id');
      $licenseKey = $config
        ->get('license_key');
      $serviceType = $config
        ->get('service_type');
      return "https://{$userId}:{$licenseKey}@" . MaxmindGeoip2WebService::BASE_URL . "/{$serviceType}/{$ipAddress}";
    }
    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