From b84271184135ef0d4cb2deee3428f3d2647fd889 Mon Sep 17 00:00:00 2001 From: jatinn Date: Fri, 20 Jan 2017 15:50:40 -0500 Subject: [PATCH 1/3] add method to close the connection socket --- .gitignore | 2 ++ customerio/__init__.py | 4 ++++ setup.py | 2 +- 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index f62c6da..42ef3fe 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,5 @@ *.pyc *.pyo tests/server.pem +customerio.egg-info/ +dist diff --git a/customerio/__init__.py b/customerio/__init__.py index 3ea09a1..3ba0aff 100644 --- a/customerio/__init__.py +++ b/customerio/__init__.py @@ -37,6 +37,10 @@ def __init__(self, site_id=None, api_key=None, host=None, port=None, url_prefix= self.setup_base_url() self.setup_connection() + def close(self): + if self.http: + self.http.close() + def setup_base_url(self): template = 'https://{host}:{port}/{prefix}' if self.port == 443: diff --git a/setup.py b/setup.py index f5ec181..d24ad74 100644 --- a/setup.py +++ b/setup.py @@ -1,6 +1,6 @@ from setuptools import find_packages, setup -VERSION = (0, 2, 2, 'final', 0) +VERSION = (0, 2, 3, 'final', 0) def get_version(): version = '%s.%s' % (VERSION[0], VERSION[1]) From 6512b13e45091bcaa18bcd719ec2436b2e4d6bb2 Mon Sep 17 00:00:00 2001 From: jatinn Date: Fri, 20 Jan 2017 15:52:06 -0500 Subject: [PATCH 2/3] add README.rst so that it is available on PyPI --- README.rst | 127 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 127 insertions(+) create mode 100644 README.rst diff --git a/README.rst b/README.rst new file mode 100644 index 0000000..909c0d5 --- /dev/null +++ b/README.rst @@ -0,0 +1,127 @@ +Customer.io Python bindings +=========================== + +This module has been tested with Python 2.6, 2.7 and 3.4 + +Installing +---------- + +.. code:: bash + + pip install customerio + +Usage +----- + +.. code:: python + + from customerio import CustomerIO + cio = CustomerIO(site_id, api_key) + cio.identify(id=5, email='customer@example.com', name='Bob', plan='premium') + cio.track(customer_id=5, name='purchased') + cio.track(customer_id=5, name='purchased', price=23.45) + +Instantiating customer.io object +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +.. code:: python + + from customerio import CustomerIO + cio = CustomerIO(site_id, api_key) + +Create or update a Customer.io customer profile +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +.. code:: python + + cio.identify(id=5, email='customer@example.com', name='Bob', plan='premium') + +| Only the id field is used to identify the customer here. Using an + existing id with +| a different email (or any other attribute) will update/overwrite any + pre-existing +| values for that field. + +You can pass any keyword arguments to the ``identify`` and ``track`` +methods. These kwargs will be converted to custom attributes. + +See original REST documentation `here`_ + +Track a custom event +~~~~~~~~~~~~~~~~~~~~ + +.. code:: python + + cio.track(customer_id=5, name='purchased') + +Track a custom event with custom data values +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +.. code:: python + + cio.track(customer_id=5, name='purchased', price=23.45, product="widget") + +You can pass any keyword arguments to the ``identify`` and ``track`` +methods. These kwargs will be converted to custom attributes. + +See original REST documentation +`here `_ + +Backfill a custom event +~~~~~~~~~~~~~~~~~~~~~~~ + +.. code:: python + + from datetime import datetime, timedelta + + customer_id = 5 + event_type = "purchase" + + # Backfill an event one hour in the past + event_date = datetime.utcnow() - timedelta(hours=1) + cio.backfill(customer_id, event_type, event_date, price=23.45, coupon=True) + + event_timestamp = 1408482633 + cio.backfill(customer_id, event_type, event_timestamp, price=34.56) + + event_timestamp = "1408482680" + cio.backfill(customer_id, event_type, event_timestamp, price=45.67) + +Event timestamp may be passed as a ``datetime.datetime`` object, an +integer or a string UNIX timestamp + +Keyword arguments to backfill work the same as a call to ``cio.track``. + +See original REST documentation +`here `_ + +Delete a customer profile +~~~~~~~~~~~~~~~~~~~~~~~~~ + +.. code:: python + + cio.delete(customer_id=5) + +Deletes the customer profile for a specified customer. + +This method returns nothing. Attempts to delete non-existent customers +will not raise any errors. + +See original REST documentation +`here `_ + +You can pass any keyword arguments to the ``identify`` and ``track`` +methods. These kwargs will be converted to custom attributes. + +Thanks +------ + +- `Dimitriy Narkevich`_ for creating the library. +- `EZL`_ for contributing customer deletes and improving README +- `Noemi Millman`_ for adding custom JSON encoder +- `Jason Kraus`_ for event backfilling + +.. _Dimitriy Narkevich: https://github.com/dimier +.. _EZL: https://github.com/ezl +.. _Noemi Millman: https://github.com/sbnoemi +.. _Jason Kraus: https://github.com/zbyte64 From cfff3f8a7e25501dd9117fa6434f27b28f9b0530 Mon Sep 17 00:00:00 2001 From: jatinn Date: Fri, 20 Jan 2017 15:53:51 -0500 Subject: [PATCH 3/3] remove README.md as github can also render README.rst --- README.md | 103 ------------------------------------------------------ 1 file changed, 103 deletions(-) delete mode 100644 README.md diff --git a/README.md b/README.md deleted file mode 100644 index f53dfbb..0000000 --- a/README.md +++ /dev/null @@ -1,103 +0,0 @@ -# Customer.io Python bindings - -This module has been tested with Python 2.6, 2.7 and 3.4 - -## Installing - -```bash -pip install customerio -``` - -## Usage - -```python -from customerio import CustomerIO -cio = CustomerIO(site_id, api_key) -cio.identify(id=5, email='customer@example.com', name='Bob', plan='premium') -cio.track(customer_id=5, name='purchased') -cio.track(customer_id=5, name='purchased', price=23.45) -``` - -### Instantiating customer.io object - -```python -from customerio import CustomerIO -cio = CustomerIO(site_id, api_key) -``` - -### Create or update a Customer.io customer profile - -```python -cio.identify(id=5, email='customer@example.com', name='Bob', plan='premium') -``` - -Only the id field is used to identify the customer here. Using an existing id with -a different email (or any other attribute) will update/overwrite any pre-existing -values for that field. - -You can pass any keyword arguments to the `identify` and `track` methods. These kwargs will be converted to custom attributes. - -See original REST documentation [here](http://customer.io/docs/api/rest.html#section-Creating_or_updating_customers) - -### Track a custom event - -```python -cio.track(customer_id=5, name='purchased') -``` - -### Track a custom event with custom data values - -```python -cio.track(customer_id=5, name='purchased', price=23.45, product="widget") -``` - -You can pass any keyword arguments to the `identify` and `track` methods. These kwargs will be converted to custom attributes. - -See original REST documentation [here](http://customer.io/docs/api/rest.html#section-Track_a_custom_event) - -### Backfill a custom event - -```python -from datetime import datetime, timedelta - -customer_id = 5 -event_type = "purchase" - -# Backfill an event one hour in the past -event_date = datetime.utcnow() - timedelta(hours=1) -cio.backfill(customer_id, event_type, event_date, price=23.45, coupon=True) - -event_timestamp = 1408482633 -cio.backfill(customer_id, event_type, event_timestamp, price=34.56) - -event_timestamp = "1408482680" -cio.backfill(customer_id, event_type, event_timestamp, price=45.67) -``` - -Event timestamp may be passed as a ```datetime.datetime``` object, an integer or a string UNIX timestamp - -Keyword arguments to backfill work the same as a call to ```cio.track```. - -See original REST documentation [here](http://customer.io/docs/api/rest.html#section-Track_a_custom_event) - -### Delete a customer profile - -```python -cio.delete(customer_id=5) -``` - -Deletes the customer profile for a specified customer. - -This method returns nothing. Attempts to delete non-existent customers will not raise any errors. - -See original REST documentation [here](http://customer.io/docs/api/rest.html#section-Deleting_customers) - - -You can pass any keyword arguments to the `identify` and `track` methods. These kwargs will be converted to custom attributes. - -## Thanks - -* [Dimitriy Narkevich](https://github.com/dimier) for creating the library. -* [EZL](https://github.com/ezl) for contributing customer deletes and improving README -* [Noemi Millman](https://github.com/sbnoemi) for adding custom JSON encoder -* [Jason Kraus](https://github.com/zbyte64) for event backfilling