diff --git a/README.md b/README.md index 207da94..6370c35 100644 --- a/README.md +++ b/README.md @@ -38,3 +38,15 @@ Simple example of calling the [Less Neglect API](http://beta.lessneglect.com/api ## Requirements - [requests](http://docs.python-requests.org/en/latest/) + +## new wip + +person = { + "person[name]": "Billy Coover", + "person[email]": "billy+1@lessneglect.com", + "person[uid]": "test-1", + "person[created_at]": 1358108502.033349, + "person[properties][is_paying]": true +} + +registered(person) diff --git a/config.py b/config.py index 88e353c..2abbda8 100644 --- a/config.py +++ b/config.py @@ -1,4 +1,23 @@ -CONSTANT_PROJECT_CODE = "" -CONSTANT_API_SECRET = "" +CONSTANT_PROJECT_CODE = "eGPFE51LUVev2" +CONSTANT_API_SECRET = "qZQgEHMbZujHaRSn1IuEx4rmLbk" LN_API_URL = "https://api.lessneglect.com/api/v2/" LN_EVENTS_ENDPOINT = "events" + +#basic event constants +LN_EVENT_REGISTERED = "registered" +LN_EVENT_UPGRADED = "upgraded" +LN_EVENT_DELETED_ACCOUNT = "deleted-account" +LN_EVENT_UPDATED_ACCOUNT = "updated-account" +LN_EVENT_LOGGED_IN = "logged-in" +LN_EVENT_LOGGED_OUT = "logged-out" +LN_EVENT_FORGOT_PASSWORD = "forgot-password" +LN_EVENT_CHANGED_PASSWORD = "changed-password" +LN_EVENT_UPDATED_PROFILE = "updated-profile" + +#item based event constants +LN_EVENT_PURCHASED = "purchased" +LN_EVENT_CREATED = "created" +LN_EVENT_UPLOADED = "uploaded" +LN_EVENT_DELETED = "deleted" +LN_EVENT_MODIFIED = "modified" +LN_EVENT_VIEWED = "viewed" diff --git a/ln.py b/ln.py index f571216..a39b364 100644 --- a/ln.py +++ b/ln.py @@ -1,6 +1,129 @@ import config, requests -def log_event(data): +#basic events + +def registered(person): + url = config.LN_API_URL + config.LN_EVENTS_ENDPOINT + req = {"event[name]": config.LN_EVENT_REGISTERED} + body = dict(person, **req) + + #debug + print body + resp = requests.post(url, data=body, auth=(config.LN_PROJECT_CODE, config.LN_API_SECRET)) + return resp + +def upgraded(person): url = config.LN_API_URL + config.LN_EVENTS_ENDPOINT + req = {"event[name]": config.LN_EVENT_UPGRADED} + body = dict(person, **req) + resp = requests.post(url, data=body, auth=(config.LN_PROJECT_CODE, config.LN_API_SECRET)) + return resp + +def deleted_account(person): + url = config.LN_API_URL + config.LN_EVENTS_ENDPOINT + req = {"event[name]": config.LN_EVENT_DELETED_ACCOUNT} + body = dict(person, **req) resp = requests.post(url, data=data, auth=(config.LN_PROJECT_CODE, config.LN_API_SECRET)) return resp + +def updated_account(person): + url = config.LN_API_URL + config.LN_EVENTS_ENDPOINT + req = {"event[name]": config.LN_EVENT_UPDATED_ACCOUNT} + body = dict(person, **req) + resp = requests.post(url, data=body, auth=(config.LN_PROJECT_CODE, config.LN_API_SECRET)) + return resp + +def logged_in(person): + url = config.LN_API_URL + config.LN_EVENTS_ENDPOINT + req = {"event[name]": config.LN_EVENT_LOGGED_IN} + body = dict(person, **req) + resp = requests.post(url, data=body, auth=(config.LN_PROJECT_CODE, config.LN_API_SECRET)) + return resp + +def logged_out(person): + url = config.LN_API_URL + config.LN_EVENTS_ENDPOINT + req = {"event[name]": config.LN_EVENT_LOGGED_OUT} + body = dict(person, **req) + resp = requests.post(url, data=body, auth=(config.LN_PROJECT_CODE, config.LN_API_SECRET)) + return resp + +def forgot_password(person): + url = config.LN_API_URL + config.LN_EVENTS_ENDPOINT + req = {"event[name]": config.LN_EVENT_FORGOT_PASSWORD} + body = dict(person, **req) + resp = requests.post(url, data=body, auth=(config.LN_PROJECT_CODE, config.LN_API_SECRET)) + return resp + +def changed_password(person): + url = config.LN_API_URL + config.LN_EVENTS_ENDPOINT + req = {"event[name]": config.LN_EVENT_CHANGED_PASSWORD} + body = dict(person, **req) + resp = requests.post(url, data=body, auth=(config.LN_PROJECT_CODE, config.LN_API_SECRET)) + return resp + +def updated_profile(person): + url = config.LN_API_URL + config.LN_EVENTS_ENDPOINT + req = {"event[name]": config.LN_EVENT_UPDATED_PROFILE} + body = dict(person, **req) + resp = requests.post(url, data=body, auth=(config.LN_PROJECT_CODE, config.LN_API_SECRET)) + return resp + +#item based events + +def purchased(person, item): + url = config.LN_API_URL + config.LN_EVENTS_ENDPOINT + req = {"event[name]": config.LN_EVENT_PURCHASED} + body = dict(person, **item) + body.update(req) + resp = requests.post(url, data=body, auth=(config.LN_PROJECT_CODE, config.LN_API_SECRET)) + return resp + +def created(person, item): + url = config.LN_API_URL + config.LN_EVENTS_ENDPOINT + req = {"event[name]": config.LN_EVENT_CREATED} + body = dict(person, **item) + body.update(req) + resp = requests.post(url, data=body, auth=(config.LN_PROJECT_CODE, config.LN_API_SECRET)) + return resp + +def uploaded(person, item): + url = config.LN_API_URL + config.LN_EVENTS_ENDPOINT + req = {"event[name]": config.LN_EVENT_UPLOADED} + body = dict(person, **item) + body.update(req) + resp = requests.post(url, data=body, auth=(config.LN_PROJECT_CODE, config.LN_API_SECRET)) + return resp + +def deleted(person, item): + url = config.LN_API_URL + config.LN_EVENTS_ENDPOINT + req = {"event[name]": config.LN_EVENT_DELETED} + body = dict(person, **item) + body.update(req) + resp = requests.post(url, data=body, auth=(config.LN_PROJECT_CODE, config.LN_API_SECRET)) + return resp + +def modified(person, item): + url = config.LN_API_URL + config.LN_EVENTS_ENDPOINT + req = {"event[name]": config.LN_EVENT_MODIFIED} + body = dict(person, **item) + body.update(req) + resp = requests.post(url, data=body, auth=(config.LN_PROJECT_CODE, config.LN_API_SECRET)) + return resp + +def viewed(person, item): + url = config.LN_API_URL + config.LN_EVENTS_ENDPOINT + req = {"event[name]": config.LN_EVENT_VIEWED} + body = dict(person, **item) + body.update(req) + resp = requests.post(url, data=body, auth=(config.LN_PROJECT_CODE, config.LN_API_SECRET)) + return resp + +#global generic event + +def log_event(data): + url = config.LN_API_URL + config.LN_EVENTS_ENDPOINT + req = {"event[name]": config.LN_EVENT_UPGRADED} + body = dict(person, **data) + body.update(req) + resp = requests.post(url, data=body, auth=(config.LN_PROJECT_CODE, config.LN_API_SECRET)) + return resp