\TransvisionAPI

API class

This class manages all of our calls to the API. This class does not return data, it only allows validating in the controller that the API query is technically correct

Calls are like this: api////////?optional_parameter1=foo&optional_parameter2=bar Example for an entity search containing bookmark: https://transvision.mozfr.org/api/v1/tm/gecko_strings/entity/en-US/fr/bookmark/?case_sensitive=case_sensitive (tm = translation memory service)

Example for the list of locales supported for a repo: https://transvision.mozfr.org/api/v1/locales/mozilla_org/

List of services: entity: Return translations for all locales of a Mozilla entity locales: Return all the locales supported for a repository repositories : Return the list of repositories supported by Transvision that can be used in the API search: Return translations + entity as key for a locale matching a search query tm: Return translations for a locale with a quality index transliterate: Return a transliterated string versions: Return the list of API versions supported with their status (stable, beta, deprecated)

This API is versioned, currently we are at v1. If we make api changes that change the results or remove services, we need to create a v2 api.

Summary

Methods
Properties
Constants
__construct()
getParameters()
getExtraParameters()
getService()
isValidRequest()
invalidAPICall()
$url
$parameters
$extra_parameters
$api_versions
$services
$error
$logging
$logger
$valid_repositories
No constants found
No protected methods found
No protected properties found
N/A
isValidServiceCall()
verifyEnoughParameters()
verifyRepositoryExists()
verifyLocaleExists()
isValidService()
log()
No private properties found
N/A

Properties

$url

$url : 

Type

$parameters

$parameters : 

Type

$extra_parameters

$extra_parameters : 

Type

$api_versions

$api_versions : 

Type

$services

$services : 

Type

$error

$error : 

Type

$logging

$logging : 

Type

$logger

$logger : 

Type

$valid_repositories

$valid_repositories : 

Type

Methods

__construct()

__construct(array  $url) 

The constructor analyzes the URL to extract its parameters

Parameters

array $url

parsed url

getParameters()

getParameters(string  $parameters) : array

Get the list of parameters for an API call.

Parameters

string $parameters

The list of parameters from the URI

Returns

array —

All the main parameters for the query

getExtraParameters()

getExtraParameters(string  $parameters) : array

Get the list of extra parameters for an API call.

Parameters

string $parameters

The $_GET list of parameters

Returns

array —

All the extra parameters as [key => value]

getService()

getService() : string

Get the name of the service queried

Returns

string —

Name of the service

isValidRequest()

isValidRequest() : boolean

Check if an API request is valid

Returns

boolean —

True if valid request, False if invalid request

invalidAPICall()

invalidAPICall(  $error = 400) 

Parameters

$error

isValidServiceCall()

isValidServiceCall(string  $service) : boolean

Check if we call a service that we do support and check that the request is technically correct

Parameters

string $service

The name of the service

Returns

boolean —

Returns True if we have a valid service call, False otherwise

verifyEnoughParameters()

verifyEnoughParameters(integer  $number) : boolean

Check that we have enough parameters in the URL to satisfy the request

Parameters

integer $number

number of compulsory parameters

Returns

boolean —

True if we can satisfy the request, False if we can't

verifyRepositoryExists()

verifyRepositoryExists(string  $repository, boolean  $alias = false) : boolean

Check that the repository asked for is one we support

Parameters

string $repository

Name of the repository

boolean $alias

Do we allow aliases for repository names, ex: 'global', to query all repositories. Default to False

Returns

boolean —

True if we support this repository, False if we don't

verifyLocaleExists()

verifyLocaleExists(string  $locale, string  $repository) : boolean

Check that a locale is available for a repository

Parameters

string $locale

Locale code we want to check

string $repository

Repository name we want to check the locale for

Returns

boolean —

True if we support the locale, False if we don't

isValidService()

isValidService() : boolean

Check if the service called is valid

Returns

boolean —

True if the service called is valid, False otherwise

log()

log(string  $message) : boolean

Utility function to log API call errors.

Parameters

string $message

Returns

boolean —

True if we logged, False if we didn't log