Beispiel #1
0
def upload_photo(form_data, user_id, user_token, lang, create=True):
    api_url = join(settings.WS_BASE_URL, PRIVATE_API_SCHEMA_URL)
    chunk_size = config.PHOTO_UPLOAD_CHUNK_SIZE

    # request headers
    authorization = {'Authorization': 'Token {}'.format(user_token)}
    headers = dict(authorization)
    headers.update({
        'Accept-Language': lang,
        'content_type': MULTIPART_CONTENT
    })

    transports = HTTPTransport(credentials=authorization, headers=headers)
    client = Client(transports=[transports])

    # get api schema
    schema_cache_key = "{}_{}".format(CACHE_SCHEMA_PREFIX_KEY, user_id)
    schema = cache.get(schema_cache_key)
    if not schema:
        schema = client.get(api_url)
        cache_set(schema_cache_key, schema)

    # get image to upload
    upload_id = form_data.pop('upload_id')
    image = MyChunkedUpload.objects.get(upload_id=upload_id)
    image_file = image.file
    filename = image.filename

    # request parameters
    data = {'filename': filename}
    offset, chunks = 0, image_file.chunks(chunk_size)
    request_path = ['photos', 'upload', 'update']
    img_id = 0

    for chunk_file in chunks:
        data.update(**{'file': ContentFile(chunk_file)})
        client.transports[0].headers._data[
            'Content-Range'] = 'bytes {}-{}/{}'.format(
                offset, offset + len(chunk_file), image_file.size)
        response = client.action(schema, request_path, params=data)
        offset = response['offset']
        img_id = response['id']
        data.update({'id': img_id})
        request_path = ['photos', 'upload', 'chunk', 'update']

    request_path = ['photos', 'upload', 'chunk', 'create']
    data.update({'md5': _checksum_file(image_file, chunk_size)})
    client.action(schema, request_path, params=data)

    # Request is not multipart, so we remove the header, otherwise uwsgi doesn't works
    client.transports[0].headers._data.pop('content_type', None)

    # upload photo information
    form_data['image'] = img_id
    form_data['original_file_name'] = filename
    if create:
        form_data['owner'] = user_id
        client.action(schema, ['photos', 'create'], params=form_data)
    else:
        client.action(schema, ['photos', 'partial_update'], params=form_data)
Beispiel #2
0
def generate_tavern_yaml(json_path):
    client = Client()
    d = client.get(json_path, format="openapi")

    output_yaml(d.links)
    for routes in d.data.keys():
        output_yaml(d.data[routes], routes)
Beispiel #3
0
    def __init__(self, request):
        super(DAMWebService, self).__init__()
        api_url = join(settings.WS_BASE_URL, PRIVATE_API_SCHEMA_URL)

        self.request = request
        self.user_id = request.user.id

        # initialize api client with user token
        user_params = cache.get("{}_{}".format(CACHE_USER_PROFILE_PREFIX_KEY,
                                               self.user_id))
        authorization = {}
        if user_params and user_params.get('token'):
            authorization = {
                'Authorization': 'Token {}'.format(user_params.get('token'))
            }
        headers = dict(authorization)
        headers.update({
            'Accept-Language':
            request.META.get('HTTP_ACCEPT_LANGUAGE', request.LANGUAGE_CODE)
        })

        transports = HTTPTransport(
            credentials=authorization,
            headers=headers,
            response_callback=self._callback_client_transport)
        self.client = Client(transports=[transports])

        # get api schema
        schema_cache_key = "{}_{}".format(CACHE_SCHEMA_PREFIX_KEY,
                                          self.user_id)
        self.schema = cache.get(schema_cache_key)
        if not self.schema:
            self.schema = self.get_or_logout(api_url)
            cache.set(schema_cache_key, self.schema)
Beispiel #4
0
    def __init__(self, request):
        super(DAMPublicWebService, self).__init__()
        api_url = join(settings.WS_BASE_URL, PUBLIC_API_SCHEMA_URL)

        self.request = request
        self.client = Client()

        self.schema = self.client.get(api_url)
Beispiel #5
0
 def post(self, request):
     serializer = RegistrationSerializer(data=request.data)
     if serializer.is_valid():
         data = serializer.data
         u = User.objects.create(username=data['username'])
         u.set_password(data['password'])
         u.save()
         name = u.username
         client = Client(user=u, name=name, url='' + name,\
                   client_id=name, client_secret='', client_type=1)
         client.save()
         return Response(serializer.data, status=status.HTTP_201_CREATED)
Beispiel #6
0
 def _action(self,
             fiware_service,
             fiware_service_path,
             keys,
             params=None,
             validate=True):
     headers = {
         'Fiware-Service': fiware_service,
         'Fiware-ServicePath': fiware_service_path
     }
     transport = HTTPTransport(headers=headers)
     client = Client(transports=[transport])
     document = client.get(self.schema_endpoint)
     return client.action(document, keys, params, validate)
Beispiel #7
0
def generate_tavern_yaml(json_path):
    client = Client()
    #print(client.__dict__)
    d = client.get(json_path, format="openapi")
    #print(d)
    #print(d.data)

    output_yaml(d.links)
    for routes in d.data.keys():
        #print(os.getcwd())
        #print(routes)
        test_dir = routes.split()[-1]
        os.mkdir(test_dir) if not os.path.isdir(test_dir) else ...
        pathlib.Path(test_dir + "/" + "__init__.py").touch()
        output_yaml(d.data[routes], test_dir)
Beispiel #8
0
 def __init__(self, page_size=None, base_site=None):
     # Init client from base Api URI
     # Hacky page size update for all future request to OlsClient
     OlsClient.page_size = page_size or def_page_size
     if base_site:
         OlsClient.site = base_site
     document = Client(decoders=[HALCodec()]).get(self.site)
     logger.debug('OlsClient [%s][%s]', document.url, self.page_size)
     # List Clients
     self.ontologies = ListClientMixin('/'.join([self.site, 'ontologies']),
                                       Ontology, document, self.page_size)
     self.terms = ListClientMixin('/'.join([self.site, 'terms']), Term,
                                  document, self.page_size)
     self.properties = ListClientMixin('/'.join([self.site, 'properties']),
                                       Property, document, self.page_size)
     self.individuals = ListClientMixin(
         '/'.join([self.site, 'individuals']), Individual, document,
         self.page_size)
     # Details client
     self.ontology = DetailClientMixin('/'.join([self.site, 'ontologies']),
                                       Ontology)
     self.term = DetailClientMixin('/'.join([self.site, 'terms']), Term)
     self.property = DetailClientMixin('/'.join([self.site, 'properties']),
                                       Property)
     self.individual = DetailClientMixin(
         '/'.join([self.site, 'individuals']), Individual)
     # Special clients
     self.search = SearchClientMixin('/'.join([self.site, 'search']),
                                     OLSHelper, document, self.page_size)
     self.detail = self.ItemClient(self.site)
Beispiel #9
0
    def get_ville_similaire(self):
        if self.__saisi != '':

            try:
                client = Client()  # self.__class__.decoders
                # connexion à l'API
                document = client.get(self.__class__.__api_de_base +
                                      'communes?nom={nom}'
                                      '&fields=population,centre,departement'
                                      '&boost=population'.format(
                                          nom=self.__saisi))

                # cette fonction est un générateur qui nous permet de limiter la recherche
                def limit_rech(limit=self.__class__.__limite):
                    num = 0
                    for un in document:
                        yield un
                        num += 1
                        if num >= limit:
                            break

                # création d'une liste des villes récupérées
                les_villes_bruites = [x for x in limit_rech()]
                # Création d'une nouvelle listes avec mes propes clée:id , value , population etc...
                # En gros je reformatte les villes envoyées par l'API
                mes_villes = []
                for myid, value in enumerate(les_villes_bruites):
                    mes_villes.append({
                        'id':
                        myid,
                        'value':
                        value['nom'],
                        'population':
                        value['population'],
                        'latitude':
                        value['centre']['coordinates'][1],
                        'longitude':
                        value['centre']['coordinates'][0]
                    })
                # cet objet a été crée lors du chargement de ce fichier
                # enregistrement du dictionnaire des villes
                je_garde.set_last_list(mes_villes)
                return json.dumps(mes_villes)
            except Exception as E:
                return ''
        else:
            return ''
Beispiel #10
0
 def __init__(self, uri, elem_class):
     """
     Init from base uri and expected element helper class
     :param uri: relative uri to base OLS url
     :param elem_class: helper class expected
     """
     self.client = Client(decoders=self.decoders)
     self.uri = uri
     self.elem_class = elem_class
Beispiel #11
0
class DAMPublicWebService(object):
    """
    For api requests without token
    """
    def __init__(self, request):
        super(DAMPublicWebService, self).__init__()
        api_url = join(settings.WS_BASE_URL, PUBLIC_API_SCHEMA_URL)

        self.request = request
        self.client = Client()

        self.schema = self.client.get(api_url)

    def password_reset(self, params):
        path_list = ['auth', 'password', 'reset', 'create']
        return self.client.action(self.schema, path_list, params=params)

    def password_reset_confirm(self, params):
        path_list = ['auth', 'password', 'reset', 'confirm', 'create']
        return self.client.action(self.schema, path_list, params=params)
Beispiel #12
0
 def __init__(self,
              host,
              port,
              user,
              token,
              params_callback=None,
              message_callback=None):
     self.base_url = self.get_service_url(host, port)
     self.client = Client(
         decoders=[
             codecs.CoreJSONCodec(),  # application/vnd.coreapi+json
             codecs.JSONCodec()  # application/json
         ],
         transports=[
             transports.CommandHTTPSTransport(
                 auth=auth.CommandClientTokenAuthentication(user=user,
                                                            token=token,
                                                            scheme='Token',
                                                            domain='*'),
                 params_callback=params_callback,
                 message_callback=message_callback)  # https only
         ])
     self.schema = self.client.get(self.base_url)
Beispiel #13
0
    def makeClient(self, username, password, *args, **kwargs):
        '''
		Make a coreapi client using the username/password authentication.

		:param username: username to authenticate as
		:type username: str

		:param password: password to authenticate with
		:type password: str

		:return: client that uses specified authentication
		:rtype: coreapi.Client
		'''
        wsse_transport = WSSEAuthenticatedHTTPTransport(
            username, password, *args, **kwargs)
        return Client(transports=[wsse_transport])
import time
import requests
from coreapi import Client
from coreapi.auth import TokenAuthentication

# """ http post http://localhost:9000/timeside/api-token-auth/ username=admin password=admin """
url = 'http://localhost:9000/timeside/api-token-auth/'
auth = {'username': '******', 'password': '******'}
r = requests.post(url, data=auth)
token = r.json()['token']

#coreapi client with the right token
auth = TokenAuthentication(scheme='Token', token=token)
client = Client(auth=auth)

#schema of the API
schema = client.get('http://localhost:9000/timeside/api/schema/')

#Item
keys = ['api', 'items', 'create']
params = {
    'title': 'Billie Jean',
    'description': 'Music from Michael Jackson',
    'external_uri': 'http://www.youtube.com/watch?v=Zi_XLOBDo_Y',
    'provider': '/timeside/api/providers/042d0121-456a-4b7d-a993-f8b040f6fc9c/'
}
item = client.action(schema, keys, params)

#Ajout dans la selection WASABI
keys = ['api', 'selections', 'partial_update']
params = {
Beispiel #15
0
# """ http post http://localhost:9000/timeside/api-token-auth/ username=admin password=admin """
# url = 'http://localhost:9000/timeside/api-token-auth/'

api_token_url = 'https://wasabi.telemeta.org/timeside/api-token-auth/'
api_schema_url = 'https://wasabi.telemeta.org/timeside/api/schema/'

auth = {'username': '******', 'password': '******'}
r = requests.post(api_token_url, data=auth)
token = r.json()['token']

print(token)

#coreapi client with the right token
auth = TokenAuthentication(scheme='Token', token=token)

client = Client(auth=auth)

#testing several request to the TimeSide core API
schema = client.get(api_schema_url)

keys = ['api', 'items', 'create']
params = {
    'title': 'foo_test',
    'source_url': 'https://www.youtube.com/watch?v=WFyC4bCYkJM',
    'external_id': 'WFyC4bCYkJM'
}
item = client.action(schema, keys, params)

print(item)

keys = ['api', 'items', 'read']
from Bio import SeqIO
import sys
import os
from collections import OrderedDict
from requests.exceptions import ConnectionError

try:
    inputfile = open(sys.argv[1], 'r')
    # to get the last argument on command line
    filename = sys.argv[-1]
    #outputfile name to store the results
    outputfilename = os.path.splitext(filename)[0] + '.txt'
    outputfilename1 = os.path.splitext(filename)[0] + 'finaltable' + '.txt'
    try:
        #Connecting to JASPAR
        client = Client()
        document = client.get('http://jaspar.genereg.net/api/v1/docs/')
    except ConnectionError as e:
        print e
        print "Database is not responding. Try again later. "
    print "Profile Inference Search Started....."
    for record in SeqIO.parse(inputfile, "fasta"):

        recordseq = record.seq

        action = ["infer", "read"]
        params = {
            "sequence": '%s' % recordseq,
        }
        result = client.action(document, action, params=params)
        data1 = record.id + "#" + str(result)
def test_keys_should_access_a_link(doc):
    client = Client()
    with pytest.raises(LinkLookupError):
        client.action(doc, 'dict')
Beispiel #18
0
 def auth_token(self, app_key):
     self.client = Client(auth=auth.TokenAuthentication(token=app_key,
                                                        scheme="Token"),
                          decoders=self.decoders)
            document = Document(title='new', content={'new': 123})
        elif link.action in ('put', 'post'):
            if params is None:
                params = {}
            document = Document(title='new',
                                content={
                                    'new': 123,
                                    'foo': params.get('foo')
                                })
        else:
            document = None

        return _handle_inplace_replacements(document, link, link_ancestors)


client = Client(transports=[MockTransport()])


@pytest.fixture
def doc():
    return Document(title='original',
                    content={
                        'nested':
                        Document(
                            content={
                                'follow':
                                Link(url='mock://example.com', action='get'),
                                'action':
                                Link(url='mock://example.com',
                                     action='post',
                                     transform='inplace',
Beispiel #20
0
class API(object):
    def __init__(self,
                 host,
                 port,
                 user,
                 token,
                 params_callback=None,
                 message_callback=None):
        self.base_url = self.get_service_url(host, port)
        self.client = Client(
            decoders=[
                codecs.CoreJSONCodec(),  # application/vnd.coreapi+json
                codecs.JSONCodec()  # application/json
            ],
            transports=[
                transports.CommandHTTPSTransport(
                    auth=auth.CommandClientTokenAuthentication(user=user,
                                                               token=token,
                                                               scheme='Token',
                                                               domain='*'),
                    params_callback=params_callback,
                    message_callback=message_callback)  # https only
            ])
        self.schema = self.client.get(self.base_url)

    def get_service_url(self, host, port):
        return "https://{}:{}/".format(host, port)

    def _normalize_data(self, data):
        if isinstance(data, dict):
            for key, value in data.items():
                data[key] = self._normalize_data(value)
        elif isinstance(data, list):
            for index, value in enumerate(data):
                data[index] = self._normalize_data(value)
        else:
            # Scalar value
            if isinstance(data, str) and len(data) == 0:
                data = None

        return data

    def _format_params(self, params):
        params = self._normalize_data(params)

        for key, value in params.items():
            if isinstance(value, dict):
                params[key] = json.dumps(value)
            elif isinstance(value, (list, tuple)):
                params[key] = json.dumps(list(value))

        return params

    def execute(self, action, params=None):
        if not params:
            params = {}
        try:
            action = action.split(' ') if isinstance(action, str) else action
            params = self._format_params(params)
            return self.client.action(self.schema, action, params=params)

        except exceptions.ErrorMessage as error:
            raise CommandError("API request error: {}\n".format(error))
Beispiel #21
0
import sys
import json
import requests
from coreapi import Client
from coreapi.auth import TokenAuthentication

# api: token - schema => url
api_token_url = 'https://wasabi.telemeta.org/timeside/api-token-auth/'
api_schema_url = 'https://wasabi.telemeta.org/timeside/api/schema/'
auth = {'username': '******', 'password': '******'}
r = requests.post(api_token_url, data=auth)
token = 'ba72b2e2570d61125b33b930aa2a15d7741fd540'

# coreapi client with the right token
auth = TokenAuthentication(scheme='Token', token=token)
client = Client(auth=auth)

# testing several request to the TimeSide core API
schema = client.get(api_schema_url)

arrayItems = []


# create
def doCreate(_id, _params):
    keys = ['api', 'items', 'create']
    try:
        item = client.action(schema, keys, _params)
    except:
        arrayItems.append({"msg": "Error, an exception occurred"})
    else:
def test_keys_should_be_a_list_or_string(doc):
    client = Client()
    with pytest.raises(TypeError):
        client.action(doc, True)
Beispiel #23
0
    for event in d:
        event['scroll'] = scroll_id
        print(event)
        try:
            client.action(schema, ['events', 'create'],
                          params=event)
        except Exception as e:
            print(e)
        finally:
            pass

#   create(scroll, title, text, datetime, image, [mediatype],
#   [source_url], [source_date], [content_url])
#   print('var oldRadioNews =', json.dumps(d, sort_keys=True, indent=4), ";\n")

if __name__ == "__main__":
    auth = BasicAuthentication(
        username='******',
        password='******'
    )
    client = Client(auth=auth)
    print(client)
    schema = client.get('http://127.0.0.1:8000/schema')
    print(schema)
    new_scroll = client.action(schema, ['api', '0', 'scrolls', 'create'],
                               params={"title": "WWII Radio News"})
    scroll_d = dict(new_scroll)
    scroll_url = "http://127.0.0.1:8000/scrolls/{}/".format(scroll_d['id'])
    print(scroll_url)
    main(client, scroll_url)
def test_keys_should_be_a_list_of_strings_or_ints(doc):
    client = Client()
    with pytest.raises(TypeError):
        client.action(doc, ['nested', {}])
Beispiel #25
0
 def __init__(self, base_url) -> None:
     super().__init__()
     self.base_url = base_url
     self.client = Client(decoders=self.decoders)
def test_keys_should_be_valid_indexes(doc):
    client = Client()
    with pytest.raises(LinkLookupError):
        client.action(doc, 'dummy')
Beispiel #27
0
import requests
from coreapi import Client
from coreapi.auth import TokenAuthentication

# """ http post http://localhost:9000/timeside/api-token-auth/ username=admin password=admin """
url = 'http://localhost:9000/timeside/api-token-auth/'
auth={'username':'******', 'password':'******'}
r = requests.post(url, data=auth)
token=r.json()['token']

#coreapi client with the right token
auth = TokenAuthentication(
    scheme='Token',
    token=token
)
client = Client(auth=auth)

#testing several request to the TimeSide core API
schema = client.get('http://localhost:9000/timeside/api/schema/')

keys = ['api', 'items', 'create']
params = {'title':'fooTest'}
client.action(schema,keys,params)

keys = ['api', 'items', 'list']
data = client.action(schema,keys)
for item in data:
    print(item['title'] + '   ' + item['uuid'])

Beispiel #28
0
class DAMWebService(object):
    """
    For api requests with token
    """
    def __init__(self, request):
        super(DAMWebService, self).__init__()
        api_url = join(settings.WS_BASE_URL, PRIVATE_API_SCHEMA_URL)

        self.request = request
        self.user_id = request.user.id

        # initialize api client with user token
        user_params = cache.get("{}_{}".format(CACHE_USER_PROFILE_PREFIX_KEY,
                                               self.user_id))
        authorization = {}
        if user_params and user_params.get('token'):
            authorization = {
                'Authorization': 'Token {}'.format(user_params.get('token'))
            }
        headers = dict(authorization)
        headers.update({
            'Accept-Language':
            request.META.get('HTTP_ACCEPT_LANGUAGE', request.LANGUAGE_CODE)
        })

        transports = HTTPTransport(
            credentials=authorization,
            headers=headers,
            response_callback=self._callback_client_transport)
        self.client = Client(transports=[transports])

        # get api schema
        schema_cache_key = "{}_{}".format(CACHE_SCHEMA_PREFIX_KEY,
                                          self.user_id)
        self.schema = cache.get(schema_cache_key)
        if not self.schema:
            self.schema = self.get_or_logout(api_url)
            cache.set(schema_cache_key, self.schema)

    def get_client_schema(self):
        return self.schema

    def _callback_client_transport(self, response):
        self.transport_status_code = response.status_code

    def get_or_logout(self, url):
        """
        Method to get the schema of the api according the client, which depends of the user who requests.
        Raise a ServiceClientException on error customizing the error code.
        """
        try:
            response = self.client.get(url)
            return response
        except ParameterError as e:
            raise ServiceClientException(HTTP_BAD_REQUEST, e)
        except CoreAPIException as e:
            raise ServiceClientException(self.transport_status_code, e)

    def action_or_logout(self,
                         path_list,
                         params,
                         use_cache=False,
                         clear_cache=False):
        """
        to execute the action
        """

        # get response from cache if use cache is
        if use_cache:
            cache_suffix_key = "_".join([
                "{}_{}".format(key, params[key])
                for key in sorted(params.keys())
            ])
            cache_key = "{}_{}_{}".format("_".join(path_list), self.user_id,
                                          cache_suffix_key)
            response = cache.get(cache_key)
            if response:
                return response

        # do request through api client
        try:
            response = self.client.action(self.schema,
                                          path_list,
                                          params=params)
            # clear all request related entries in cache
            if clear_cache:
                cache_delete_startswith(path_list[0])
                return response
            # if response successful status code
            if use_cache:
                cache_set(cache_key, response)
            return response
        except ParameterError as e:
            raise ServiceClientException(HTTP_BAD_REQUEST, e)
        except CoreAPIException as e:
            raise ServiceClientException(self.transport_status_code, e)

    # auth

    def password_change(self, params):
        return self.action_or_logout(['auth', 'password', 'change', 'create'],
                                     params=params)

    # users

    def get_user_info(self):
        return self.action_or_logout(['whoami', 'list'], {})

    def get_user(self, user_id):
        return self.action_or_logout(['users', 'read'], params={'id': user_id})

    def get_users_list(self, **kwargs):
        return self.action_or_logout(['users', 'list'], params=kwargs)

    def user_create(self, params):
        return self.action_or_logout(['users', 'create'], params=params)

    def user_edit(self, params):
        return self.action_or_logout(['users', 'partial_update'],
                                     params=params)

    def delete_user(self, user_id):
        return self.action_or_logout(['users', 'delete'],
                                     params={'id': user_id})

    # groups

    def get_groups_list(self, **kwargs):
        return self.action_or_logout(['groups', 'list'], params=kwargs)

    # albums

    def get_albums_list(self, **kwargs):
        return self.action_or_logout(['albums', 'list'], params=kwargs)

    def get_album(self, album_id):
        return self.action_or_logout(['albums', 'read'],
                                     params={'id': album_id})

    def create_album(self, params):
        return self.action_or_logout(['albums', 'create'], params)

    def update_album(self, params):
        return self.action_or_logout(['albums', 'partial_update'], params)

    def delete_album(self, album_id):
        return self.action_or_logout(['albums', 'delete'],
                                     params={'id': album_id})

    # photos

    def search_photos_list(self, **kwargs):
        return self.action_or_logout(['search', 'list'], params=kwargs)

    def get_photos_list(self, **kwargs):
        return self.action_or_logout(['photos', 'list'], params=kwargs)

    def get_photo(self, photo_id):
        return self.action_or_logout(['photos', 'read'],
                                     params={'id': photo_id})

    def create_photo(self, params):
        return self.action_or_logout(['photos', 'create'], params=params)

    def update_photo(self, params):
        return self.action_or_logout(['photos', 'partial_update'], params)

    def update_photo_multiple(self, params):
        return self.action_or_logout(['photos', 'addition', 'partial_update'],
                                     params)

    def delete_photo(self, photo_id):
        return self.action_or_logout(['photos', 'delete'],
                                     params={'id': photo_id})

    # galleries

    def get_galleries_list(self, **kwargs):
        return self.action_or_logout(['galleries', 'list'], params=kwargs)

    def get_gallery(self, gallery_id):
        return self.action_or_logout(['galleries', 'read'],
                                     params={'id': gallery_id})

    def create_gallery(self, params):
        return self.action_or_logout(['galleries', 'create'], params=params)

    def update_gallery(self, params):
        return self.action_or_logout(['galleries', 'partial_update'], params)

    def delete_gallery(self, gallery_id):
        return self.action_or_logout(['galleries', 'delete'],
                                     params={'id': gallery_id})

    # categories

    def get_categories_simple_list(self, **kwargs):
        """
        Categories list with only 'id' and 'title' information
        """
        return self.action_or_logout(['categories', 'flat', 'list'],
                                     params=kwargs,
                                     use_cache=True)

    def get_categories_list(self, **kwargs):
        return self.action_or_logout(['categories', 'list'],
                                     params=kwargs,
                                     use_cache=True)

    def get_category(self, category_id):
        return self.action_or_logout(['categories', 'read'],
                                     params={'id': category_id},
                                     use_cache=True)

    def create_category(self, params):
        return self.action_or_logout(['categories', 'create'],
                                     params=params,
                                     clear_cache=True)

    def update_category(self, params):
        return self.action_or_logout(['categories', 'update'],
                                     params,
                                     clear_cache=True)

    def delete_category(self, category_id):
        return self.action_or_logout(['categories', 'delete'],
                                     params={'id': category_id},
                                     clear_cache=True)

    # metadata

    def get_names_list(self, **kwargs):
        """
        Tag-Name list filtered by a part of its content
        """
        return self.action_or_logout(['names', 'list'], params=kwargs)

    def get_keywords_list(self, **kwargs):
        """
        Tag-Name list filtered by a part of its content
        """
        return self.action_or_logout(['keywords', 'list'], params=kwargs)

    # copyrights

    def get_authors_list(self, **kwargs):
        """
        Photo author list filtered by a part of its name
        """
        return self.action_or_logout(['authors', 'list'], params=kwargs)

    def get_copyrights_list(self, **kwargs):
        """
        Copyright list filtered by a part of its name
        """
        return self.action_or_logout(['copyrights', 'list'], params=kwargs)

    def get_restrictions_list(self, **kwargs):
        """
        Restriction list filtered by a part of its title
        """
        return self.action_or_logout(['restrictions', 'list'], params=kwargs)

    # link

    def create_link(self, params):
        return self.action_or_logout(['link', 'create'], params=params)

    def delete_link(self, params):
        return self.action_or_logout(['link', 'delete'], params=params)

    # logger

    def logger_view(self, params):
        params['action'] = ACTION_VIEW_PHOTO
        return self.logger_action(params)

    def logger_download(self, params):
        params['action'] = ACTION_DOWNLOAD_PHOTO
        return self.logger_action(params)

    def logger_action(self, params):
        return self.action_or_logout(['logger', 'create'], params=params)

    def get_log_list(self, **kwargs):
        return self.action_or_logout(['logger', 'list'], params=kwargs)

    def get_photo_upload_log_list(self, **kwargs):
        return self.action_or_logout(['photos', 'upload', 'list'],
                                     params=kwargs)

    # exports

    def export_logger(self, kwargs):
        return self.action_or_logout(['exports', 'logger', 'list'],
                                     params=kwargs)

    # flickr

    def flickr_import(self, params):
        return self.action_or_logout(['photos', 'import', 'album', 'create'],
                                     params=params)

    # photo type

    def get_photo_type_list(self, **params):
        return self.action_or_logout(['types', 'list'], params=params)