{"action":"created","comment":{"url":"https://api.github.com/repos/edx/ecommerce-worker/pulls/comments/71573898","id":71573898,"diff_hunk":"@@ -0,0 +1,250 @@\n+\"\"\"\n+This file contains celery tasks for email marketing signal handler.\n+\"\"\"\n+\n+from celery import shared_task\n+from celery.utils.log import get_task_logger\n+from sailthru.sailthru_client import SailthruClient\n+from sailthru.sailthru_error import SailthruClientError\n+\n+from ecommerce_worker.sailthru.v1.sailthru_cache import Cache\n+from ecommerce_worker.utils import get_configuration\n+\n+logger = get_task_logger(__name__)  # pylint: disable=invalid-name\n+cache = Cache()  # pylint: disable=invalid-name\n+\n+\n+# pylint: disable=not-callable\n+@shared_task(bind=True, ignore_result=True)\n+def update_course_enrollment(self, email, course_url, purchase_incomplete, mode,\n+                             unit_cost=None, course_id=None,\n+                             currency=None, message_id=None, site_code=None):  # pylint: disable=unused-argument\n+    \"\"\"Adds/updates Sailthru when a user adds to cart/purchases/upgrades a course\n+\n+     Args:\n+        email(str): The user's email address\n+        course_url(str): Course home page url\n+        incomplete(boolean): True if adding to cart\n+        mode(object): enroll mode (audit, verification, ...)\n+        unit_cost: cost if purchase event\n+        course_id(CourseKey): course id\n+        currency(str): currency if purchase event - currently ignored since Sailthru only supports USD\n+        message_id(str): value from Sailthru marketing campaign cookie\n+        site_code(str): site code\n+    Returns:\n+        None\n+    \"\"\"\n+    # Get configuration\n+    config = get_configuration('SAILTHRU', site_code=site_code, allow_none=True)\n+\n+    # Return if Sailthru integration disabled\n+    if not _get_configuration(config, 'SAILTHRU_ENABLE', default=True):\n+        return\n+\n+    # Make sure key and secret configured\n+    sailthru_key = _get_configuration(config, 'SAILTHRU_KEY')\n+    sailthru_secret = _get_configuration(config, 'SAILTHRU_SECRET')\n+    if sailthru_key is None or sailthru_secret is None:\n+        logger.error(\"Sailthru key and or secret not specified for site %s\", site_code)\n+        return\n+\n+    # Use event type to figure out processing required\n+    new_enroll = False\n+    send_template = None\n+\n+    if not purchase_incomplete:\n+        if mode == 'verified':\n+            # upgrade complete\n+            send_template = _get_configuration(config, 'SAILTHRU_UPGRADE_TEMPLATE')\n+        else:\n+            # paid course purchase complete\n+            new_enroll = True\n+            send_template = _get_configuration(config, 'SAILTHRU_PURCHASE_TEMPLATE')\n+\n+    sailthru_client = SailthruClient(sailthru_key, sailthru_secret)\n+\n+    # update the \"unenrolled\" course array in the user record on Sailthru if new enroll or unenroll\n+    if new_enroll:\n+        if not _update_unenrolled_list(sailthru_client, email, course_url, False):\n+            _schedule_retry(self, config)\n+\n+    # Get course data from Sailthru content library or cache\n+    course_data = _get_course_content(course_url, sailthru_client, site_code, config)\n+\n+    # build item description\n+    # Sailthru requires the price be specified in cents\n+    #  https://getstarted.sailthru.com/new-for-developers-overview/advanced-features/purchase/\n+    item = _build_purchase_item(course_id, course_url, unit_cost * 100, mode, course_data)","path":"ecommerce_worker/sailthru/v1/tasks.py","position":77,"original_position":77,"commit_id":"83dc1bd5133272ca6dd93071d9bc074d4147c49c","original_commit_id":"83dc1bd5133272ca6dd93071d9bc074d4147c49c","user":{"login":"rlucioni","id":969289,"avatar_url":"https://avatars.githubusercontent.com/u/969289?v=3","gravatar_id":"","url":"https://api.github.com/users/rlucioni","html_url":"https://github.com/rlucioni","followers_url":"https://api.github.com/users/rlucioni/followers","following_url":"https://api.github.com/users/rlucioni/following{/other_user}","gists_url":"https://api.github.com/users/rlucioni/gists{/gist_id}","starred_url":"https://api.github.com/users/rlucioni/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rlucioni/subscriptions","organizations_url":"https://api.github.com/users/rlucioni/orgs","repos_url":"https://api.github.com/users/rlucioni/repos","events_url":"https://api.github.com/users/rlucioni/events{/privacy}","received_events_url":"https://api.github.com/users/rlucioni/received_events","type":"User","site_admin":false},"body":"Ah, I didn't realize that. I see your comment now, too.","created_at":"2016-07-20T17:52:31Z","updated_at":"2016-07-20T17:52:31Z","html_url":"https://github.com/edx/ecommerce-worker/pull/17#discussion_r71573898","pull_request_url":"https://api.github.com/repos/edx/ecommerce-worker/pulls/17","_links":{"self":{"href":"https://api.github.com/repos/edx/ecommerce-worker/pulls/comments/71573898"},"html":{"href":"https://github.com/edx/ecommerce-worker/pull/17#discussion_r71573898"},"pull_request":{"href":"https://api.github.com/repos/edx/ecommerce-worker/pulls/17"}}},"pull_request":{"url":"https://api.github.com/repos/edx/ecommerce-worker/pulls/17","id":76297439,"html_url":"https://github.com/edx/ecommerce-worker/pull/17","diff_url":"https://github.com/edx/ecommerce-worker/pull/17.diff","patch_url":"https://github.com/edx/ecommerce-worker/pull/17.patch","issue_url":"https://api.github.com/repos/edx/ecommerce-worker/issues/17","number":17,"state":"open","locked":false,"title":"Added worker code to inform Sailthru about purchases","user":{"login":"PaulWattenberger","id":10393732,"avatar_url":"https://avatars.githubusercontent.com/u/10393732?v=3","gravatar_id":"","url":"https://api.github.com/users/PaulWattenberger","html_url":"https://github.com/PaulWattenberger","followers_url":"https://api.github.com/users/PaulWattenberger/followers","following_url":"https://api.github.com/users/PaulWattenberger/following{/other_user}","gists_url":"https://api.github.com/users/PaulWattenberger/gists{/gist_id}","starred_url":"https://api.github.com/users/PaulWattenberger/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/PaulWattenberger/subscriptions","organizations_url":"https://api.github.com/users/PaulWattenberger/orgs","repos_url":"https://api.github.com/users/PaulWattenberger/repos","events_url":"https://api.github.com/users/PaulWattenberger/events{/privacy}","received_events_url":"https://api.github.com/users/PaulWattenberger/received_events","type":"User","site_admin":false},"body":"This is the worker change needed for ecommerce to post purchase events to Sailthru.","created_at":"2016-07-05T15:48:36Z","updated_at":"2016-07-20T17:52:31Z","closed_at":null,"merged_at":null,"merge_commit_sha":"6321f561edf18e8ec6938db7a21111ae054ccb44","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/edx/ecommerce-worker/pulls/17/commits","review_comments_url":"https://api.github.com/repos/edx/ecommerce-worker/pulls/17/comments","review_comment_url":"https://api.github.com/repos/edx/ecommerce-worker/pulls/comments{/number}","comments_url":"https://api.github.com/repos/edx/ecommerce-worker/issues/17/comments","statuses_url":"https://api.github.com/repos/edx/ecommerce-worker/statuses/83dc1bd5133272ca6dd93071d9bc074d4147c49c","head":{"label":"edx:pwattenberger/sailthru","ref":"pwattenberger/sailthru","sha":"83dc1bd5133272ca6dd93071d9bc074d4147c49c","user":{"login":"edx","id":3179841,"avatar_url":"https://avatars.githubusercontent.com/u/3179841?v=3","gravatar_id":"","url":"https://api.github.com/users/edx","html_url":"https://github.com/edx","followers_url":"https://api.github.com/users/edx/followers","following_url":"https://api.github.com/users/edx/following{/other_user}","gists_url":"https://api.github.com/users/edx/gists{/gist_id}","starred_url":"https://api.github.com/users/edx/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/edx/subscriptions","organizations_url":"https://api.github.com/users/edx/orgs","repos_url":"https://api.github.com/users/edx/repos","events_url":"https://api.github.com/users/edx/events{/privacy}","received_events_url":"https://api.github.com/users/edx/received_events","type":"Organization","site_admin":false},"repo":{"id":42269790,"name":"ecommerce-worker","full_name":"edx/ecommerce-worker","owner":{"login":"edx","id":3179841,"avatar_url":"https://avatars.githubusercontent.com/u/3179841?v=3","gravatar_id":"","url":"https://api.github.com/users/edx","html_url":"https://github.com/edx","followers_url":"https://api.github.com/users/edx/followers","following_url":"https://api.github.com/users/edx/following{/other_user}","gists_url":"https://api.github.com/users/edx/gists{/gist_id}","starred_url":"https://api.github.com/users/edx/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/edx/subscriptions","organizations_url":"https://api.github.com/users/edx/orgs","repos_url":"https://api.github.com/users/edx/repos","events_url":"https://api.github.com/users/edx/events{/privacy}","received_events_url":"https://api.github.com/users/edx/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/edx/ecommerce-worker","description":"","fork":false,"url":"https://api.github.com/repos/edx/ecommerce-worker","forks_url":"https://api.github.com/repos/edx/ecommerce-worker/forks","keys_url":"https://api.github.com/repos/edx/ecommerce-worker/keys{/key_id}","collaborators_url":"https://api.github.com/repos/edx/ecommerce-worker/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/edx/ecommerce-worker/teams","hooks_url":"https://api.github.com/repos/edx/ecommerce-worker/hooks","issue_events_url":"https://api.github.com/repos/edx/ecommerce-worker/issues/events{/number}","events_url":"https://api.github.com/repos/edx/ecommerce-worker/events","assignees_url":"https://api.github.com/repos/edx/ecommerce-worker/assignees{/user}","branches_url":"https://api.github.com/repos/edx/ecommerce-worker/branches{/branch}","tags_url":"https://api.github.com/repos/edx/ecommerce-worker/tags","blobs_url":"https://api.github.com/repos/edx/ecommerce-worker/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/edx/ecommerce-worker/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/edx/ecommerce-worker/git/refs{/sha}","trees_url":"https://api.github.com/repos/edx/ecommerce-worker/git/trees{/sha}","statuses_url":"https://api.github.com/repos/edx/ecommerce-worker/statuses/{sha}","languages_url":"https://api.github.com/repos/edx/ecommerce-worker/languages","stargazers_url":"https://api.github.com/repos/edx/ecommerce-worker/stargazers","contributors_url":"https://api.github.com/repos/edx/ecommerce-worker/contributors","subscribers_url":"https://api.github.com/repos/edx/ecommerce-worker/subscribers","subscription_url":"https://api.github.com/repos/edx/ecommerce-worker/subscription","commits_url":"https://api.github.com/repos/edx/ecommerce-worker/commits{/sha}","git_commits_url":"https://api.github.com/repos/edx/ecommerce-worker/git/commits{/sha}","comments_url":"https://api.github.com/repos/edx/ecommerce-worker/comments{/number}","issue_comment_url":"https://api.github.com/repos/edx/ecommerce-worker/issues/comments{/number}","contents_url":"https://api.github.com/repos/edx/ecommerce-worker/contents/{+path}","compare_url":"https://api.github.com/repos/edx/ecommerce-worker/compare/{base}...{head}","merges_url":"https://api.github.com/repos/edx/ecommerce-worker/merges","archive_url":"https://api.github.com/repos/edx/ecommerce-worker/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/edx/ecommerce-worker/downloads","issues_url":"https://api.github.com/repos/edx/ecommerce-worker/issues{/number}","pulls_url":"https://api.github.com/repos/edx/ecommerce-worker/pulls{/number}","milestones_url":"https://api.github.com/repos/edx/ecommerce-worker/milestones{/number}","notifications_url":"https://api.github.com/repos/edx/ecommerce-worker/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/edx/ecommerce-worker/labels{/name}","releases_url":"https://api.github.com/repos/edx/ecommerce-worker/releases{/id}","deployments_url":"https://api.github.com/repos/edx/ecommerce-worker/deployments","created_at":"2015-09-10T20:45:12Z","updated_at":"2016-01-21T15:39:27Z","pushed_at":"2016-07-19T20:39:30Z","git_url":"git://github.com/edx/ecommerce-worker.git","ssh_url":"git@github.com:edx/ecommerce-worker.git","clone_url":"https://github.com/edx/ecommerce-worker.git","svn_url":"https://github.com/edx/ecommerce-worker","homepage":null,"size":49,"stargazers_count":0,"watchers_count":0,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":1,"mirror_url":null,"open_issues_count":1,"forks":1,"open_issues":1,"watchers":0,"default_branch":"master"}},"base":{"label":"edx:master","ref":"master","sha":"a937e046b88f0cde7371a081dde698bb1d32c6b2","user":{"login":"edx","id":3179841,"avatar_url":"https://avatars.githubusercontent.com/u/3179841?v=3","gravatar_id":"","url":"https://api.github.com/users/edx","html_url":"https://github.com/edx","followers_url":"https://api.github.com/users/edx/followers","following_url":"https://api.github.com/users/edx/following{/other_user}","gists_url":"https://api.github.com/users/edx/gists{/gist_id}","starred_url":"https://api.github.com/users/edx/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/edx/subscriptions","organizations_url":"https://api.github.com/users/edx/orgs","repos_url":"https://api.github.com/users/edx/repos","events_url":"https://api.github.com/users/edx/events{/privacy}","received_events_url":"https://api.github.com/users/edx/received_events","type":"Organization","site_admin":false},"repo":{"id":42269790,"name":"ecommerce-worker","full_name":"edx/ecommerce-worker","owner":{"login":"edx","id":3179841,"avatar_url":"https://avatars.githubusercontent.com/u/3179841?v=3","gravatar_id":"","url":"https://api.github.com/users/edx","html_url":"https://github.com/edx","followers_url":"https://api.github.com/users/edx/followers","following_url":"https://api.github.com/users/edx/following{/other_user}","gists_url":"https://api.github.com/users/edx/gists{/gist_id}","starred_url":"https://api.github.com/users/edx/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/edx/subscriptions","organizations_url":"https://api.github.com/users/edx/orgs","repos_url":"https://api.github.com/users/edx/repos","events_url":"https://api.github.com/users/edx/events{/privacy}","received_events_url":"https://api.github.com/users/edx/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/edx/ecommerce-worker","description":"","fork":false,"url":"https://api.github.com/repos/edx/ecommerce-worker","forks_url":"https://api.github.com/repos/edx/ecommerce-worker/forks","keys_url":"https://api.github.com/repos/edx/ecommerce-worker/keys{/key_id}","collaborators_url":"https://api.github.com/repos/edx/ecommerce-worker/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/edx/ecommerce-worker/teams","hooks_url":"https://api.github.com/repos/edx/ecommerce-worker/hooks","issue_events_url":"https://api.github.com/repos/edx/ecommerce-worker/issues/events{/number}","events_url":"https://api.github.com/repos/edx/ecommerce-worker/events","assignees_url":"https://api.github.com/repos/edx/ecommerce-worker/assignees{/user}","branches_url":"https://api.github.com/repos/edx/ecommerce-worker/branches{/branch}","tags_url":"https://api.github.com/repos/edx/ecommerce-worker/tags","blobs_url":"https://api.github.com/repos/edx/ecommerce-worker/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/edx/ecommerce-worker/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/edx/ecommerce-worker/git/refs{/sha}","trees_url":"https://api.github.com/repos/edx/ecommerce-worker/git/trees{/sha}","statuses_url":"https://api.github.com/repos/edx/ecommerce-worker/statuses/{sha}","languages_url":"https://api.github.com/repos/edx/ecommerce-worker/languages","stargazers_url":"https://api.github.com/repos/edx/ecommerce-worker/stargazers","contributors_url":"https://api.github.com/repos/edx/ecommerce-worker/contributors","subscribers_url":"https://api.github.com/repos/edx/ecommerce-worker/subscribers","subscription_url":"https://api.github.com/repos/edx/ecommerce-worker/subscription","commits_url":"https://api.github.com/repos/edx/ecommerce-worker/commits{/sha}","git_commits_url":"https://api.github.com/repos/edx/ecommerce-worker/git/commits{/sha}","comments_url":"https://api.github.com/repos/edx/ecommerce-worker/comments{/number}","issue_comment_url":"https://api.github.com/repos/edx/ecommerce-worker/issues/comments{/number}","contents_url":"https://api.github.com/repos/edx/ecommerce-worker/contents/{+path}","compare_url":"https://api.github.com/repos/edx/ecommerce-worker/compare/{base}...{head}","merges_url":"https://api.github.com/repos/edx/ecommerce-worker/merges","archive_url":"https://api.github.com/repos/edx/ecommerce-worker/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/edx/ecommerce-worker/downloads","issues_url":"https://api.github.com/repos/edx/ecommerce-worker/issues{/number}","pulls_url":"https://api.github.com/repos/edx/ecommerce-worker/pulls{/number}","milestones_url":"https://api.github.com/repos/edx/ecommerce-worker/milestones{/number}","notifications_url":"https://api.github.com/repos/edx/ecommerce-worker/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/edx/ecommerce-worker/labels{/name}","releases_url":"https://api.github.com/repos/edx/ecommerce-worker/releases{/id}","deployments_url":"https://api.github.com/repos/edx/ecommerce-worker/deployments","created_at":"2015-09-10T20:45:12Z","updated_at":"2016-01-21T15:39:27Z","pushed_at":"2016-07-19T20:39:30Z","git_url":"git://github.com/edx/ecommerce-worker.git","ssh_url":"git@github.com:edx/ecommerce-worker.git","clone_url":"https://github.com/edx/ecommerce-worker.git","svn_url":"https://github.com/edx/ecommerce-worker","homepage":null,"size":49,"stargazers_count":0,"watchers_count":0,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":1,"mirror_url":null,"open_issues_count":1,"forks":1,"open_issues":1,"watchers":0,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/edx/ecommerce-worker/pulls/17"},"html":{"href":"https://github.com/edx/ecommerce-worker/pull/17"},"issue":{"href":"https://api.github.com/repos/edx/ecommerce-worker/issues/17"},"comments":{"href":"https://api.github.com/repos/edx/ecommerce-worker/issues/17/comments"},"review_comments":{"href":"https://api.github.com/repos/edx/ecommerce-worker/pulls/17/comments"},"review_comment":{"href":"https://api.github.com/repos/edx/ecommerce-worker/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/edx/ecommerce-worker/pulls/17/commits"},"statuses":{"href":"https://api.github.com/repos/edx/ecommerce-worker/statuses/83dc1bd5133272ca6dd93071d9bc074d4147c49c"}}}}
{"actor":{"display_login":"rlucioni"}}