Skip to content

Commit

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

.. module:: teambition.api.entries

.. autoclass:: Entries
:members:
1 change: 1 addition & 0 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ Welcome to teambition-api's documentation!
webhooks
bookkeepings
entrycategories
entries


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 @@ -21,6 +21,7 @@
from teambition.api.webhooks import Webhooks # NOQA
from teambition.api.bookkeepings import BookKeepings # NOQA
from teambition.api.entrycategories import EntryCategories # NOQA
from teambition.api.entries import Entries # NOQA

__all__ = [
'OAuth',
Expand All @@ -43,4 +44,5 @@
'Activities',
'BookKeepings',
'EntryCategories',
'Entries',
]
126 changes: 126 additions & 0 deletions teambition/api/entries.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
# -*- coding: utf-8 -*-
from __future__ import absolute_import, unicode_literals
from optionaldict import optionaldict

from teambition.api.base import TeambitionAPI


class Entries(TeambitionAPI):

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

def create(self, project_id, category_id, content, amount, type,
note=None, visiable=None, tag_ids=None, involve_members=None):
"""
新建账目
详情请参考
http://docs.teambition.com/wiki/bookkeeping-entry#bookkeeping-entry-create
:param project_id: 项目 ID
:param category_id: 账目分类 ID
:param content: 内容
:param amount: 金额
:param type: 类型,1 为收入,-1 为支出
:param note: 可选,备注
:param visiable: 可选,可见范围
:param tag_ids: 可选,标签 ID 列表
:param involve_members: 可选,参与者 ID 列表
:return: 返回的 JSON 数据包
"""
data = optionaldict(
_projectId=project_id,
_entryCategoryId=category_id,
content=content,
amount=amount,
type=type,
note=note,
visiable=visiable,
tagIds=tag_ids,
involveMembers=involve_members
)
return self._post(
'api/entries',
data=data
)

def delete(self, id):
"""
删除账目
详情请参考
http://docs.teambition.com/wiki/bookkeeping-entry#bookkeeping-entry-delete
:param id: 账目 ID
:return: 返回的 JSON 数据包
"""
return self._delete('api/entries/{0}'.format(id))

def update(self, id, content, amount, note=None):
"""
更新账目
详情请参考
http://docs.teambition.com/wiki/bookkeeping-entry#bookkeeping-entry-update
:param id: 账目 ID
:param content: 内容
:param amount: 金额
:param note: 可选,备注
:return: 返回的 JSON 数据包
"""
data = optionaldict(
content=content,
amount=amount,
note=note
)
return self._put(
'api/entries/{0}'.format(id),
data=data
)

def approval(self, id):
"""
审批账目
详情请参考
http://docs.teambition.com/wiki/bookkeeping-entry#bookkeeping-entry-approval
:param id: 账目 ID
:return: 返回的 JSON 数据包
"""
return self._post('api/entries/{0}/approval'.format(id))

def unapproval(self, id):
"""
取消审批账目
详情请参考
http://docs.teambition.com/wiki/bookkeeping-entry#bookkeeping-entry-cancel_the_approval
:param id: 账目 ID
:return: 返回的 JSON 数据包
"""
return self._delete('api/entries/{0}/approval'.format(id))
2 changes: 2 additions & 0 deletions teambition/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ class Teambition(object):
""":doc:`bookkeepings`"""
entrycategories = api.EntryCategories()
"""doc:`entrycategories`"""
entries = api.Entries()
""":doc:`entries`"""

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

0 comments on commit 6733f92

Please sign in to comment.