You are here

countries_api_service.module in Country codes API 5

Same filename and directory in other branches
  1. 6 contrib/countries_api_service/countries_api_service.module

The module which exposes services related to countries_api TODO: Continue adding methods as services

File

contrib/countries_api_service/countries_api_service.module
View source
<?php

/**
 * @file
 * The module which exposes services related to countries_api
 * TODO: Continue adding methods as services
 */
define('COUNTRIES_API_SERVICE_PERM', 'load raw regions data');

/**
 * Implementation of hook_help().
 */
function countries_api_service_help($section) {
  switch ($section) {
    case 'admin/help#service_countries_api':
      return '<p>' . t('Provides countries api methods to services applications. Requires services.module.</p>') . '<p>';
  }
}

/**
 * Implementation of hook_perm()
**/
function countries_api_service_perm() {
  return array(
    COUNTRIES_API_SERVICE_PERM,
  );
}

/**
 * Function to check user access
**/
function countries_api_service_access() {
  return user_access(COUNTRIES_API_SERVICE_PERM);
}

/**
 * Implementation of hook_service()
**/
function countries_api_service_service() {
  return array(
    array(
      '#method' => 'countries_api.countries_api_get_country',
      '#callback' => 'countries_api_service_get_country',
      '#key' => FALSE,
      '#args' => array(
        array(
          '#name' => 'code',
          '#type' => 'string',
          '#description' => t('An iso3 country code.'),
        ),
      ),
      '#return' => 'array',
      '#help' => t('Returns an array of country fields.'),
    ),
    array(
      '#method' => 'countries_api.countries_api_service_iso2_get_country',
      '#callback' => 'countries_api_service_iso2_get_country',
      '#key' => FALSE,
      '#args' => array(
        array(
          '#name' => 'code',
          '#type' => 'string',
          '#description' => t('An iso2 country code.'),
        ),
      ),
      '#return' => 'array',
      '#help' => t('Returns an array of country fields.'),
    ),
    array(
      '#method' => 'countries_api.countries_api_service_iso3_get_country',
      '#callback' => 'countries_api_service_iso3_get_country',
      '#key' => FALSE,
      '#args' => array(
        array(
          '#name' => 'code',
          '#type' => 'string',
          '#description' => t('An iso3 country code.'),
        ),
      ),
      '#return' => 'array',
      '#help' => t('Returns an array of country fields.'),
    ),
  );
}

/**
* Service for accessing countries_api_get_country()
* @param $code 
*  An string containging the iso3 country value
* @return string
*  Returns an array containing the country fields 
**/
function countries_api_service_get_country($code) {
  $countries = countries_api_service_get_country($code);
  if (!$countries) {
    return services_error(t('No countries where found with the given argument.'));
  }
  return $countries;
}

/**
 * Service for accessing countries_api_iso2_get_country()
 * @param $code 
 *  An string containing the iso2 country value
 * @return string
 *  Returns an array containing the country fields
 */
function countries_api_service_iso2_get_country($code) {
  $countries = countries_api_iso2_get_country($code);
  if (!$countries) {
    return services_error(t('No countries where found with the given argument.'));
  }
  return $countries;
}

/**
 * Service for accessing countries_api_iso3_get_country()
 * @param $code 
 *  An string containg the iso3 value
 * @return string
 *  Returns an array containing the country fields
 */
function countries_api_service_iso3_get_country($code) {
  $countries = countries_api_iso3_get_country($code);
  if (!$countries) {
    return services_error(t('No countries where found with the given argument.'));
  }
  return $countries;
}

Functions

Constants

Namesort descending Description
COUNTRIES_API_SERVICE_PERM @file The module which exposes services related to countries_api TODO: Continue adding methods as services