Code

To make things even easier, we have put together a PHP library that can be used to implement our API. Over time we hope to add more implementations.

PHP Class

<?php

  class CompleteAPI
  {
    private $apiKey;
    private $base_url = 'http://localhost/namhost2017/public_html/v1/';

    public function __construct($_apiKey = '')
    {
      $this->apiKey = $_apiKey;
    }

    public function whois($domainName)
    {
      $result = $this->doEndpointCall('whois', $domainName);
      return $result;
    }

    public function getCurrencies($baseCurrency = 'USD')
    {
      $result = $this->doEndpointCall('currency', $baseCurrency);
      return $result;
    }

    public function geoLocate($ipAddress)
    {
      $result = $this->doEndpointCall('geolocate', $ipAddress);
      return $result;
    }

    public function getCreditBalance()
    {
      $result = $this->doEndpointCall('balance');
      return $result;
    }

    public function sms($number, $message)
    {
      $result = $this->doEndpointCall(
        'sms',
        array($number),
        array(
          'message' => $message,
        )
      );
      return $result;
    }

    private function doEndpointCall($action, $parameters = array(), $queryParameters = array())
    {
      $url = $this->base_url.$this->apiKey.'/'.$action;
      if (!empty($parameters)) $url .= '/'.implode('/', $parameters);
      if (!empty($queryParameters)) {
        $url = $url.'?'.http_build_query($queryParameters);
      }

      $result = file_get_contents($url);
      $jsonDecode = json_decode($result);
      return $jsonDecode;
    }

  }

Sample Usage

<?php

  require_once "CompleteAPI.class.php"; 
  $apiKey = "123";
  $completeAPI = new CompleteAPI($apiKey);
  
  // 1. Lookups
  // --------------------------------------------------------------------------

    // 1.1 Whois
    $result = $completeAPI->whois("completeapi.com");
  
    // 1.2 SMS
    $result = $completeAPI->sms("264123456789", "Hello! SMS Text Goes here!");
  
    // 1.3 Currency
    $result = $completeAPI->getCurrencies("ZAR");
  
    // 1.4 GeoLocations
    $result = $completeAPI->geoLocate("123.123.123.123");
  
  // --------------------------------------------------------------------------
    
  // 2. Balance
  
  $result = $completeAPI->getCreditBalance();
    
?>
Copyright © Namhost Internet Services (Pty) Ltd | Privacy Policy | Terms of Use