You are here

abstract class WebServiceUtilityBase in Smart IP 8.3

Same name and namespace in other branches
  1. 8.4 src/WebServiceUtilityBase.php \Drupal\smart_ip\WebServiceUtilityBase
  2. 8.2 src/WebServiceUtilityBase.php \Drupal\smart_ip\WebServiceUtilityBase

Web service utility methods class wrapper.

@package Drupal\smart_ip

Hierarchy

Expanded class hierarchy of WebServiceUtilityBase

3 files declare their use of WebServiceUtilityBase
WebServiceUtility.php in modules/smart_ip_ipinfodb_web_service/src/WebServiceUtility.php
Contains \Drupal\smart_ip_ipinfodb_web_service\WebServiceUtility.
WebServiceUtility.php in modules/smart_ip_abstract_web_service/src/WebServiceUtility.php
Contains \Drupal\smart_ip_abstract_web_service\WebServiceUtility.
WebServiceUtility.php in modules/smart_ip_maxmind_geoip2_web_service/src/WebServiceUtility.php
Contains \Drupal\smart_ip_maxmind_geoip2_web_service\WebServiceUtility.

File

src/WebServiceUtilityBase.php, line 15
Contains \Drupal\smart_ip\WebServiceUtilityBase.

Namespace

Drupal\smart_ip
View source
abstract class WebServiceUtilityBase implements WebServiceUtilityInterface {

  /**
   * {@inheritdoc}
   */
  public static function sendRequest($url = NULL) {
    if (!empty($url)) {
      try {
        $response = \Drupal::httpClient()
          ->get($url, [
          'headers' => [
            'Accept' => 'application/json',
          ],
        ]);
        $data = (string) $response
          ->getBody();
        if (empty($data)) {
          \Drupal::logger('smart_ip')
            ->error(t('Empty response from @url', [
            '@url' => $url,
          ]));
        }
        else {
          return $data;
        }
      } catch (\Exception $e) {
        \Drupal::logger('smart_ip')
          ->error(t('Sending request failed: @error', [
          '@error' => $e
            ->getMessage(),
        ]));
      }
    }
    return '';
  }

}

Members

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