tracim.views.example_api.example_api_controller   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 111
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 6
eloc 69
dl 0
loc 111
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A ExampleApiController.get_user() 0 15 1
A ExampleApiController.get_users() 0 20 1
A ExampleApiController.del_user() 0 9 1
A ExampleApiController.bind() 0 15 1
A ExampleApiController.add_user() 0 17 1
A ExampleApiController.about() 0 9 1
1
# -*- coding: utf-8 -*-
0 ignored issues
show
Coding Style introduced by
This module should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
2
# TODO - G.M - 10-04-2018 - [cleanup][tempExample] - Drop this file
0 ignored issues
show
Coding Style introduced by
TODO and FIXME comments should generally be avoided.
Loading history...
3
from datetime import datetime
4
5
from pyramid.config import Configurator
6
7
from hapic.data import HapicData
8
9
from tracim.extensions import hapic
10
from tracim.views.controllers import Controller
11
from tracim.views.example_api.schema import *
0 ignored issues
show
Coding Style introduced by
The usage of wildcard imports like tracim.views.example_api.schema should generally be avoided.
Loading history...
Unused Code introduced by
marshmallow was imported with wildcard, but is not used.
Loading history...
Unused Code introduced by
PaginationSchema was imported with wildcard, but is not used.
Loading history...
12
13
14
class ExampleApiController(Controller):
0 ignored issues
show
Coding Style introduced by
This class should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
Unused Code introduced by
The variable __class__ seems to be unused.
Loading history...
15
16
    @hapic.with_api_doc()
17
    @hapic.output_body(AboutResponseSchema())
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable AboutResponseSchema does not seem to be defined.
Loading history...
18
    def about(self, context, request):
0 ignored issues
show
Unused Code introduced by
The argument context seems to be unused.
Loading history...
Unused Code introduced by
The argument request seems to be unused.
Loading history...
Coding Style introduced by
This method could be written as a function/class method.

If a method does not access any attributes of the class, it could also be implemented as a function or static method. This can help improve readability. For example

class Foo:
    def some_method(self, x, y):
        return x + y;

could be written as

class Foo:
    @classmethod
    def some_method(cls, x, y):
        return x + y;
Loading history...
19
        """
20
        General information about this API.
21
        """
22
        return {
23
            'version': '1.2.3',
24
            'datetime': datetime(2017, 12, 7, 10, 55, 8, 488996),
25
        }
26
27
    @hapic.with_api_doc()
28
    @hapic.output_body(ListsUserSchema())
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable ListsUserSchema does not seem to be defined.
Loading history...
29
    def get_users(self, context, request):
0 ignored issues
show
Unused Code introduced by
The argument context seems to be unused.
Loading history...
Unused Code introduced by
The argument request seems to be unused.
Loading history...
Coding Style introduced by
This method could be written as a function/class method.

If a method does not access any attributes of the class, it could also be implemented as a function or static method. This can help improve readability. For example

class Foo:
    def some_method(self, x, y):
        return x + y;

could be written as

class Foo:
    @classmethod
    def some_method(cls, x, y):
        return x + y;
Loading history...
30
        """
31
        Obtain users list.
32
        """
33
        return {
34
            'item_nb': 1,
35
            'items': [
36
                {
37
                    'id': 4,
38
                    'username': 'some_user',
39
                    'display_name': 'Damien Accorsi',
40
                    'company': 'Algoo',
41
                },
42
            ],
43
            'pagination': {
44
                'first_id': 0,
45
                'last_id': 5,
46
                'current_id': 0,
47
            }
48
        }
49
50
    @hapic.with_api_doc()
51
    @hapic.input_path(UserPathSchema())
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable UserPathSchema does not seem to be defined.
Loading history...
52
    @hapic.output_body(UserSchema())
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable UserSchema does not seem to be defined.
Loading history...
53
    def get_user(self, context, request, hapic_data: HapicData):
0 ignored issues
show
Unused Code introduced by
The argument hapic_data seems to be unused.
Loading history...
Unused Code introduced by
The argument context seems to be unused.
Loading history...
Unused Code introduced by
The argument request seems to be unused.
Loading history...
Coding Style introduced by
This method could be written as a function/class method.

If a method does not access any attributes of the class, it could also be implemented as a function or static method. This can help improve readability. For example

class Foo:
    def some_method(self, x, y):
        return x + y;

could be written as

class Foo:
    @classmethod
    def some_method(cls, x, y):
        return x + y;
Loading history...
54
        """
55
        Obtain one user
56
        """
57
        return {
58
             'id': 4,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation (remove 1 space).
Loading history...
59
             'username': 'some_user',
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation (remove 1 space).
Loading history...
60
             'email_address': '[email protected]',
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation (remove 1 space).
Loading history...
61
             'first_name': 'Damien',
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation (remove 1 space).
Loading history...
62
             'last_name': 'Accorsi',
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation (remove 1 space).
Loading history...
63
             'display_name': 'Damien Accorsi',
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation (remove 1 space).
Loading history...
64
             'company': 'Algoo',
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation (remove 1 space).
Loading history...
65
        }
66
67
    @hapic.with_api_doc()
68
    # TODO - G.M - 2017-12-5 - Support input_forms ?
0 ignored issues
show
Coding Style introduced by
TODO and FIXME comments should generally be avoided.
Loading history...
69
    # TODO - G.M - 2017-12-5 - Support exclude, only ?
0 ignored issues
show
Coding Style introduced by
TODO and FIXME comments should generally be avoided.
Loading history...
70
    @hapic.input_body(UserSchema(exclude=('id',)))
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable UserSchema does not seem to be defined.
Loading history...
Coding Style introduced by
This method could be written as a function/class method.

If a method does not access any attributes of the class, it could also be implemented as a function or static method. This can help improve readability. For example

class Foo:
    def some_method(self, x, y):
        return x + y;

could be written as

class Foo:
    @classmethod
    def some_method(cls, x, y):
        return x + y;
Loading history...
71
    @hapic.output_body(UserSchema())
72
    def add_user(self, context, request, hapic_data: HapicData):
0 ignored issues
show
Unused Code introduced by
The argument hapic_data seems to be unused.
Loading history...
Unused Code introduced by
The argument context seems to be unused.
Loading history...
Unused Code introduced by
The argument request seems to be unused.
Loading history...
73
        """
74
        Add new user
75
        """
76
        return {
77
             'id': 4,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation (remove 1 space).
Loading history...
78
             'username': 'some_user',
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation (remove 1 space).
Loading history...
79
             'email_address': '[email protected]',
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation (remove 1 space).
Loading history...
80
             'first_name': 'Damien',
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation (remove 1 space).
Loading history...
81
             'last_name': 'Accorsi',
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation (remove 1 space).
Loading history...
82
             'display_name': 'Damien Accorsi',
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation (remove 1 space).
Loading history...
83
             'company': 'Algoo',
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation (remove 1 space).
Loading history...
84
        }
85
86
    @hapic.with_api_doc()
87
    @hapic.output_body(NoContentSchema(),
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable NoContentSchema does not seem to be defined.
Loading history...
88
                       default_http_code=204)
89
    @hapic.input_path(UserPathSchema())
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable UserPathSchema does not seem to be defined.
Loading history...
90
    def del_user(self, context, request, hapic_data: HapicData):
0 ignored issues
show
Unused Code introduced by
The argument hapic_data seems to be unused.
Loading history...
Unused Code introduced by
The argument context seems to be unused.
Loading history...
Unused Code introduced by
The argument request seems to be unused.
Loading history...
Coding Style introduced by
This method could be written as a function/class method.

If a method does not access any attributes of the class, it could also be implemented as a function or static method. This can help improve readability. For example

class Foo:
    def some_method(self, x, y):
        return x + y;

could be written as

class Foo:
    @classmethod
    def some_method(cls, x, y):
        return x + y;
Loading history...
91
        """
92
        delete user
93
        """
94
        return NoContentSchema()
95
96
    def bind(self, configurator: Configurator):
97
        configurator.add_route('about', '/about', request_method='GET')
98
        configurator.add_view(self.about, route_name='about', renderer='json')
99
100
        configurator.add_route('get_users', '/users', request_method='GET')  # nopep8
101
        configurator.add_view(self.get_users, route_name='get_users', renderer='json')  # nopep8
102
103
        configurator.add_route('get_user', '/users/{id}', request_method='GET')  # nopep8
104
        configurator.add_view(self.get_user, route_name='get_user', renderer='json')  # nopep8
105
106
        configurator.add_route('add_user', '/users/', request_method='POST')  # nopep8
107
        configurator.add_view(self.add_user, route_name='add_user', renderer='json')  # nopep8
108
109
        configurator.add_route('del_user', '/users/{id}', request_method='DELETE')  # nopep8
110
        configurator.add_view(self.del_user, route_name='del_user', renderer='json')  # nopep8
111