Skip to content

oschlegel/phraseapp-apispec

 
 

Repository files navigation

PhraseApp API Spec

DISCLAIMER: Highly experimental swagger mappings for the PhraseApp API. Use at your own risk. Feedback and patches always welcome!

Swagger Examples

All examples rely on having a valid PhraseApp API token in your ENV.

$ export PHRASEAPP_ACCESS_TOKEN=<valid-api-token>

In case you want to re-generate the swagger libraries with the provides script you also need to have docker installed.

Python

(Re-)generate the python library (if necessary):

$ bash swagger_gen.sh python

Install the python package from inside the generated code:

$ cd swagger/examples/python
$ python setup.py install --user

You can then use the python library like this:

from __future__ import print_function
import phraseapp
import os

config = phraseapp.Configuration()
config.api_key['Authorization'] = os.getenv("PHRASEAPP_ACCESS_TOKEN")
config.api_key_prefix['Authorization'] = "token"

client = phraseapp.ApiClient(configuration = config)
api = phraseapp.DefaultApi(client)

for project in api.projects_get():
    print(project.id, project.name)
    for locale in api.projects_project_id_locales_get(project.id):
        print("  ", locale.id, locale.name, locale.code)

PHP

(Re-)generate the python library (if necessary):

$ bash swagger_gen.sh php

Vendor dependencies with composer:

$ cd swagger/examples/php/SwaggerClient-php
$ composer install

You can then use the php library like this:

<?php
require_once('swagger/examples/php/SwaggerClient-php/vendor/autoload.php');

$config = Swagger\Client\Configuration::getDefaultConfiguration();
$config->setApiKey('Authorization', $_SERVER["PHRASEAPP_ACCESS_TOKEN"]);
$config->setApiKeyPrefix('Authorization', "token");

$api_instance = new Swagger\Client\Api\DefaultApi(null, $config);

try {
  $projects = $api_instance->projectsGet();
  foreach ($projects as $project) {
    printf("%s: %s\n", $project->getId(), $project->getName());
    foreach ($api_instance->projectsProjectIdLocalesGet($project->getId()) as $locale) {
      printf("  %s %s %s\n", $locale->getId(), $locale->getName(), $locale->getCode());
    }
  }

} catch (Exception $e) {
    echo 'Exception when calling DefaultApi->accountsAccountIdGlossariesGet: ', $e->getMessage(), PHP_EOL;
}
?>

About

PhraseApp API Spec

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • PHP 62.4%
  • Python 37.4%
  • Other 0.2%