Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
dadb969
fixerupper
tahoe Sep 21, 2017
8f82fd0
removed password
tahoe Sep 21, 2017
b4664b1
lets go
tahoe Sep 21, 2017
9e14cd6
relative imports
tahoe Sep 21, 2017
54c37ac
dick
tahoe Sep 21, 2017
351d50a
removed dist
tahoe Sep 21, 2017
668cb88
version update
tahoe Sep 21, 2017
a1b6960
fucking urllib2
tahoe Sep 21, 2017
a745e40
moar refactoring
tahoe Sep 21, 2017
dbb0409
last rel import fix
tahoe Sep 21, 2017
3dfc065
last rel import fix
tahoe Sep 21, 2017
9514491
at least globals call should work right?
tahoe Sep 21, 2017
84b33df
fixed dynamic rel imports
tahoe Sep 21, 2017
151e2df
not ready
tahoe Sep 22, 2017
e3f035a
doesn't like put
tahoe Sep 22, 2017
16f8b15
left some swp files
tahoe Sep 22, 2017
d781ff2
...
tahoe Sep 22, 2017
ab4d64a
removed Subscriber since it is just an alias for Contact and added in…
tahoe Sep 23, 2017
e95de1e
updated base class to not pass post_data if there wasn't any
tahoe Sep 23, 2017
da564e0
updated method returns to just return the request object rather than …
tahoe Sep 23, 2017
ac331d7
testing out some shorthand methods and calling super now on the paren…
tahoe Sep 25, 2017
0bc4073
moved shortcut commands to main object
tahoe Sep 25, 2017
241d700
mostly done for now
tahoe Sep 25, 2017
452a5cc
just some pep shit
tahoe Sep 25, 2017
4cf3b4d
shorter lines for split screen
tahoe Sep 25, 2017
13565c5
tags becomes tags since it's gonna be a string
tahoe Sep 26, 2017
261fd6d
tags becomes tag
tahoe Sep 26, 2017
5277ece
left out a few super() calls for __init__
tahoe Sep 27, 2017
a2615c1
removed self from super() call in the subclasses...
tahoe Oct 13, 2017
6dba909
Python 2.7 compatible super calls in constructors
tkrevh Mar 20, 2018
ecafe68
Revert "Python 2.7 compatible super calls in constructors"
tkrevh Mar 20, 2018
361494a
Python 2.7 compatible super calls in constructors
tkrevh Mar 20, 2018
af232a4
Fixed the base Connector class definition
tkrevh Mar 20, 2018
9304f4d
Merge pull request #1 from tkrevh/python2.7
tahoe Mar 20, 2018
696832e
tagged version 0.9.2
tahoe Mar 20, 2018
b215ae4
Update README.md
tahoe Jul 22, 2018
796db86
Update README.md
tahoe Jul 22, 2018
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
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
# Compiled Python Files
*.pyc
*.swp
dist/*
*.egg-info/
21 changes: 21 additions & 0 deletions LICENSE.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
The MIT License (MIT)

Copyright (c) 2014 Thomas Forbes

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
29 changes: 13 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,30 +1,27 @@
## Installation

You can install **active-campaign-python** by downloading the source.
You can install **active-campaign-python** from pypi

[Click here to download the source (.zip)](https://github.com/adulmec/active-campaign-python/zipball/master) which includes all dependencies.

`from includes.ActiveCampaign import ActiveCampaign`

Fill in your URL and API Key in the `includes/Config.py` file, and you are good to go!
`pip install active-campaign-python`

## Example Usage

### includes/Config.py
`from includes.Config import ACTIVECAMPAIGN_URL, ACTIVECAMPAIGN_API_KEY`

### examples.py

<pre>
from includes.ActiveCampaign import ActiveCampaign
from includes.Config import ACTIVECAMPAIGN_URL, ACTIVECAMPAIGN_API_KEY
from activecampaign import ActiveCampaign

# url provided to you by ActiveCampaign
base_url = '<your url>'
# api key provided to you by ActiveCampaign
api_key = '<your api_key>'

ac = ActiveCampaign(ACTIVECAMPAIGN_URL, ACTIVECAMPAIGN_API_KEY)
print ac.api('account/view')
ac = ActiveCampaign(base_url, api_key)
print(ac.api('account/view'))
</pre>

See our [examples file](https://github.com/adulmec/active-campaign-python/blob/master/examples.py) or the comments from files in **includes** folder for more in-depth samples.
Each of the endpoint subclasses have comments at the bottom

## Prerequisites

1. A valid ActiveCampaign **hosted** account (trial or paid).

## That is all for now
107 changes: 107 additions & 0 deletions activecampaign/Account.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
from .ActiveCampaign import (
ActiveCampaign,
fmt_params,
fmt_noparams
)
import requests as rq


class Account(ActiveCampaign):

def __init__(self, url, api_key):
self.url = url
self.api_key = api_key
super(Account, self).__init__(url, api_key)

def add(self, params, post_data={}):
rq_url = fmt_noparams(
self.url,
'account_add',
self.output
)
response = rq.post(rq_url, data=post_data)
return response

def cancel(self, params, post_data={}):
rq_url = fmt_params(
self.url,
'account_cancel',
self.output,
params
)
response = rq.get(rq_url)
return response

def edit(self, params, post_data={}):
rq_url = fmt_noparams(
self.url,
'account_edit',
self.output
)
response = rq.post(rq_url, data=post_data)
return response

def list_(self, params, post_data={}):
rq_url = fmt_params(
self.url,
'account_list',
self.output,
params
)
response = rq.get(rq_url)
return response

def name_check(self, params, post_data={}):
rq_url = fmt_params(
self.url,
'account_name_check',
self.output,
params
)
response = rq.get(rq_url)
return response

def plans(self, params, post_data={}):
rq_url = fmt_params(
self.url,
'account_plans',
self.output,
params
)
response = rq.get(rq_url)
return response

def status(self, params, post_data={}):
rq_url = fmt_params(
self.url,
'account_status',
self.output,
params
)
response = rq.get(rq_url)
return response

def status_set(self, params, post_data={}):
rq_url = fmt_params(
self.url,
'account_status_set',
self.output,
params
)
response = rq.get(rq_url)
return response

def view(self, params, post_data={}):
rq_url = fmt_noparams(
self.url,
'account_view',
self.output
)
response = rq.get(rq_url)
return response


"""
## view
#print ac.api('account/view')
"""
172 changes: 172 additions & 0 deletions activecampaign/ActiveCampaign.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,172 @@
from importlib import import_module
from .Connector import Connector

# formatters for making life easier, don't you want it that way?
fmt_params = '{}&api_action={}&api_output={}&{}'.format
fmt_noparams = '{}&api_action={}&api_output={}'.format


def get_mod(cls, parent):
source_module = import_module(".{}".format(cls), parent)
class1 = getattr(source_module, cls) # get Subscriber
return class1


class ActiveCampaign(Connector):

def __init__(self, url, api_key, api_user='', api_pass=''):
self.url = url
self.api_key = api_key
self.URL = url
self.APIKEY = api_key
super(ActiveCampaign, self).__init__(url, api_key, api_user, api_pass)

def api(self, path, post_data={}):
# IE: "contact/view"
components = path.split('/')
component = components[0]

if '?' in components[1]:
# query params appended to method
# IE: contact/edit?overwrite=0
method_arr = components[1].split('?')
method = method_arr[0]
params = method_arr[1]
else:
# just a method provided
# IE: "contact/view
if components[1]:
method = components[1]
params = ''
else:
return 'Invalid method.'

# adjustments
if component == 'branding':
# reserved word
component = 'design'
elif component == 'sync':
component = 'contact'
method = 'sync'
elif component == 'singlesignon':
component = 'auth'

# "contact" becomes "Contact"
class1 = '{}'.format(component.capitalize())
class1 = get_mod(class1, 'activecampaign')
class1 = class1(self.URL, self.APIKEY) # Subscriber()

if method == 'list':
# reserved word
method = 'list_'

if method in dir(class1):
if post_data:
return getattr(class1, method)(params, post_data)
else:
return getattr(class1, method)(params)
return None

# extra methods I created for shorthand scripting
# get
def _get_contact_by_id(self, cid=None):
"""Get a contact by ID

Arguments:
cid:str contact/subscriber ID
"""
response = self.api('contact/view?id={}'.format(cid))
return response

def _get_contact_by_email(self, email=None):
"""Get a contact by email

Arguments:
email:str contact/company Email
"""
response = self.api('contact/view?email={}'.format(email))
return response

# delete
def _delete_contact_by_id(self, cid=None):
"""Delete a contact/company

Arguments:
cid:str contact/susbscriber ID
"""
response = self.api('contact/delete?id={}'.format(cid))
return response

# create
def _create_contact(self, data=None):
"""Create a contact/company

Arguments:
data:dict proper definition of a contact dict
"""
response = self.api('contact/ad', post_data=data)
return response
# end contact section

# create
def _add_tags_by_id(self, cid=None, tag=None):
""" Add tags by id for company/contact

Arguments:
cid:str contact/susbscriber ID
tags:list(str) list of tags as strings
"""
response = self.api('contact/tag_add',
post_data={'id': cid, 'tags':tag})
return response

# delete
def _delete_tags_by_id(self, cid=None, tag=None):
""" Delete a tag by a contact/susbscriber ID

Arguments:
cid:str contact/susbscriber ID
tags:list(str) list of tags as strings
"""
response = self.api('contact/tag_remove',
post_data={'id': cid, 'tags':tag})
return response

def _add_note_by_id(self, cid=None, note=""):
""" Add a Note for a contact/company

Arguments:
cid:str contact/susbscriber ID
note:str a note
"""
data = {"id": cid, "note": note}
response = self.api('contact/note_add?id={}'.format(cid),
post_data=data)
return response

# delete
def _delete_note_by_id(self, nid=None):
""" Delete a note by a note ID

Arguments:
nid:str note ID to delete
"""
response = self.api('contact/note_delete?noteid={}'.format(nid))
return response
# end contact components (properties, tags...)

# list contacts
def _list_contacts(self):
"""List all contacts

"""
response = self.api('contact/list?ids=all')
return response

# list organizations, not very usefull but still
def _list_orgs(self):
"""List all organizations

"""
response = self.api('organization/list')
return response
Loading