Skip to content

Commit

Permalink
Merge pull request #1 from kebe7jun/master
Browse files Browse the repository at this point in the history
+ add subscription api.
  • Loading branch information
yowenter authored Jul 28, 2017
2 parents 4e4b0fb + 7fc5899 commit d5fc8fb
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 17 deletions.
12 changes: 8 additions & 4 deletions daovoice/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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)

13 changes: 4 additions & 9 deletions daovoice/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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

14 changes: 14 additions & 0 deletions daovoice/service/subscription.py
Original file line number Diff line number Diff line change
@@ -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

13 changes: 9 additions & 4 deletions examples/example.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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="[email protected]")

0 comments on commit d5fc8fb

Please sign in to comment.