This repository was archived by the owner on Mar 4, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 59
Feature/mailchimp api preference api #816
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
0f29c8e
AS#131482348128949, Refactor Mailchimp API wrapper to be generic user…
3c8d51c
Merge branch 'dev' into feature/mailchimp-api-preference-api
a6b7105
AS#131482348128949, Refactor Mailchimp API wrapper to be generic user…
53bfec8
AS#131482348128949, Refactor Mailchimp API wrapper to be generic user…
a7892a8
AS#131482348128949, Refactor Mailchimp API wrapper to be generic user…
645a6a4
Merge branch 'dev' into feature/mailchimp-api-preference-api
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,24 +3,24 @@ import angular from 'angular' | |
(function() { | ||
'use strict' | ||
|
||
angular.module('tc.services').factory('MailchimpService', MailchimpService) | ||
angular.module('tc.services').factory('UserPreferencesService', UserPreferencesService) | ||
|
||
MailchimpService.$inject = ['$http', 'logger', 'Restangular', 'CONSTANTS', 'ApiService', '$q'] | ||
UserPreferencesService.$inject = ['$http', 'logger', 'Restangular', 'CONSTANTS', 'ApiService', '$q'] | ||
|
||
function MailchimpService($http, logger, Restangular, CONSTANTS, ApiService, $q) { | ||
var mailchimpApi = ApiService.getApiServiceProvider('MAILCHIMP') | ||
function UserPreferencesService($http, logger, Restangular, CONSTANTS, ApiService, $q) { | ||
var mailchimpApi = ApiService.getApiServiceProvider('PREFERENCES') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please rename the variable to prefService or something similar to avoid confusion. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for pointing it out. |
||
var service = { | ||
getMemberSubscription: getMemberSubscription, | ||
addSubscription: addSubscription | ||
getEmailPreferences: getEmailPreferences, | ||
saveEmailPreferences: saveEmailPreferences | ||
} | ||
return service | ||
|
||
function getMemberSubscription(user) { | ||
function getEmailPreferences(user) { | ||
return $q(function(resolve, reject) { | ||
mailchimpApi.one('mailchimp/lists', CONSTANTS.MAILCHIMP_LIST_ID) | ||
.one('members', user.userId).get() | ||
mailchimpApi.one('users', user.userId) | ||
.one('preferences', 'email').get() | ||
.then(function(resp) { | ||
resolve(resp) | ||
resolve(resp.subscriptions) | ||
}) | ||
.catch(function(err) { | ||
if (err.status === 404) { | ||
|
@@ -40,23 +40,22 @@ import angular from 'angular' | |
} | ||
|
||
|
||
function addSubscription(user, preferences) { | ||
var subscription = { | ||
userId: user.userId, | ||
function saveEmailPreferences(user, preferences) { | ||
var settings = { | ||
firstName: user.firstName, | ||
lastName: user.lastName, | ||
interests: {} | ||
subscriptions: {} | ||
} | ||
if (!preferences) { | ||
subscription.interests[CONSTANTS.MAILCHIMP_NL_GEN] = true | ||
settings.subscriptions['TOPCODER_NL_GEN'] = true | ||
} else { | ||
subscription.interests = preferences | ||
settings.subscriptions = preferences | ||
} | ||
return $q(function(resolve, reject) { | ||
mailchimpApi.one('mailchimp/lists', CONSTANTS.MAILCHIMP_LIST_ID) | ||
.customPUT(subscription, 'members') | ||
mailchimpApi.one('users', user.userId) | ||
.customPUT({ param: settings }, 'preferences/email') | ||
.then(function(resp) { | ||
resolve(resp) | ||
resolve(resp.subscriptions) | ||
}) | ||
.catch(function(err) { | ||
logger.error('Error adding member to subscription list', err) | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't this point to API_URL (api.topcoder.com) instead?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, you are correct. Thanks.