From dadb96905b647a0b7d6bf376079137c98b698c26 Mon Sep 17 00:00:00 2001 From: Dennis Durling Date: Thu, 21 Sep 2017 10:15:14 -0700 Subject: [PATCH 01/36] fixerupper --- README.md | 26 ++--- {includes => activecampaign}/Account.py | 9 +- .../ActiveCampaign.py | 6 +- {includes => activecampaign}/Campaign.py | 3 +- {includes => activecampaign}/Connector.py | 3 +- activecampaign/Contact.py | 107 ++++++++++++++++++ {includes => activecampaign}/Design.py | 3 +- {includes => activecampaign}/Form.py | 3 +- {includes => activecampaign}/Group.py | 4 +- {includes => activecampaign}/List.py | 7 +- {includes => activecampaign}/Message.py | 4 +- {includes => activecampaign}/Subscriber.py | 4 +- {includes => activecampaign}/User.py | 4 +- activecampaign/__init__.py | 1 + examples.py | 26 ++--- includes/Config.py | 3 - includes/__init__.py | 0 setup.py | 2 + 18 files changed, 152 insertions(+), 63 deletions(-) rename {includes => activecampaign}/Account.py (92%) rename {includes => activecampaign}/ActiveCampaign.py (91%) rename {includes => activecampaign}/Campaign.py (99%) rename {includes => activecampaign}/Connector.py (94%) create mode 100644 activecampaign/Contact.py rename {includes => activecampaign}/Design.py (95%) rename {includes => activecampaign}/Form.py (94%) rename {includes => activecampaign}/Group.py (97%) rename {includes => activecampaign}/List.py (96%) rename {includes => activecampaign}/Message.py (99%) rename {includes => activecampaign}/Subscriber.py (98%) rename {includes => activecampaign}/User.py (98%) create mode 100644 activecampaign/__init__.py delete mode 100644 includes/Config.py delete mode 100644 includes/__init__.py create mode 100644 setup.py diff --git a/README.md b/README.md index b8249d1..440a66c 100644 --- a/README.md +++ b/README.md @@ -1,29 +1,25 @@ ## 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` +
+from activecampaign import ActiveCampaign
 
-### examples.py
+# url provided to you by ActiveCampaign
+base_url = ''
+# api key provided to you by ActiveCampaign
+api_key = ''
 
-
-from includes.ActiveCampaign import ActiveCampaign
-from includes.Config import ACTIVECAMPAIGN_URL, ACTIVECAMPAIGN_API_KEY
+ac = ActiveCampaign(base_url,  api_key)
+print(ac.api('account/view'))
 
-ac = ActiveCampaign(ACTIVECAMPAIGN_URL, ACTIVECAMPAIGN_API_KEY)
-print ac.api('account/view')
 
-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 diff --git a/includes/Account.py b/activecampaign/Account.py similarity index 92% rename from includes/Account.py rename to activecampaign/Account.py index 3ba001e..fc253be 100644 --- a/includes/Account.py +++ b/activecampaign/Account.py @@ -1,5 +1,3 @@ - -from Config import ACTIVECAMPAIGN_URL, ACTIVECAMPAIGN_API_KEY from ActiveCampaign import ActiveCampaign import json import urllib2, urllib @@ -58,9 +56,8 @@ def view(self, params, post_data = {}): response = json.loads(urllib2.urlopen(request_url).read()) return response - -if __name__ == '__main__': - ac = ActiveCampaign(ACTIVECAMPAIGN_URL, ACTIVECAMPAIGN_API_KEY) +""" ## view - #print ac.api('account/view') \ No newline at end of file + #print ac.api('account/view') +""" diff --git a/includes/ActiveCampaign.py b/activecampaign/ActiveCampaign.py similarity index 91% rename from includes/ActiveCampaign.py rename to activecampaign/ActiveCampaign.py index f28cfd2..6a1ba08 100644 --- a/includes/ActiveCampaign.py +++ b/activecampaign/ActiveCampaign.py @@ -1,5 +1,3 @@ - -from Config import ACTIVECAMPAIGN_URL, ACTIVECAMPAIGN_API_KEY from Connector import Connector class ActiveCampaign(Connector): @@ -7,6 +5,8 @@ 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 Connector.__init__(self, url, api_key, api_user, api_pass) def api(self, path, post_data = {}): @@ -42,7 +42,7 @@ def api(self, path, post_data = {}): class1 = '%s' % component.capitalize() # IE: "subscriber" becomes "Subscriber" source_module = __import__(class1, globals(), locals(), [], -1) # import Subscriber class1 = getattr(source_module, class1) # get Subscriber - class1 = class1(ACTIVECAMPAIGN_URL, ACTIVECAMPAIGN_API_KEY) # Subscriber() + class1 = class1(self.URL, self.APIKEY) # Subscriber() # subscriber.view() if method == 'list': diff --git a/includes/Campaign.py b/activecampaign/Campaign.py similarity index 99% rename from includes/Campaign.py rename to activecampaign/Campaign.py index f296738..f2a0d8d 100644 --- a/includes/Campaign.py +++ b/activecampaign/Campaign.py @@ -1,4 +1,3 @@ -from Config import ACTIVECAMPAIGN_URL, ACTIVECAMPAIGN_API_KEY from ActiveCampaign import ActiveCampaign import simplejson as json import urllib2, urllib @@ -108,6 +107,7 @@ def status(self, params, post_data = {}): response = json.loads(urllib2.urlopen(request_url).read()) return response +""" if __name__ == '__main__': ac = ActiveCampaign(ACTIVECAMPAIGN_URL, ACTIVECAMPAIGN_API_KEY) @@ -184,3 +184,4 @@ def status(self, params, post_data = {}): ## report_status ## print ac.api('campaign/status?id=13&status=5') +""" diff --git a/includes/Connector.py b/activecampaign/Connector.py similarity index 94% rename from includes/Connector.py rename to activecampaign/Connector.py index dce70e4..c127c1a 100644 --- a/includes/Connector.py +++ b/activecampaign/Connector.py @@ -1,5 +1,4 @@ import json -from Config import ACTIVECAMPAIGN_URL, ACTIVECAMPAIGN_API_KEY import urllib2 class Connector(): @@ -26,6 +25,8 @@ def credentials_test(self): jdata = json.loads(urllib2.urlopen(test_url).read()) return jdata['result_code'] == 1 +""" if __name__ == '__main__': c = Connector(ACTIVECAMPAIGN_URL, ACTIVECAMPAIGN_API_KEY) print c.credentials_test() +""" diff --git a/activecampaign/Contact.py b/activecampaign/Contact.py new file mode 100644 index 0000000..0278466 --- /dev/null +++ b/activecampaign/Contact.py @@ -0,0 +1,107 @@ +from ActiveCampaign import ActiveCampaign +import json +import urllib2, urllib + +class Contact(ActiveCampaign): + + def __init__(self, url, api_key): + self.url = url + self.api_key = api_key + ActiveCampaign.__init__(self, url, api_key) + + def add(self, params, post_data): + request_url = '%s&api_action=contact_add&api_output=%s' % (self.url, self.output) + post_data = urllib.urlencode(post_data) + req = urllib2.Request(request_url, post_data) + response = json.loads(urllib2.urlopen(req).read()) + return response + + def delete_list(self, params, post_data = {}): + request_url = '%s&api_action=contact_delete_list&api_output=%s&%s' % (self.url, self.output, params) + response = json.loads(urllib2.urlopen(request_url).read()) + return response + + def delete(self, params, post_data = {}): + request_url = '%s&api_action=contact_delete&api_output=%s&%s' % (self.url, self.output, params) + response = json.loads(urllib2.urlopen(request_url).read()) + return response + + def edit(self, params, post_data): + request_url = '%s&api_action=contact_edit&api_output=%s' % (self.url, self.output) + post_data = urllib.urlencode(post_data) + req = urllib2.Request(request_url, post_data) + response = json.loads(urllib2.urlopen(req).read()) + return response + + def list_(self, params, post_data = {}): + request_url = '%s&api_action=contact_list&api_output=%s&%s' % (self.url, self.output, params) + response = json.loads(urllib2.urlopen(request_url).read()) + return response + + def me(self, params, post_data = {}): + request_url = '%s&api_action=contact_me&api_output=%s' % (self.url, self.output) + response = json.loads(urllib2.urlopen(request_url).read()) + return response + + def view(self, params, post_data = {}): + if params.startswith('email='): + action = 'contact_view_email' + elif params.startswith('hash='): + action = 'contact_view_hash' + elif params.startswith('id='): + action = 'contact_view' + request_url = '%s&api_action=%s&api_output=%s&%s' % (self.url, action, self.output, params) + response = json.loads(urllib2.urlopen(request_url).read()) + return response + +""" +if __name__ == '__main__': + ac = ActiveCampaign(ACTIVECAMPAIGN_URL, ACTIVECAMPAIGN_API_KEY) + + ## add +## user = { +## 'username': 'johnsmith', +## 'first_name': 'John', +## 'last_name': 'Smith', +## 'password': 'mypwd', +## 'password_r': 'mypwd', +## 'email': 'person@example.com', +## 'group[3]' : 3 +## } +## print ac.api('user/add', user) + + ## delete_list +## print ac.api('user/delete_list?ids=3,4') + + ## delete +## print ac.api('user/delete?id=5') + + ## edit +## user = { +## 'username': 'johnsmith', +## 'first_name': 'John', +## 'last_name': 'Smyth', +## 'password': 'mynwqpwd', +## 'password_r': 'mynewpwd', +## 'email': 'person@example.com', +## 'group[3]' : 3, +## 'id' : 6 +## } +## print ac.api('user/edit', user) + + ## list +## print ac.api('user/list?ids=1,6') + + ## me +## print ac.api('user/me') + + ## view email +## print ac.api('user/view?email=person@example.com') + + ## view username +## print ac.api('user/view?username=johnsmith') + + ## view id +## print ac.api('user/view?id=1') + +""" diff --git a/includes/Design.py b/activecampaign/Design.py similarity index 95% rename from includes/Design.py rename to activecampaign/Design.py index 3410b83..ccb1106 100644 --- a/includes/Design.py +++ b/activecampaign/Design.py @@ -1,4 +1,3 @@ -from Config import ACTIVECAMPAIGN_URL, ACTIVECAMPAIGN_API_KEY from ActiveCampaign import ActiveCampaign import json import urllib2, urllib @@ -22,6 +21,7 @@ def view(self, params, post_data): response = json.loads(urllib2.urlopen(request_url).read()) return response +""" if __name__ == '__main__': ac = ActiveCampaign(ACTIVECAMPAIGN_URL, ACTIVECAMPAIGN_API_KEY) @@ -44,3 +44,4 @@ def view(self, params, post_data): ## view print ac.api('branding/view') +""" diff --git a/includes/Form.py b/activecampaign/Form.py similarity index 94% rename from includes/Form.py rename to activecampaign/Form.py index 0e16f9d..4a932c2 100644 --- a/includes/Form.py +++ b/activecampaign/Form.py @@ -1,4 +1,3 @@ -from Config import ACTIVECAMPAIGN_URL, ACTIVECAMPAIGN_API_KEY from ActiveCampaign import ActiveCampaign import json import urllib2, urllib @@ -21,6 +20,7 @@ def html(self, params, post_data = {}): response = json.loads(urllib2.urlopen(request_url).read()) return response +""" if __name__ == '__main__': ac = ActiveCampaign(ACTIVECAMPAIGN_URL, ACTIVECAMPAIGN_API_KEY) @@ -29,3 +29,4 @@ def html(self, params, post_data = {}): ## html #print ac.api('form/html?id=1142') +""" diff --git a/includes/Group.py b/activecampaign/Group.py similarity index 97% rename from includes/Group.py rename to activecampaign/Group.py index d9d9751..524634e 100644 --- a/includes/Group.py +++ b/activecampaign/Group.py @@ -1,5 +1,3 @@ - -from Config import ACTIVECAMPAIGN_URL, ACTIVECAMPAIGN_API_KEY from ActiveCampaign import ActiveCampaign import json import urllib2, urllib @@ -45,6 +43,7 @@ def view(self, params, post_data = {}): response = json.loads(urllib2.urlopen(request_url).read()) return response +""" if __name__ == '__main__': ac = ActiveCampaign(ACTIVECAMPAIGN_URL, ACTIVECAMPAIGN_API_KEY) @@ -77,3 +76,4 @@ def view(self, params, post_data = {}): ## view #print ac.api('group/view?id=7') +""" diff --git a/includes/List.py b/activecampaign/List.py similarity index 96% rename from includes/List.py rename to activecampaign/List.py index 4267324..f14f245 100644 --- a/includes/List.py +++ b/activecampaign/List.py @@ -1,5 +1,3 @@ - -from Config import ACTIVECAMPAIGN_URL, ACTIVECAMPAIGN_API_KEY from ActiveCampaign import ActiveCampaign import json import urllib2, urllib @@ -74,9 +72,7 @@ def view(self, params, post_data = {}): response = json.loads(urllib2.urlopen(request_url).read()) return response -if __name__ == '__main__': - ac = ActiveCampaign(ACTIVECAMPAIGN_URL, ACTIVECAMPAIGN_API_KEY) - +""" ## add #list1 = { # 'name': 'The List', @@ -145,3 +141,4 @@ def view(self, params, post_data = {}): ## view #print ac.api('list/view?id=1') +""" diff --git a/includes/Message.py b/activecampaign/Message.py similarity index 99% rename from includes/Message.py rename to activecampaign/Message.py index 9eec401..6f625a9 100644 --- a/includes/Message.py +++ b/activecampaign/Message.py @@ -1,5 +1,3 @@ - -from Config import ACTIVECAMPAIGN_URL, ACTIVECAMPAIGN_API_KEY from ActiveCampaign import ActiveCampaign import json import urllib2, urllib @@ -93,6 +91,7 @@ def view(self, params, post_data = {}): return response +""" if __name__ == '__main__': ac = ActiveCampaign(ACTIVECAMPAIGN_URL, ACTIVECAMPAIGN_API_KEY) @@ -188,3 +187,4 @@ def view(self, params, post_data = {}): ## template_list ## print ac.api('message/template_list?ids=76') +""" diff --git a/includes/Subscriber.py b/activecampaign/Subscriber.py similarity index 98% rename from includes/Subscriber.py rename to activecampaign/Subscriber.py index 3cce8f3..1c26dad 100644 --- a/includes/Subscriber.py +++ b/activecampaign/Subscriber.py @@ -1,5 +1,3 @@ - -from Config import ACTIVECAMPAIGN_URL, ACTIVECAMPAIGN_API_KEY from ActiveCampaign import ActiveCampaign import json import urllib2, urllib @@ -69,6 +67,7 @@ def view(self, params, post_data = {}): response = json.loads(urllib2.urlopen(request_url).read()) return response +""" if __name__ == '__main__': ac = ActiveCampaign(ACTIVECAMPAIGN_URL, ACTIVECAMPAIGN_API_KEY) @@ -124,3 +123,4 @@ def view(self, params, post_data = {}): ## view hash ## print ac.api('subscriber/view?hash=3eeda4735e93f5407fced5ed45ddae82') +""" diff --git a/includes/User.py b/activecampaign/User.py similarity index 98% rename from includes/User.py rename to activecampaign/User.py index 72a4e9b..9d4eb75 100644 --- a/includes/User.py +++ b/activecampaign/User.py @@ -1,5 +1,3 @@ - -from Config import ACTIVECAMPAIGN_URL, ACTIVECAMPAIGN_API_KEY from ActiveCampaign import ActiveCampaign import json import urllib2, urllib @@ -56,6 +54,7 @@ def view(self, params, post_data = {}): response = json.loads(urllib2.urlopen(request_url).read()) return response +""" if __name__ == '__main__': ac = ActiveCampaign(ACTIVECAMPAIGN_URL, ACTIVECAMPAIGN_API_KEY) @@ -105,3 +104,4 @@ def view(self, params, post_data = {}): ## view id ## print ac.api('user/view?id=1') +""" diff --git a/activecampaign/__init__.py b/activecampaign/__init__.py new file mode 100644 index 0000000..2501648 --- /dev/null +++ b/activecampaign/__init__.py @@ -0,0 +1 @@ +from ActiveCampaign import ActiveCampaign diff --git a/examples.py b/examples.py index 756223a..99f5adc 100644 --- a/examples.py +++ b/examples.py @@ -1,22 +1,10 @@ -from includes.ActiveCampaign import ActiveCampaign -from includes.Config import ACTIVECAMPAIGN_URL, ACTIVECAMPAIGN_API_KEY +from activecampaign import ActiveCampaign -if __name__ == '__main__': - ac = ActiveCampaign(ACTIVECAMPAIGN_URL, ACTIVECAMPAIGN_API_KEY) +# url provided to you by ActiveCampaign +base_url = '' +# api key provided to you by ActiveCampaign +api_key = '' - ## delete subscriber - #print ac.api('subscriber/delete?id=10') +ac = ActiveCampaign(base_url, api_key) +print(ac.api('account/view')) - ## delete_list - #print ac.api('subscriber/delete_list?ids=9,11') - - # edit subscriber - subscriber = { - 'id': 12, - 'email': 'person@example.com', - 'first_name': 'John', - 'last_name': 'Smith', - 'p[1]': 1, - 'status[1]': 1, - } - print ac.api('subscriber/edit', subscriber) diff --git a/includes/Config.py b/includes/Config.py deleted file mode 100644 index d222caf..0000000 --- a/includes/Config.py +++ /dev/null @@ -1,3 +0,0 @@ - -ACTIVECAMPAIGN_URL = 'YOUR_ACTIVECAMPAIGN_URL' -ACTIVECAMPAIGN_API_KEY = 'YOUR_ACTIVECAMPAIGN_API_KEY' diff --git a/includes/__init__.py b/includes/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/setup.py b/setup.py new file mode 100644 index 0000000..b2e90ef --- /dev/null +++ b/setup.py @@ -0,0 +1,2 @@ +simplejson==3.11.1 +ipython>=5.0.0 From 8f82fd0c953962458d94602e4c476fa0358a72ef Mon Sep 17 00:00:00 2001 From: Dennis Durling Date: Thu, 21 Sep 2017 11:46:53 -0700 Subject: [PATCH 02/36] removed password --- .coveralls.yml | 1 + .travis.yml | 13 +++ LICENSE.txt | 21 ++++ readme.rst | 87 ++++++++++++++ setup.py | 45 +++++++- setup.py.bk | 53 +++++++++ tests/__init__.py | 1 + tests/models.py | 29 +++++ tests/test_basic.py | 250 ++++++++++++++++++++++++++++++++++++++++ travis_requirements.txt | 9 ++ 10 files changed, 507 insertions(+), 2 deletions(-) create mode 100644 .coveralls.yml create mode 100644 .travis.yml create mode 100644 LICENSE.txt create mode 100644 readme.rst create mode 100644 setup.py.bk create mode 100644 tests/__init__.py create mode 100644 tests/models.py create mode 100644 tests/test_basic.py create mode 100644 travis_requirements.txt diff --git a/.coveralls.yml b/.coveralls.yml new file mode 100644 index 0000000..8b7d458 --- /dev/null +++ b/.coveralls.yml @@ -0,0 +1 @@ +repo_token: trDaz6JVs4lTsjkVGDZiWXoNn76tkBvok \ No newline at end of file diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..6ca7591 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,13 @@ +language: python +python: +- '2.7' +- '3.3' +- '3.4' +- '3.5' +- pypy +- pypy3 +install: +- pip install -r travis_requirements.txt +- python setup.py install +script: coverage run --source=datatables -m pytest -v +after_success: coveralls diff --git a/LICENSE.txt b/LICENSE.txt new file mode 100644 index 0000000..c838777 --- /dev/null +++ b/LICENSE.txt @@ -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. diff --git a/readme.rst b/readme.rst new file mode 100644 index 0000000..6550add --- /dev/null +++ b/readme.rst @@ -0,0 +1,87 @@ + +==================== +Flask-restful only version of orf/datatables with Flask-restless style filtering +==================== + +Additional Functionality +------------ +One thing I needed to do so that this would support our needs internally is +to support arbitrary join depth to be able to do search and sort functionality +on the results. With Orf's version, I was only able to order by or search on 2 +levels deep of a query result. Now that level is arbitrary such that you can +provide a column on say a Subnet table that is associated with a location +through relations like subnet.vlan.switch.rack.location and make the location name +filterable AND orderable with just "vlan__switch__rack__location__name" + +Installation +------------ + +The package is available on PyPI and is passing tests on Python 2.7, 3.3 and 3.4 +Working on getting this on PyPI + +.. code-block:: bash + + pip install flask_datatables + +Usage +----- + + +This is SUPER simple. In datatables I provide a function called get_resource that can be used to create a +datatables api endpoint with full flask-restless style filtering built in. + + +Additional data such as hyperlinks can be added via DataTable.add_data, which accepts a callable that is called for +each instance. Check out the usage example below for more info. + + +Example +------- + +**models.py** + +.. code-block:: python + + class User(Base): + __tablename__ = 'users' + + id = Column(Integer, primary_key=True) + full_name = Column(Text) + created_at = Column(DateTime, default=datetime.datetime.utcnow) + + + + class Address(Base): + __tablename__ = 'addresses' + + id = Column(Integer, primary_key=True) + description = Column(Text) + user_id = Column(Integer, ForeignKey('users.id')) + + user = relationship("User", backref=backref("address", uselist=False)) + + def __repr__(self): + return "{}".format(self.description) + + +**api.py** + +.. code-block:: python + + from model import Session, User, Address + from datatables import * + + app = Flask(__name__) + api = Api(app) + # add User resource + resource, path, endpoint = get_resource(Resource, User, Session, basepath="/") + api.add_resource(resource, path, endpoint=endpoint) + + # add Address resource + resource, path, endpoint = get_resource(Resource, Address, Session, basepath="/") + api.add_resource(resource, path, endpoint=endpoint) + + if __name__ == '__main__': + app.run(host='127.0.0.1', port=5001, debug=True) + + diff --git a/setup.py b/setup.py index b2e90ef..0c617c0 100644 --- a/setup.py +++ b/setup.py @@ -1,2 +1,43 @@ -simplejson==3.11.1 -ipython>=5.0.0 +from setuptools import setup +import os + +desc = open("readme.rst").read() if os.path.isfile("readme.rst") else "" + + +setup( + name='flask_datatables', + version='0.6.17', + packages=['flask_datatables', 'flask_datatables.views'], + url='https://github.com/tahoe/flask_datatables/', + download_url='https://github.com/tahoe/flask_datatables/tarball/0.6.15', + license='MIT', + long_description=desc, + keywords='datatables sqlalchemy flask', + author='Dennis Durling', + author_email='djdtahoe@gmail.com', + description='Integrates SQLAlchemy with DataTables (framework Flask)', + zip_safe=False, + include_package_data=True, + classifiers=[ + 'Environment :: Web Environment', + 'Framework :: Flask', + 'Intended Audience :: Developers', + 'License :: OSI Approved :: MIT License', + 'Programming Language :: Python', + 'Programming Language :: Python :: 2.7', + 'Programming Language :: Python :: 3.3', + 'Programming Language :: Python :: 3.4', + 'Programming Language :: Python :: 3.5', + 'Topic :: Internet :: WWW/HTTP', + 'Topic :: Software Development :: Libraries', + 'Topic :: Software Development :: Libraries :: Python Modules', + ], + install_requires=[ + 'querystring_parser==1.2.3', + 'sqlalchemy>=1.0.11', + 'flask==0.10.1', + 'flask-restful>=0.3.5', + 'Faker==0.7.12', + ], +) + diff --git a/setup.py.bk b/setup.py.bk new file mode 100644 index 0000000..ef8046d --- /dev/null +++ b/setup.py.bk @@ -0,0 +1,53 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + + +try: + from setuptools import setup +except ImportError: + from distutils.core import setup + + +with open('README.rst') as readme_file: + readme = readme_file.read() + +requirements = [ + 'requests' +] + +test_requirements = [ + # none yet +] + +setup( + name='active-campaign-python', + version='0.5.0', + description="Python ActiveCampaign API client", + long_description=readme, + author="Dennis Durling", + author_email='djdtahoe@gmail.com', + url='https://github.com/tahoe/active-campaign-python', + packages=[ + 'activecampaign', + ], + package_dir={'activecampaign': + 'activecampaign'}, + include_package_data=True, + install_requires=requirements, + license="BSD", + zip_safe=False, + keywords='activecampaign', + classifiers=[ + 'Intended Audience :: Developers', + 'License :: OSI Approved :: BSD License', + 'Natural Language :: English', + "Programming Language :: Python :: 2", + 'Programming Language :: Python :: 2.7', + 'Programming Language :: Python :: 3', + 'Programming Language :: Python :: 3.3', + 'Programming Language :: Python :: 3.4', + 'Programming Language :: Python :: 3.5', + ], + test_suite='tests', + tests_require=test_requirements +) diff --git a/tests/__init__.py b/tests/__init__.py new file mode 100644 index 0000000..68190aa --- /dev/null +++ b/tests/__init__.py @@ -0,0 +1 @@ +__author__ = 'dennis' diff --git a/tests/models.py b/tests/models.py new file mode 100644 index 0000000..daf61dd --- /dev/null +++ b/tests/models.py @@ -0,0 +1,29 @@ +import datetime + +from sqlalchemy.ext.declarative import declarative_base +from sqlalchemy import Column, Integer, Text, DateTime, ForeignKey, create_engine +from sqlalchemy.orm import relationship, sessionmaker, backref + +Base = declarative_base() + + +class User(Base): + __tablename__ = 'users' + + id = Column(Integer, primary_key=True) + full_name = Column(Text) + created_at = Column(DateTime, default=datetime.datetime.utcnow) + + + +class Address(Base): + __tablename__ = 'addresses' + + id = Column(Integer, primary_key=True) + description = Column(Text) + user_id = Column(Integer, ForeignKey('users.id')) + + user = relationship("User", backref=backref("address", uselist=False)) + + def __repr__(self): + return "{}".format(self.description) diff --git a/tests/test_basic.py b/tests/test_basic.py new file mode 100644 index 0000000..f6ce2d3 --- /dev/null +++ b/tests/test_basic.py @@ -0,0 +1,250 @@ +from sqlalchemy import create_engine +from sqlalchemy.orm import sessionmaker +import faker +from querystring_parser import parser +import json +from .models import * +from flask_datatables import * +import os + + +class TestDataTables: + def setup_method(self, method): + if os.path.isfile('testdb.db'): + os.unlink('testdb.db') + engine = create_engine('sqlite:///testdb.db', echo=True) + Base.metadata.create_all(engine) + Session = sessionmaker(bind=engine) + + self.session = Session() + + # initialize DB with 10 fake items + if not self.session.query(User).all(): + self.make_data(10) + + def make_data(self, user_count): + f = faker.Faker() + users = [] + + for i in range(user_count): + user, addr = self.make_user(f.name(), f.street_address()) + users.append(user) + + self.session.add_all(users) + self.session.commit() + + def make_user(self, name, address): + addr = Address() + addr.description = address + + u = User() + u.full_name = name + u.address = addr + + return u, addr + + def make_params_str(self, order=None, search=None, start=0, length=10, urlfilter=None, + columns=("id", "name", "address")): + x = { + "draw": "1", + "search[value]": "", + "search[regex]": "false", + "order[0][column]": "1", + "order[0][dir]": "asc", + "start": str(start), + "length": str(length) + } + + for i, item in enumerate(columns): + b = "columns[{}]".format(i) + x[b + "[data]"] = item + x[b + "[name]"] = "" + x[b + "[searchable]"] = "true" + x[b + "[orderable]"] = "true" + x[b + "[search][value]"] = "" + x[b + "[search][regex]"] = "false" + + for i, item in enumerate(order or []): + for key, value in item.items(): + x["order[{}][{}]".format(i, key)] = str(value) + + if search: + for key, value in search.items(): + x["search[{}]".format(key)] = str(value) + + # this mimics an actual request + y = "" + if urlfilter: + y += "q={}&".format(urlfilter) + y += "{}={}&".format('draw', x['draw']) + y += "&".join("{}={}".format(k, v) for k, v in x.items() if k != 'draw') + + return y + + def make_params(self, **kwargs): + y = self.make_params_str(**kwargs) + # use parser to parse the request into a dict we can use in DataTable + return parser.parse(y) + + + + def test_basic_function(self): + req = self.make_params() + + table = DataTable(req, User, self.session.query(User), [ + "id", + ("name", "full_name"), + ("address", "address.description"), + ]) + + x = table.json() + + assert len(x["data"]) == 10 + + def test_relation_ordering(self): + u1, addr_asc = self.make_user("SomeUser", "0" * 15) + u2, addr_desc = self.make_user("SomeOtherUser", "z" * 15) + self.session.add_all((u1, u2)) + self.session.commit() + + req = self.make_params(order=[{"column": 2, "dir": "desc"}]) + table = DataTable(req, + User, + self.session.query(User), + [ + "id", + ("name", "full_name"), + ("address", "address.description") + ]) + result = table.json() + assert result["data"][0]["address"] == addr_desc.description + + req = self.make_params(order=[{"column": 2, "dir": "asc"}]) + table = DataTable(req, + User, + self.session.query(User), + [ + "id", + ("name", "full_name"), + ("address", "address.description") + ]) + result = table.json() + assert result["data"][0]["address"] == addr_asc.description + + def test_relation_urlfilter(self): + """ This tests the flask-restless integrated filtering + In this test case we are filtering on a relationship. + Look at filtering in flask-restless documentation for more + filter options + """ + u1, addr_a = self.make_user("userOne", "a") + u2, addr_b = self.make_user("userTwo", "b") + self.session.add_all((u1, u2)) + self.session.commit() + + # create a filter (flask-restless style, key will be 'q', set in the make_params function + urlfilter = json.dumps({"filters":[{"name": "address__description", "op": "has", "val": "a"}]}) + + # this is a fake request as we pretend to have gotten from datatables js + req = self.make_params(urlfilter=urlfilter) + + # if q is in the request.keys() we do the resltess filtering on the query + if 'q' in req.keys(): + query = views.search(self.session, User, req) + + # build the datatable with the query + table = DataTable(req, User, query, [ + "id", + ("name", "full_name"), + ("address", "address.description") + ]) + + # get result + result = table.json() + assert result["data"][0]["address"] == addr_a.description + assert len(result["data"]) == 1 + + # same for b + urlfilter = json.dumps({"filters":[{"name": "address__description", "op": "has", "val": "b"}]}) + req = self.make_params(urlfilter=urlfilter) + if 'q' in req.keys(): + query = views.search(self.session, User, req) + + table = DataTable(req, User, query, [ + "id", + ("name", "full_name"), + ("address", "address.description") + ]) + result = table.json() + assert result["data"][0]["address"] == addr_b.description + assert len(result["data"]) == 1 + + + def test_error(self): + """ make sure we are able to capture failures... """ + req = self.make_params() + req["start"] = "invalid" + + table = DataTable(req, + User, + self.session.query(User), + ["id"]) + assert "error" in table.json() + + req = self.make_params() + del req["start"] + + table = DataTable(req, + User, + self.session.query(User), + ["id"]) + assert "error" in table.json() + + + def test_search(self): + """ Test the basic search functionality. + This method is not required but here to show that it works + The main search/filter method is to use the ?q={"filters":[...]} + method from flask-restless that I have incorporated which + provides much more flexibility in searching deep relations + """ + user, addr = self.make_user("Silly Sally", "Silly Sally Road") + user2, addr2 = self.make_user("Silly Billy", "Silly Billy Road") + self.session.add_all((user, user2)) + self.session.commit() + + req = self.make_params(search={ + "value": "Silly Sally" + }) + + table = DataTable(req, User, self.session.query(User), [("name", "full_name")]) + results = table.json() + assert len(results["data"]) == 1 + + req = self.make_params(search={ + "value": "Silly" + }) + + table = DataTable(req, User, self.session.query(User), [("name", "full_name")]) + results = table.json() + assert len(results["data"]) == 2 + + + def test_datatables(self): + """ Test the datatables function get_resource """ + import flask_restful as rest + from flask import current_app, Flask + app = current_app or Flask('test') + api = rest.Api(app) + + Resource, path, endpoint = get_resource(rest.Resource, User, self.session, basepath='/api/') + api.add_resource(Resource, path, endpoint=endpoint) + + client = app.test_client() + params = self.make_params_str(columns=('id', 'full_name', 'created_at')) + response = client.get('/api/users?%s' % params) + assert response.status_code == 200 + + str_response = response.data.decode('utf-8') + obj = json.loads(str_response) + assert len(obj['data']) == 10 diff --git a/travis_requirements.txt b/travis_requirements.txt new file mode 100644 index 0000000..99d6efd --- /dev/null +++ b/travis_requirements.txt @@ -0,0 +1,9 @@ +flask +flask-restful +querystring_parser +sqlalchemy +coverage==3.7.1 +sqlalchemy_utils +pytest +fake-factory +coveralls From b4664b101c9d298d15e6627e5650781ea6199741 Mon Sep 17 00:00:00 2001 From: Dennis Durling Date: Thu, 21 Sep 2017 12:00:06 -0700 Subject: [PATCH 03/36] lets go --- .coveralls.yml | 1 - .travis.yml | 13 --- readme.rst | 87 -------------- setup.py | 64 +++++----- setup.py.bk | 53 --------- tests/__init__.py | 1 - tests/models.py | 29 ----- tests/test_basic.py | 250 ---------------------------------------- travis_requirements.txt | 9 -- 9 files changed, 35 insertions(+), 472 deletions(-) delete mode 100644 .coveralls.yml delete mode 100644 .travis.yml delete mode 100644 readme.rst delete mode 100644 setup.py.bk delete mode 100644 tests/__init__.py delete mode 100644 tests/models.py delete mode 100644 tests/test_basic.py delete mode 100644 travis_requirements.txt diff --git a/.coveralls.yml b/.coveralls.yml deleted file mode 100644 index 8b7d458..0000000 --- a/.coveralls.yml +++ /dev/null @@ -1 +0,0 @@ -repo_token: trDaz6JVs4lTsjkVGDZiWXoNn76tkBvok \ No newline at end of file diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 6ca7591..0000000 --- a/.travis.yml +++ /dev/null @@ -1,13 +0,0 @@ -language: python -python: -- '2.7' -- '3.3' -- '3.4' -- '3.5' -- pypy -- pypy3 -install: -- pip install -r travis_requirements.txt -- python setup.py install -script: coverage run --source=datatables -m pytest -v -after_success: coveralls diff --git a/readme.rst b/readme.rst deleted file mode 100644 index 6550add..0000000 --- a/readme.rst +++ /dev/null @@ -1,87 +0,0 @@ - -==================== -Flask-restful only version of orf/datatables with Flask-restless style filtering -==================== - -Additional Functionality ------------- -One thing I needed to do so that this would support our needs internally is -to support arbitrary join depth to be able to do search and sort functionality -on the results. With Orf's version, I was only able to order by or search on 2 -levels deep of a query result. Now that level is arbitrary such that you can -provide a column on say a Subnet table that is associated with a location -through relations like subnet.vlan.switch.rack.location and make the location name -filterable AND orderable with just "vlan__switch__rack__location__name" - -Installation ------------- - -The package is available on PyPI and is passing tests on Python 2.7, 3.3 and 3.4 -Working on getting this on PyPI - -.. code-block:: bash - - pip install flask_datatables - -Usage ------ - - -This is SUPER simple. In datatables I provide a function called get_resource that can be used to create a -datatables api endpoint with full flask-restless style filtering built in. - - -Additional data such as hyperlinks can be added via DataTable.add_data, which accepts a callable that is called for -each instance. Check out the usage example below for more info. - - -Example -------- - -**models.py** - -.. code-block:: python - - class User(Base): - __tablename__ = 'users' - - id = Column(Integer, primary_key=True) - full_name = Column(Text) - created_at = Column(DateTime, default=datetime.datetime.utcnow) - - - - class Address(Base): - __tablename__ = 'addresses' - - id = Column(Integer, primary_key=True) - description = Column(Text) - user_id = Column(Integer, ForeignKey('users.id')) - - user = relationship("User", backref=backref("address", uselist=False)) - - def __repr__(self): - return "{}".format(self.description) - - -**api.py** - -.. code-block:: python - - from model import Session, User, Address - from datatables import * - - app = Flask(__name__) - api = Api(app) - # add User resource - resource, path, endpoint = get_resource(Resource, User, Session, basepath="/") - api.add_resource(resource, path, endpoint=endpoint) - - # add Address resource - resource, path, endpoint = get_resource(Resource, Address, Session, basepath="/") - api.add_resource(resource, path, endpoint=endpoint) - - if __name__ == '__main__': - app.run(host='127.0.0.1', port=5001, debug=True) - - diff --git a/setup.py b/setup.py index 0c617c0..526ab97 100644 --- a/setup.py +++ b/setup.py @@ -1,43 +1,49 @@ -from setuptools import setup -import os +#!/usr/bin/env python +# -*- coding: utf-8 -*- -desc = open("readme.rst").read() if os.path.isfile("readme.rst") else "" +try: + from setuptools import setup +except ImportError: + from distutils.core import setup +finally: + import os + +readme = open("README.md").read() if os.path.isfile("README.md") else "" + +requirements = [ + 'requests' +] + +test_requirements = [ + # none yet +] setup( - name='flask_datatables', - version='0.6.17', - packages=['flask_datatables', 'flask_datatables.views'], - url='https://github.com/tahoe/flask_datatables/', - download_url='https://github.com/tahoe/flask_datatables/tarball/0.6.15', - license='MIT', - long_description=desc, - keywords='datatables sqlalchemy flask', - author='Dennis Durling', + name='active-campaign-python', + version='0.5.0', + description="Python ActiveCampaign API client", + long_description=readme, + author="Dennis Durling", author_email='djdtahoe@gmail.com', - description='Integrates SQLAlchemy with DataTables (framework Flask)', - zip_safe=False, + url='https://github.com/tahoe/active-campaign-python', + packages=[ 'activecampaign', ], + package_dir={'activecampaign': 'activecampaign'}, include_package_data=True, + install_requires=requirements, + license="MIT", + zip_safe=False, + keywords='activecampaign', classifiers=[ - 'Environment :: Web Environment', - 'Framework :: Flask', 'Intended Audience :: Developers', - 'License :: OSI Approved :: MIT License', - 'Programming Language :: Python', + 'License :: OSI Approved :: BSD License', + 'Natural Language :: English', + "Programming Language :: Python :: 2", 'Programming Language :: Python :: 2.7', + 'Programming Language :: Python :: 3', 'Programming Language :: Python :: 3.3', 'Programming Language :: Python :: 3.4', 'Programming Language :: Python :: 3.5', - 'Topic :: Internet :: WWW/HTTP', - 'Topic :: Software Development :: Libraries', - 'Topic :: Software Development :: Libraries :: Python Modules', - ], - install_requires=[ - 'querystring_parser==1.2.3', - 'sqlalchemy>=1.0.11', - 'flask==0.10.1', - 'flask-restful>=0.3.5', - 'Faker==0.7.12', - ], + ] ) diff --git a/setup.py.bk b/setup.py.bk deleted file mode 100644 index ef8046d..0000000 --- a/setup.py.bk +++ /dev/null @@ -1,53 +0,0 @@ -#!/usr/bin/env python -# -*- coding: utf-8 -*- - - -try: - from setuptools import setup -except ImportError: - from distutils.core import setup - - -with open('README.rst') as readme_file: - readme = readme_file.read() - -requirements = [ - 'requests' -] - -test_requirements = [ - # none yet -] - -setup( - name='active-campaign-python', - version='0.5.0', - description="Python ActiveCampaign API client", - long_description=readme, - author="Dennis Durling", - author_email='djdtahoe@gmail.com', - url='https://github.com/tahoe/active-campaign-python', - packages=[ - 'activecampaign', - ], - package_dir={'activecampaign': - 'activecampaign'}, - include_package_data=True, - install_requires=requirements, - license="BSD", - zip_safe=False, - keywords='activecampaign', - classifiers=[ - 'Intended Audience :: Developers', - 'License :: OSI Approved :: BSD License', - 'Natural Language :: English', - "Programming Language :: Python :: 2", - 'Programming Language :: Python :: 2.7', - 'Programming Language :: Python :: 3', - 'Programming Language :: Python :: 3.3', - 'Programming Language :: Python :: 3.4', - 'Programming Language :: Python :: 3.5', - ], - test_suite='tests', - tests_require=test_requirements -) diff --git a/tests/__init__.py b/tests/__init__.py deleted file mode 100644 index 68190aa..0000000 --- a/tests/__init__.py +++ /dev/null @@ -1 +0,0 @@ -__author__ = 'dennis' diff --git a/tests/models.py b/tests/models.py deleted file mode 100644 index daf61dd..0000000 --- a/tests/models.py +++ /dev/null @@ -1,29 +0,0 @@ -import datetime - -from sqlalchemy.ext.declarative import declarative_base -from sqlalchemy import Column, Integer, Text, DateTime, ForeignKey, create_engine -from sqlalchemy.orm import relationship, sessionmaker, backref - -Base = declarative_base() - - -class User(Base): - __tablename__ = 'users' - - id = Column(Integer, primary_key=True) - full_name = Column(Text) - created_at = Column(DateTime, default=datetime.datetime.utcnow) - - - -class Address(Base): - __tablename__ = 'addresses' - - id = Column(Integer, primary_key=True) - description = Column(Text) - user_id = Column(Integer, ForeignKey('users.id')) - - user = relationship("User", backref=backref("address", uselist=False)) - - def __repr__(self): - return "{}".format(self.description) diff --git a/tests/test_basic.py b/tests/test_basic.py deleted file mode 100644 index f6ce2d3..0000000 --- a/tests/test_basic.py +++ /dev/null @@ -1,250 +0,0 @@ -from sqlalchemy import create_engine -from sqlalchemy.orm import sessionmaker -import faker -from querystring_parser import parser -import json -from .models import * -from flask_datatables import * -import os - - -class TestDataTables: - def setup_method(self, method): - if os.path.isfile('testdb.db'): - os.unlink('testdb.db') - engine = create_engine('sqlite:///testdb.db', echo=True) - Base.metadata.create_all(engine) - Session = sessionmaker(bind=engine) - - self.session = Session() - - # initialize DB with 10 fake items - if not self.session.query(User).all(): - self.make_data(10) - - def make_data(self, user_count): - f = faker.Faker() - users = [] - - for i in range(user_count): - user, addr = self.make_user(f.name(), f.street_address()) - users.append(user) - - self.session.add_all(users) - self.session.commit() - - def make_user(self, name, address): - addr = Address() - addr.description = address - - u = User() - u.full_name = name - u.address = addr - - return u, addr - - def make_params_str(self, order=None, search=None, start=0, length=10, urlfilter=None, - columns=("id", "name", "address")): - x = { - "draw": "1", - "search[value]": "", - "search[regex]": "false", - "order[0][column]": "1", - "order[0][dir]": "asc", - "start": str(start), - "length": str(length) - } - - for i, item in enumerate(columns): - b = "columns[{}]".format(i) - x[b + "[data]"] = item - x[b + "[name]"] = "" - x[b + "[searchable]"] = "true" - x[b + "[orderable]"] = "true" - x[b + "[search][value]"] = "" - x[b + "[search][regex]"] = "false" - - for i, item in enumerate(order or []): - for key, value in item.items(): - x["order[{}][{}]".format(i, key)] = str(value) - - if search: - for key, value in search.items(): - x["search[{}]".format(key)] = str(value) - - # this mimics an actual request - y = "" - if urlfilter: - y += "q={}&".format(urlfilter) - y += "{}={}&".format('draw', x['draw']) - y += "&".join("{}={}".format(k, v) for k, v in x.items() if k != 'draw') - - return y - - def make_params(self, **kwargs): - y = self.make_params_str(**kwargs) - # use parser to parse the request into a dict we can use in DataTable - return parser.parse(y) - - - - def test_basic_function(self): - req = self.make_params() - - table = DataTable(req, User, self.session.query(User), [ - "id", - ("name", "full_name"), - ("address", "address.description"), - ]) - - x = table.json() - - assert len(x["data"]) == 10 - - def test_relation_ordering(self): - u1, addr_asc = self.make_user("SomeUser", "0" * 15) - u2, addr_desc = self.make_user("SomeOtherUser", "z" * 15) - self.session.add_all((u1, u2)) - self.session.commit() - - req = self.make_params(order=[{"column": 2, "dir": "desc"}]) - table = DataTable(req, - User, - self.session.query(User), - [ - "id", - ("name", "full_name"), - ("address", "address.description") - ]) - result = table.json() - assert result["data"][0]["address"] == addr_desc.description - - req = self.make_params(order=[{"column": 2, "dir": "asc"}]) - table = DataTable(req, - User, - self.session.query(User), - [ - "id", - ("name", "full_name"), - ("address", "address.description") - ]) - result = table.json() - assert result["data"][0]["address"] == addr_asc.description - - def test_relation_urlfilter(self): - """ This tests the flask-restless integrated filtering - In this test case we are filtering on a relationship. - Look at filtering in flask-restless documentation for more - filter options - """ - u1, addr_a = self.make_user("userOne", "a") - u2, addr_b = self.make_user("userTwo", "b") - self.session.add_all((u1, u2)) - self.session.commit() - - # create a filter (flask-restless style, key will be 'q', set in the make_params function - urlfilter = json.dumps({"filters":[{"name": "address__description", "op": "has", "val": "a"}]}) - - # this is a fake request as we pretend to have gotten from datatables js - req = self.make_params(urlfilter=urlfilter) - - # if q is in the request.keys() we do the resltess filtering on the query - if 'q' in req.keys(): - query = views.search(self.session, User, req) - - # build the datatable with the query - table = DataTable(req, User, query, [ - "id", - ("name", "full_name"), - ("address", "address.description") - ]) - - # get result - result = table.json() - assert result["data"][0]["address"] == addr_a.description - assert len(result["data"]) == 1 - - # same for b - urlfilter = json.dumps({"filters":[{"name": "address__description", "op": "has", "val": "b"}]}) - req = self.make_params(urlfilter=urlfilter) - if 'q' in req.keys(): - query = views.search(self.session, User, req) - - table = DataTable(req, User, query, [ - "id", - ("name", "full_name"), - ("address", "address.description") - ]) - result = table.json() - assert result["data"][0]["address"] == addr_b.description - assert len(result["data"]) == 1 - - - def test_error(self): - """ make sure we are able to capture failures... """ - req = self.make_params() - req["start"] = "invalid" - - table = DataTable(req, - User, - self.session.query(User), - ["id"]) - assert "error" in table.json() - - req = self.make_params() - del req["start"] - - table = DataTable(req, - User, - self.session.query(User), - ["id"]) - assert "error" in table.json() - - - def test_search(self): - """ Test the basic search functionality. - This method is not required but here to show that it works - The main search/filter method is to use the ?q={"filters":[...]} - method from flask-restless that I have incorporated which - provides much more flexibility in searching deep relations - """ - user, addr = self.make_user("Silly Sally", "Silly Sally Road") - user2, addr2 = self.make_user("Silly Billy", "Silly Billy Road") - self.session.add_all((user, user2)) - self.session.commit() - - req = self.make_params(search={ - "value": "Silly Sally" - }) - - table = DataTable(req, User, self.session.query(User), [("name", "full_name")]) - results = table.json() - assert len(results["data"]) == 1 - - req = self.make_params(search={ - "value": "Silly" - }) - - table = DataTable(req, User, self.session.query(User), [("name", "full_name")]) - results = table.json() - assert len(results["data"]) == 2 - - - def test_datatables(self): - """ Test the datatables function get_resource """ - import flask_restful as rest - from flask import current_app, Flask - app = current_app or Flask('test') - api = rest.Api(app) - - Resource, path, endpoint = get_resource(rest.Resource, User, self.session, basepath='/api/') - api.add_resource(Resource, path, endpoint=endpoint) - - client = app.test_client() - params = self.make_params_str(columns=('id', 'full_name', 'created_at')) - response = client.get('/api/users?%s' % params) - assert response.status_code == 200 - - str_response = response.data.decode('utf-8') - obj = json.loads(str_response) - assert len(obj['data']) == 10 diff --git a/travis_requirements.txt b/travis_requirements.txt deleted file mode 100644 index 99d6efd..0000000 --- a/travis_requirements.txt +++ /dev/null @@ -1,9 +0,0 @@ -flask -flask-restful -querystring_parser -sqlalchemy -coverage==3.7.1 -sqlalchemy_utils -pytest -fake-factory -coveralls From 9e14cd63553b5fca6d63a1ca084a2f097ec530c9 Mon Sep 17 00:00:00 2001 From: Dennis Durling Date: Thu, 21 Sep 2017 12:08:11 -0700 Subject: [PATCH 04/36] relative imports --- activecampaign/Account.py | 2 +- activecampaign/ActiveCampaign.py | 2 +- activecampaign/Campaign.py | 2 +- activecampaign/Contact.py | 2 +- activecampaign/Design.py | 2 +- activecampaign/Form.py | 2 +- activecampaign/Group.py | 2 +- activecampaign/List.py | 2 +- activecampaign/Message.py | 2 +- activecampaign/Subscriber.py | 2 +- activecampaign/User.py | 2 +- activecampaign/__init__.py | 2 +- 12 files changed, 12 insertions(+), 12 deletions(-) diff --git a/activecampaign/Account.py b/activecampaign/Account.py index fc253be..2e71aa4 100644 --- a/activecampaign/Account.py +++ b/activecampaign/Account.py @@ -1,4 +1,4 @@ -from ActiveCampaign import ActiveCampaign +from .ActiveCampaign import ActiveCampaign import json import urllib2, urllib diff --git a/activecampaign/ActiveCampaign.py b/activecampaign/ActiveCampaign.py index 6a1ba08..2719add 100644 --- a/activecampaign/ActiveCampaign.py +++ b/activecampaign/ActiveCampaign.py @@ -1,4 +1,4 @@ -from Connector import Connector +from .Connector import Connector class ActiveCampaign(Connector): diff --git a/activecampaign/Campaign.py b/activecampaign/Campaign.py index f2a0d8d..dde637c 100644 --- a/activecampaign/Campaign.py +++ b/activecampaign/Campaign.py @@ -1,4 +1,4 @@ -from ActiveCampaign import ActiveCampaign +from .ActiveCampaign import ActiveCampaign import simplejson as json import urllib2, urllib import datetime, time diff --git a/activecampaign/Contact.py b/activecampaign/Contact.py index 0278466..02c4abf 100644 --- a/activecampaign/Contact.py +++ b/activecampaign/Contact.py @@ -1,4 +1,4 @@ -from ActiveCampaign import ActiveCampaign +from .ActiveCampaign import ActiveCampaign import json import urllib2, urllib diff --git a/activecampaign/Design.py b/activecampaign/Design.py index ccb1106..64519c4 100644 --- a/activecampaign/Design.py +++ b/activecampaign/Design.py @@ -1,4 +1,4 @@ -from ActiveCampaign import ActiveCampaign +from .ActiveCampaign import ActiveCampaign import json import urllib2, urllib diff --git a/activecampaign/Form.py b/activecampaign/Form.py index 4a932c2..1e05f84 100644 --- a/activecampaign/Form.py +++ b/activecampaign/Form.py @@ -1,4 +1,4 @@ -from ActiveCampaign import ActiveCampaign +from .ActiveCampaign import ActiveCampaign import json import urllib2, urllib diff --git a/activecampaign/Group.py b/activecampaign/Group.py index 524634e..a6da6da 100644 --- a/activecampaign/Group.py +++ b/activecampaign/Group.py @@ -1,4 +1,4 @@ -from ActiveCampaign import ActiveCampaign +from .ActiveCampaign import ActiveCampaign import json import urllib2, urllib diff --git a/activecampaign/List.py b/activecampaign/List.py index f14f245..cecd23c 100644 --- a/activecampaign/List.py +++ b/activecampaign/List.py @@ -1,4 +1,4 @@ -from ActiveCampaign import ActiveCampaign +from .ActiveCampaign import ActiveCampaign import json import urllib2, urllib diff --git a/activecampaign/Message.py b/activecampaign/Message.py index 6f625a9..a046ff0 100644 --- a/activecampaign/Message.py +++ b/activecampaign/Message.py @@ -1,4 +1,4 @@ -from ActiveCampaign import ActiveCampaign +from .ActiveCampaign import ActiveCampaign import json import urllib2, urllib import datetime diff --git a/activecampaign/Subscriber.py b/activecampaign/Subscriber.py index 1c26dad..16e21f9 100644 --- a/activecampaign/Subscriber.py +++ b/activecampaign/Subscriber.py @@ -1,4 +1,4 @@ -from ActiveCampaign import ActiveCampaign +from .ActiveCampaign import ActiveCampaign import json import urllib2, urllib diff --git a/activecampaign/User.py b/activecampaign/User.py index 9d4eb75..7782a5d 100644 --- a/activecampaign/User.py +++ b/activecampaign/User.py @@ -1,4 +1,4 @@ -from ActiveCampaign import ActiveCampaign +from .ActiveCampaign import ActiveCampaign import json import urllib2, urllib diff --git a/activecampaign/__init__.py b/activecampaign/__init__.py index 2501648..829e2f0 100644 --- a/activecampaign/__init__.py +++ b/activecampaign/__init__.py @@ -1 +1 @@ -from ActiveCampaign import ActiveCampaign +from .ActiveCampaign import ActiveCampaign From 54c37acfa36169b44046bcc15e17083bdc722339 Mon Sep 17 00:00:00 2001 From: Dennis Durling Date: Thu, 21 Sep 2017 12:08:30 -0700 Subject: [PATCH 05/36] dick --- active_campaign_python.egg-info/PKG-INFO | 47 ++++++++++++++++++ active_campaign_python.egg-info/SOURCES.txt | 21 ++++++++ .../dependency_links.txt | 1 + active_campaign_python.egg-info/not-zip-safe | 1 + active_campaign_python.egg-info/requires.txt | 1 + active_campaign_python.egg-info/top_level.txt | 1 + dist/active-campaign-python-0.5.0.tar.gz | Bin 0 -> 6427 bytes 7 files changed, 72 insertions(+) create mode 100644 active_campaign_python.egg-info/PKG-INFO create mode 100644 active_campaign_python.egg-info/SOURCES.txt create mode 100644 active_campaign_python.egg-info/dependency_links.txt create mode 100644 active_campaign_python.egg-info/not-zip-safe create mode 100644 active_campaign_python.egg-info/requires.txt create mode 100644 active_campaign_python.egg-info/top_level.txt create mode 100644 dist/active-campaign-python-0.5.0.tar.gz diff --git a/active_campaign_python.egg-info/PKG-INFO b/active_campaign_python.egg-info/PKG-INFO new file mode 100644 index 0000000..0f27d83 --- /dev/null +++ b/active_campaign_python.egg-info/PKG-INFO @@ -0,0 +1,47 @@ +Metadata-Version: 1.1 +Name: active-campaign-python +Version: 0.5.0 +Summary: Python ActiveCampaign API client +Home-page: https://github.com/tahoe/active-campaign-python +Author: Dennis Durling +Author-email: djdtahoe@gmail.com +License: MIT +Description-Content-Type: UNKNOWN +Description: ## Installation + + You can install **active-campaign-python** from pypi + + `pip install active-campaign-python` + + ## Example Usage + +
+        from activecampaign import ActiveCampaign
+        
+        # url provided to you by ActiveCampaign
+        base_url = ''
+        # api key provided to you by ActiveCampaign
+        api_key = ''
+        
+        ac = ActiveCampaign(base_url,  api_key)
+        print(ac.api('account/view'))
+        
+        
+ + Each of the endpoint subclasses have comments at the bottom + + ## Prerequisites + + 1. A valid ActiveCampaign **hosted** account (trial or paid). + +Keywords: activecampaign +Platform: UNKNOWN +Classifier: Intended Audience :: Developers +Classifier: License :: OSI Approved :: BSD License +Classifier: Natural Language :: English +Classifier: Programming Language :: Python :: 2 +Classifier: Programming Language :: Python :: 2.7 +Classifier: Programming Language :: Python :: 3 +Classifier: Programming Language :: Python :: 3.3 +Classifier: Programming Language :: Python :: 3.4 +Classifier: Programming Language :: Python :: 3.5 diff --git a/active_campaign_python.egg-info/SOURCES.txt b/active_campaign_python.egg-info/SOURCES.txt new file mode 100644 index 0000000..282d0a8 --- /dev/null +++ b/active_campaign_python.egg-info/SOURCES.txt @@ -0,0 +1,21 @@ +README.md +setup.py +active_campaign_python.egg-info/PKG-INFO +active_campaign_python.egg-info/SOURCES.txt +active_campaign_python.egg-info/dependency_links.txt +active_campaign_python.egg-info/not-zip-safe +active_campaign_python.egg-info/requires.txt +active_campaign_python.egg-info/top_level.txt +activecampaign/Account.py +activecampaign/ActiveCampaign.py +activecampaign/Campaign.py +activecampaign/Connector.py +activecampaign/Contact.py +activecampaign/Design.py +activecampaign/Form.py +activecampaign/Group.py +activecampaign/List.py +activecampaign/Message.py +activecampaign/Subscriber.py +activecampaign/User.py +activecampaign/__init__.py \ No newline at end of file diff --git a/active_campaign_python.egg-info/dependency_links.txt b/active_campaign_python.egg-info/dependency_links.txt new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/active_campaign_python.egg-info/dependency_links.txt @@ -0,0 +1 @@ + diff --git a/active_campaign_python.egg-info/not-zip-safe b/active_campaign_python.egg-info/not-zip-safe new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/active_campaign_python.egg-info/not-zip-safe @@ -0,0 +1 @@ + diff --git a/active_campaign_python.egg-info/requires.txt b/active_campaign_python.egg-info/requires.txt new file mode 100644 index 0000000..f229360 --- /dev/null +++ b/active_campaign_python.egg-info/requires.txt @@ -0,0 +1 @@ +requests diff --git a/active_campaign_python.egg-info/top_level.txt b/active_campaign_python.egg-info/top_level.txt new file mode 100644 index 0000000..1bcbd4d --- /dev/null +++ b/active_campaign_python.egg-info/top_level.txt @@ -0,0 +1 @@ +activecampaign diff --git a/dist/active-campaign-python-0.5.0.tar.gz b/dist/active-campaign-python-0.5.0.tar.gz new file mode 100644 index 0000000000000000000000000000000000000000..0e79e4eee84804f67552c54c81d94a19b9c972a3 GIT binary patch literal 6427 zcmV+$8RX_4iwFqY48&Oi|72-%bT46JbZK^FEn{JAaA9d@ZY^+mbZBpGEif)ME-)^1 zVR8WNJ!x~>II{W7U%_?Cp`53K)VZsQlJzFejNeQ$sT})i%H`71A|x@PNDc|b(QM6s ze`tUQc!(lx%Aq1MRWU_08t85u-HisI&anO!wPxzdR`rG1vNw2XnJu|JXv>{P-@^&ZK}aM}9+$)6?qX`Kg?f0w)uYx!4A{-0drwC&BE6@|#Zr*!*| zM7fs#-k-T+t;BOG=a-(GMSW#k4vu{lysw{KD|lZ!hN0hdo8F5c%na3aMQA6DXzsJI zAc*AA&|I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%arxVger5FlfZsk`isv?HA|xmI{jU$N zL@$}o@m9rahfLAGs^(%1$2k$u3v*%U?vevLdFNOQM_sLmz$2huyCQGh6Ao(*@b*Y5 zl%ZD;yj?g$zi5Vmm*HACtL@l3#eYo0i^yqW8!Z+sa2a$8%>Sd&V7vc^OqWsr&p;;0 z;-H@Yt1W+jux;aS_&)wWZ~tE?|53kR-~aI-kFWUDLt{Pu7w-Qbe*5(P<;8~`-G8V5 zPZ`C>|KW)Isr&x}Jb{fQ_{P4lOX}}_`KfjJ_VsT8IR`D75{W%b0%RpwritLV+w?Rq@;09G3c2a%UR%y8 zd=9Vt60!~hh$nt>Q$PE$nD=)n)lU`1|41*nkN!7`>woqAZx1Se zU&6H(Soi+|{XcEezDxg?WAWBHiC)e>` zb^ouQYWIKN6R@L|4gv=!m4xXHI|nmE^pbq-L>L>q+$V%D zO}x>Nz68YmLi_@Bzj)CO<5=Sm-jP-hm#2lD<7E)}Fcx=&J49gf#XCf@WCT1!;Btg8 z6oqe(3g+k)g>M(n(J!21Ae1ow=bYakl|BC}BRCSGp8xClzn=f=`M;k3>-oQ)|MxWi p*H8V_PyN(S{nStW)KC4?PyN(S{nStW)X$Io{6F3uP+I^P0RY0C;)wtN literal 0 HcmV?d00001 From 351d50a792038eee53a7111b291b65106dc30fa7 Mon Sep 17 00:00:00 2001 From: Dennis Durling Date: Thu, 21 Sep 2017 12:09:06 -0700 Subject: [PATCH 06/36] removed dist --- .gitignore | 1 + dist/active-campaign-python-0.5.0.tar.gz | Bin 6427 -> 0 bytes 2 files changed, 1 insertion(+) delete mode 100644 dist/active-campaign-python-0.5.0.tar.gz diff --git a/.gitignore b/.gitignore index aa408b8..574f916 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ # Compiled Python Files *.pyc +dist/* diff --git a/dist/active-campaign-python-0.5.0.tar.gz b/dist/active-campaign-python-0.5.0.tar.gz deleted file mode 100644 index 0e79e4eee84804f67552c54c81d94a19b9c972a3..0000000000000000000000000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: Dennis Durling Date: Thu, 21 Sep 2017 12:09:39 -0700 Subject: [PATCH 07/36] version update --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 526ab97..5c4decd 100644 --- a/setup.py +++ b/setup.py @@ -21,7 +21,7 @@ setup( name='active-campaign-python', - version='0.5.0', + version='0.5.1', description="Python ActiveCampaign API client", long_description=readme, author="Dennis Durling", From a1b69601b15b3040e96deb61c913167cc423d52f Mon Sep 17 00:00:00 2001 From: Dennis Durling Date: Thu, 21 Sep 2017 12:13:29 -0700 Subject: [PATCH 08/36] fucking urllib2 --- .gitignore | 1 + active_campaign_python.egg-info/PKG-INFO | 47 ------------------- active_campaign_python.egg-info/SOURCES.txt | 21 --------- .../dependency_links.txt | 1 - active_campaign_python.egg-info/not-zip-safe | 1 - active_campaign_python.egg-info/requires.txt | 1 - active_campaign_python.egg-info/top_level.txt | 1 - 7 files changed, 1 insertion(+), 72 deletions(-) delete mode 100644 active_campaign_python.egg-info/PKG-INFO delete mode 100644 active_campaign_python.egg-info/SOURCES.txt delete mode 100644 active_campaign_python.egg-info/dependency_links.txt delete mode 100644 active_campaign_python.egg-info/not-zip-safe delete mode 100644 active_campaign_python.egg-info/requires.txt delete mode 100644 active_campaign_python.egg-info/top_level.txt diff --git a/.gitignore b/.gitignore index 574f916..fd30689 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ # Compiled Python Files *.pyc dist/* +*.egg-info/ diff --git a/active_campaign_python.egg-info/PKG-INFO b/active_campaign_python.egg-info/PKG-INFO deleted file mode 100644 index 0f27d83..0000000 --- a/active_campaign_python.egg-info/PKG-INFO +++ /dev/null @@ -1,47 +0,0 @@ -Metadata-Version: 1.1 -Name: active-campaign-python -Version: 0.5.0 -Summary: Python ActiveCampaign API client -Home-page: https://github.com/tahoe/active-campaign-python -Author: Dennis Durling -Author-email: djdtahoe@gmail.com -License: MIT -Description-Content-Type: UNKNOWN -Description: ## Installation - - You can install **active-campaign-python** from pypi - - `pip install active-campaign-python` - - ## Example Usage - -
-        from activecampaign import ActiveCampaign
-        
-        # url provided to you by ActiveCampaign
-        base_url = ''
-        # api key provided to you by ActiveCampaign
-        api_key = ''
-        
-        ac = ActiveCampaign(base_url,  api_key)
-        print(ac.api('account/view'))
-        
-        
- - Each of the endpoint subclasses have comments at the bottom - - ## Prerequisites - - 1. A valid ActiveCampaign **hosted** account (trial or paid). - -Keywords: activecampaign -Platform: UNKNOWN -Classifier: Intended Audience :: Developers -Classifier: License :: OSI Approved :: BSD License -Classifier: Natural Language :: English -Classifier: Programming Language :: Python :: 2 -Classifier: Programming Language :: Python :: 2.7 -Classifier: Programming Language :: Python :: 3 -Classifier: Programming Language :: Python :: 3.3 -Classifier: Programming Language :: Python :: 3.4 -Classifier: Programming Language :: Python :: 3.5 diff --git a/active_campaign_python.egg-info/SOURCES.txt b/active_campaign_python.egg-info/SOURCES.txt deleted file mode 100644 index 282d0a8..0000000 --- a/active_campaign_python.egg-info/SOURCES.txt +++ /dev/null @@ -1,21 +0,0 @@ -README.md -setup.py -active_campaign_python.egg-info/PKG-INFO -active_campaign_python.egg-info/SOURCES.txt -active_campaign_python.egg-info/dependency_links.txt -active_campaign_python.egg-info/not-zip-safe -active_campaign_python.egg-info/requires.txt -active_campaign_python.egg-info/top_level.txt -activecampaign/Account.py -activecampaign/ActiveCampaign.py -activecampaign/Campaign.py -activecampaign/Connector.py -activecampaign/Contact.py -activecampaign/Design.py -activecampaign/Form.py -activecampaign/Group.py -activecampaign/List.py -activecampaign/Message.py -activecampaign/Subscriber.py -activecampaign/User.py -activecampaign/__init__.py \ No newline at end of file diff --git a/active_campaign_python.egg-info/dependency_links.txt b/active_campaign_python.egg-info/dependency_links.txt deleted file mode 100644 index 8b13789..0000000 --- a/active_campaign_python.egg-info/dependency_links.txt +++ /dev/null @@ -1 +0,0 @@ - diff --git a/active_campaign_python.egg-info/not-zip-safe b/active_campaign_python.egg-info/not-zip-safe deleted file mode 100644 index 8b13789..0000000 --- a/active_campaign_python.egg-info/not-zip-safe +++ /dev/null @@ -1 +0,0 @@ - diff --git a/active_campaign_python.egg-info/requires.txt b/active_campaign_python.egg-info/requires.txt deleted file mode 100644 index f229360..0000000 --- a/active_campaign_python.egg-info/requires.txt +++ /dev/null @@ -1 +0,0 @@ -requests diff --git a/active_campaign_python.egg-info/top_level.txt b/active_campaign_python.egg-info/top_level.txt deleted file mode 100644 index 1bcbd4d..0000000 --- a/active_campaign_python.egg-info/top_level.txt +++ /dev/null @@ -1 +0,0 @@ -activecampaign From a745e40366b5b9ebbef4167e311e2708b5a5791a Mon Sep 17 00:00:00 2001 From: Dennis Durling Date: Thu, 21 Sep 2017 14:45:54 -0700 Subject: [PATCH 09/36] moar refactoring --- activecampaign/Account.py | 144 +++++++++----- activecampaign/ActiveCampaign.py | 19 +- activecampaign/Campaign.py | 310 ++++++++++++++++++++----------- activecampaign/Connector.py | 21 ++- activecampaign/Contact.py | 109 +++++++---- activecampaign/Design.py | 35 ++-- activecampaign/Form.py | 45 +++-- activecampaign/Group.py | 111 +++++++---- activecampaign/List.py | 170 +++++++++++------ activecampaign/Message.py | 218 ++++++++++++++-------- activecampaign/Subscriber.py | 132 ++++++++----- activecampaign/User.py | 135 +++++++++----- activecampaign/__init__.py | 2 +- setup.py | 2 +- 14 files changed, 933 insertions(+), 520 deletions(-) diff --git a/activecampaign/Account.py b/activecampaign/Account.py index 2e71aa4..a233e93 100644 --- a/activecampaign/Account.py +++ b/activecampaign/Account.py @@ -1,6 +1,10 @@ -from .ActiveCampaign import ActiveCampaign -import json -import urllib2, urllib +from .ActiveCampaign import ( + ActiveCampaign, + fmt_params, + fmt_noparams +) +import requests as rq + class Account(ActiveCampaign): @@ -9,53 +13,93 @@ def __init__(self, url, api_key): self.api_key = api_key ActiveCampaign.__init__(self, url, api_key) - def add(self, params, post_data): - request_url = '%s&api_action=account_add&api_output=%s' % (self.url, self.output) - post_data = urllib.urlencode(post_data) - req = urllib2.Request(request_url, post_data) - response = json.loads(urllib2.urlopen(req).read()) - return response - - def cancel(self, params, post_data = {}): - request_url = '%s&api_action=account_cancel&api_output=%s&%s' % (self.url, self.output, params) - response = json.loads(urllib2.urlopen(request_url).read()) - return response - - def edit(self, params, post_data): - request_url = '%s&api_action=account_edit&api_output=%s' % (self.url, self.output) - response = json.loads(urllib2.urlopen(request_url).read()) - return response - - def list_(self, params, post_data = {}): - request_url = '%s&api_action=account_list&api_output=%s&%s' % (self.url, self.output, params) - response = json.loads(urllib2.urlopen(request_url).read()) - return response - - def name_check(self, params, post_data = {}): - request_url = '%s&api_action=account_name_check&api_output=%s&%s' % (self.url, self.output, params) - response = json.loads(urllib2.urlopen(request_url).read()) - return response - - def plans(self, params, post_data = {}): - request_url = '%s&api_action=account_plans&api_output=%s&%s' % (self.url, self.output, params) - response = json.loads(urllib2.urlopen(request_url).read()) - return response - - def status(self, params, post_data = {}): - request_url = '%s&api_action=account_status&api_output=%s&%s' % (self.url, self.output, params) - response = json.loads(urllib2.urlopen(request_url).read()) - return response - - def status_set(self, params, post_data = {}): - request_url = '%s&api_action=account_status_set&api_output=%s&%s' % (self.url, self.output, params) - response = json.loads(urllib2.urlopen(request_url).read()) - return response - - def view(self, params, post_data = {}): - request_url = '%s&api_action=account_view&api_output=%s' % (self.url, self.output) - response = json.loads(urllib2.urlopen(request_url).read()) - return response - + 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.json() + + def cancel(self, params, post_data={}): + rq_url = fmt_params( + self.url, + 'account_cancel', + self.output, + params + ) + response = rq.get(rq_url) + return response.json() + + def edit(self, params, post_data={}): + rq_url = fmt_noparams( + self.url, + 'account_edit', + self.output + ) + response = rq.get(rq_url) + return response.json() + + def list_(self, params, post_data={}): + rq_url = fmt_params( + self.url, + 'account_list', + self.output, + params + ) + response = rq.get(rq_url) + return response.json() + + 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.json() + + def plans(self, params, post_data={}): + rq_url = fmt_params( + self.url, + 'account_plans', + self.output, + params + ) + response = rq.get(rq_url) + return response.json() + + def status(self, params, post_data={}): + rq_url = fmt_params( + self.url, + 'account_status', + self.output, + params + ) + response = rq.get(rq_url) + return response.json() + + 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.json() + + def view(self, params, post_data={}): + rq_url = fmt_noparams( + self.url, + 'account_view', + self.output + ) + response = rq.get(rq_url) + return response.json() + """ ## view diff --git a/activecampaign/ActiveCampaign.py b/activecampaign/ActiveCampaign.py index 2719add..0b06fd8 100644 --- a/activecampaign/ActiveCampaign.py +++ b/activecampaign/ActiveCampaign.py @@ -1,15 +1,20 @@ 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 + + class ActiveCampaign(Connector): - def __init__(self, url, api_key, api_user = '', api_pass = ''): + 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 Connector.__init__(self, url, api_key, api_user, api_pass) - def api(self, path, post_data = {}): + def api(self, path, post_data={}): # IE: "subscriber/view" components = path.split('/') component = components[0] @@ -39,10 +44,12 @@ def api(self, path, post_data = {}): elif component == 'singlesignon': component = 'auth' - class1 = '%s' % component.capitalize() # IE: "subscriber" becomes "Subscriber" - source_module = __import__(class1, globals(), locals(), [], -1) # import Subscriber - class1 = getattr(source_module, class1) # get Subscriber - class1 = class1(self.URL, self.APIKEY) # Subscriber() + # "subscriber" becomes "Subscriber" + class1 = '{}'.format(component.capitalize()) + source_module = __import__( + class1, globals(), locals(), [], -1) # import Subscriber + class1 = getattr(source_module, class1) # get Subscriber + class1 = class1(self.URL, self.APIKEY) # Subscriber() # subscriber.view() if method == 'list': diff --git a/activecampaign/Campaign.py b/activecampaign/Campaign.py index dde637c..4678e2b 100644 --- a/activecampaign/Campaign.py +++ b/activecampaign/Campaign.py @@ -1,7 +1,10 @@ -from .ActiveCampaign import ActiveCampaign -import simplejson as json -import urllib2, urllib -import datetime, time +from .ActiveCampaign import ( + ActiveCampaign, + fmt_params, + fmt_noparams +) +import requests as rq + class Campaign(ActiveCampaign): @@ -11,111 +14,204 @@ def __init__(self, url, api_key): ActiveCampaign.__init__(self, url, api_key) def create(self, params, post_data): - request_url = '%s&api_action=campaign_create&api_output=%s' % (self.url, self.output) - post_data = urllib.urlencode(post_data) - req = urllib2.Request(request_url, post_data) - response = json.loads(urllib2.urlopen(req).read()) - return response - - def delete(self, params, post_data = {}): - request_url = '%s&api_action=campaign_delete&api_output=%s&%s' % (self.url, self.output, params) - response = json.loads(urllib2.urlopen(request_url).read()) - return response - - def delete_list(self, params, post_data = {}): - request_url = '%s&api_action=campaign_delete_list&api_output=%s&%s' % (self.url, self.output, params) - response = json.loads(urllib2.urlopen(request_url).read()) - return response - - def list_(self, params, post_data = {}): - request_url = '%s&api_action=campaign_list&api_output=%s&%s' % (self.url, self.output, params) - response = json.loads(urllib2.urlopen(request_url).read()) - return response - - def paginator(self, params, post_data = {}): - request_url = '%s&api_action=campaign_paginator&api_output=%s&%s' % (self.url, self.output, params) - response = json.loads(urllib2.urlopen(request_url).read()) - return response - - def report_bounce_list(self, params, post_data = {}): - request_url = '%s&api_action=campaign_report_bounce_list&api_output=%s&%s' % (self.url, self.output, params) - response = json.loads(urllib2.urlopen(request_url).read()) - return response - - def report_bounce_totals(self, params, post_data = {}): - request_url = '%s&api_action=campaign_report_bounce_totals&api_output=%s&%s' % (self.url, self.output, params) - response = json.loads(urllib2.urlopen(request_url).read()) - return response - - def report_forward_list(self, params, post_data = {}): - request_url = '%s&api_action=campaign_report_forward_list&api_output=%s&%s' % (self.url, self.output, params) - response = json.loads(urllib2.urlopen(request_url).read()) - return response - - def report_forward_totals(self, params, post_data = {}): - request_url = '%s&api_action=campaign_report_forward_totals&api_output=%s&%s' % (self.url, self.output, params) - response = json.loads(urllib2.urlopen(request_url).read()) - return response - - def report_link_list(self, params, post_data = {}): - request_url = '%s&api_action=campaign_report_link_list&api_output=%s&%s' % (self.url, self.output, params) - response = json.loads(urllib2.urlopen(request_url).read()) - return response - - def report_link_totals(self, params, post_data = {}): - request_url = '%s&api_action=campaign_report_link_totals&api_output=%s&%s' % (self.url, self.output, params) - response = json.loads(urllib2.urlopen(request_url).read()) - return response - - def report_open_list(self, params, post_data = {}): - request_url = '%s&api_action=campaign_report_open_list&api_output=%s&%s' % (self.url, self.output, params) - response = json.loads(urllib2.urlopen(request_url).read()) - return response - - def report_open_totals(self, params, post_data = {}): - request_url = '%s&api_action=campaign_report_open_totals&api_output=%s&%s' % (self.url, self.output, params) - response = json.loads(urllib2.urlopen(request_url).read()) - return response - - def report_totals(self, params, post_data = {}): - request_url = '%s&api_action=campaign_report_totals&api_output=%s&%s' % (self.url, self.output, params) - response = json.loads(urllib2.urlopen(request_url).read()) - return response - - def report_unopen_list(self, params, post_data = {}): - request_url = '%s&api_action=campaign_report_unopen_list&api_output=%s&%s' % (self.url, self.output, params) - response = json.loads(urllib2.urlopen(request_url).read()) - return response - - def report_unsubscription_list(self, params, post_data = {}): - request_url = '%s&api_action=campaign_report_unsubscription_list&api_output=%s&%s' % (self.url, self.output, params) - response = json.loads(urllib2.urlopen(request_url).read()) - return response - - def report_unsubscription_totals(self, params, post_data = {}): - request_url = '%s&api_action=campaign_report_unsubscription_totals&api_output=%s&%s' % (self.url, self.output, params) - response = json.loads(urllib2.urlopen(request_url).read()) - return response - - def send(self, params, post_data = {}): - request_url = '%s&api_action=campaign_send&api_output=%s&%s' % (self.url, self.output, params) - response = json.loads(urllib2.urlopen(request_url).read()) - return response - - def status(self, params, post_data = {}): - request_url = '%s&api_action=campaign_status&api_output=%s&%s' % (self.url, self.output, params) - response = json.loads(urllib2.urlopen(request_url).read()) - return response - + rq_url = fmt_noparams( + self.url, + 'campaign_create', + self.output + ) + response = rq.post(rq_url, data=post_data) + return response.json() + + def delete(self, params, post_data={}): + rq_url = fmt_params( + self.url, + 'campaign_delete', + self.output, + params + ) + response = rq.get(rq_url) + return response.json() + + def delete_list(self, params, post_data={}): + rq_url = fmt_params( + self.url, + 'campaign_delete_list', + self.output, + params + ) + response = rq.get(rq_url) + return response.json() + + def list_(self, params, post_data={}): + rq_url = fmt_params( + self.url, + 'campaign_list', + self.output, + params + ) + response = rq.get(rq_url) + return response.json() + + def paginator(self, params, post_data={}): + rq_url = fmt_params( + self.url, + 'campaign_paginator', + self.output, + params + ) + response = rq.get(rq_url) + return response.json() + + def report_bounce_list(self, params, post_data={}): + rq_url = fmt_params( + self.url, + 'campaign_report_bounce_list', + self.output, + params + ) + response = rq.get(rq_url) + return response.json() + + def report_bounce_totals(self, params, post_data={}): + rq_url = fmt_params( + self.url, + 'campaign_report_bounce_totals', + self.output, + params + ) + response = rq.get(rq_url) + return response.json() + + def report_forward_list(self, params, post_data={}): + rq_url = fmt_params( + self.url, + 'campaign_report_forward_list', + self.output, + params + ) + response = rq.get(rq_url) + return response.json() + + def report_forward_totals(self, params, post_data={}): + rq_url = fmt_params( + self.url, + 'campaign_report_forward_totals', + self.output, + params + ) + response = rq.get(rq_url) + return response.json() + + def report_link_list(self, params, post_data={}): + rq_url = fmt_params( + self.url, + 'campaign_report_link_list', + self.output, + params + ) + response = rq.get(rq_url) + return response.json() + + def report_link_totals(self, params, post_data={}): + rq_url = fmt_params( + self.url, + 'campaign_report_link_totals', + self.output, + params + ) + response = rq.get(rq_url) + return response.json() + + def report_open_list(self, params, post_data={}): + rq_url = fmt_params( + self.url, + 'campaign_report_open_list', + self.output, + params + ) + response = rq.get(rq_url) + return response.json() + + def report_open_totals(self, params, post_data={}): + rq_url = fmt_params( + self.url, + 'campaign_report_open_totals', + self.output, + params + ) + response = rq.get(rq_url) + return response.json() + + def report_totals(self, params, post_data={}): + rq_url = fmt_params( + self.url, + 'campaign_report_totals', + self.output, + params + ) + response = rq.get(rq_url) + return response.json() + + def report_unopen_list(self, params, post_data={}): + rq_url = fmt_params( + self.url, + 'campaign_report_unopen_list', + self.output, + params + ) + response = rq.get(rq_url) + return response.json() + + def report_unsubscription_list(self, params, post_data={}): + rq_url = fmt_params( + self.url, + 'campaign_report_unsubscription_list', + self.output, + params + ) + response = rq.get(rq_url) + return response.json() + + def report_unsubscription_totals(self, params, post_data={}): + rq_url = fmt_params( + self.url, + 'campaign_report_unsubscription_totals', + self.output, + params + ) + response = rq.get(rq_url) + return response.json() + + def send(self, params, post_data={}): + rq_url = fmt_params( + self.url, + 'campaign_send', + self.output, + params + ) + response = rq.get(rq_url) + return response.json() + + def status(self, params, post_data={}): + rq_url = fmt_params( + self.url, + 'campaign_status', + self.output, + params + ) + response = rq.get(rq_url) + return response.json() + + """ if __name__ == '__main__': ac = ActiveCampaign(ACTIVECAMPAIGN_URL, ACTIVECAMPAIGN_API_KEY) ## create - sdate = datetime.datetime.now() + datetime.timedelta(hours = 0, minutes = 2) + sdate = datetime.datetime.now() + datetime.timedelta(hours=0, minutes=2) campaign = { 'type': 'single', - 'name': 'testActiveCampaign: %s' % datetime.datetime.now(), + 'name': 'testActiveCampaign: {}'.formatdatetime.datetime.now(), 'sdate': time.strftime('%Y-%m-%d %H:%M:%S', sdate.timetuple()), 'status': 1, 'public': 1, @@ -129,7 +225,6 @@ def status(self, params, post_data = {}): time2 = time() print ac.api('campaign/create', campaign) print 'diff2 = %.5f seconds' %(time() - time2) - ## delete ## print ac.api('campaign/delete?id=12') @@ -141,7 +236,8 @@ def status(self, params, post_data = {}): ## print ac.api('campaign/list?ids=3,4') ## paginator -## print ac.api('campaign/paginator?sort=&offset=0&limit=20&filter=0&public=0') +## print ac.api('campaign/paginator?sort=&offset=0&limit=20&' + 'filter=0&public=0') ## report_bounce_list ## print ac.api('campaign/report_bounce_list?campaignid=3') @@ -177,10 +273,12 @@ def status(self, params, post_data = {}): ## print ac.api('campaign/report_unsubscription_list?campaignid=13') ## report_unsubscription_totals -## print ac.api('campaign/report_unsubscription_totals?campaignid=13&messageid=2') +## print ac.api('campaign/report_unsubscription_totals?campaignid=13&' + 'messageid=2') ## report_send -## print ac.api('campaign/send?campaignid=13&messageid=2&type=mime&action=send&email=person@example.com') +## print ac.api('campaign/send?campaignid=13&messageid=2&type=mime&' + 'action=send&email=person@example.com') ## report_status ## print ac.api('campaign/status?id=13&status=5') diff --git a/activecampaign/Connector.py b/activecampaign/Connector.py index c127c1a..847848b 100644 --- a/activecampaign/Connector.py +++ b/activecampaign/Connector.py @@ -1,12 +1,12 @@ -import json -import urllib2 +import requests as rq + class Connector(): - def __init__(self, url, api_key, api_user = '', api_pass = ''): + def __init__(self, url, api_key, api_user='', api_pass=''): self.output = 'json' self.base = '' - + if url != 'https://www.activecampaign.com': # not set reseller self.base = '/admin' @@ -15,15 +15,18 @@ def __init__(self, url, api_key, api_user = '', api_pass = ''): url = url[:-1] if api_key: - self.url = '%s%s/api.php?api_key=%s' % (url, self.base, api_key) + self.url = '{}{}/api.php?api_key={}'\ + .format(url, self.base, api_key) else: - self.url = '%s%s/api.php?api_user=%s&api_pass=%s' % (url, self.base, api_user, api_pass) + self.url = '{}{}/api.php?api_user={}&api_pass={}'\ + .format(url, self.base, api_user, api_pass) self.api_key = api_key def credentials_test(self): - test_url = '%s&api_action=group_view&api_output=%s&id=3' % (self.url, self.output) - jdata = json.loads(urllib2.urlopen(test_url).read()) - return jdata['result_code'] == 1 + test_url = '{}&api_action=group_view&api_output={}&id=3'\ + .format(self.url, self.output) + return rq.get(test_url).status_code == 200 + """ if __name__ == '__main__': diff --git a/activecampaign/Contact.py b/activecampaign/Contact.py index 02c4abf..1ed4a08 100644 --- a/activecampaign/Contact.py +++ b/activecampaign/Contact.py @@ -1,6 +1,10 @@ -from .ActiveCampaign import ActiveCampaign -import json -import urllib2, urllib +from .ActiveCampaign import ( + ActiveCampaign, + fmt_params, + fmt_noparams +) +import requests as rq + class Contact(ActiveCampaign): @@ -10,49 +14,78 @@ def __init__(self, url, api_key): ActiveCampaign.__init__(self, url, api_key) def add(self, params, post_data): - request_url = '%s&api_action=contact_add&api_output=%s' % (self.url, self.output) - post_data = urllib.urlencode(post_data) - req = urllib2.Request(request_url, post_data) - response = json.loads(urllib2.urlopen(req).read()) - return response - - def delete_list(self, params, post_data = {}): - request_url = '%s&api_action=contact_delete_list&api_output=%s&%s' % (self.url, self.output, params) - response = json.loads(urllib2.urlopen(request_url).read()) - return response - - def delete(self, params, post_data = {}): - request_url = '%s&api_action=contact_delete&api_output=%s&%s' % (self.url, self.output, params) - response = json.loads(urllib2.urlopen(request_url).read()) - return response - + rq_url = fmt_noparams( + self.url, + 'contact_add', + self.output + ) + response = rq.get(rq_url, data=post_data) + return response.json() + + def delete_list(self, params, post_data={}): + rq_url = fmt_params( + self.url, + 'contact_delete_list', + self.output, + params + ) + response = rq.get(rq_url) + return response.json() + + def delete(self, params, post_data={}): + rq_url = fmt_params( + self.url, + 'contact_delete', + self.output, + params + ) + response = rq.get(rq_url) + return response.json() + def edit(self, params, post_data): - request_url = '%s&api_action=contact_edit&api_output=%s' % (self.url, self.output) - post_data = urllib.urlencode(post_data) - req = urllib2.Request(request_url, post_data) - response = json.loads(urllib2.urlopen(req).read()) - return response - - def list_(self, params, post_data = {}): - request_url = '%s&api_action=contact_list&api_output=%s&%s' % (self.url, self.output, params) - response = json.loads(urllib2.urlopen(request_url).read()) - return response - - def me(self, params, post_data = {}): - request_url = '%s&api_action=contact_me&api_output=%s' % (self.url, self.output) - response = json.loads(urllib2.urlopen(request_url).read()) - return response + rq_url = fmt_noparams( + self.url, + 'contact_edit', + self.output + ) + response = rq.get(rq_url, data=post_data) + return response.json() - def view(self, params, post_data = {}): + def list_(self, params, post_data={}): + rq_url = fmt_params( + self.url, + 'contact_list', + self.output, + params + ) + response = rq.get(rq_url) + return response.json() + + def me(self, params, post_data={}): + rq_url = fmt_noparams( + self.url, + 'contact_me', + self.output + ) + response = rq.get(rq_url) + return response.json() + + def view(self, params, post_data={}): if params.startswith('email='): action = 'contact_view_email' elif params.startswith('hash='): action = 'contact_view_hash' elif params.startswith('id='): action = 'contact_view' - request_url = '%s&api_action=%s&api_output=%s&%s' % (self.url, action, self.output, params) - response = json.loads(urllib2.urlopen(request_url).read()) - return response + rq_url = fmt_params( + self.url, + action, + self.output, + params + ) + response = rq.get(rq_url) + return response.json() + """ if __name__ == '__main__': diff --git a/activecampaign/Design.py b/activecampaign/Design.py index 64519c4..0d67df1 100644 --- a/activecampaign/Design.py +++ b/activecampaign/Design.py @@ -1,6 +1,10 @@ -from .ActiveCampaign import ActiveCampaign -import json -import urllib2, urllib +from .ActiveCampaign import ( + ActiveCampaign, + fmt_params, + fmt_noparams +) +import requests as rq + class Design(ActiveCampaign): @@ -10,17 +14,24 @@ def __init__(self, url, api_key): ActiveCampaign.__init__(self, url, api_key) def edit(self, params, post_data): - request_url = '%s&api_action=branding_edit&api_output=%s' % (self.url, self.output) - post_data = urllib.urlencode(post_data) - req = urllib2.Request(request_url, post_data) - response = json.loads(urllib2.urlopen(req).read()) + rq_url = fmt_noparams( + self.url, + 'branding_edit', + self.output + ) + response = rq.post(rq_url, data=post_data) return response - + def view(self, params, post_data): - request_url = '%s&api_action=branding_view&api_output=%s' % (self.url, self.output) - response = json.loads(urllib2.urlopen(request_url).read()) - return response - + rq_url = fmt_noparams( + self.url, + 'branding_view', + self.output + ) + response = rq.get(rq_url) + return response.json() + + """ if __name__ == '__main__': ac = ActiveCampaign(ACTIVECAMPAIGN_URL, ACTIVECAMPAIGN_API_KEY) diff --git a/activecampaign/Form.py b/activecampaign/Form.py index 1e05f84..3bfcc1a 100644 --- a/activecampaign/Form.py +++ b/activecampaign/Form.py @@ -1,6 +1,10 @@ -from .ActiveCampaign import ActiveCampaign -import json -import urllib2, urllib +from .ActiveCampaign import ( + ActiveCampaign, + fmt_params, + fmt_noparams +) +import requests as rq + class Form(ActiveCampaign): @@ -9,24 +13,33 @@ def __init__(self, url, api_key): self.api_key = api_key ActiveCampaign.__init__(self, url, api_key) - def getforms(self, params, post_data = {}): - request_url = '%s&api_action=form_getforms&api_output=%s' % (self.url, self.output) - response = json.loads(urllib2.urlopen(request_url).read()) - return response - - def html(self, params, post_data = {}): - request_url = '%s&api_action=form_html&api_output=%s&%s' % (self.url, self.output, params) - #print urllib2.urlopen(request_url).read() - response = json.loads(urllib2.urlopen(request_url).read()) - return response - + def getforms(self, params, post_data={}): + rq_url = fmt_noparams( + self.url, + 'form_getforms', + self.output + ) + response = rq.get(rq_url, data=post_data) + return response.json() + + def html(self, params, post_data={}): + rq_url = fmt_params( + self.url, + 'form_html', + self.output, + params + ) + response = rq.get(rq_url) + return response.json() + + """ if __name__ == '__main__': ac = ActiveCampaign(ACTIVECAMPAIGN_URL, ACTIVECAMPAIGN_API_KEY) - + ## getforms #print ac.api('form/getforms') - + ## html #print ac.api('form/html?id=1142') """ diff --git a/activecampaign/Group.py b/activecampaign/Group.py index a6da6da..a07ea88 100644 --- a/activecampaign/Group.py +++ b/activecampaign/Group.py @@ -1,6 +1,10 @@ -from .ActiveCampaign import ActiveCampaign -import json -import urllib2, urllib +from .ActiveCampaign import ( + ActiveCampaign, + fmt_params, + fmt_noparams +) +import requests as rq + class Group(ActiveCampaign): @@ -10,43 +14,68 @@ def __init__(self, url, api_key): ActiveCampaign.__init__(self, url, api_key) def add(self, params, post_data): - request_url = '%s&api_action=group_add&api_output=%s' % (self.url, self.output) - post_data = urllib.urlencode(post_data) - req = urllib2.Request(request_url, post_data) - response = json.loads(urllib2.urlopen(req).read()) - return response - - def delete_list(self, params, post_data = {}): - request_url = '%s&api_action=group_delete_list&api_output=%s&%s' % (self.url, self.output, params) - response = json.loads(urllib2.urlopen(request_url).read()) - return response - - def delete(self, params, post_data = {}): - request_url = '%s&api_action=group_delete&api_output=%s&%s' % (self.url, self.output, params) - response = json.loads(urllib2.urlopen(request_url).read()) - return response - + rq_url = fmt_noparams( + self.url, + 'group_add', + self.output + ) + response = rq.get(rq_url, data=post_data) + return response.json() + + def delete_list(self, params, post_data={}): + rq_url = fmt_params( + self.url, + 'group_delete_list', + self.output, + params + ) + response = rq.get(rq_url) + return response.json() + + def delete(self, params, post_data={}): + rq_url = fmt_params( + self.url, + 'group_delete', + self.output, + params + ) + response = rq.get(rq_url) + return response.json() + def edit(self, params, post_data): - request_url = '%s&api_action=group_edit&api_output=%s' % (self.url, self.output) - post_data = urllib.urlencode(post_data) - req = urllib2.Request(request_url, post_data) - response = json.loads(urllib2.urlopen(req).read()) - return response - - def list_(self, params, post_data = {}): - request_url = '%s&api_action=group_list&api_output=%s&%s' % (self.url, self.output, params) - response = json.loads(urllib2.urlopen(request_url).read()) - return response - - def view(self, params, post_data = {}): - request_url = '%s&api_action=group_view&api_output=%s&%s' % (self.url, self.output, params) - response = json.loads(urllib2.urlopen(request_url).read()) - return response + rq_url = fmt_noparams( + self.url, + 'group_edit', + self.output + ) + response = rq.get(rq_url, data=post_data) + return response.json() + + def list_(self, params, post_data={}): + rq_url = fmt_params( + self.url, + 'group_list', + self.output, + params + ) + response = rq.get(rq_url) + return response.json() + + def view(self, params, post_data={}): + rq_url = fmt_params( + self.url, + 'group_view', + self.output, + params + ) + response = rq.get(rq_url) + return response.json() + """ if __name__ == '__main__': ac = ActiveCampaign(ACTIVECAMPAIGN_URL, ACTIVECAMPAIGN_API_KEY) - + ## add # group = { # 'title': 'second-test-group', @@ -55,22 +84,22 @@ def view(self, params, post_data = {}): # 'pg_form_edit' : 1, # 'pg_subscriber_add' : 1, # 'pg_subscriber_delete' : 0 - # } + # } # print ac.api('group/add', group) - + ## delete_list #print ac.api('group/delete_list?ids=4,5') - + ## delete #print ac.api('group/delete?id=6') - + ## edit # group = { # 'title': 'second-group', # 'id' : 7 - # } + # } # print ac.api('group/edit', group) - + ## list #print ac.api('group/list?ids=1,7') diff --git a/activecampaign/List.py b/activecampaign/List.py index cecd23c..f970e04 100644 --- a/activecampaign/List.py +++ b/activecampaign/List.py @@ -1,6 +1,10 @@ -from .ActiveCampaign import ActiveCampaign -import json -import urllib2, urllib +from .ActiveCampaign import ( + ActiveCampaign, + fmt_params, + fmt_noparams +) +import requests as rq + class List(ActiveCampaign): @@ -10,68 +14,112 @@ def __init__(self, url, api_key): ActiveCampaign.__init__(self, url, api_key) def add(self, params, post_data): - request_url = '%s&api_action=list_add&api_output=%s' % (self.url, self.output) - post_data = urllib.urlencode(post_data) - req = urllib2.Request(request_url, post_data) - response = json.loads(urllib2.urlopen(req).read()) - return response - - def delete(self, params, post_data = {}): - request_url = '%s&api_action=list_delete&api_output=%s&%s' % (self.url, self.output, params) - response = json.loads(urllib2.urlopen(request_url).read()) - return response - - def delete_list(self, params, post_data = {}): - request_url = '%s&api_action=list_delete_list&api_output=%s&%s' % (self.url, self.output, params) - response = json.loads(urllib2.urlopen(request_url).read()) - return response + rq_url = fmt_noparams( + self.url, + 'list_add', + self.output + ) + response = rq.get(rq_url, data=post_data) + return response.json() + + def delete(self, params, post_data={}): + rq_url = fmt_params( + self.url, + 'list_delete', + self.output, + params + ) + response = rq.get(rq_url) + return response.json() + + def delete_list(self, params, post_data={}): + rq_url = fmt_params( + self.url, + 'list_delete_list', + self.output, + params + ) + response = rq.get(rq_url) + return response.json() def edit(self, params, post_data): - request_url = '%s&api_action=list_edit&api_output=%s' % (self.url, self.output) - post_data = urllib.urlencode(post_data) - req = urllib2.Request(request_url, post_data) - response = json.loads(urllib2.urlopen(req).read()) - return response + rq_url = fmt_noparams( + self.url, + 'list_edit', + self.output + ) + response = rq.get(rq_url, data=post_data) + return response.json() def field_add(self, params, post_data): - request_url = '%s&api_action=list_field_add&api_output=%s' % (self.url, self.output) - post_data = urllib.urlencode(post_data) - req = urllib2.Request(request_url, post_data) - response = json.loads(urllib2.urlopen(req).read()) - return response - - def field_delete(self, params, post_data = {}): - request_url = '%s&api_action=list_field_delete&api_output=%s&%s' % (self.url, self.output, params) - response = json.loads(urllib2.urlopen(request_url).read()) - return response + rq_url = fmt_noparams( + self.url, + 'list_field_add', + self.output + ) + response = rq.get(rq_url, data=post_data) + return response.json() + + def field_delete(self, params, post_data={}): + rq_url = fmt_params( + self.url, + 'list_field_delete', + self.output, + params + ) + response = rq.get(rq_url) + return response.json() def field_edit(self, params, post_data): - request_url = '%s&api_action=list_field_edit&api_output=%s' % (self.url, self.output) - post_data = urllib.urlencode(post_data) - req = urllib2.Request(request_url, post_data) - response = json.loads(urllib2.urlopen(req).read()) - return response - - def field_view(self, params, post_data = {}): - request_url = '%s&api_action=list_field_view&api_output=%s&%s' % (self.url, self.output, params) - response = json.loads(urllib2.urlopen(request_url).read()) - return response - - def list_(self, params, post_data = {}): - request_url = '%s&api_action=list_list&api_output=%s&%s' % (self.url, self.output, params) - response = json.loads(urllib2.urlopen(request_url).read()) - return response - - def paginator(self, params, post_data = {}): - request_url = '%s&api_action=list_paginator&api_output=%s&%s' % (self.url, self.output, params) - response = json.loads(urllib2.urlopen(request_url).read()) - return response - - def view(self, params, post_data = {}): - request_url = '%s&api_action=list_view&api_output=%s&%s' % (self.url, self.output, params) - response = json.loads(urllib2.urlopen(request_url).read()) - return response - + rq_url = fmt_noparams( + self.url, + 'list_field_edit', + self.output + ) + response = rq.get(rq_url, data=post_data) + return response.json() + + def field_view(self, params, post_data={}): + rq_url = fmt_params( + self.url, + 'list_field_view', + self.output, + params + ) + response = rq.get(rq_url) + return response.json() + + def list_(self, params, post_data={}): + rq_url = fmt_params( + self.url, + 'list_list', + self.output, + params + ) + response = rq.get(rq_url) + return response.json() + + def paginator(self, params, post_data={}): + rq_url = fmt_params( + self.url, + 'list_paginator', + self.output, + params + ) + response = rq.get(rq_url) + return response.json() + + def view(self, params, post_data={}): + rq_url = fmt_params( + self.url, + 'list_view', + self.output, + params + ) + response = rq.get(rq_url) + return response.json() + + """ ## add #list1 = { @@ -81,7 +129,7 @@ def view(self, params, post_data = {}): # 'sender_city': 'Bucharest', # 'sender_zip': '123456', # 'sender_country': 'Romania' - #} + #} #print ac.api('list/add', list1) ## delete @@ -99,7 +147,7 @@ def view(self, params, post_data = {}): # 'sender_city': 'Bucharest', # 'sender_zip': '123456', # 'sender_country': 'Romania' - #} + #} #print ac.api('list/edit', list1) ## field_add diff --git a/activecampaign/Message.py b/activecampaign/Message.py index a046ff0..9446ed3 100644 --- a/activecampaign/Message.py +++ b/activecampaign/Message.py @@ -1,7 +1,10 @@ -from .ActiveCampaign import ActiveCampaign -import json -import urllib2, urllib -import datetime +from .ActiveCampaign import ( + ActiveCampaign, + fmt_params, + fmt_noparams +) +import requests as rq + class Message(ActiveCampaign): @@ -11,84 +14,139 @@ def __init__(self, url, api_key): ActiveCampaign.__init__(self, url, api_key) def add(self, params, post_data): - request_url = '%s&api_action=message_add&api_output=%s' % (self.url, self.output) - post_data = urllib.urlencode(post_data) - req = urllib2.Request(request_url, post_data) - response = json.loads(urllib2.urlopen(req).read()) - return response - - def delete_list(self, params, post_data = {}): - request_url = '%s&api_action=message_delete_list&api_output=%s&%s' % (self.url, self.output, params) - response = json.loads(urllib2.urlopen(request_url).read()) - return response - - def delete(self, params, post_data = {}): - request_url = '%s&api_action=message_delete&api_output=%s&%s' % (self.url, self.output, params) - response = json.loads(urllib2.urlopen(request_url).read()) - return response + rq_url = fmt_noparams( + self.url, + 'message_add', + self.output + ) + response = rq.get(rq_url, data=post_data) + return response.json() + + def delete_list(self, params, post_data={}): + rq_url = fmt_params( + self.url, + 'message_delete_list', + self.output, + params + ) + response = rq.get(rq_url) + return response.json() + + def delete(self, params, post_data={}): + rq_url = fmt_params( + self.url, + 'message_delete', + self.output, + params + ) + response = rq.get(rq_url) + return response.json() def edit(self, params, post_data): - request_url = '%s&api_action=message_edit&api_output=%s' % (self.url, self.output) - post_data = urllib.urlencode(post_data) - req = urllib2.Request(request_url, post_data) - response = json.loads(urllib2.urlopen(req).read()) - return response - - def list_(self, params, post_data = {}): - request_url = '%s&api_action=message_list&api_output=%s&%s' % (self.url, self.output, params) - response = json.loads(urllib2.urlopen(request_url).read()) - return response + rq_url = fmt_noparams( + self.url, + 'message_edit', + self.output + ) + response = rq.get(rq_url, data=post_data) + return response.json() + + def list_(self, params, post_data={}): + rq_url = fmt_params( + self.url, + 'message_list', + self.output, + params + ) + response = rq.get(rq_url) + return response.json() def template_add(self, params, post_data): - request_url = '%s&api_action=message_template_add&api_output=%s' % (self.url, self.output) - post_data = urllib.urlencode(post_data) - req = urllib2.Request(request_url, post_data) - response = json.loads(urllib2.urlopen(req).read()) - return response - - def template_delete_list(self, params, post_data = {}): - request_url = '%s&api_action=message_template_delete_list&api_output=%s&%s' % (self.url, self.output, params) - response = json.loads(urllib2.urlopen(request_url).read()) - return response - - def template_delete(self, params, post_data = {}): - request_url = '%s&api_action=message_template_delete&api_output=%s&%s' % (self.url, self.output, params) - response = json.loads(urllib2.urlopen(request_url).read()) - return response + rq_url = fmt_noparams( + self.url, + 'message_template_add', + self.output + ) + response = rq.get(rq_url, data=post_data) + return response.json() + + def template_delete_list(self, params, post_data={}): + rq_url = fmt_params( + self.url, + 'message_template_delete_list', + self.output, + params + ) + response = rq.get(rq_url) + return response.json() + + def template_delete(self, params, post_data={}): + rq_url = fmt_params( + self.url, + 'message_template_delete', + self.output, + params + ) + response = rq.get(rq_url) + return response.json() def template_edit(self, params, post_data): - request_url = '%s&api_action=message_template_edit&api_output=%s' % (self.url, self.output) - post_data = urllib.urlencode(post_data) - req = urllib2.Request(request_url, post_data) - response = json.loads(urllib2.urlopen(req).read()) - return response - - def template_export(self, params, post_data = {}): - request_url = '%s&api_action=message_template_export&api_output=%s&%s' % (self.url, self.output, params) - response = json.loads(urllib2.urlopen(request_url).read()) - return response + rq_url = fmt_noparams( + self.url, + 'message_template_edit', + self.output + ) + response = rq.get(rq_url, data=post_data) + return response.json() + + def template_export(self, params, post_data={}): + rq_url = fmt_params( + self.url, + 'message_template_export', + self.output, + params + ) + response = rq.get(rq_url) + return response.json() def template_import(self, params, post_data): - request_url = '%s&api_action=message_template_import&api_output=%s' % (self.url, self.output) - post_data = urllib.urlencode(post_data) - req = urllib2.Request(request_url, post_data) - response = json.loads(urllib2.urlopen(req).read()) - return response - - def template_list(self, params, post_data = {}): - request_url = '%s&api_action=message_template_list&api_output=%s&%s' % (self.url, self.output, params) - response = json.loads(urllib2.urlopen(request_url).read()) - return response - - def template_view(self, params, post_data = {}): - request_url = '%s&api_action=message_template_view&api_output=%s&%s' % (self.url, self.output, params) - response = json.loads(urllib2.urlopen(request_url).read()) - return response - - def view(self, params, post_data = {}): - request_url = '%s&api_action=message_view&api_output=%s&%s' % (self.url, self.output, params) - response = json.loads(urllib2.urlopen(request_url).read()) - return response + rq_url = fmt_noparams( + self.url, + 'message_template_import', + self.output + ) + response = rq.get(rq_url, data=post_data) + return response.json() + + def template_list(self, params, post_data={}): + rq_url = fmt_params( + self.url, + 'message_template_list', + self.output, + params + ) + response = rq.get(rq_url) + return response.json() + + def template_view(self, params, post_data={}): + rq_url = fmt_params( + self.url, + 'message_template_view', + self.output, + params + ) + response = rq.get(rq_url) + return response.json() + + def view(self, params, post_data={}): + rq_url = fmt_params( + self.url, + 'message_view', + self.output, + params + ) + response = rq.get(rq_url) + return response.json() """ @@ -137,7 +195,8 @@ def view(self, params, post_data = {}): ## template = { ## 'name': 'My New Template', ## 'subject': 'New Subject', -## 'html': 'New Template

This template was added via the API

', +## 'html': 'New Template

+## This template was added via the API

', ## 'template_scope': 'all', ## 'tags[]': 'Holiday', ## 'p[1]': 1 @@ -154,7 +213,8 @@ def view(self, params, post_data = {}): ## template = { ## 'id': 54, ## 'name': 'My New Template', -## 'html': 'New Template

This template was added via the API

', +## 'html': 'New Template

+## This template was added via the API

', ## 'p[1]': 1 ## } ## print ac.api('message/template_edit', template) @@ -177,14 +237,14 @@ def view(self, params, post_data = {}): ## 'urls[0]': 'http://example.com/template.xml' ## } ## print ac.api('message/template_import', template) - + ## template_view ## print ac.api('message/template_view?id=54') - + ## view ## print ac.api('message/view?id=1') ## template_list ## print ac.api('message/template_list?ids=76') - + """ diff --git a/activecampaign/Subscriber.py b/activecampaign/Subscriber.py index 16e21f9..3411878 100644 --- a/activecampaign/Subscriber.py +++ b/activecampaign/Subscriber.py @@ -1,6 +1,9 @@ -from .ActiveCampaign import ActiveCampaign -import json -import urllib2, urllib +from .ActiveCampaign import ( + ActiveCampaign, + fmt_params, +) +import requests as rq + class Subscriber(ActiveCampaign): @@ -10,51 +13,76 @@ def __init__(self, url, api_key): ActiveCampaign.__init__(self, url, api_key) def add(self, params, post_data): - request_url = '%s&api_action=subscriber_add&api_output=%s' % (self.url, self.output) - if params: - request_url = '%s&%s' % (request_url, params) - post_data = urllib.urlencode(post_data) - req = urllib2.Request(request_url, post_data) - response = json.loads(urllib2.urlopen(req).read()) - return response - - def delete(self, params, post_data = {}): - request_url = '%s&api_action=subscriber_delete&api_output=%s&%s' % (self.url, self.output, params) - response = json.loads(urllib2.urlopen(request_url).read()) - return response - - def delete_list(self, params, post_data = {}): - request_url = '%s&api_action=subscriber_delete_list&api_output=%s&%s' % (self.url, self.output, params) - response = json.loads(urllib2.urlopen(request_url).read()) - return response + rq_url = fmt_params( + self.url, + 'subscriber_add', + self.output, + params + ) + response = rq.get(rq_url, data=post_data) + return response.json() + + def delete(self, params, post_data={}): + rq_url = fmt_params( + self.url, + 'subscriber_delete', + self.output, + params + ) + response = rq.get(rq_url) + return response.json() + + def delete_list(self, params, post_data={}): + rq_url = fmt_params( + self.url, + 'subscriber_delete_list', + self.output, + params + ) + response = rq.get(rq_url) + return response.json() def edit(self, params, post_data): - request_url = '%s&api_action=subscriber_edit&api_output=%s&%s' % (self.url, self.output, params) - post_data = urllib.urlencode(post_data) - req = urllib2.Request(request_url, post_data) - response = json.loads(urllib2.urlopen(req).read()) - return response - - def list_(self, params, post_data = {}): - request_url = '%s&api_action=subscriber_list&api_output=%s&%s' % (self.url, self.output, params) - response = json.loads(urllib2.urlopen(request_url).read()) - return response - - def paginator(self, params, post_data = {}): - request_url = '%s&api_action=subscriber_paginator&api_output=%s&%s' % (self.url, self.output, params) - response = json.loads(urllib2.urlopen(request_url).read()) - return response + rq_url = fmt_params( + self.url, + 'subscriber_edit', + self.output, + params + ) + response = rq.get(rq_url, data=post_data) + return response.json() + + def list_(self, params, post_data={}): + rq_url = fmt_params( + self.url, + 'subscriber_list', + self.output, + params + ) + response = rq.get(rq_url) + return response.json() + + def paginator(self, params, post_data={}): + rq_url = fmt_params( + self.url, + 'subscriber_paginator', + self.output, + params + ) + response = rq.get(rq_url) + return response.json() def sync(self, params, post_data): - request_url = '%s&api_action=subscriber_sync&api_output=%s' % (self.url, self.output) - if params: - request_url = '%s&%s' % (request_url, params) - post_data = urllib.urlencode(post_data) - req = urllib2.Request(request_url, post_data) - response = json.loads(urllib2.urlopen(req).read()) - return response - - def view(self, params, post_data = {}): + rq_url = fmt_params( + self.url, + 'subscriber_sync', + self.output, + params + ) + response = rq.get(rq_url, data=post_data) + return response.json() + + def view(self, params, post_data={}): if params.startswith('email='): action = 'subscriber_view_email' elif params.startswith('hash='): @@ -63,9 +91,15 @@ def view(self, params, post_data = {}): action = 'subscriber_view' else: action = 'subscriber_view' - request_url = '%s&api_action=%s&api_output=%s&%s' % (self.url, action, self.output, params) - response = json.loads(urllib2.urlopen(request_url).read()) - return response + rq_url = fmt_params( + self.url, + action, + self.output, + params + ) + response = rq.get(rq_url) + return response.json() + """ if __name__ == '__main__': @@ -116,10 +150,10 @@ def view(self, params, post_data = {}): ## view id ## print ac.api('subscriber/view?id=12') - + ## view email ## print ac.api('subscriber/view?email=person@example.com') - + ## view hash ## print ac.api('subscriber/view?hash=3eeda4735e93f5407fced5ed45ddae82') diff --git a/activecampaign/User.py b/activecampaign/User.py index 7782a5d..48d9ab3 100644 --- a/activecampaign/User.py +++ b/activecampaign/User.py @@ -1,6 +1,10 @@ -from .ActiveCampaign import ActiveCampaign -import json -import urllib2, urllib +from .ActiveCampaign import ( + ActiveCampaign, + fmt_params, + fmt_noparams +) +import requests as rq + class User(ActiveCampaign): @@ -10,54 +14,83 @@ def __init__(self, url, api_key): ActiveCampaign.__init__(self, url, api_key) def add(self, params, post_data): - request_url = '%s&api_action=user_add&api_output=%s' % (self.url, self.output) - post_data = urllib.urlencode(post_data) - req = urllib2.Request(request_url, post_data) - response = json.loads(urllib2.urlopen(req).read()) - return response - - def delete_list(self, params, post_data = {}): - request_url = '%s&api_action=user_delete_list&api_output=%s&%s' % (self.url, self.output, params) - response = json.loads(urllib2.urlopen(request_url).read()) - return response - - def delete(self, params, post_data = {}): - request_url = '%s&api_action=user_delete&api_output=%s&%s' % (self.url, self.output, params) - response = json.loads(urllib2.urlopen(request_url).read()) - return response - + rq_url = fmt_noparams( + self.url, + 'user_add', + self.output + ) + response = rq.get(rq_url, data=post_data) + return response.json() + + def delete_list(self, params, post_data={}): + rq_url = fmt_params( + self.url, + 'user_delete_list', + self.output, + params + ) + response = rq.get(rq_url, data=post_data) + return response.json() + + def delete(self, params, post_data={}): + rq_url = fmt_params( + self.url, + 'user_delete', + self.output, + params + ) + response = rq.get(rq_url, data=post_data) + return response.json() + def edit(self, params, post_data): - request_url = '%s&api_action=user_edit&api_output=%s' % (self.url, self.output) - post_data = urllib.urlencode(post_data) - req = urllib2.Request(request_url, post_data) - response = json.loads(urllib2.urlopen(req).read()) - return response - - def list_(self, params, post_data = {}): - request_url = '%s&api_action=user_list&api_output=%s&%s' % (self.url, self.output, params) - response = json.loads(urllib2.urlopen(request_url).read()) - return response - - def me(self, params, post_data = {}): - request_url = '%s&api_action=user_me&api_output=%s' % (self.url, self.output) - response = json.loads(urllib2.urlopen(request_url).read()) - return response - - def view(self, params, post_data = {}): + rq_url = fmt_noparams( + self.url, + 'user_edit', + self.output + ) + response = rq.get(rq_url, data=post_data) + return response.json() + + def list_(self, params, post_data={}): + rq_url = fmt_params( + self.url, + 'user_list', + self.output, + params + ) + response = rq.get(rq_url) + return response.json() + + def me(self, params, post_data={}): + rq_url = fmt_noparams( + self.url, + 'user_me', + self.output + ) + response = rq.get(rq_url) + return response.json() + + def view(self, params, post_data={}): if params.startswith('email='): action = 'user_view_email' elif params.startswith('username='): action = 'user_view_username' elif params.startswith('id='): action = 'user_view' - request_url = '%s&api_action=%s&api_output=%s&%s' % (self.url, action, self.output, params) - response = json.loads(urllib2.urlopen(request_url).read()) - return response + rq_url = fmt_params( + self.url, + action, + self.output, + params + ) + response = rq.get(rq_url) + return response.json() + """ if __name__ == '__main__': ac = ActiveCampaign(ACTIVECAMPAIGN_URL, ACTIVECAMPAIGN_API_KEY) - + ## add ## user = { ## 'username': 'johnsmith', @@ -67,15 +100,15 @@ def view(self, params, post_data = {}): ## 'password_r': 'mypwd', ## 'email': 'person@example.com', ## 'group[3]' : 3 -## } +## } ## print ac.api('user/add', user) - + ## delete_list ## print ac.api('user/delete_list?ids=3,4') - + ## delete ## print ac.api('user/delete?id=5') - + ## edit ## user = { ## 'username': 'johnsmith', @@ -86,22 +119,22 @@ def view(self, params, post_data = {}): ## 'email': 'person@example.com', ## 'group[3]' : 3, ## 'id' : 6 -## } +## } ## print ac.api('user/edit', user) - + ## list ## print ac.api('user/list?ids=1,6') - + ## me ## print ac.api('user/me') - + ## view email ## print ac.api('user/view?email=person@example.com') - + ## view username ## print ac.api('user/view?username=johnsmith') - + ## view id ## print ac.api('user/view?id=1') - + """ diff --git a/activecampaign/__init__.py b/activecampaign/__init__.py index 829e2f0..2501648 100644 --- a/activecampaign/__init__.py +++ b/activecampaign/__init__.py @@ -1 +1 @@ -from .ActiveCampaign import ActiveCampaign +from ActiveCampaign import ActiveCampaign diff --git a/setup.py b/setup.py index 5c4decd..eefffe5 100644 --- a/setup.py +++ b/setup.py @@ -21,7 +21,7 @@ setup( name='active-campaign-python', - version='0.5.1', + version='0.5.2', description="Python ActiveCampaign API client", long_description=readme, author="Dennis Durling", From dbb0409162bf522c064a2ce85df298a9b5c720b4 Mon Sep 17 00:00:00 2001 From: Dennis Durling Date: Thu, 21 Sep 2017 14:48:02 -0700 Subject: [PATCH 10/36] last rel import fix --- activecampaign/__init__.py | 2 +- setup.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/activecampaign/__init__.py b/activecampaign/__init__.py index 2501648..829e2f0 100644 --- a/activecampaign/__init__.py +++ b/activecampaign/__init__.py @@ -1 +1 @@ -from ActiveCampaign import ActiveCampaign +from .ActiveCampaign import ActiveCampaign diff --git a/setup.py b/setup.py index eefffe5..7fba45c 100644 --- a/setup.py +++ b/setup.py @@ -21,7 +21,7 @@ setup( name='active-campaign-python', - version='0.5.2', + version='0.5.3', description="Python ActiveCampaign API client", long_description=readme, author="Dennis Durling", From 3dfc065d0e986a81fe3516e3657b587b702d6587 Mon Sep 17 00:00:00 2001 From: Dennis Durling Date: Thu, 21 Sep 2017 14:48:23 -0700 Subject: [PATCH 11/36] last rel import fix --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 7fba45c..f291951 100644 --- a/setup.py +++ b/setup.py @@ -21,7 +21,7 @@ setup( name='active-campaign-python', - version='0.5.3', + version='0.5.4', description="Python ActiveCampaign API client", long_description=readme, author="Dennis Durling", From 95144917bbcfc035d163296840cf1ee0fca9f57e Mon Sep 17 00:00:00 2001 From: Dennis Durling Date: Thu, 21 Sep 2017 14:50:21 -0700 Subject: [PATCH 12/36] at least globals call should work right? --- activecampaign/ActiveCampaign.py | 2 +- setup.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/activecampaign/ActiveCampaign.py b/activecampaign/ActiveCampaign.py index 0b06fd8..37c7f4a 100644 --- a/activecampaign/ActiveCampaign.py +++ b/activecampaign/ActiveCampaign.py @@ -47,7 +47,7 @@ def api(self, path, post_data={}): # "subscriber" becomes "Subscriber" class1 = '{}'.format(component.capitalize()) source_module = __import__( - class1, globals(), locals(), [], -1) # import Subscriber + class1, globals(), locals(), [], 0) # import Subscriber class1 = getattr(source_module, class1) # get Subscriber class1 = class1(self.URL, self.APIKEY) # Subscriber() # subscriber.view() diff --git a/setup.py b/setup.py index f291951..ebbbb18 100644 --- a/setup.py +++ b/setup.py @@ -21,7 +21,7 @@ setup( name='active-campaign-python', - version='0.5.4', + version='0.5.5', description="Python ActiveCampaign API client", long_description=readme, author="Dennis Durling", From 84b33df646ea3673598f62434284a1ae5dbe6870 Mon Sep 17 00:00:00 2001 From: Dennis Durling Date: Thu, 21 Sep 2017 16:13:44 -0700 Subject: [PATCH 13/36] fixed dynamic rel imports --- activecampaign/ActiveCampaign.py | 12 ++++++++---- examples.py | 1 - setup.py | 5 ++--- 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/activecampaign/ActiveCampaign.py b/activecampaign/ActiveCampaign.py index 37c7f4a..22b5524 100644 --- a/activecampaign/ActiveCampaign.py +++ b/activecampaign/ActiveCampaign.py @@ -1,3 +1,4 @@ +from importlib import import_module from .Connector import Connector # formatters for making life easier, don't you want it that way? @@ -5,6 +6,12 @@ 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=''): @@ -46,11 +53,8 @@ def api(self, path, post_data={}): # "subscriber" becomes "Subscriber" class1 = '{}'.format(component.capitalize()) - source_module = __import__( - class1, globals(), locals(), [], 0) # import Subscriber - class1 = getattr(source_module, class1) # get Subscriber + class1 = get_mod(class1, 'activecampaign') class1 = class1(self.URL, self.APIKEY) # Subscriber() - # subscriber.view() if method == 'list': # reserved word diff --git a/examples.py b/examples.py index 99f5adc..b736ac5 100644 --- a/examples.py +++ b/examples.py @@ -7,4 +7,3 @@ ac = ActiveCampaign(base_url, api_key) print(ac.api('account/view')) - diff --git a/setup.py b/setup.py index ebbbb18..b9d7ad9 100644 --- a/setup.py +++ b/setup.py @@ -21,13 +21,13 @@ setup( name='active-campaign-python', - version='0.5.5', + version='0.6.0', description="Python ActiveCampaign API client", long_description=readme, author="Dennis Durling", author_email='djdtahoe@gmail.com', url='https://github.com/tahoe/active-campaign-python', - packages=[ 'activecampaign', ], + packages=['activecampaign', ], package_dir={'activecampaign': 'activecampaign'}, include_package_data=True, install_requires=requirements, @@ -46,4 +46,3 @@ 'Programming Language :: Python :: 3.5', ] ) - From 151e2df41d0a24f54c6e717b8cfec865477b38f7 Mon Sep 17 00:00:00 2001 From: Dennis Durling Date: Thu, 21 Sep 2017 18:27:58 -0700 Subject: [PATCH 14/36] not ready --- activecampaign/Contact.py | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/activecampaign/Contact.py b/activecampaign/Contact.py index 1ed4a08..f3990f6 100644 --- a/activecampaign/Contact.py +++ b/activecampaign/Contact.py @@ -19,7 +19,7 @@ def add(self, params, post_data): 'contact_add', self.output ) - response = rq.get(rq_url, data=post_data) + response = rq.post(rq_url, data=post_data) return response.json() def delete_list(self, params, post_data={}): @@ -90,7 +90,7 @@ def view(self, params, post_data={}): """ if __name__ == '__main__': ac = ActiveCampaign(ACTIVECAMPAIGN_URL, ACTIVECAMPAIGN_API_KEY) - + ## add ## user = { ## 'username': 'johnsmith', @@ -100,15 +100,15 @@ def view(self, params, post_data={}): ## 'password_r': 'mypwd', ## 'email': 'person@example.com', ## 'group[3]' : 3 -## } +## } ## print ac.api('user/add', user) - + ## delete_list ## print ac.api('user/delete_list?ids=3,4') - + ## delete ## print ac.api('user/delete?id=5') - + ## edit ## user = { ## 'username': 'johnsmith', @@ -119,22 +119,22 @@ def view(self, params, post_data={}): ## 'email': 'person@example.com', ## 'group[3]' : 3, ## 'id' : 6 -## } +## } ## print ac.api('user/edit', user) - + ## list ## print ac.api('user/list?ids=1,6') - + ## me ## print ac.api('user/me') - + ## view email ## print ac.api('user/view?email=person@example.com') - + ## view username ## print ac.api('user/view?username=johnsmith') - + ## view id ## print ac.api('user/view?id=1') - + """ From e3f035a7027b712494569535937b17042984485c Mon Sep 17 00:00:00 2001 From: Dennis Durling Date: Thu, 21 Sep 2017 19:23:03 -0700 Subject: [PATCH 15/36] doesn't like put --- activecampaign/.Contact.py.swp | Bin 0 -> 12288 bytes activecampaign/.List.py.swp | Bin 0 -> 16384 bytes activecampaign/Contact.py | 2 +- activecampaign/List.py | 2 +- 4 files changed, 2 insertions(+), 2 deletions(-) create mode 100644 activecampaign/.Contact.py.swp create mode 100644 activecampaign/.List.py.swp diff --git a/activecampaign/.Contact.py.swp b/activecampaign/.Contact.py.swp new file mode 100644 index 0000000000000000000000000000000000000000..1c409bcd67d75bf80ba2d13def00fe62cd901156 GIT binary patch literal 12288 zcmeI2+iP4!9LFbZv}#ig7L17Em{`t6Hk-s~D1k*o8YHQyRntn4dN|oLo1A!VIWyaB zh}8!le5eXi`ykc_p&(LQAAIq_))y}iUhogF3iUz77X_sX3V!EYcQ?tdF$q$c10T-W zncw_oe&63*c9SzZaCl;h?kx-uT%ClRGi#|Cr|rSQh-Hmfa`=rGQeP zQGtpm_wC(9hVC5(iPXb0QD*E;9=_%3DBEK{Q+bhx%?F7PV;lS4;j#ZbPs zCJaRzq1q}z*BSZ-=T$E-^*~xXOD?PWRa0BlCbp<9uCTBTE_9hHY4W&(w~gvOl&zq~ zU=r!9uTK&wn`g;R1|e%{kuDRd1E!Bus)>*$vzcIW%H5xd9~HK2rKhPI%HP-6I;?Es z!Z0D++6k=7)}|zDMIMrDMwwbs-H;}^pc0LxwA$vT333o3{Td}?Z!~-*Z7hBxEjKzg zJ#lz^Y;@}2=)^+@^h1w5oTs#*aP;7WzJGkCmsn-0hto^fX|YH(UB`lUbzK`F;ocMW zB6|v$s01!<-1l703JX~9xoF#os-toYCs-`ZF_8-v^-5r87TJ@u_l>}CIFXOZ#hG0$ zcopGSM4lvt@-APw^W6Hf&=~%+(x^Z5Uv`8ZxzDZQ1_oLwdOJ^-o28c8FdJe-4GUZt zf#6l7F^AousP&GdW*AUBqDEKxyus&N`;%7x)MK>SqWv)+90Q0)l0lVgX}HlzOOkSVUw3|`kG106!kPQ8 z(i@$98%uEHW37m{cDZgK=~xNffqH*=QVu+a7V1lB+(VB14O?yaH$reyWAxs%Pv~_u~hyWe?ZYZ(%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NdWi+4#S>FG zYpt}`%nF`U)KZn9T3AAo(fa=c*1U(XKBo15I$WuAFKfjKqFw_AFS!W0$+mn!FKQr z*alXERiFd>je4H~C%~tG{P+;4ODUifPzopolmbctrGQdEDR6NrK)dR+>KN&SgEpvx z^Nsj)gMzA`Pz-JFF7mMg$u>EKg3m>^rO7gJK9g;2X)2hO;2uKUQnzL1vMsUcq0H6o z({dga^0PRz!CzTsim9G2-i{1%&x;EUVuGFc(Q?b}6D`Of*HVq;$1jd6OdLe4wTy0V zJxHe_{f1TI<%cis+DwLGh7O!a_k_zmUl=`*$QkSx`upmGu5k?bAZXHm+ n8K$$08qGkkpr4RJSBg3op`(_pq9 Date: Fri, 22 Sep 2017 09:47:18 -0700 Subject: [PATCH 16/36] left some swp files --- .gitignore | 1 + activecampaign/.Contact.py.swp | Bin 12288 -> 0 bytes activecampaign/.List.py.swp | Bin 16384 -> 0 bytes 3 files changed, 1 insertion(+) delete mode 100644 activecampaign/.Contact.py.swp delete mode 100644 activecampaign/.List.py.swp diff --git a/.gitignore b/.gitignore index fd30689..7e51e8b 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ # Compiled Python Files *.pyc +*.swp dist/* *.egg-info/ diff --git a/activecampaign/.Contact.py.swp b/activecampaign/.Contact.py.swp deleted file mode 100644 index 1c409bcd67d75bf80ba2d13def00fe62cd901156..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 12288 zcmeI2+iP4!9LFbZv}#ig7L17Em{`t6Hk-s~D1k*o8YHQyRntn4dN|oLo1A!VIWyaB zh}8!le5eXi`ykc_p&(LQAAIq_))y}iUhogF3iUz77X_sX3V!EYcQ?tdF$q$c10T-W zncw_oe&63*c9SzZaCl;h?kx-uT%ClRGi#|Cr|rSQh-Hmfa`=rGQeP zQGtpm_wC(9hVC5(iPXb0QD*E;9=_%3DBEK{Q+bhx%?F7PV;lS4;j#ZbPs zCJaRzq1q}z*BSZ-=T$E-^*~xXOD?PWRa0Bl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jiyTpGOcZM+UHg%5^9?>MPOn{Dc5Uw+!rGyLVdgp z*;$fLXlq70|F}6`;VpvO{DAv%>fZjm9(&cec@@(9E*Rg$`TJJk{QpzHuWjLDC z>r3@;k@WiXl4r#!;wMV)8lF+~89hdq&#gkrDG9eEWCw{Ng67xzO+FCTH;M>yppZDZ zEEJU}6ooF!NHR*E=LL-{Bq>jGSUm2IFZ8@2jO?b(vldPuZ(XCuv<=~S<8yh)%!T4N z^~CYHOcwMD#odC*t$Yo-c5LVTdfu!BgJo#g#DhA1qTyCHmKlAHE;*ECZRu@)ZcS}F zXAbGuQZ>IP)Tox#mETzB=K9EvOH0*UugyEHmQ5afqq3+o(0!Cwc(oRXp=w^&puub7 zaxMBd**K4m#)CF~qEyf*zh_BehTkMH9f&*yI>)4MvHjMb)J z*I*EjariC{ertYv_*3(guA802l@s+7&l??LJ31L4-B6ewJcrH`vy_S z&nSqdhG#R4X<^PXd_P##BrEGgFB@hSUB?rc8uyhjbN4mF#~hf+D$zVNdWi+4#S>FG zYpt}`%nF`U)KZn9T3AAo(fa=c*1U(XKBo15I$WuAFKfjKqFw_AFS!W0$+mn!FKQr z*alXERiFd>je4H~C%~tG{P+;4ODUifPzopolmbctrGQdEDR6NrK)dR+>KN&SgEpvx z^Nsj)gMzA`Pz-JFF7mMg$u>EKg3m>^rO7gJK9g;2X)2hO;2uKUQnzL1vMsUcq0H6o z({dga^0PRz!CzTsim9G2-i{1%&x;EUVuGFc(Q?b}6D`Of*HVq;$1jd6OdLe4wTy0V zJxHe_{f1TI<%cis+DwLGh7O!a_k_zmUl=`*$QkSx`upmGu5k?bAZXHm+ n8K$$08qGkkpr4RJSBg3op`(_pq9 Date: Fri, 22 Sep 2017 12:06:54 -0700 Subject: [PATCH 17/36] ... --- activecampaign/Account.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/activecampaign/Account.py b/activecampaign/Account.py index a233e93..eb52d2c 100644 --- a/activecampaign/Account.py +++ b/activecampaign/Account.py @@ -38,7 +38,7 @@ def edit(self, params, post_data={}): 'account_edit', self.output ) - response = rq.get(rq_url) + response = rq.post(rq_url, data=post_data) return response.json() def list_(self, params, post_data={}): From ab4d64a9762a71559cf7c2c78aebea23502b95ae Mon Sep 17 00:00:00 2001 From: Dennis Durling Date: Fri, 22 Sep 2017 19:41:01 -0700 Subject: [PATCH 18/36] removed Subscriber since it is just an alias for Contact and added in the rest of the functionality to Contact --- activecampaign/ActiveCampaign.py | 10 +- activecampaign/Contact.py | 129 ++++++++++++++++--------- activecampaign/Group.py | 4 +- activecampaign/Subscriber.py | 160 ------------------------------- setup.py | 2 +- 5 files changed, 92 insertions(+), 213 deletions(-) delete mode 100644 activecampaign/Subscriber.py diff --git a/activecampaign/ActiveCampaign.py b/activecampaign/ActiveCampaign.py index 22b5524..ebb3952 100644 --- a/activecampaign/ActiveCampaign.py +++ b/activecampaign/ActiveCampaign.py @@ -22,19 +22,19 @@ def __init__(self, url, api_key, api_user='', api_pass=''): Connector.__init__(self, url, api_key, api_user, api_pass) def api(self, path, post_data={}): - # IE: "subscriber/view" + # IE: "contact/view" components = path.split('/') component = components[0] if '?' in components[1]: # query params appended to method - # IE: subscriber/edit?overwrite=0 + # IE: contact/edit?overwrite=0 method_arr = components[1].split('?') method = method_arr[0] params = method_arr[1] else: # just a method provided - # IE: "subscriber/view + # IE: "contact/view if components[1]: method = components[1] params = '' @@ -46,12 +46,12 @@ def api(self, path, post_data={}): # reserved word component = 'design' elif component == 'sync': - component = 'subscriber' + component = 'contact' method = 'sync' elif component == 'singlesignon': component = 'auth' - # "subscriber" becomes "Subscriber" + # "contact" becomes "Contact" class1 = '{}'.format(component.capitalize()) class1 = get_mod(class1, 'activecampaign') class1 = class1(self.URL, self.APIKEY) # Subscriber() diff --git a/activecampaign/Contact.py b/activecampaign/Contact.py index 17b3328..20d6fb3 100644 --- a/activecampaign/Contact.py +++ b/activecampaign/Contact.py @@ -13,63 +13,94 @@ def __init__(self, url, api_key): self.api_key = api_key ActiveCampaign.__init__(self, url, api_key) - def add(self, params, post_data): - rq_url = fmt_noparams( - self.url, - 'contact_add', - self.output - ) + def add(self, params, post_data={}): + if params: + rq_url = fmt_params(self.url, 'contact_add', self.output, params) + else: + rq_url = fmt_noparams(self.url, 'contact_add', + self.output) response = rq.post(rq_url, data=post_data) return response.json() - def delete_list(self, params, post_data={}): - rq_url = fmt_params( - self.url, - 'contact_delete_list', - self.output, - params - ) + def automation_list(self, params): + rq_url = fmt_params(self.url, 'contact_add', + self.output, params) + response = rq.post(rq_url) + return response.json() + + def delete_list(self, params): + rq_url = fmt_params(self.url, 'contact_delete_list', + self.output, params) response = rq.get(rq_url) return response.json() - def delete(self, params, post_data={}): - rq_url = fmt_params( - self.url, - 'contact_delete', - self.output, - params - ) + def delete(self, params): + rq_url = fmt_params(self.url, 'contact_delete', + self.output, params) response = rq.get(rq_url) return response.json() - def edit(self, params, post_data): - rq_url = fmt_noparams( - self.url, - 'contact_edit', - self.output - ) + def edit(self, params, post_data={}): + rq_url = fmt_noparams(self.url, 'contact_edit', self.output) response = rq.post(rq_url, data=post_data) return response.json() - def list_(self, params, post_data={}): - rq_url = fmt_params( - self.url, - 'contact_list', - self.output, - params - ) + def list_(self, params): + rq_url = fmt_params(self.url, 'contact_list', + self.output, params) response = rq.get(rq_url) return response.json() - def me(self, params, post_data={}): - rq_url = fmt_noparams( - self.url, - 'contact_me', - self.output - ) + def note_add(self, params, post_data={}): + rq_url = fmt_params(self.url, 'contact_note_add', + self.output, params) + response = rq.post(rq_url, data=post_data) + return response.json() + + def note_edit(self, params, post_data={}): + rq_url = fmt_params(self.url, 'contact_note_edit', + self.output, params) + response = rq.post(rq_url, data=post_data) + return response.json() + + def note_delete(self, params): + rq_url = fmt_noparams(self.url, 'contact_note_delete', self.output) + response = rq.post(rq_url) + return response.json() + + def paginator(self, params): + rq_url = fmt_params(self.url, 'contact_paginator', + self.output, params) response = rq.get(rq_url) return response.json() + def sync(self, params, post_data): + if params: + rq_url = fmt_params(self.url, 'contact_sync', + self.output, params) + else: + rq_url = fmt_noparams(self.url, 'contact_sync', self.output) + response = rq.post(rq_url, data=post_data) + return response.json() + + def tag_add(self, params, post_data={}): + if params: + rq_url = fmt_params(self.url, 'contact_tag_add', + self.output, params) + else: + rq_url = fmt_noparams(self.url, 'contact_tag_add', self.output) + response = rq.post(rq_url, data=post_data) + return response.json() + + def tag_remove(self, params, post_data={}): + if params: + rq_url = fmt_params(self.url, 'contact_tag_remove', + self.output, params) + else: + rq_url = fmt_noparams(self.url, 'contact_tag_remove', self.output) + response = rq.post(rq_url, data=post_data) + return response.json() + def view(self, params, post_data={}): if params.startswith('email='): action = 'contact_view_email' @@ -77,12 +108,10 @@ def view(self, params, post_data={}): action = 'contact_view_hash' elif params.startswith('id='): action = 'contact_view' - rq_url = fmt_params( - self.url, - action, - self.output, - params - ) + else: + action = 'contact_view' + rq_url = fmt_params(self.url, action, + self.output, params) response = rq.get(rq_url) return response.json() @@ -137,4 +166,14 @@ def view(self, params, post_data={}): ## view id ## print ac.api('user/view?id=1') + ## sync +## contact = { +## 'email': 'person@example.com', +## 'first_name': 'John', +## 'last_name': 'Smith', +## 'p[1]': 1, +## 'status[1]': 1, +## } +## print ac.api('contact/sync', contact) + """ diff --git a/activecampaign/Group.py b/activecampaign/Group.py index a07ea88..b45c1fa 100644 --- a/activecampaign/Group.py +++ b/activecampaign/Group.py @@ -82,8 +82,8 @@ def view(self, params, post_data={}): # 'descript' : 'This group is created from API', # 'lists[1]' : 1, # 'pg_form_edit' : 1, - # 'pg_subscriber_add' : 1, - # 'pg_subscriber_delete' : 0 + # 'pg_contact_add' : 1, + # 'pg_contact_delete' : 0 # } # print ac.api('group/add', group) diff --git a/activecampaign/Subscriber.py b/activecampaign/Subscriber.py deleted file mode 100644 index 3411878..0000000 --- a/activecampaign/Subscriber.py +++ /dev/null @@ -1,160 +0,0 @@ -from .ActiveCampaign import ( - ActiveCampaign, - fmt_params, -) -import requests as rq - - -class Subscriber(ActiveCampaign): - - def __init__(self, url, api_key): - self.url = url - self.api_key = api_key - ActiveCampaign.__init__(self, url, api_key) - - def add(self, params, post_data): - rq_url = fmt_params( - self.url, - 'subscriber_add', - self.output, - params - ) - response = rq.get(rq_url, data=post_data) - return response.json() - - def delete(self, params, post_data={}): - rq_url = fmt_params( - self.url, - 'subscriber_delete', - self.output, - params - ) - response = rq.get(rq_url) - return response.json() - - def delete_list(self, params, post_data={}): - rq_url = fmt_params( - self.url, - 'subscriber_delete_list', - self.output, - params - ) - response = rq.get(rq_url) - return response.json() - - def edit(self, params, post_data): - rq_url = fmt_params( - self.url, - 'subscriber_edit', - self.output, - params - ) - response = rq.get(rq_url, data=post_data) - return response.json() - - def list_(self, params, post_data={}): - rq_url = fmt_params( - self.url, - 'subscriber_list', - self.output, - params - ) - response = rq.get(rq_url) - return response.json() - - def paginator(self, params, post_data={}): - rq_url = fmt_params( - self.url, - 'subscriber_paginator', - self.output, - params - ) - response = rq.get(rq_url) - return response.json() - - def sync(self, params, post_data): - rq_url = fmt_params( - self.url, - 'subscriber_sync', - self.output, - params - ) - response = rq.get(rq_url, data=post_data) - return response.json() - - def view(self, params, post_data={}): - if params.startswith('email='): - action = 'subscriber_view_email' - elif params.startswith('hash='): - action = 'subscriber_view_hash' - elif params.startswith('id='): - action = 'subscriber_view' - else: - action = 'subscriber_view' - rq_url = fmt_params( - self.url, - action, - self.output, - params - ) - response = rq.get(rq_url) - return response.json() - - -""" -if __name__ == '__main__': - ac = ActiveCampaign(ACTIVECAMPAIGN_URL, ACTIVECAMPAIGN_API_KEY) - - ## add -## subscriber = { -## 'email': 'person@example.com', -## 'first_name': 'John', -## 'last_name': 'Smith', -## 'p[1]': 1, -## 'status[1]': 1, -## } -## print ac.api('subscriber/add', subscriber) - - ## delete -## print ac.api('subscriber/delete?id=10') - - ## delete_list -## print ac.api('subscriber/delete_list?ids=9,11') - - ## edit -## subscriber = { -## 'id': 12, -## 'email': 'person@example.com', -## 'first_name': 'Johnny', -## 'last_name': 'Smith', -## 'p[1]': 1, -## 'status[1]': 1 -## } -## print ac.api('subscriber/edit', subscriber) - - ## list -## print ac.api('subscriber/list?ids=1,12') - - ## paginator -## print ac.api('subscriber/paginator?sort=&offset=0&limit=20&filter=0') - - ## sync -## subscriber = { -## 'email': 'person@example.com', -## 'first_name': 'John', -## 'last_name': 'Smith', -## 'p[1]': 1, -## 'status[1]': 1, -## } -## print ac.api('subscriber/sync', subscriber) - - ## view id -## print ac.api('subscriber/view?id=12') - - ## view email -## print ac.api('subscriber/view?email=person@example.com') - - ## view hash -## print ac.api('subscriber/view?hash=3eeda4735e93f5407fced5ed45ddae82') - -""" diff --git a/setup.py b/setup.py index b9d7ad9..32bebd0 100644 --- a/setup.py +++ b/setup.py @@ -21,7 +21,7 @@ setup( name='active-campaign-python', - version='0.6.0', + version='0.7.0', description="Python ActiveCampaign API client", long_description=readme, author="Dennis Durling", From e95de1e71f6b8adb046c1a51d69793b7cb747013 Mon Sep 17 00:00:00 2001 From: Dennis Durling Date: Fri, 22 Sep 2017 19:47:21 -0700 Subject: [PATCH 19/36] updated base class to not pass post_data if there wasn't any --- activecampaign/ActiveCampaign.py | 5 ++++- setup.py | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/activecampaign/ActiveCampaign.py b/activecampaign/ActiveCampaign.py index ebb3952..1117e0b 100644 --- a/activecampaign/ActiveCampaign.py +++ b/activecampaign/ActiveCampaign.py @@ -61,5 +61,8 @@ def api(self, path, post_data={}): method = 'list_' if method in dir(class1): - return getattr(class1, method)(params, post_data) + if post_data: + return getattr(class1, method)(params, post_data) + else: + return getattr(class1, method)(params) return None diff --git a/setup.py b/setup.py index 32bebd0..f82e698 100644 --- a/setup.py +++ b/setup.py @@ -21,7 +21,7 @@ setup( name='active-campaign-python', - version='0.7.0', + version='0.7.1', description="Python ActiveCampaign API client", long_description=readme, author="Dennis Durling", From da564e0c4ae0bc2d4d69b4de637f5634d2cdd577 Mon Sep 17 00:00:00 2001 From: Dennis Durling Date: Sat, 23 Sep 2017 15:04:26 -0700 Subject: [PATCH 20/36] updated method returns to just return the request object rather than the .json() output since it might error and better to be in the main program for now --- activecampaign/Account.py | 18 +++++++++--------- activecampaign/Campaign.py | 38 +++++++++++++++++++------------------- activecampaign/Contact.py | 28 ++++++++++++++-------------- activecampaign/Design.py | 2 +- activecampaign/Form.py | 4 ++-- activecampaign/Group.py | 12 ++++++------ activecampaign/List.py | 22 +++++++++++----------- activecampaign/Message.py | 28 ++++++++++++++-------------- activecampaign/User.py | 14 +++++++------- setup.py | 2 +- 10 files changed, 84 insertions(+), 84 deletions(-) diff --git a/activecampaign/Account.py b/activecampaign/Account.py index eb52d2c..aade44e 100644 --- a/activecampaign/Account.py +++ b/activecampaign/Account.py @@ -20,7 +20,7 @@ def add(self, params, post_data={}): self.output ) response = rq.post(rq_url, data=post_data) - return response.json() + return response def cancel(self, params, post_data={}): rq_url = fmt_params( @@ -30,7 +30,7 @@ def cancel(self, params, post_data={}): params ) response = rq.get(rq_url) - return response.json() + return response def edit(self, params, post_data={}): rq_url = fmt_noparams( @@ -39,7 +39,7 @@ def edit(self, params, post_data={}): self.output ) response = rq.post(rq_url, data=post_data) - return response.json() + return response def list_(self, params, post_data={}): rq_url = fmt_params( @@ -49,7 +49,7 @@ def list_(self, params, post_data={}): params ) response = rq.get(rq_url) - return response.json() + return response def name_check(self, params, post_data={}): rq_url = fmt_params( @@ -59,7 +59,7 @@ def name_check(self, params, post_data={}): params ) response = rq.get(rq_url) - return response.json() + return response def plans(self, params, post_data={}): rq_url = fmt_params( @@ -69,7 +69,7 @@ def plans(self, params, post_data={}): params ) response = rq.get(rq_url) - return response.json() + return response def status(self, params, post_data={}): rq_url = fmt_params( @@ -79,7 +79,7 @@ def status(self, params, post_data={}): params ) response = rq.get(rq_url) - return response.json() + return response def status_set(self, params, post_data={}): rq_url = fmt_params( @@ -89,7 +89,7 @@ def status_set(self, params, post_data={}): params ) response = rq.get(rq_url) - return response.json() + return response def view(self, params, post_data={}): rq_url = fmt_noparams( @@ -98,7 +98,7 @@ def view(self, params, post_data={}): self.output ) response = rq.get(rq_url) - return response.json() + return response """ diff --git a/activecampaign/Campaign.py b/activecampaign/Campaign.py index 4678e2b..24bf1c0 100644 --- a/activecampaign/Campaign.py +++ b/activecampaign/Campaign.py @@ -20,7 +20,7 @@ def create(self, params, post_data): self.output ) response = rq.post(rq_url, data=post_data) - return response.json() + return response def delete(self, params, post_data={}): rq_url = fmt_params( @@ -30,7 +30,7 @@ def delete(self, params, post_data={}): params ) response = rq.get(rq_url) - return response.json() + return response def delete_list(self, params, post_data={}): rq_url = fmt_params( @@ -40,7 +40,7 @@ def delete_list(self, params, post_data={}): params ) response = rq.get(rq_url) - return response.json() + return response def list_(self, params, post_data={}): rq_url = fmt_params( @@ -50,7 +50,7 @@ def list_(self, params, post_data={}): params ) response = rq.get(rq_url) - return response.json() + return response def paginator(self, params, post_data={}): rq_url = fmt_params( @@ -60,7 +60,7 @@ def paginator(self, params, post_data={}): params ) response = rq.get(rq_url) - return response.json() + return response def report_bounce_list(self, params, post_data={}): rq_url = fmt_params( @@ -70,7 +70,7 @@ def report_bounce_list(self, params, post_data={}): params ) response = rq.get(rq_url) - return response.json() + return response def report_bounce_totals(self, params, post_data={}): rq_url = fmt_params( @@ -80,7 +80,7 @@ def report_bounce_totals(self, params, post_data={}): params ) response = rq.get(rq_url) - return response.json() + return response def report_forward_list(self, params, post_data={}): rq_url = fmt_params( @@ -90,7 +90,7 @@ def report_forward_list(self, params, post_data={}): params ) response = rq.get(rq_url) - return response.json() + return response def report_forward_totals(self, params, post_data={}): rq_url = fmt_params( @@ -100,7 +100,7 @@ def report_forward_totals(self, params, post_data={}): params ) response = rq.get(rq_url) - return response.json() + return response def report_link_list(self, params, post_data={}): rq_url = fmt_params( @@ -110,7 +110,7 @@ def report_link_list(self, params, post_data={}): params ) response = rq.get(rq_url) - return response.json() + return response def report_link_totals(self, params, post_data={}): rq_url = fmt_params( @@ -120,7 +120,7 @@ def report_link_totals(self, params, post_data={}): params ) response = rq.get(rq_url) - return response.json() + return response def report_open_list(self, params, post_data={}): rq_url = fmt_params( @@ -130,7 +130,7 @@ def report_open_list(self, params, post_data={}): params ) response = rq.get(rq_url) - return response.json() + return response def report_open_totals(self, params, post_data={}): rq_url = fmt_params( @@ -140,7 +140,7 @@ def report_open_totals(self, params, post_data={}): params ) response = rq.get(rq_url) - return response.json() + return response def report_totals(self, params, post_data={}): rq_url = fmt_params( @@ -150,7 +150,7 @@ def report_totals(self, params, post_data={}): params ) response = rq.get(rq_url) - return response.json() + return response def report_unopen_list(self, params, post_data={}): rq_url = fmt_params( @@ -160,7 +160,7 @@ def report_unopen_list(self, params, post_data={}): params ) response = rq.get(rq_url) - return response.json() + return response def report_unsubscription_list(self, params, post_data={}): rq_url = fmt_params( @@ -170,7 +170,7 @@ def report_unsubscription_list(self, params, post_data={}): params ) response = rq.get(rq_url) - return response.json() + return response def report_unsubscription_totals(self, params, post_data={}): rq_url = fmt_params( @@ -180,7 +180,7 @@ def report_unsubscription_totals(self, params, post_data={}): params ) response = rq.get(rq_url) - return response.json() + return response def send(self, params, post_data={}): rq_url = fmt_params( @@ -190,7 +190,7 @@ def send(self, params, post_data={}): params ) response = rq.get(rq_url) - return response.json() + return response def status(self, params, post_data={}): rq_url = fmt_params( @@ -200,7 +200,7 @@ def status(self, params, post_data={}): params ) response = rq.get(rq_url) - return response.json() + return response """ diff --git a/activecampaign/Contact.py b/activecampaign/Contact.py index 20d6fb3..e13d6d2 100644 --- a/activecampaign/Contact.py +++ b/activecampaign/Contact.py @@ -20,59 +20,59 @@ def add(self, params, post_data={}): rq_url = fmt_noparams(self.url, 'contact_add', self.output) response = rq.post(rq_url, data=post_data) - return response.json() + return response def automation_list(self, params): rq_url = fmt_params(self.url, 'contact_add', self.output, params) response = rq.post(rq_url) - return response.json() + return response def delete_list(self, params): rq_url = fmt_params(self.url, 'contact_delete_list', self.output, params) response = rq.get(rq_url) - return response.json() + return response def delete(self, params): rq_url = fmt_params(self.url, 'contact_delete', self.output, params) response = rq.get(rq_url) - return response.json() + return response def edit(self, params, post_data={}): rq_url = fmt_noparams(self.url, 'contact_edit', self.output) response = rq.post(rq_url, data=post_data) - return response.json() + return response def list_(self, params): rq_url = fmt_params(self.url, 'contact_list', self.output, params) response = rq.get(rq_url) - return response.json() + return response def note_add(self, params, post_data={}): rq_url = fmt_params(self.url, 'contact_note_add', self.output, params) response = rq.post(rq_url, data=post_data) - return response.json() + return response def note_edit(self, params, post_data={}): rq_url = fmt_params(self.url, 'contact_note_edit', self.output, params) response = rq.post(rq_url, data=post_data) - return response.json() + return response def note_delete(self, params): rq_url = fmt_noparams(self.url, 'contact_note_delete', self.output) response = rq.post(rq_url) - return response.json() + return response def paginator(self, params): rq_url = fmt_params(self.url, 'contact_paginator', self.output, params) response = rq.get(rq_url) - return response.json() + return response def sync(self, params, post_data): if params: @@ -81,7 +81,7 @@ def sync(self, params, post_data): else: rq_url = fmt_noparams(self.url, 'contact_sync', self.output) response = rq.post(rq_url, data=post_data) - return response.json() + return response def tag_add(self, params, post_data={}): if params: @@ -90,7 +90,7 @@ def tag_add(self, params, post_data={}): else: rq_url = fmt_noparams(self.url, 'contact_tag_add', self.output) response = rq.post(rq_url, data=post_data) - return response.json() + return response def tag_remove(self, params, post_data={}): if params: @@ -99,7 +99,7 @@ def tag_remove(self, params, post_data={}): else: rq_url = fmt_noparams(self.url, 'contact_tag_remove', self.output) response = rq.post(rq_url, data=post_data) - return response.json() + return response def view(self, params, post_data={}): if params.startswith('email='): @@ -113,7 +113,7 @@ def view(self, params, post_data={}): rq_url = fmt_params(self.url, action, self.output, params) response = rq.get(rq_url) - return response.json() + return response """ diff --git a/activecampaign/Design.py b/activecampaign/Design.py index 0d67df1..aa1f9cd 100644 --- a/activecampaign/Design.py +++ b/activecampaign/Design.py @@ -29,7 +29,7 @@ def view(self, params, post_data): self.output ) response = rq.get(rq_url) - return response.json() + return response """ diff --git a/activecampaign/Form.py b/activecampaign/Form.py index 3bfcc1a..f711e9d 100644 --- a/activecampaign/Form.py +++ b/activecampaign/Form.py @@ -20,7 +20,7 @@ def getforms(self, params, post_data={}): self.output ) response = rq.get(rq_url, data=post_data) - return response.json() + return response def html(self, params, post_data={}): rq_url = fmt_params( @@ -30,7 +30,7 @@ def html(self, params, post_data={}): params ) response = rq.get(rq_url) - return response.json() + return response """ diff --git a/activecampaign/Group.py b/activecampaign/Group.py index b45c1fa..050352d 100644 --- a/activecampaign/Group.py +++ b/activecampaign/Group.py @@ -20,7 +20,7 @@ def add(self, params, post_data): self.output ) response = rq.get(rq_url, data=post_data) - return response.json() + return response def delete_list(self, params, post_data={}): rq_url = fmt_params( @@ -30,7 +30,7 @@ def delete_list(self, params, post_data={}): params ) response = rq.get(rq_url) - return response.json() + return response def delete(self, params, post_data={}): rq_url = fmt_params( @@ -40,7 +40,7 @@ def delete(self, params, post_data={}): params ) response = rq.get(rq_url) - return response.json() + return response def edit(self, params, post_data): rq_url = fmt_noparams( @@ -49,7 +49,7 @@ def edit(self, params, post_data): self.output ) response = rq.get(rq_url, data=post_data) - return response.json() + return response def list_(self, params, post_data={}): rq_url = fmt_params( @@ -59,7 +59,7 @@ def list_(self, params, post_data={}): params ) response = rq.get(rq_url) - return response.json() + return response def view(self, params, post_data={}): rq_url = fmt_params( @@ -69,7 +69,7 @@ def view(self, params, post_data={}): params ) response = rq.get(rq_url) - return response.json() + return response """ diff --git a/activecampaign/List.py b/activecampaign/List.py index c71dc4b..3973557 100644 --- a/activecampaign/List.py +++ b/activecampaign/List.py @@ -20,7 +20,7 @@ def add(self, params, post_data): self.output ) response = rq.post(rq_url, data=post_data) - return response.json() + return response def delete(self, params, post_data={}): rq_url = fmt_params( @@ -30,7 +30,7 @@ def delete(self, params, post_data={}): params ) response = rq.get(rq_url) - return response.json() + return response def delete_list(self, params, post_data={}): rq_url = fmt_params( @@ -40,7 +40,7 @@ def delete_list(self, params, post_data={}): params ) response = rq.get(rq_url) - return response.json() + return response def edit(self, params, post_data): rq_url = fmt_noparams( @@ -49,7 +49,7 @@ def edit(self, params, post_data): self.output ) response = rq.get(rq_url, data=post_data) - return response.json() + return response def field_add(self, params, post_data): rq_url = fmt_noparams( @@ -58,7 +58,7 @@ def field_add(self, params, post_data): self.output ) response = rq.get(rq_url, data=post_data) - return response.json() + return response def field_delete(self, params, post_data={}): rq_url = fmt_params( @@ -68,7 +68,7 @@ def field_delete(self, params, post_data={}): params ) response = rq.get(rq_url) - return response.json() + return response def field_edit(self, params, post_data): rq_url = fmt_noparams( @@ -77,7 +77,7 @@ def field_edit(self, params, post_data): self.output ) response = rq.get(rq_url, data=post_data) - return response.json() + return response def field_view(self, params, post_data={}): rq_url = fmt_params( @@ -87,7 +87,7 @@ def field_view(self, params, post_data={}): params ) response = rq.get(rq_url) - return response.json() + return response def list_(self, params, post_data={}): rq_url = fmt_params( @@ -97,7 +97,7 @@ def list_(self, params, post_data={}): params ) response = rq.get(rq_url) - return response.json() + return response def paginator(self, params, post_data={}): rq_url = fmt_params( @@ -107,7 +107,7 @@ def paginator(self, params, post_data={}): params ) response = rq.get(rq_url) - return response.json() + return response def view(self, params, post_data={}): rq_url = fmt_params( @@ -117,7 +117,7 @@ def view(self, params, post_data={}): params ) response = rq.get(rq_url) - return response.json() + return response """ diff --git a/activecampaign/Message.py b/activecampaign/Message.py index 9446ed3..dffd558 100644 --- a/activecampaign/Message.py +++ b/activecampaign/Message.py @@ -20,7 +20,7 @@ def add(self, params, post_data): self.output ) response = rq.get(rq_url, data=post_data) - return response.json() + return response def delete_list(self, params, post_data={}): rq_url = fmt_params( @@ -30,7 +30,7 @@ def delete_list(self, params, post_data={}): params ) response = rq.get(rq_url) - return response.json() + return response def delete(self, params, post_data={}): rq_url = fmt_params( @@ -40,7 +40,7 @@ def delete(self, params, post_data={}): params ) response = rq.get(rq_url) - return response.json() + return response def edit(self, params, post_data): rq_url = fmt_noparams( @@ -49,7 +49,7 @@ def edit(self, params, post_data): self.output ) response = rq.get(rq_url, data=post_data) - return response.json() + return response def list_(self, params, post_data={}): rq_url = fmt_params( @@ -59,7 +59,7 @@ def list_(self, params, post_data={}): params ) response = rq.get(rq_url) - return response.json() + return response def template_add(self, params, post_data): rq_url = fmt_noparams( @@ -68,7 +68,7 @@ def template_add(self, params, post_data): self.output ) response = rq.get(rq_url, data=post_data) - return response.json() + return response def template_delete_list(self, params, post_data={}): rq_url = fmt_params( @@ -78,7 +78,7 @@ def template_delete_list(self, params, post_data={}): params ) response = rq.get(rq_url) - return response.json() + return response def template_delete(self, params, post_data={}): rq_url = fmt_params( @@ -88,7 +88,7 @@ def template_delete(self, params, post_data={}): params ) response = rq.get(rq_url) - return response.json() + return response def template_edit(self, params, post_data): rq_url = fmt_noparams( @@ -97,7 +97,7 @@ def template_edit(self, params, post_data): self.output ) response = rq.get(rq_url, data=post_data) - return response.json() + return response def template_export(self, params, post_data={}): rq_url = fmt_params( @@ -107,7 +107,7 @@ def template_export(self, params, post_data={}): params ) response = rq.get(rq_url) - return response.json() + return response def template_import(self, params, post_data): rq_url = fmt_noparams( @@ -116,7 +116,7 @@ def template_import(self, params, post_data): self.output ) response = rq.get(rq_url, data=post_data) - return response.json() + return response def template_list(self, params, post_data={}): rq_url = fmt_params( @@ -126,7 +126,7 @@ def template_list(self, params, post_data={}): params ) response = rq.get(rq_url) - return response.json() + return response def template_view(self, params, post_data={}): rq_url = fmt_params( @@ -136,7 +136,7 @@ def template_view(self, params, post_data={}): params ) response = rq.get(rq_url) - return response.json() + return response def view(self, params, post_data={}): rq_url = fmt_params( @@ -146,7 +146,7 @@ def view(self, params, post_data={}): params ) response = rq.get(rq_url) - return response.json() + return response """ diff --git a/activecampaign/User.py b/activecampaign/User.py index 48d9ab3..783f30a 100644 --- a/activecampaign/User.py +++ b/activecampaign/User.py @@ -20,7 +20,7 @@ def add(self, params, post_data): self.output ) response = rq.get(rq_url, data=post_data) - return response.json() + return response def delete_list(self, params, post_data={}): rq_url = fmt_params( @@ -30,7 +30,7 @@ def delete_list(self, params, post_data={}): params ) response = rq.get(rq_url, data=post_data) - return response.json() + return response def delete(self, params, post_data={}): rq_url = fmt_params( @@ -40,7 +40,7 @@ def delete(self, params, post_data={}): params ) response = rq.get(rq_url, data=post_data) - return response.json() + return response def edit(self, params, post_data): rq_url = fmt_noparams( @@ -49,7 +49,7 @@ def edit(self, params, post_data): self.output ) response = rq.get(rq_url, data=post_data) - return response.json() + return response def list_(self, params, post_data={}): rq_url = fmt_params( @@ -59,7 +59,7 @@ def list_(self, params, post_data={}): params ) response = rq.get(rq_url) - return response.json() + return response def me(self, params, post_data={}): rq_url = fmt_noparams( @@ -68,7 +68,7 @@ def me(self, params, post_data={}): self.output ) response = rq.get(rq_url) - return response.json() + return response def view(self, params, post_data={}): if params.startswith('email='): @@ -84,7 +84,7 @@ def view(self, params, post_data={}): params ) response = rq.get(rq_url) - return response.json() + return response """ diff --git a/setup.py b/setup.py index f82e698..7558920 100644 --- a/setup.py +++ b/setup.py @@ -21,7 +21,7 @@ setup( name='active-campaign-python', - version='0.7.1', + version='0.7.2', description="Python ActiveCampaign API client", long_description=readme, author="Dennis Durling", From ac331d779f90d5e400aa899b628fd0a0f4cdaca4 Mon Sep 17 00:00:00 2001 From: Dennis Durling Date: Sun, 24 Sep 2017 22:33:56 -0700 Subject: [PATCH 21/36] testing out some shorthand methods and calling super now on the parent class since I want to sublcass this class --- activecampaign/ActiveCampaign.py | 2 +- activecampaign/Contact.py | 92 ++++++++++++++++++++++++++++++++ setup.py | 2 +- 3 files changed, 94 insertions(+), 2 deletions(-) diff --git a/activecampaign/ActiveCampaign.py b/activecampaign/ActiveCampaign.py index 1117e0b..8ac18dd 100644 --- a/activecampaign/ActiveCampaign.py +++ b/activecampaign/ActiveCampaign.py @@ -19,7 +19,7 @@ def __init__(self, url, api_key, api_user='', api_pass=''): self.api_key = api_key self.URL = url self.APIKEY = api_key - Connector.__init__(self, url, api_key, api_user, api_pass) + super().__init__(url, api_key, api_user, api_pass) def api(self, path, post_data={}): # IE: "contact/view" diff --git a/activecampaign/Contact.py b/activecampaign/Contact.py index e13d6d2..9e62dd3 100644 --- a/activecampaign/Contact.py +++ b/activecampaign/Contact.py @@ -115,6 +115,98 @@ def view(self, params, post_data={}): response = rq.get(rq_url) return response + ## 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, tags=None): + """ Add tags by id for company/contact + + Arguments: + cid:str contact/susbscriber ID + tags:list(str) list of tags as strings + """ + if not isinstance(tags, list): + raise AttributeError("tags must be a list of strings") + response = self.api('contact/tag_add?id={}'.format(cid), + post_data={'tags':tags}) + return self._response + + # delete + def _delete_tags_by_id(self, cid=None, tags=None): + """ Delete a tag by a contact/susbscriber ID + + Arguments: + cid:str contact/susbscriber ID + tags:list(str) list of tags as strings + """ + if not isinstance(tags, list): + raise AttributeError("tags must be a list of strings") + response = self.api('contact/tag_remove?id={}'.format(cid), + post_data={'tags':tags}) + return self._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...) + """ if __name__ == '__main__': diff --git a/setup.py b/setup.py index 7558920..807ffda 100644 --- a/setup.py +++ b/setup.py @@ -21,7 +21,7 @@ setup( name='active-campaign-python', - version='0.7.2', + version='0.7.3', description="Python ActiveCampaign API client", long_description=readme, author="Dennis Durling", From 0bc4073b61cd98b268fc5417fcc5cc7b67dd77a4 Mon Sep 17 00:00:00 2001 From: Dennis Durling Date: Sun, 24 Sep 2017 22:41:46 -0700 Subject: [PATCH 22/36] moved shortcut commands to main object --- activecampaign/ActiveCampaign.py | 92 ++++++++++++++++++++++++++++++++ activecampaign/Contact.py | 92 -------------------------------- setup.py | 2 +- 3 files changed, 93 insertions(+), 93 deletions(-) diff --git a/activecampaign/ActiveCampaign.py b/activecampaign/ActiveCampaign.py index 8ac18dd..e4b114a 100644 --- a/activecampaign/ActiveCampaign.py +++ b/activecampaign/ActiveCampaign.py @@ -66,3 +66,95 @@ def api(self, path, 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, tags=None): + """ Add tags by id for company/contact + + Arguments: + cid:str contact/susbscriber ID + tags:list(str) list of tags as strings + """ + if not isinstance(tags, list): + raise AttributeError("tags must be a list of strings") + response = self.api('contact/tag_add?id={}'.format(cid), + post_data={'tags':tags}) + return self._response + + # delete + def _delete_tags_by_id(self, cid=None, tags=None): + """ Delete a tag by a contact/susbscriber ID + + Arguments: + cid:str contact/susbscriber ID + tags:list(str) list of tags as strings + """ + if not isinstance(tags, list): + raise AttributeError("tags must be a list of strings") + response = self.api('contact/tag_remove?id={}'.format(cid), + post_data={'tags':tags}) + return self._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...) diff --git a/activecampaign/Contact.py b/activecampaign/Contact.py index 9e62dd3..e13d6d2 100644 --- a/activecampaign/Contact.py +++ b/activecampaign/Contact.py @@ -115,98 +115,6 @@ def view(self, params, post_data={}): response = rq.get(rq_url) return response - ## 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, tags=None): - """ Add tags by id for company/contact - - Arguments: - cid:str contact/susbscriber ID - tags:list(str) list of tags as strings - """ - if not isinstance(tags, list): - raise AttributeError("tags must be a list of strings") - response = self.api('contact/tag_add?id={}'.format(cid), - post_data={'tags':tags}) - return self._response - - # delete - def _delete_tags_by_id(self, cid=None, tags=None): - """ Delete a tag by a contact/susbscriber ID - - Arguments: - cid:str contact/susbscriber ID - tags:list(str) list of tags as strings - """ - if not isinstance(tags, list): - raise AttributeError("tags must be a list of strings") - response = self.api('contact/tag_remove?id={}'.format(cid), - post_data={'tags':tags}) - return self._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...) - """ if __name__ == '__main__': diff --git a/setup.py b/setup.py index 807ffda..0fe8aca 100644 --- a/setup.py +++ b/setup.py @@ -21,7 +21,7 @@ setup( name='active-campaign-python', - version='0.7.3', + version='0.7.4', description="Python ActiveCampaign API client", long_description=readme, author="Dennis Durling", From 241d7000375768a14dc71632fd44d5b41e0c6268 Mon Sep 17 00:00:00 2001 From: Dennis Durling Date: Sun, 24 Sep 2017 23:44:53 -0700 Subject: [PATCH 23/36] mostly done for now --- activecampaign/ActiveCampaign.py | 16 ++++++++++++++++ activecampaign/Contact.py | 2 +- activecampaign/Organization.py | 20 ++++++++++++++++++++ setup.py | 2 +- 4 files changed, 38 insertions(+), 2 deletions(-) create mode 100644 activecampaign/Organization.py diff --git a/activecampaign/ActiveCampaign.py b/activecampaign/ActiveCampaign.py index e4b114a..e180532 100644 --- a/activecampaign/ActiveCampaign.py +++ b/activecampaign/ActiveCampaign.py @@ -158,3 +158,19 @@ def _delete_note_by_id(self, nid=None): 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 diff --git a/activecampaign/Contact.py b/activecampaign/Contact.py index e13d6d2..acbc697 100644 --- a/activecampaign/Contact.py +++ b/activecampaign/Contact.py @@ -11,7 +11,7 @@ class Contact(ActiveCampaign): def __init__(self, url, api_key): self.url = url self.api_key = api_key - ActiveCampaign.__init__(self, url, api_key) + super().__init__(url, api_key) def add(self, params, post_data={}): if params: diff --git a/activecampaign/Organization.py b/activecampaign/Organization.py new file mode 100644 index 0000000..74a8b0d --- /dev/null +++ b/activecampaign/Organization.py @@ -0,0 +1,20 @@ +from .ActiveCampaign import ( + ActiveCampaign, + fmt_params, + fmt_noparams +) +import requests as rq + + +class Organization(ActiveCampaign): + + def __init__(self, url, api_key): + self.url = url + self.api_key = api_key + super.__init__(url, api_key) + + def list_(self, params): + rq_url = fmt_params(self.url, 'organization_list', + self.output, params) + response = rq.get(rq_url) + return response diff --git a/setup.py b/setup.py index 0fe8aca..2539da5 100644 --- a/setup.py +++ b/setup.py @@ -21,7 +21,7 @@ setup( name='active-campaign-python', - version='0.7.4', + version='0.8.0', description="Python ActiveCampaign API client", long_description=readme, author="Dennis Durling", From 452a5ccc21c0b1d184bd05e0c0319abdc2a8f03c Mon Sep 17 00:00:00 2001 From: Dennis Durling Date: Mon, 25 Sep 2017 13:36:34 -0700 Subject: [PATCH 24/36] just some pep shit --- activecampaign/ActiveCampaign.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/activecampaign/ActiveCampaign.py b/activecampaign/ActiveCampaign.py index e180532..f20e851 100644 --- a/activecampaign/ActiveCampaign.py +++ b/activecampaign/ActiveCampaign.py @@ -67,7 +67,7 @@ def api(self, path, post_data={}): return getattr(class1, method)(params) return None - ## extra methods I created for shorthand scripting + # extra methods I created for shorthand scripting # get def _get_contact_by_id(self, cid=None): """Get a contact by ID @@ -106,7 +106,7 @@ def _create_contact(self, data=None): """ response = self.api('contact/ad', post_data=data) return response - ## end contact section + # end contact section # create def _add_tags_by_id(self, cid=None, tags=None): @@ -119,8 +119,8 @@ def _add_tags_by_id(self, cid=None, tags=None): if not isinstance(tags, list): raise AttributeError("tags must be a list of strings") response = self.api('contact/tag_add?id={}'.format(cid), - post_data={'tags':tags}) - return self._response + post_data={'tags': tags}) + return response # delete def _delete_tags_by_id(self, cid=None, tags=None): @@ -133,8 +133,8 @@ def _delete_tags_by_id(self, cid=None, tags=None): if not isinstance(tags, list): raise AttributeError("tags must be a list of strings") response = self.api('contact/tag_remove?id={}'.format(cid), - post_data={'tags':tags}) - return self._response + post_data={'tags': tags}) + return response def _add_note_by_id(self, cid=None, note=""): """ Add a Note for a contact/company @@ -143,7 +143,7 @@ def _add_note_by_id(self, cid=None, note=""): cid:str contact/susbscriber ID note:str a note """ - data = {"id": cid, "note":note} + data = {"id": cid, "note": note} response = self.api('contact/note_add?id={}'.format(cid), post_data=data) return response @@ -157,7 +157,7 @@ def _delete_note_by_id(self, nid=None): """ response = self.api('contact/note_delete?noteid={}'.format(nid)) return response - ## end contact components (properties, tags...) + # end contact components (properties, tags...) # list contacts def _list_contacts(self): From 4cf3b4d7b67dd4b2e7cc94e8094f6ef28dc57d85 Mon Sep 17 00:00:00 2001 From: Dennis Durling Date: Mon, 25 Sep 2017 15:48:18 -0700 Subject: [PATCH 25/36] shorter lines for split screen --- activecampaign/Contact.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/activecampaign/Contact.py b/activecampaign/Contact.py index acbc697..dc2d7fb 100644 --- a/activecampaign/Contact.py +++ b/activecampaign/Contact.py @@ -15,7 +15,8 @@ def __init__(self, url, api_key): def add(self, params, post_data={}): if params: - rq_url = fmt_params(self.url, 'contact_add', self.output, params) + rq_url = fmt_params(self.url, 'contact_add', + self.output, params) else: rq_url = fmt_noparams(self.url, 'contact_add', self.output) @@ -64,7 +65,8 @@ def note_edit(self, params, post_data={}): return response def note_delete(self, params): - rq_url = fmt_noparams(self.url, 'contact_note_delete', self.output) + rq_url = fmt_noparams(self.url, 'contact_note_delete', + self.output) response = rq.post(rq_url) return response @@ -88,7 +90,8 @@ def tag_add(self, params, post_data={}): rq_url = fmt_params(self.url, 'contact_tag_add', self.output, params) else: - rq_url = fmt_noparams(self.url, 'contact_tag_add', self.output) + rq_url = fmt_noparams(self.url, 'contact_tag_add', + self.output) response = rq.post(rq_url, data=post_data) return response @@ -97,7 +100,8 @@ def tag_remove(self, params, post_data={}): rq_url = fmt_params(self.url, 'contact_tag_remove', self.output, params) else: - rq_url = fmt_noparams(self.url, 'contact_tag_remove', self.output) + rq_url = fmt_noparams(self.url, 'contact_tag_remove', + self.output) response = rq.post(rq_url, data=post_data) return response From 13565c5f998f82ea51f29ce5df62bbd029c610a5 Mon Sep 17 00:00:00 2001 From: Dennis Durling Date: Tue, 26 Sep 2017 12:49:42 -0700 Subject: [PATCH 26/36] tags becomes tags since it's gonna be a string --- activecampaign/ActiveCampaign.py | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/activecampaign/ActiveCampaign.py b/activecampaign/ActiveCampaign.py index f20e851..513cfd4 100644 --- a/activecampaign/ActiveCampaign.py +++ b/activecampaign/ActiveCampaign.py @@ -109,31 +109,27 @@ def _create_contact(self, data=None): # end contact section # create - def _add_tags_by_id(self, cid=None, tags=None): + 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 """ - if not isinstance(tags, list): - raise AttributeError("tags must be a list of strings") - response = self.api('contact/tag_add?id={}'.format(cid), - post_data={'tags': tags}) + response = self.api('contact/tag_add', + post_data={'id': cid, 'tags':tag}) return response # delete - def _delete_tags_by_id(self, cid=None, tags=None): + 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 """ - if not isinstance(tags, list): - raise AttributeError("tags must be a list of strings") - response = self.api('contact/tag_remove?id={}'.format(cid), - post_data={'tags': tags}) + response = self.api('contact/tag_remove', + post_data={'id': cid, 'tags':tag}) return response def _add_note_by_id(self, cid=None, note=""): From 261fd6d452f7aaf1550d9fccaad0e6707db4ef29 Mon Sep 17 00:00:00 2001 From: Dennis Durling Date: Tue, 26 Sep 2017 12:50:14 -0700 Subject: [PATCH 27/36] tags becomes tag --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 2539da5..deb72cd 100644 --- a/setup.py +++ b/setup.py @@ -21,7 +21,7 @@ setup( name='active-campaign-python', - version='0.8.0', + version='0.8.1', description="Python ActiveCampaign API client", long_description=readme, author="Dennis Durling", From 5277ece98d2b8605ae514c3b007dcedfc03bf792 Mon Sep 17 00:00:00 2001 From: Dennis Durling Date: Wed, 27 Sep 2017 09:04:43 -0700 Subject: [PATCH 28/36] left out a few super() calls for __init__ --- activecampaign/Account.py | 2 +- activecampaign/Campaign.py | 2 +- activecampaign/Design.py | 2 +- activecampaign/Form.py | 2 +- activecampaign/Group.py | 2 +- activecampaign/List.py | 2 +- activecampaign/Message.py | 2 +- activecampaign/Organization.py | 2 +- activecampaign/User.py | 2 +- setup.py | 2 +- 10 files changed, 10 insertions(+), 10 deletions(-) diff --git a/activecampaign/Account.py b/activecampaign/Account.py index aade44e..1e90dec 100644 --- a/activecampaign/Account.py +++ b/activecampaign/Account.py @@ -11,7 +11,7 @@ class Account(ActiveCampaign): def __init__(self, url, api_key): self.url = url self.api_key = api_key - ActiveCampaign.__init__(self, url, api_key) + super().__init__(self, url, api_key) def add(self, params, post_data={}): rq_url = fmt_noparams( diff --git a/activecampaign/Campaign.py b/activecampaign/Campaign.py index 24bf1c0..0c07255 100644 --- a/activecampaign/Campaign.py +++ b/activecampaign/Campaign.py @@ -11,7 +11,7 @@ class Campaign(ActiveCampaign): def __init__(self, url, api_key): self.url = url self.api_key = api_key - ActiveCampaign.__init__(self, url, api_key) + super().__init__(self, url, api_key) def create(self, params, post_data): rq_url = fmt_noparams( diff --git a/activecampaign/Design.py b/activecampaign/Design.py index aa1f9cd..986de48 100644 --- a/activecampaign/Design.py +++ b/activecampaign/Design.py @@ -11,7 +11,7 @@ class Design(ActiveCampaign): def __init__(self, url, api_key): self.url = url self.api_key = api_key - ActiveCampaign.__init__(self, url, api_key) + super().__init__(self, url, api_key) def edit(self, params, post_data): rq_url = fmt_noparams( diff --git a/activecampaign/Form.py b/activecampaign/Form.py index f711e9d..7634784 100644 --- a/activecampaign/Form.py +++ b/activecampaign/Form.py @@ -11,7 +11,7 @@ class Form(ActiveCampaign): def __init__(self, url, api_key): self.url = url self.api_key = api_key - ActiveCampaign.__init__(self, url, api_key) + super().__init__(self, url, api_key) def getforms(self, params, post_data={}): rq_url = fmt_noparams( diff --git a/activecampaign/Group.py b/activecampaign/Group.py index 050352d..ec0ca19 100644 --- a/activecampaign/Group.py +++ b/activecampaign/Group.py @@ -11,7 +11,7 @@ class Group(ActiveCampaign): def __init__(self, url, api_key): self.url = url self.api_key = api_key - ActiveCampaign.__init__(self, url, api_key) + super().__init__(self, url, api_key) def add(self, params, post_data): rq_url = fmt_noparams( diff --git a/activecampaign/List.py b/activecampaign/List.py index 3973557..93f70bb 100644 --- a/activecampaign/List.py +++ b/activecampaign/List.py @@ -11,7 +11,7 @@ class List(ActiveCampaign): def __init__(self, url, api_key): self.url = url self.api_key = api_key - ActiveCampaign.__init__(self, url, api_key) + super().__init__(self, url, api_key) def add(self, params, post_data): rq_url = fmt_noparams( diff --git a/activecampaign/Message.py b/activecampaign/Message.py index dffd558..cc1037e 100644 --- a/activecampaign/Message.py +++ b/activecampaign/Message.py @@ -11,7 +11,7 @@ class Message(ActiveCampaign): def __init__(self, url, api_key): self.url = url self.api_key = api_key - ActiveCampaign.__init__(self, url, api_key) + super().__init__(self, url, api_key) def add(self, params, post_data): rq_url = fmt_noparams( diff --git a/activecampaign/Organization.py b/activecampaign/Organization.py index 74a8b0d..c3fd23e 100644 --- a/activecampaign/Organization.py +++ b/activecampaign/Organization.py @@ -11,7 +11,7 @@ class Organization(ActiveCampaign): def __init__(self, url, api_key): self.url = url self.api_key = api_key - super.__init__(url, api_key) + super().__init__(url, api_key) def list_(self, params): rq_url = fmt_params(self.url, 'organization_list', diff --git a/activecampaign/User.py b/activecampaign/User.py index 783f30a..f59e4b0 100644 --- a/activecampaign/User.py +++ b/activecampaign/User.py @@ -11,7 +11,7 @@ class User(ActiveCampaign): def __init__(self, url, api_key): self.url = url self.api_key = api_key - ActiveCampaign.__init__(self, url, api_key) + super().__init__(self, url, api_key) def add(self, params, post_data): rq_url = fmt_noparams( diff --git a/setup.py b/setup.py index deb72cd..7a647ac 100644 --- a/setup.py +++ b/setup.py @@ -21,7 +21,7 @@ setup( name='active-campaign-python', - version='0.8.1', + version='0.8.2', description="Python ActiveCampaign API client", long_description=readme, author="Dennis Durling", From a2615c1bcea33307f5a319dcfffb3b8bb40248c1 Mon Sep 17 00:00:00 2001 From: Dennis Durling Date: Fri, 13 Oct 2017 17:42:13 -0400 Subject: [PATCH 29/36] removed self from super() call in the subclasses... bumping to 0.9.0 --- activecampaign/Account.py | 2 +- activecampaign/Campaign.py | 2 +- activecampaign/Design.py | 2 +- activecampaign/Form.py | 2 +- activecampaign/Group.py | 2 +- activecampaign/List.py | 2 +- activecampaign/Message.py | 2 +- activecampaign/User.py | 2 +- setup.py | 2 +- 9 files changed, 9 insertions(+), 9 deletions(-) diff --git a/activecampaign/Account.py b/activecampaign/Account.py index 1e90dec..adac163 100644 --- a/activecampaign/Account.py +++ b/activecampaign/Account.py @@ -11,7 +11,7 @@ class Account(ActiveCampaign): def __init__(self, url, api_key): self.url = url self.api_key = api_key - super().__init__(self, url, api_key) + super().__init__(url, api_key) def add(self, params, post_data={}): rq_url = fmt_noparams( diff --git a/activecampaign/Campaign.py b/activecampaign/Campaign.py index 0c07255..56f669f 100644 --- a/activecampaign/Campaign.py +++ b/activecampaign/Campaign.py @@ -11,7 +11,7 @@ class Campaign(ActiveCampaign): def __init__(self, url, api_key): self.url = url self.api_key = api_key - super().__init__(self, url, api_key) + super().__init__(url, api_key) def create(self, params, post_data): rq_url = fmt_noparams( diff --git a/activecampaign/Design.py b/activecampaign/Design.py index 986de48..4302408 100644 --- a/activecampaign/Design.py +++ b/activecampaign/Design.py @@ -11,7 +11,7 @@ class Design(ActiveCampaign): def __init__(self, url, api_key): self.url = url self.api_key = api_key - super().__init__(self, url, api_key) + super().__init__(url, api_key) def edit(self, params, post_data): rq_url = fmt_noparams( diff --git a/activecampaign/Form.py b/activecampaign/Form.py index 7634784..729c136 100644 --- a/activecampaign/Form.py +++ b/activecampaign/Form.py @@ -11,7 +11,7 @@ class Form(ActiveCampaign): def __init__(self, url, api_key): self.url = url self.api_key = api_key - super().__init__(self, url, api_key) + super().__init__(url, api_key) def getforms(self, params, post_data={}): rq_url = fmt_noparams( diff --git a/activecampaign/Group.py b/activecampaign/Group.py index ec0ca19..7e344b2 100644 --- a/activecampaign/Group.py +++ b/activecampaign/Group.py @@ -11,7 +11,7 @@ class Group(ActiveCampaign): def __init__(self, url, api_key): self.url = url self.api_key = api_key - super().__init__(self, url, api_key) + super().__init__(url, api_key) def add(self, params, post_data): rq_url = fmt_noparams( diff --git a/activecampaign/List.py b/activecampaign/List.py index 93f70bb..d3500eb 100644 --- a/activecampaign/List.py +++ b/activecampaign/List.py @@ -11,7 +11,7 @@ class List(ActiveCampaign): def __init__(self, url, api_key): self.url = url self.api_key = api_key - super().__init__(self, url, api_key) + super().__init__(url, api_key) def add(self, params, post_data): rq_url = fmt_noparams( diff --git a/activecampaign/Message.py b/activecampaign/Message.py index cc1037e..059270c 100644 --- a/activecampaign/Message.py +++ b/activecampaign/Message.py @@ -11,7 +11,7 @@ class Message(ActiveCampaign): def __init__(self, url, api_key): self.url = url self.api_key = api_key - super().__init__(self, url, api_key) + super().__init__(url, api_key) def add(self, params, post_data): rq_url = fmt_noparams( diff --git a/activecampaign/User.py b/activecampaign/User.py index f59e4b0..23292fe 100644 --- a/activecampaign/User.py +++ b/activecampaign/User.py @@ -11,7 +11,7 @@ class User(ActiveCampaign): def __init__(self, url, api_key): self.url = url self.api_key = api_key - super().__init__(self, url, api_key) + super().__init__(url, api_key) def add(self, params, post_data): rq_url = fmt_noparams( diff --git a/setup.py b/setup.py index 7a647ac..1afe57a 100644 --- a/setup.py +++ b/setup.py @@ -21,7 +21,7 @@ setup( name='active-campaign-python', - version='0.8.2', + version='0.9.0', description="Python ActiveCampaign API client", long_description=readme, author="Dennis Durling", From 6dba909669b34a35b44432ed814124b0605aeca2 Mon Sep 17 00:00:00 2001 From: Tadej Krevh Date: Tue, 20 Mar 2018 15:56:16 +0100 Subject: [PATCH 30/36] Python 2.7 compatible super calls in constructors --- activecampaign/Account.py | 2 +- activecampaign/ActiveCampaign.py | 2 +- activecampaign/Campaign.py | 2 +- activecampaign/Contact.py | 2 +- activecampaign/Design.py | 2 +- activecampaign/Form.py | 2 +- activecampaign/Group.py | 2 +- activecampaign/List.py | 2 +- activecampaign/Message.py | 2 +- activecampaign/Organization.py | 2 +- activecampaign/User.py | 2 +- setup.py | 2 +- 12 files changed, 12 insertions(+), 12 deletions(-) diff --git a/activecampaign/Account.py b/activecampaign/Account.py index adac163..1316004 100644 --- a/activecampaign/Account.py +++ b/activecampaign/Account.py @@ -11,7 +11,7 @@ class Account(ActiveCampaign): def __init__(self, url, api_key): self.url = url self.api_key = api_key - super().__init__(url, api_key) + super(Account, self).__init__(url, api_key) def add(self, params, post_data={}): rq_url = fmt_noparams( diff --git a/activecampaign/ActiveCampaign.py b/activecampaign/ActiveCampaign.py index 513cfd4..40a94dc 100644 --- a/activecampaign/ActiveCampaign.py +++ b/activecampaign/ActiveCampaign.py @@ -19,7 +19,7 @@ def __init__(self, url, api_key, api_user='', api_pass=''): self.api_key = api_key self.URL = url self.APIKEY = api_key - super().__init__(url, api_key, api_user, api_pass) + super(ActiveCampaign, self).__init__(url, api_key, api_user, api_pass) def api(self, path, post_data={}): # IE: "contact/view" diff --git a/activecampaign/Campaign.py b/activecampaign/Campaign.py index 56f669f..34367df 100644 --- a/activecampaign/Campaign.py +++ b/activecampaign/Campaign.py @@ -11,7 +11,7 @@ class Campaign(ActiveCampaign): def __init__(self, url, api_key): self.url = url self.api_key = api_key - super().__init__(url, api_key) + super(Campaign, self).__init__(url, api_key) def create(self, params, post_data): rq_url = fmt_noparams( diff --git a/activecampaign/Contact.py b/activecampaign/Contact.py index dc2d7fb..eac6324 100644 --- a/activecampaign/Contact.py +++ b/activecampaign/Contact.py @@ -11,7 +11,7 @@ class Contact(ActiveCampaign): def __init__(self, url, api_key): self.url = url self.api_key = api_key - super().__init__(url, api_key) + super(Contact, self).__init__(url, api_key) def add(self, params, post_data={}): if params: diff --git a/activecampaign/Design.py b/activecampaign/Design.py index 4302408..01f7dd3 100644 --- a/activecampaign/Design.py +++ b/activecampaign/Design.py @@ -11,7 +11,7 @@ class Design(ActiveCampaign): def __init__(self, url, api_key): self.url = url self.api_key = api_key - super().__init__(url, api_key) + super(Design, self).__init__(url, api_key) def edit(self, params, post_data): rq_url = fmt_noparams( diff --git a/activecampaign/Form.py b/activecampaign/Form.py index 729c136..bdc1878 100644 --- a/activecampaign/Form.py +++ b/activecampaign/Form.py @@ -11,7 +11,7 @@ class Form(ActiveCampaign): def __init__(self, url, api_key): self.url = url self.api_key = api_key - super().__init__(url, api_key) + super(Form, self).__init__(url, api_key) def getforms(self, params, post_data={}): rq_url = fmt_noparams( diff --git a/activecampaign/Group.py b/activecampaign/Group.py index 7e344b2..45fea6b 100644 --- a/activecampaign/Group.py +++ b/activecampaign/Group.py @@ -11,7 +11,7 @@ class Group(ActiveCampaign): def __init__(self, url, api_key): self.url = url self.api_key = api_key - super().__init__(url, api_key) + super(Group, self).__init__(url, api_key) def add(self, params, post_data): rq_url = fmt_noparams( diff --git a/activecampaign/List.py b/activecampaign/List.py index d3500eb..e23ce82 100644 --- a/activecampaign/List.py +++ b/activecampaign/List.py @@ -11,7 +11,7 @@ class List(ActiveCampaign): def __init__(self, url, api_key): self.url = url self.api_key = api_key - super().__init__(url, api_key) + super(List, self).__init__(url, api_key) def add(self, params, post_data): rq_url = fmt_noparams( diff --git a/activecampaign/Message.py b/activecampaign/Message.py index 059270c..a1e3061 100644 --- a/activecampaign/Message.py +++ b/activecampaign/Message.py @@ -11,7 +11,7 @@ class Message(ActiveCampaign): def __init__(self, url, api_key): self.url = url self.api_key = api_key - super().__init__(url, api_key) + super(Message, self).__init__(url, api_key) def add(self, params, post_data): rq_url = fmt_noparams( diff --git a/activecampaign/Organization.py b/activecampaign/Organization.py index c3fd23e..cbe9f0a 100644 --- a/activecampaign/Organization.py +++ b/activecampaign/Organization.py @@ -11,7 +11,7 @@ class Organization(ActiveCampaign): def __init__(self, url, api_key): self.url = url self.api_key = api_key - super().__init__(url, api_key) + super(Organization, self).__init__(url, api_key) def list_(self, params): rq_url = fmt_params(self.url, 'organization_list', diff --git a/activecampaign/User.py b/activecampaign/User.py index 23292fe..af396bf 100644 --- a/activecampaign/User.py +++ b/activecampaign/User.py @@ -11,7 +11,7 @@ class User(ActiveCampaign): def __init__(self, url, api_key): self.url = url self.api_key = api_key - super().__init__(url, api_key) + super(User, self).__init__(url, api_key) def add(self, params, post_data): rq_url = fmt_noparams( diff --git a/setup.py b/setup.py index 1afe57a..a4f0b0e 100644 --- a/setup.py +++ b/setup.py @@ -21,7 +21,7 @@ setup( name='active-campaign-python', - version='0.9.0', + version='0.9.1', description="Python ActiveCampaign API client", long_description=readme, author="Dennis Durling", From ecafe682519f2acbfde4627776d726ac4bb05cbc Mon Sep 17 00:00:00 2001 From: Tadej Krevh Date: Tue, 20 Mar 2018 15:56:45 +0100 Subject: [PATCH 31/36] Revert "Python 2.7 compatible super calls in constructors" This reverts commit 6dba909669b34a35b44432ed814124b0605aeca2. --- activecampaign/Account.py | 2 +- activecampaign/ActiveCampaign.py | 2 +- activecampaign/Campaign.py | 2 +- activecampaign/Contact.py | 2 +- activecampaign/Design.py | 2 +- activecampaign/Form.py | 2 +- activecampaign/Group.py | 2 +- activecampaign/List.py | 2 +- activecampaign/Message.py | 2 +- activecampaign/Organization.py | 2 +- activecampaign/User.py | 2 +- setup.py | 2 +- 12 files changed, 12 insertions(+), 12 deletions(-) diff --git a/activecampaign/Account.py b/activecampaign/Account.py index 1316004..adac163 100644 --- a/activecampaign/Account.py +++ b/activecampaign/Account.py @@ -11,7 +11,7 @@ class Account(ActiveCampaign): def __init__(self, url, api_key): self.url = url self.api_key = api_key - super(Account, self).__init__(url, api_key) + super().__init__(url, api_key) def add(self, params, post_data={}): rq_url = fmt_noparams( diff --git a/activecampaign/ActiveCampaign.py b/activecampaign/ActiveCampaign.py index 40a94dc..513cfd4 100644 --- a/activecampaign/ActiveCampaign.py +++ b/activecampaign/ActiveCampaign.py @@ -19,7 +19,7 @@ def __init__(self, url, api_key, api_user='', api_pass=''): self.api_key = api_key self.URL = url self.APIKEY = api_key - super(ActiveCampaign, self).__init__(url, api_key, api_user, api_pass) + super().__init__(url, api_key, api_user, api_pass) def api(self, path, post_data={}): # IE: "contact/view" diff --git a/activecampaign/Campaign.py b/activecampaign/Campaign.py index 34367df..56f669f 100644 --- a/activecampaign/Campaign.py +++ b/activecampaign/Campaign.py @@ -11,7 +11,7 @@ class Campaign(ActiveCampaign): def __init__(self, url, api_key): self.url = url self.api_key = api_key - super(Campaign, self).__init__(url, api_key) + super().__init__(url, api_key) def create(self, params, post_data): rq_url = fmt_noparams( diff --git a/activecampaign/Contact.py b/activecampaign/Contact.py index eac6324..dc2d7fb 100644 --- a/activecampaign/Contact.py +++ b/activecampaign/Contact.py @@ -11,7 +11,7 @@ class Contact(ActiveCampaign): def __init__(self, url, api_key): self.url = url self.api_key = api_key - super(Contact, self).__init__(url, api_key) + super().__init__(url, api_key) def add(self, params, post_data={}): if params: diff --git a/activecampaign/Design.py b/activecampaign/Design.py index 01f7dd3..4302408 100644 --- a/activecampaign/Design.py +++ b/activecampaign/Design.py @@ -11,7 +11,7 @@ class Design(ActiveCampaign): def __init__(self, url, api_key): self.url = url self.api_key = api_key - super(Design, self).__init__(url, api_key) + super().__init__(url, api_key) def edit(self, params, post_data): rq_url = fmt_noparams( diff --git a/activecampaign/Form.py b/activecampaign/Form.py index bdc1878..729c136 100644 --- a/activecampaign/Form.py +++ b/activecampaign/Form.py @@ -11,7 +11,7 @@ class Form(ActiveCampaign): def __init__(self, url, api_key): self.url = url self.api_key = api_key - super(Form, self).__init__(url, api_key) + super().__init__(url, api_key) def getforms(self, params, post_data={}): rq_url = fmt_noparams( diff --git a/activecampaign/Group.py b/activecampaign/Group.py index 45fea6b..7e344b2 100644 --- a/activecampaign/Group.py +++ b/activecampaign/Group.py @@ -11,7 +11,7 @@ class Group(ActiveCampaign): def __init__(self, url, api_key): self.url = url self.api_key = api_key - super(Group, self).__init__(url, api_key) + super().__init__(url, api_key) def add(self, params, post_data): rq_url = fmt_noparams( diff --git a/activecampaign/List.py b/activecampaign/List.py index e23ce82..d3500eb 100644 --- a/activecampaign/List.py +++ b/activecampaign/List.py @@ -11,7 +11,7 @@ class List(ActiveCampaign): def __init__(self, url, api_key): self.url = url self.api_key = api_key - super(List, self).__init__(url, api_key) + super().__init__(url, api_key) def add(self, params, post_data): rq_url = fmt_noparams( diff --git a/activecampaign/Message.py b/activecampaign/Message.py index a1e3061..059270c 100644 --- a/activecampaign/Message.py +++ b/activecampaign/Message.py @@ -11,7 +11,7 @@ class Message(ActiveCampaign): def __init__(self, url, api_key): self.url = url self.api_key = api_key - super(Message, self).__init__(url, api_key) + super().__init__(url, api_key) def add(self, params, post_data): rq_url = fmt_noparams( diff --git a/activecampaign/Organization.py b/activecampaign/Organization.py index cbe9f0a..c3fd23e 100644 --- a/activecampaign/Organization.py +++ b/activecampaign/Organization.py @@ -11,7 +11,7 @@ class Organization(ActiveCampaign): def __init__(self, url, api_key): self.url = url self.api_key = api_key - super(Organization, self).__init__(url, api_key) + super().__init__(url, api_key) def list_(self, params): rq_url = fmt_params(self.url, 'organization_list', diff --git a/activecampaign/User.py b/activecampaign/User.py index af396bf..23292fe 100644 --- a/activecampaign/User.py +++ b/activecampaign/User.py @@ -11,7 +11,7 @@ class User(ActiveCampaign): def __init__(self, url, api_key): self.url = url self.api_key = api_key - super(User, self).__init__(url, api_key) + super().__init__(url, api_key) def add(self, params, post_data): rq_url = fmt_noparams( diff --git a/setup.py b/setup.py index a4f0b0e..1afe57a 100644 --- a/setup.py +++ b/setup.py @@ -21,7 +21,7 @@ setup( name='active-campaign-python', - version='0.9.1', + version='0.9.0', description="Python ActiveCampaign API client", long_description=readme, author="Dennis Durling", From 361494af923b9398a503ff07f44675bb1cecf721 Mon Sep 17 00:00:00 2001 From: Tadej Krevh Date: Tue, 20 Mar 2018 15:59:20 +0100 Subject: [PATCH 32/36] Python 2.7 compatible super calls in constructors --- activecampaign/Account.py | 2 +- activecampaign/ActiveCampaign.py | 2 +- activecampaign/Campaign.py | 2 +- activecampaign/Contact.py | 2 +- activecampaign/Design.py | 2 +- activecampaign/Form.py | 2 +- activecampaign/Group.py | 2 +- activecampaign/List.py | 2 +- activecampaign/Message.py | 2 +- activecampaign/Organization.py | 2 +- activecampaign/User.py | 2 +- setup.py | 2 +- 12 files changed, 12 insertions(+), 12 deletions(-) diff --git a/activecampaign/Account.py b/activecampaign/Account.py index adac163..1316004 100644 --- a/activecampaign/Account.py +++ b/activecampaign/Account.py @@ -11,7 +11,7 @@ class Account(ActiveCampaign): def __init__(self, url, api_key): self.url = url self.api_key = api_key - super().__init__(url, api_key) + super(Account, self).__init__(url, api_key) def add(self, params, post_data={}): rq_url = fmt_noparams( diff --git a/activecampaign/ActiveCampaign.py b/activecampaign/ActiveCampaign.py index 513cfd4..40a94dc 100644 --- a/activecampaign/ActiveCampaign.py +++ b/activecampaign/ActiveCampaign.py @@ -19,7 +19,7 @@ def __init__(self, url, api_key, api_user='', api_pass=''): self.api_key = api_key self.URL = url self.APIKEY = api_key - super().__init__(url, api_key, api_user, api_pass) + super(ActiveCampaign, self).__init__(url, api_key, api_user, api_pass) def api(self, path, post_data={}): # IE: "contact/view" diff --git a/activecampaign/Campaign.py b/activecampaign/Campaign.py index 56f669f..34367df 100644 --- a/activecampaign/Campaign.py +++ b/activecampaign/Campaign.py @@ -11,7 +11,7 @@ class Campaign(ActiveCampaign): def __init__(self, url, api_key): self.url = url self.api_key = api_key - super().__init__(url, api_key) + super(Campaign, self).__init__(url, api_key) def create(self, params, post_data): rq_url = fmt_noparams( diff --git a/activecampaign/Contact.py b/activecampaign/Contact.py index dc2d7fb..eac6324 100644 --- a/activecampaign/Contact.py +++ b/activecampaign/Contact.py @@ -11,7 +11,7 @@ class Contact(ActiveCampaign): def __init__(self, url, api_key): self.url = url self.api_key = api_key - super().__init__(url, api_key) + super(Contact, self).__init__(url, api_key) def add(self, params, post_data={}): if params: diff --git a/activecampaign/Design.py b/activecampaign/Design.py index 4302408..01f7dd3 100644 --- a/activecampaign/Design.py +++ b/activecampaign/Design.py @@ -11,7 +11,7 @@ class Design(ActiveCampaign): def __init__(self, url, api_key): self.url = url self.api_key = api_key - super().__init__(url, api_key) + super(Design, self).__init__(url, api_key) def edit(self, params, post_data): rq_url = fmt_noparams( diff --git a/activecampaign/Form.py b/activecampaign/Form.py index 729c136..bdc1878 100644 --- a/activecampaign/Form.py +++ b/activecampaign/Form.py @@ -11,7 +11,7 @@ class Form(ActiveCampaign): def __init__(self, url, api_key): self.url = url self.api_key = api_key - super().__init__(url, api_key) + super(Form, self).__init__(url, api_key) def getforms(self, params, post_data={}): rq_url = fmt_noparams( diff --git a/activecampaign/Group.py b/activecampaign/Group.py index 7e344b2..45fea6b 100644 --- a/activecampaign/Group.py +++ b/activecampaign/Group.py @@ -11,7 +11,7 @@ class Group(ActiveCampaign): def __init__(self, url, api_key): self.url = url self.api_key = api_key - super().__init__(url, api_key) + super(Group, self).__init__(url, api_key) def add(self, params, post_data): rq_url = fmt_noparams( diff --git a/activecampaign/List.py b/activecampaign/List.py index d3500eb..e23ce82 100644 --- a/activecampaign/List.py +++ b/activecampaign/List.py @@ -11,7 +11,7 @@ class List(ActiveCampaign): def __init__(self, url, api_key): self.url = url self.api_key = api_key - super().__init__(url, api_key) + super(List, self).__init__(url, api_key) def add(self, params, post_data): rq_url = fmt_noparams( diff --git a/activecampaign/Message.py b/activecampaign/Message.py index 059270c..a1e3061 100644 --- a/activecampaign/Message.py +++ b/activecampaign/Message.py @@ -11,7 +11,7 @@ class Message(ActiveCampaign): def __init__(self, url, api_key): self.url = url self.api_key = api_key - super().__init__(url, api_key) + super(Message, self).__init__(url, api_key) def add(self, params, post_data): rq_url = fmt_noparams( diff --git a/activecampaign/Organization.py b/activecampaign/Organization.py index c3fd23e..cbe9f0a 100644 --- a/activecampaign/Organization.py +++ b/activecampaign/Organization.py @@ -11,7 +11,7 @@ class Organization(ActiveCampaign): def __init__(self, url, api_key): self.url = url self.api_key = api_key - super().__init__(url, api_key) + super(Organization, self).__init__(url, api_key) def list_(self, params): rq_url = fmt_params(self.url, 'organization_list', diff --git a/activecampaign/User.py b/activecampaign/User.py index 23292fe..af396bf 100644 --- a/activecampaign/User.py +++ b/activecampaign/User.py @@ -11,7 +11,7 @@ class User(ActiveCampaign): def __init__(self, url, api_key): self.url = url self.api_key = api_key - super().__init__(url, api_key) + super(User, self).__init__(url, api_key) def add(self, params, post_data): rq_url = fmt_noparams( diff --git a/setup.py b/setup.py index 1afe57a..a4f0b0e 100644 --- a/setup.py +++ b/setup.py @@ -21,7 +21,7 @@ setup( name='active-campaign-python', - version='0.9.0', + version='0.9.1', description="Python ActiveCampaign API client", long_description=readme, author="Dennis Durling", From af232a429158b5a9cc5e10e13421a1d43ba45397 Mon Sep 17 00:00:00 2001 From: Tadej Krevh Date: Tue, 20 Mar 2018 16:13:48 +0100 Subject: [PATCH 33/36] Fixed the base Connector class definition --- activecampaign/Connector.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/activecampaign/Connector.py b/activecampaign/Connector.py index 847848b..f006264 100644 --- a/activecampaign/Connector.py +++ b/activecampaign/Connector.py @@ -1,7 +1,7 @@ import requests as rq -class Connector(): +class Connector(object): def __init__(self, url, api_key, api_user='', api_pass=''): self.output = 'json' From 696832e2f137c14ad83a791df4d1f8581817547e Mon Sep 17 00:00:00 2001 From: Dennis Durling Date: Tue, 20 Mar 2018 11:05:36 -0700 Subject: [PATCH 34/36] tagged version 0.9.2 --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index a4f0b0e..7c64183 100644 --- a/setup.py +++ b/setup.py @@ -21,7 +21,7 @@ setup( name='active-campaign-python', - version='0.9.1', + version='0.9.2', description="Python ActiveCampaign API client", long_description=readme, author="Dennis Durling", From b215ae4de145573236e64f0d978b60ba563534aa Mon Sep 17 00:00:00 2001 From: Dennis Date: Sat, 21 Jul 2018 19:49:40 -0700 Subject: [PATCH 35/36] Update README.md --- README.md | 1 - 1 file changed, 1 deletion(-) diff --git a/README.md b/README.md index 440a66c..e892fc7 100644 --- a/README.md +++ b/README.md @@ -16,7 +16,6 @@ api_key = '' ac = ActiveCampaign(base_url, api_key) print(ac.api('account/view')) -

Each of the endpoint subclasses have comments at the bottom From 796db869145cb1f0179dd4c2d9f277b137aa70ea Mon Sep 17 00:00:00 2001 From: Dennis Date: Sat, 21 Jul 2018 19:50:30 -0700 Subject: [PATCH 36/36] Update README.md --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index e892fc7..b015344 100644 --- a/README.md +++ b/README.md @@ -23,3 +23,5 @@ 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