Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Close method #31

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
*.pyc
*.pyo
tests/server.pem
customerio.egg-info/
dist
103 changes: 0 additions & 103 deletions README.md

This file was deleted.

127 changes: 127 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
@@ -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='[email protected]', 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='[email protected]', 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 <http://customer.io/docs/api/rest.html#section-Track_a_custom_event>`_

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 <http://customer.io/docs/api/rest.html#section-Track_a_custom_event>`_

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 <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`_ 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
4 changes: 4 additions & 0 deletions customerio/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
@@ -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])
Expand Down