From 7fc5899475a1915f88695e7efa40675c3e7aa623 Mon Sep 17 00:00:00 2001 From: KEBE Date: Fri, 28 Jul 2017 10:23:27 +0800 Subject: [PATCH] + add subscription api. --- daovoice/client.py | 12 ++++++++---- daovoice/models.py | 13 ++++--------- daovoice/service/subscription.py | 14 ++++++++++++++ examples/example.py | 13 +++++++++---- 4 files changed, 35 insertions(+), 17 deletions(-) create mode 100644 daovoice/service/subscription.py diff --git a/daovoice/client.py b/daovoice/client.py index 86dc5a7..57d73f8 100644 --- a/daovoice/client.py +++ b/daovoice/client.py @@ -17,7 +17,7 @@ def __init__(self, base_url=DAOVOICE_API, timeout=DEFAULT_TIMEOUT, headers=None, self.base_url = base_url[:-1] else: self.base_url = base_url - + self._timeout = timeout self.headers = headers or DEFAULT_HEADERS.copy() if token: @@ -71,15 +71,19 @@ def admins(self): from daovoice.service import admin return admin.Admin(self) + @property + def subscriptions(self): + from daovoice.service import subscription + return subscription.Subscription(self) + @property def message(self): from daovoice.service import message return message.Message(self) - + @property def user(self): from daovoice.service import user - + return user.User(self) - diff --git a/daovoice/models.py b/daovoice/models.py index d67283b..f4f6629 100644 --- a/daovoice/models.py +++ b/daovoice/models.py @@ -20,19 +20,11 @@ def from_resp_json(cls, resp_json): elif isinstance(resp_json, list): return [cls(l) for l in resp_json] - def __setattr__(self, key, value): if hasattr(self, key) and getattr(self, key) != value: self.changed_attributes.append(key) super(Model, self).__setattr__(key, value) - - - - - - - class Conversation(Model): @@ -62,10 +54,13 @@ class Admin(Author): resource_path = "admins" +class Subscription(Model): + resource_path = "subscriptions" + + class User(Author): resource_path = "users" class Company(Model): pass - diff --git a/daovoice/service/subscription.py b/daovoice/service/subscription.py new file mode 100644 index 0000000..196003d --- /dev/null +++ b/daovoice/service/subscription.py @@ -0,0 +1,14 @@ +#!/usr/bin/env python +# coding=utf-8 +# Created by kebe + +from base_service import BaseService +from daovoice import models +from daovoice.api_operations import SimpleAll, Save, Get + + +class Subscription(BaseService, SimpleAll, Save, Get): + @property + def resource_class(self): + return models.Subscription + diff --git a/examples/example.py b/examples/example.py index d3fa608..71a4164 100644 --- a/examples/example.py +++ b/examples/example.py @@ -1,13 +1,13 @@ +import os from daovoice.client import Client # init client -client = Client(base_url="http://api.daovoice.co/v1", - token="EF802AE9611FD09B0F8B3BBFA13703A6061E20A9D5D68A36689845108D7D71C3") +client = Client(token=os.getenv('TOKEN', '')) # get conversation -conversation = client.conversations.get(id="0204274f-0e61-4c15-a794-9e950aca0eb0") +conversation = client.conversations.get(id="11678500-4f3f-4ca3-a322-c5ced27d77f3") print conversation.conversation_parts print conversation.conversation_message @@ -20,8 +20,13 @@ for ad in admins: print ad.name +subscriptions = client.subscriptions.all() + +for sub in subscriptions: + print sub.subscription_id + # reply conversation -client.conversations.reply(id="0204274f-0e61-4c15-a794-9e950aca0eb0", admin_id=admins[0].admin_id, body="hello") +client.conversations.reply(id="11678500-4f3f-4ca3-a322-c5ced27d77f3", admin_id=admins[0].admin_id, body="hello") # create user print client.user.create(user_id="test_134", name="example", email="example@daovoice.io")