From b3db5ebcc5aa6744c922b63757ba9b1dbababada Mon Sep 17 00:00:00 2001 From: flc Date: Thu, 19 Feb 2015 19:39:40 +0100 Subject: [PATCH 1/7] refine Intercom.send_request_to_path a bit --- intercom/__init__.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/intercom/__init__.py b/intercom/__init__.py index a714b246..cb01aade 100644 --- a/intercom/__init__.py +++ b/intercom/__init__.py @@ -67,8 +67,11 @@ def send_request_to_path(cls, method, path, params=None): 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): From 29375ba7ba6a03ce21d97de80cf76197fcc06a5d Mon Sep 17 00:00:00 2001 From: flc Date: Thu, 19 Feb 2015 19:47:45 +0100 Subject: [PATCH 2/7] fix setup.py --- setup.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/setup.py b/setup.py index 7f2d57e9..295f201f 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( From 044c671d665039b1faa07416833264fb36c3daaf Mon Sep 17 00:00:00 2001 From: flc Date: Thu, 19 Feb 2015 19:51:23 +0100 Subject: [PATCH 3/7] add inflection to install_requires --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 295f201f..d1333777 100644 --- a/setup.py +++ b/setup.py @@ -28,6 +28,6 @@ classifiers=[], packages=find_packages(), include_package_data=True, - install_requires=["requests"], + install_requires=["requests", "inflection"], zip_safe=False ) From ec2204c43f8baf673e1518066a05f2e6b943839d Mon Sep 17 00:00:00 2001 From: flc Date: Fri, 20 Feb 2015 02:05:28 +0100 Subject: [PATCH 4/7] allow None in custom attributes --- intercom/lib/flat_store.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) 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) From b58dbe72959c95acd92fd4343f2fe83c8bb35c93 Mon Sep 17 00:00:00 2001 From: flc Date: Tue, 3 Mar 2015 02:15:24 +0100 Subject: [PATCH 5/7] add Message class to conversations module; add logger; fix Messages example in readme --- README.md | 8 ++++---- intercom/__init__.py | 18 +++++++++++++----- intercom/conversation.py | 4 ++++ 3 files changed, 21 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 149d17e5..b6c48ce4 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 @@ -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 cb01aade..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,6 +70,7 @@ 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) diff --git a/intercom/conversation.py b/intercom/conversation.py index 50bdc7d4..a05139d7 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, FindAll, Find, Load, Save, Reply): + pass From 98a88d21929bb23c08fc6f0497bf4868dee7db51 Mon Sep 17 00:00:00 2001 From: flc Date: Tue, 3 Mar 2015 02:17:33 +0100 Subject: [PATCH 6/7] fix Message example --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index b6c48ce4..c5d03ee4 100644 --- a/README.md +++ b/README.md @@ -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": { From bd783f53a2f3efe951fedfc380c28a47bf8f02d5 Mon Sep 17 00:00:00 2001 From: flc Date: Tue, 3 Mar 2015 02:40:03 +0100 Subject: [PATCH 7/7] Message only supports create --- intercom/conversation.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/intercom/conversation.py b/intercom/conversation.py index a05139d7..c33dc331 100644 --- a/intercom/conversation.py +++ b/intercom/conversation.py @@ -10,5 +10,5 @@ class Conversation(Resource, FindAll, Find, Load, Save, Reply): pass -class Message(Resource, FindAll, Find, Load, Save, Reply): +class Message(Resource, Save): pass