diff --git a/README.md b/README.md index 149d17e5..c5d03ee4 100644 --- a/README.md +++ b/README.md @@ -198,7 +198,7 @@ for convo in Conversation.find_all( # the users email for convo in Conversation.find_all(email='joe@example.com',type='user'): ... -# Iterate over through all conversations (read + unread) with a user based on +# Iterate over through all conversations (read + unread) with a user based on # the users email for convo in Conversation.find_all( email='joe@example.com', type='user', unread=False): @@ -226,7 +226,7 @@ conversation.reply( message_type= comment', body='foo') # Admin (identified by email) replies with a comment conversation.reply( - type='admin', email='bob@example.com', + type='admin', email='bob@example.com', message_type='comment', body='bar') # MARKING A CONVERSATION AS READ @@ -271,7 +271,7 @@ Tag.count() ``` python # InApp message from admin to user -Message.create({ +Message.create(**{ "message_type": "inapp", "body": "What's up :)", "from": { @@ -285,7 +285,7 @@ Message.create({ }) # Email message from admin to user -Message.create({ +Message.create(**{ "message_type": "email", "subject": "Hey there", "body": "What's up :)", @@ -301,7 +301,7 @@ Message.create({ }) # Message from a user -Message.create({ +Message.create(**{ "from": { "type": "user", "id": "536e564f316c83104c000020" diff --git a/intercom/__init__.py b/intercom/__init__.py index a714b246..6fb8e520 100644 --- a/intercom/__init__.py +++ b/intercom/__init__.py @@ -1,17 +1,21 @@ # -*- coding: utf-8 -*- -from datetime import datetime -from json import JSONEncoder -from .errors import ArgumentError -from .lib.setter_property import SetterProperty - import copy import json +import logging import random import re import requests import time +from datetime import datetime + +from json import JSONEncoder + +from .errors import ArgumentError +from .lib.setter_property import SetterProperty + + __version__ = '2.0-alpha' @@ -26,6 +30,9 @@ Intercom.app_api_key to use this client." +logger = logging.getLogger("intercom") + + class _Config(object): app_id = None app_api_key = None @@ -63,12 +70,16 @@ def send_request_to_path(cls, method, path, params=None): req_params['params'] = params req_params['headers'] = headers + logger.debug("req params: %s", req_params) resp = requests.request( method, url, timeout=cls._config.timeout, auth=(Intercom.app_id, Intercom.app_api_key), **req_params) - if resp.content: + # the events api sends a "202 Accepted" without a body content + # well, actually they send back a whitespace, hence the .strip() here + if resp.content.strip(): return json.loads(resp.content) + return dict() @classmethod def get(cls, path, **params): diff --git a/intercom/conversation.py b/intercom/conversation.py index 50bdc7d4..c33dc331 100644 --- a/intercom/conversation.py +++ b/intercom/conversation.py @@ -8,3 +8,7 @@ class Conversation(Resource, FindAll, Find, Load, Save, Reply): pass + + +class Message(Resource, Save): + pass diff --git a/intercom/lib/flat_store.py b/intercom/lib/flat_store.py index ce06ff77..1618c804 100644 --- a/intercom/lib/flat_store.py +++ b/intercom/lib/flat_store.py @@ -10,9 +10,10 @@ def __setitem__(self, key, value): if not ( isinstance(value, numbers.Real) or isinstance(value, basestring) - ): + ) and value is not None: raise ValueError( - "custom data only allows string and real number values") + "custom data only allows string, real number or None values" + ) if not isinstance(key, basestring): raise ValueError("custom data only allows string keys") super(FlatStore, self).__setitem__(key, value) diff --git a/setup.py b/setup.py index 7f2d57e9..d1333777 100644 --- a/setup.py +++ b/setup.py @@ -10,9 +10,9 @@ from setuptools import find_packages from setuptools import setup -with file(os.path.join('intercom', 'intercom.py')) as init: +with open(os.path.join('intercom', '__init__.py')) as init: source = init.read() - m = re.search("__version__ = '(\d+\.\d+\.\d+)'", source, re.M) + m = re.search("__version__ = '(.+)'", source, re.M) __version__ = m.groups()[0] setup( @@ -28,6 +28,6 @@ classifiers=[], packages=find_packages(), include_package_data=True, - install_requires=["requests"], + install_requires=["requests", "inflection"], zip_safe=False )