Completed
Push — master ( 19353a...3ab454 )
by dotzero
02:31
created

Api.__init__()   A

Complexity

Conditions 2

Size

Total Lines 16

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 1
CRAP Score 5.2516

Importance

Changes 10
Bugs 0 Features 0
Metric Value
cc 2
c 10
b 0
f 0
dl 0
loc 16
ccs 1
cts 15
cp 0.0667
crap 5.2516
rs 9.4285
1
# -*- coding: utf-8 -*-
2
#
3
# Copyright (c) 2016 dotzero <[email protected]>
4
#
5
# Permission is hereby granted, free of charge, to any person obtaining a copy
6
# of this software and associated documentation files (the "Software"), to deal
7
# in the Software without restriction, including without limitation the rights
8
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
# copies of the Software, and to permit persons to whom the Software is
10
# furnished to do so, subject to the following conditions:
11
#
12
# The above copyright notice and this permission notice shall be included
13
# in all copies or substantial portions of the Software.
14
#
15
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
# SOFTWARE.
22 1
"""Этот модуль содержит клиент для получения доступа к ресурсам API."""
23
24 1
from .resources.comments import CommentsResource
25 1
from .resources.company import CompanyResource
26 1
from .resources.feed import FeedResource
27 1
from .resources.flow import FlowResource
28 1
from .resources.hub import HubResource
29 1
from .resources.poll import PollResource
30 1
from .resources.post import PostResource
31 1
from .resources.search import SearchResource
32 1
from .resources.settings import SettingsResource
33 1
from .resources.tracker import TrackerResource
34 1
from .resources.user import UserResource
35 1
from habrahabr.errors import ApiHandlerError
36 1
from habrahabr.utils import lazy
37
38
39 1
class Api(object):
40
    """Этот объект содержит клиент для получения доступа к ресурсам API.
41
42
    Args:
43
        auth (object): Экземпляр класса Auth.
44
    """
45
46 1
    def __init__(self, auth=None):
47
        """Конструктор.
48
49
        :param auth: Экземпляр класса Auth.
50
        :rtype: object
51
        """
52 1
        if auth is None:
53
            raise ApiHandlerError('Auth handler is not defined')
54 1
        self.auth = auth
55
56 1
    @lazy
57
    def comments(self):
58
        """Ресурс работы с комментариями.
59
60
        :returns: CommentsResource.
61
        :rtype: object
62
        """
63 1
        return CommentsResource(self.auth)
64
65 1
    @lazy
66
    def company(self):
67
        """Ресурс работы с компаниями.
68
69
        :returns: CompanyResource.
70
        :rtype: object
71
        """
72 1
        return CompanyResource(self.auth)
73
74 1
    @lazy
75
    def feed(self):
76
        """Ресурс работы с основной лентой постов.
77
78
        :returns: FeedResource.
79
        :rtype: object
80
        """
81 1
        return FeedResource(self.auth)
82
83 1
    @lazy
84
    def flow(self):
85
        """Ресурс работы с потоками.
86
87
        :returns: FlowResource.
88
        :rtype: object
89
        """
90 1
        return FlowResource(self.auth)
91
92 1
    @lazy
93
    def hub(self):
94
        """Ресурс работы с хабами.
95
96
        :returns: HubResource.
97
        :rtype: object
98
        """
99 1
        return HubResource(self.auth)
100
101 1
    @lazy
102
    def poll(self):
103
        """Ресурс работы с опросами.
104
105
        :returns: PollResource.
106
        :rtype: object
107
        """
108 1
        return PollResource(self.auth)
109
110 1
    @lazy
111
    def post(self):
112
        """Ресурс работы с постами.
113
114
        :returns: PostResource.
115
        :rtype: object
116
        """
117 1
        return PostResource(self.auth)
118
119 1
    @lazy
120
    def search(self):
121
        """Ресурс работы с поиском.
122
123
        :returns: SearchResource.
124
        :rtype: object
125
        """
126 1
        return SearchResource(self.auth)
127
128 1
    @lazy
129
    def settings(self):
130
        """Ресурс работы с настройками профиля.
131
132
        :returns: SettingsResource.
133
        :rtype: object
134
        """
135 1
        return SettingsResource(self.auth)
136
137 1
    @lazy
138
    def tracker(self):
139
        """Ресурс работы с трекером.
140
141
        :returns: TrackerResource.
142
        :rtype: object
143
        """
144 1
        return TrackerResource(self.auth)
145
146 1
    @lazy
147
    def user(self):
148
        """Ресурс работы с пользователями.
149
150
        :returns: UserResource.
151
        :rtype: object
152
        """
153
        return UserResource(self.auth)
154