You are here

regions_api_service.module in Country codes API 6

The module which exposes services related to regions_api

File

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

/**
 * @file
 * The module which exposes services related to regions_api
 */
define('REGIONS_API_SERVICE_PERM', 'load raw regions data');

/**
 * Implementation of hook_help().
 */
function regions_api_service_help($path, $arg) {
  switch ($path) {
    case 'admin/help#service_regions_api':
      return '<p>' . t('Provides regions api methods to services applications. Requires services.module.') . '</p>';
  }
}

/**
 * Implementation of hook_perm().
 */
function regions_api_service_perm() {
  return array(
    REGIONS_API_SERVICE_PERM,
  );
}

/**
 * Function to check user access
 */
function regions_api_service_access($account) {
  return user_access(REGIONS_API_SERVICE_PERM, $account);
}

/**
 * Implementation of hook_service().
 */
function regions_api_service_service() {
  return array(
    array(
      '#method' => 'regions_api.load',
      '#callback' => 'regions_api_service_load',
      '#key' => FALSE,
      '#args' => array(
        array(
          '#name' => 'iso2',
          '#type' => 'string',
          '#description' => t('An iso2 country code.'),
        ),
      ),
      '#return' => 'array',
      '#help' => t('Returns an array of regions.'),
    ),
  );
}

/**
 * Returns an array of countries
 */
function regions_api_service_load($iso2) {
  $regions = regions_api_iso2_get_options_array($iso2);
  if (!$regions) {
    return services_error(t('No regions where found with the given argument.'));
  }
  return $regions;
}

Functions

Namesort descending Description
regions_api_service_access Function to check user access
regions_api_service_help Implementation of hook_help().
regions_api_service_load Returns an array of countries
regions_api_service_perm Implementation of hook_perm().
regions_api_service_service Implementation of hook_service().

Constants

Namesort descending Description
REGIONS_API_SERVICE_PERM @file The module which exposes services related to regions_api