Skip to content

Commit

Permalink
Add entrycategories APIs
Browse files Browse the repository at this point in the history
  • Loading branch information
messense committed May 23, 2015
1 parent 72044a6 commit 609e0d6
Show file tree
Hide file tree
Showing 5 changed files with 89 additions and 1 deletion.
7 changes: 7 additions & 0 deletions docs/entrycategories.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
账目分类接口
=================

.. module:: teambition.api.entrycategories

.. autoclass:: EntryCategories
:members:
2 changes: 1 addition & 1 deletion docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ Welcome to teambition-api's documentation!
activities
webhooks
bookkeepings

entrycategories


Indices and tables
Expand Down
2 changes: 2 additions & 0 deletions teambition/api/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
from teambition.api.activities import Activities # NOQA
from teambition.api.webhooks import Webhooks # NOQA
from teambition.api.bookkeepings import BookKeepings # NOQA
from teambition.api.entrycategories import EntryCategories # NOQA

__all__ = [
'OAuth',
Expand All @@ -41,4 +42,5 @@
'ObjectLinks',
'Activities',
'BookKeepings',
'EntryCategories',
]
77 changes: 77 additions & 0 deletions teambition/api/entrycategories.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
# -*- coding: utf-8 -*-
from __future__ import absolute_import, unicode_literals
from teambition.api.base import TeambitionAPI


class EntryCategories(TeambitionAPI):

def get(self, id=None, project_id=None):
"""
获取账目分类
详情请参考
http://docs.teambition.com/wiki/bookkeeping-entrycategory#bookkeeping-entrycategory-get
:param id: 可选,账目分类 ID
:param project_id: 可选,项目 ID
:return: 返回的 JSON 数据包
"""
assert id or project_id
params = {}
if id:
endpoint = 'api/entrycategories/{0}'.format(id)
elif project_id:
endpoint = 'api/entrycategories'
params['_projectId'] = project_id
return self._get(endpoint, params=params)

def create(self, project_id, title, type):
"""
新建账目分类
详情请参考
http://docs.teambition.com/wiki/bookkeeping-entrycategory#bookkeeping-entrycategory-create
:param project_id: 项目 ID
:param title: 标题
:param type: 账目类型,1 为收入,-1 为支出
:return: 返回的 JSON 数据包
"""
return self._post(
'api/entrycategories',
data={
'_projectId': project_id,
'title': title,
'type': type
}
)

def delete(self, id):
"""
删除账目分类 只允许删除非默认分类
详情请参考
http://docs.teambition.com/wiki/bookkeeping-entrycategory#bookkeeping-entrycategory-delete
:param id: 账目分类 ID
:return: 返回的 JSON 数据包
"""
return self._delete('api/entrycategories/{0}'.format(id))

def update(self, id, title):
"""
更新账目分类
详情请参考
http://docs.teambition.com/wiki/bookkeeping-entrycategory#bookkeeping-entrycategory-update
:param id: 账目分类 ID
:param title: 标题
:return: 返回的 JSON 数据包
"""
return self._put(
'api/entrycategories/{0}'.format(id),
data={
'title': title
}
)
2 changes: 2 additions & 0 deletions teambition/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ class Teambition(object):
""":doc:`webhooks`"""
bookkeepings = api.BookKeepings()
""":doc:`bookkeepings`"""
entrycategories = api.EntryCategories()
"""doc:`entrycategories`"""

def __new__(cls, *args, **kwargs):
self = super(Teambition, cls).__new__(cls)
Expand Down

0 comments on commit 609e0d6

Please sign in to comment.