countries_api_service.module in Country codes API 6
The module which exposes services related to countries_api.
File
contrib/countries_api_service/countries_api_service.module
View source
<?php
define('COUNTRIES_API_SERVICE_PERM', 'load raw countries data');
function countries_api_service_help($path, $arg) {
switch ($path) {
case 'admin/help#service_countries_api':
return '<p>' . t('Provides countries api methods to services applications. Requires services.module.') . '</p>';
}
}
function countries_api_service_perm() {
return array(
COUNTRIES_API_SERVICE_PERM,
);
}
function countries_api_service_access($account) {
return user_access(COUNTRIES_API_SERVICE_PERM, $account);
}
function countries_api_service_service() {
return array(
array(
'#method' => 'countries_api.get_options_array',
'#callback' => 'countries_api_service_get_options_array',
'#key' => FALSE,
'#args' => array(
array(
'#name' => 'first element value',
'#type' => 'string',
'#description' => t("The value of the first element in the array (defaults to '')"),
'#optional' => TRUE,
),
array(
'#name' => 'first element label',
'#type' => 'string',
'#description' => t("The label of the first value in the array (defaults to 'Please Choose')"),
'#optional' => TRUE,
),
),
'#return' => 'array',
'#help' => t('Returns an associative array in $country["iso2"] => $country["printable_name"] format.'),
),
);
}
function countries_api_service_get_options_array($value = '', $label = 'Please Choose') {
$countries = countries_api_get_options_array(array(
$value => $label,
));
if (!$countries) {
return services_error(t('No countries where found.'));
}
return $countries;
}