Skip to content

Commit f033f96

Browse files
Merge pull request #43 from teamsnap/add-broadcast-email
Add broadcast email
2 parents a1a4b0d + 1c3c885 commit f033f96

File tree

10 files changed

+304
-11
lines changed

10 files changed

+304
-11
lines changed

lib/teamsnap.js

Lines changed: 69 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -465,6 +465,71 @@ exports.bulkMarkUnsetAvailabilities = function(memberId, statusCode, callback) {
465465

466466
});
467467

468+
require.register("collections/broadcastEmails", function(exports, require, module) {
469+
exports.loadBroadcastEmails = function(params, callback) {
470+
if (this.isId(params)) {
471+
params = {
472+
id: params
473+
};
474+
} else if (!(params && typeof params === 'object')) {
475+
throw new TSArgsError('teamsnap.loadBroadcastEmails', 'must provide an id or query parameters');
476+
}
477+
return this.loadItems('broadcastEmail', params, callback);
478+
};
479+
480+
exports.createBroadcastEmail = function(data) {
481+
return this.createItem(data, {
482+
type: 'broadcastEmail'
483+
});
484+
};
485+
486+
exports.saveBroadcastEmail = function(broadcastEmail, callback) {
487+
var _ref;
488+
if (!broadcastEmail) {
489+
throw new TSArgsError('teamsnap.saveBroadcastEmail', "`broadcastEmail` must be provided");
490+
}
491+
if (!this.isItem(broadcastEmail, 'broadcastEmail')) {
492+
throw new TSArgsError('teamsnap.saveBroadcastEmail', "`type` must be 'broadcastEmail'");
493+
}
494+
if (!broadcastEmail.teamId) {
495+
return this.reject('You must provide a team id.', 'teamId', callback);
496+
}
497+
if (!broadcastEmail.memberId) {
498+
return this.reject('You must provide a member id.', 'memberId', callback);
499+
}
500+
if (!((_ref = broadcastEmail.body) != null ? _ref.trim() : void 0)) {
501+
return this.reject('You must provide the text alert body.', 'body', callback);
502+
}
503+
return this.saveItem(broadcastEmail, callback);
504+
};
505+
506+
exports.deleteBroadcastEmail = function(broadcastEmail, callback) {
507+
if (!broadcastEmail) {
508+
throw new TSArgsError('teamsnap.deleteBroadcastEmail', '`broadcastEmail` must be provided');
509+
}
510+
return this.deleteItem(broadcastEmail, callback);
511+
};
512+
513+
exports.uploadAttachment = function(broadcastEmailId, file, callback) {
514+
var params;
515+
if (typeof FormData === 'undefined') {
516+
this.reject('Your browser does not support the new file upload APIs.', 'file', callback);
517+
}
518+
if (!file) {
519+
throw new TSArgsError('teamsnap.uploadAttachment', 'file is required');
520+
}
521+
if (!broadcastEmailId) {
522+
throw new TSArgsError('teamsnap.uploadAttachment', 'broadcastEmailId is required');
523+
}
524+
params = {
525+
broadcastEmailId: broadcastEmailId,
526+
file: file
527+
};
528+
return this.collections.broadcastEmails.exec('uploadAttachment', params);
529+
};
530+
531+
});
532+
468533
require.register("collections/broadcastSms", function(exports, require, module) {
469534
exports.loadBroadcastSmses = function(params, callback) {
470535
if (this.isId(params)) {
@@ -4401,6 +4466,8 @@ add(require('./collections/assignments'));
44014466

44024467
add(require('./collections/availabilities'));
44034468

4469+
add(require('./collections/broadcastEmails'));
4470+
44044471
add(require('./collections/broadcastSms'));
44054472

44064473
add(require('./collections/contactEmailAddresses'));
@@ -4509,7 +4576,7 @@ _ref = require('./model'), Collection = _ref.Collection, Item = _ref.Item;
45094576
require('./errors');
45104577

45114578
TeamSnap = (function() {
4512-
TeamSnap.prototype.version = '1.2.1';
4579+
TeamSnap.prototype.version = '1.3.0';
45134580

45144581
TeamSnap.prototype.promises = promises;
45154582

@@ -4549,7 +4616,7 @@ var plural, pluralLookup, singularLookup, teamTypes, teamsnap, type, typeLookup,
45494616

45504617
teamsnap = exports;
45514618

4552-
types = ['user', 'assignment', 'availability', 'broadcastSms', 'contact', 'contactEmailAddress', 'contactPhoneNumber', 'customDatum', 'customField', 'leagueCustomDatum', 'leagueCustomField', 'divisionLocation', 'divisionMember', 'divisionMemberPreferences', 'event', 'forumPost', 'forumSubscription', 'forumTopic', 'leagueRegistrantDocument', 'location', 'member', 'memberEmailAddress', 'memberFile', 'memberLink', 'memberPayment', 'memberPhoneNumber', 'memberPreferences', 'opponent', 'opponentResults', 'paymentNote', 'plan', 'smsGateway', 'sponsor', 'sport', 'team', 'teamFee', 'teamPaypalPreferences', 'teamPreferences', 'teamPublicSite', 'teamResults', 'timeZone', 'trackedItem', 'trackedItemStatus'];
4619+
types = ['user', 'assignment', 'availability', 'broadcastEmail', 'broadcastSms', 'contact', 'contactEmailAddress', 'contactPhoneNumber', 'customDatum', 'customField', 'leagueCustomDatum', 'leagueCustomField', 'divisionLocation', 'divisionMember', 'divisionMemberPreferences', 'event', 'forumPost', 'forumSubscription', 'forumTopic', 'leagueRegistrantDocument', 'location', 'member', 'memberEmailAddress', 'memberFile', 'memberLink', 'memberPayment', 'memberPhoneNumber', 'memberPreferences', 'opponent', 'opponentResults', 'paymentNote', 'plan', 'smsGateway', 'sponsor', 'sport', 'team', 'teamFee', 'teamPaypalPreferences', 'teamPreferences', 'teamPublicSite', 'teamResults', 'timeZone', 'trackedItem', 'trackedItemStatus'];
45534620

45544621
teamTypes = types.slice();
45554622

lib/teamsnap.min.js

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/test/js/test.js

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,101 @@ describe('Availabilities', function() {
135135

136136
});
137137

138+
require.register("test/broadcastEmail", function(exports, require, module) {
139+
describe('Broadcast Emails', function() {
140+
var email, recipient, sender;
141+
email = null;
142+
sender = null;
143+
recipient = null;
144+
before(function(done) {
145+
sender = teamsnap.createMember();
146+
sender.teamId = team.id;
147+
sender.firstName = 'Test';
148+
return teamsnap.saveMember(sender, function(err, result) {
149+
var memberEmail;
150+
expect(err).to.be["null"];
151+
memberEmail = teamsnap.createMemberEmailAddress();
152+
memberEmail.memberId = sender.id;
153+
memberEmail.email = "[email protected]";
154+
return teamsnap.saveMemberEmailAddress(memberEmail, function(err, result) {
155+
expect(err).to.be["null"];
156+
return done();
157+
});
158+
});
159+
});
160+
before(function(done) {
161+
recipient = teamsnap.createMember();
162+
recipient.teamId = team.id;
163+
recipient.firstName = 'Test';
164+
return teamsnap.saveMember(recipient, function(err, result) {
165+
var memberEmail;
166+
expect(err).to.be["null"];
167+
memberEmail = teamsnap.createMemberEmailAddress();
168+
memberEmail.memberId = recipient.id;
169+
memberEmail.email = "[email protected]";
170+
return teamsnap.saveMemberEmailAddress(memberEmail, function(err, result) {
171+
expect(err).to.be["null"];
172+
return done();
173+
});
174+
});
175+
});
176+
after(function(done) {
177+
return teamsnap.deleteMember(sender, function(err, result) {
178+
expect(err).to.be["null"];
179+
return done();
180+
});
181+
});
182+
after(function(done) {
183+
return teamsnap.deleteMember(recipient, function(err, result) {
184+
expect(err).to.be["null"];
185+
return done();
186+
});
187+
});
188+
it('should be able to create a broadcast email', function(done) {
189+
email = teamsnap.createBroadcastEmail();
190+
email.teamId = team.id;
191+
email.memberId = sender.id;
192+
email.body = "Hello world";
193+
email.subject = "Subject!";
194+
email.recipientIds = [recipient.id];
195+
return teamsnap.saveBroadcastEmail(email, function(err, result) {
196+
expect(err).to.be["null"];
197+
result.should.have.property('type', 'broadcastEmail');
198+
result.should.have.property('recipientCount', 1);
199+
result.should.have.property('memberId', sender.id);
200+
result.should.have.property('body', "Hello world");
201+
return done();
202+
});
203+
});
204+
it('should be able to load all broadcast emails for a team', function(done) {
205+
return teamsnap.loadBroadcastEmails({
206+
teamId: team.id
207+
}, function(err, result) {
208+
expect(err).to.be["null"];
209+
result.should.be.an('array');
210+
result.should.have.property('length', 1);
211+
return done();
212+
});
213+
});
214+
it('should be able to load a single broadcast email', function(done) {
215+
return teamsnap.loadBroadcastEmails(email.id, function(err, result) {
216+
expect(err).to.be["null"];
217+
result.should.be.an('array');
218+
result.should.have.property('length', 1);
219+
result[0].should.have.property('id', email.id);
220+
return done();
221+
});
222+
});
223+
return it('should be able to delete a broadcast email', function(done) {
224+
return teamsnap.deleteBroadcastEmail(email, function(err, result) {
225+
expect(err).to.be["null"];
226+
return done();
227+
});
228+
});
229+
});
230+
231+
});
232+
138233
require.register("test/broadcastSms", function(exports, require, module) {
139234
describe('Broadcast Smses', function() {
140235
var recipient, sender, sms;

lib/test/js/test.min.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "teamsnap.js",
3-
"version": "1.2.1",
3+
"version": "1.3.0",
44
"description": "A JavaScript library for using the TeamSnap API.",
55
"author": "Jacob Wright with TeamSnap (http://www.teamsnap.com)",
66
"homepage": "https://github.com/teamsnap/teamsnap-javascript-sdk",
@@ -26,4 +26,4 @@
2626
"uglify-js-brunch": "latest",
2727
"coffeelint-brunch": "latest"
2828
}
29-
}
29+
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
exports.loadBroadcastEmails = (params, callback) ->
2+
if @isId params
3+
params = id: params
4+
else unless params and typeof params is 'object'
5+
throw new TSArgsError 'teamsnap.loadBroadcastEmails', 'must provide an id
6+
or query parameters'
7+
8+
@loadItems 'broadcastEmail', params, callback
9+
10+
exports.createBroadcastEmail = (data) ->
11+
@createItem data,
12+
type: 'broadcastEmail'
13+
14+
exports.saveBroadcastEmail = (broadcastEmail, callback) ->
15+
unless broadcastEmail
16+
throw new TSArgsError 'teamsnap.saveBroadcastEmail', "`broadcastEmail` must
17+
be provided"
18+
unless @isItem broadcastEmail, 'broadcastEmail'
19+
throw new TSArgsError 'teamsnap.saveBroadcastEmail', "`type` must
20+
be 'broadcastEmail'"
21+
unless broadcastEmail.teamId
22+
return @reject 'You must provide a team id.', 'teamId', callback
23+
unless broadcastEmail.memberId
24+
return @reject 'You must provide a member id.', 'memberId', callback
25+
unless broadcastEmail.body?.trim()
26+
return @reject 'You must provide the text alert body.',
27+
'body', callback
28+
29+
@saveItem broadcastEmail, callback
30+
31+
exports.deleteBroadcastEmail = (broadcastEmail, callback) ->
32+
unless broadcastEmail
33+
throw new TSArgsError 'teamsnap.deleteBroadcastEmail', '`broadcastEmail`
34+
must be provided'
35+
36+
@deleteItem broadcastEmail, callback
37+
38+
exports.uploadAttachment = (broadcastEmailId, file, callback) ->
39+
if typeof FormData is 'undefined'
40+
@reject 'Your browser does not support the new file upload APIs.', 'file',
41+
callback
42+
unless file
43+
throw new TSArgsError 'teamsnap.uploadAttachment',
44+
'file is required'
45+
unless broadcastEmailId
46+
throw new TSArgsError 'teamsnap.uploadAttachment',
47+
'broadcastEmailId is required'
48+
49+
params = broadcastEmailId: broadcastEmailId, file: file
50+
51+
@collections.broadcastEmails.exec('uploadAttachment', params)

src/sdk.coffee

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,7 @@ add require './persistence'
159159
add require './collections/teams'
160160
add require './collections/assignments'
161161
add require './collections/availabilities'
162+
add require './collections/broadcastEmails'
162163
add require './collections/broadcastSms'
163164
add require './collections/contactEmailAddresses'
164165
add require './collections/contactPhoneNumbers'

src/teamsnap.coffee

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ promises = require './promises'
33
require './errors'
44

55
class TeamSnap
6-
version: '1.2.1'
6+
version: '1.3.0'
77
promises: promises
88
when: promises.when
99
TeamSnap: TeamSnap
@@ -20,4 +20,4 @@ require './sdk'
2020

2121

2222
unless String::trim
23-
String::trim = -> @replace /^\s+|\s+$/g, ''
23+
String::trim = -> @replace /^\s+|\s+$/g, ''

src/types.coffee

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ types = [
44
'user'
55
'assignment'
66
'availability'
7+
'broadcastEmail'
78
'broadcastSms'
89
'contact'
910
'contactEmailAddress'

test/broadcastEmail.coffee

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
describe 'Broadcast Emails', ->
2+
3+
email = null
4+
sender = null
5+
recipient = null
6+
7+
before (done) ->
8+
sender = teamsnap.createMember()
9+
sender.teamId = team.id
10+
sender.firstName = 'Test'
11+
teamsnap.saveMember sender, (err, result) ->
12+
expect(err).to.be.null
13+
memberEmail = teamsnap.createMemberEmailAddress()
14+
memberEmail.memberId = sender.id
15+
memberEmail.email = "[email protected]"
16+
teamsnap.saveMemberEmailAddress memberEmail, (err, result) ->
17+
expect(err).to.be.null
18+
done()
19+
20+
before (done) ->
21+
recipient = teamsnap.createMember()
22+
recipient.teamId = team.id
23+
recipient.firstName = 'Test'
24+
teamsnap.saveMember recipient, (err, result) ->
25+
expect(err).to.be.null
26+
memberEmail = teamsnap.createMemberEmailAddress()
27+
memberEmail.memberId = recipient.id
28+
memberEmail.email = "[email protected]"
29+
teamsnap.saveMemberEmailAddress memberEmail, (err, result) ->
30+
expect(err).to.be.null
31+
done()
32+
33+
after (done) ->
34+
teamsnap.deleteMember sender, (err, result) ->
35+
expect(err).to.be.null
36+
done()
37+
38+
after (done) ->
39+
teamsnap.deleteMember recipient, (err, result) ->
40+
expect(err).to.be.null
41+
done()
42+
43+
it 'should be able to create a broadcast email', (done) ->
44+
email = teamsnap.createBroadcastEmail()
45+
email.teamId = team.id
46+
email.memberId = sender.id
47+
email.body = "Hello world"
48+
email.subject = "Subject!"
49+
email.recipientIds = [recipient.id]
50+
teamsnap.saveBroadcastEmail email, (err, result) ->
51+
expect(err).to.be.null
52+
result.should.have.property('type', 'broadcastEmail')
53+
result.should.have.property('recipientCount', 1)
54+
result.should.have.property('memberId', sender.id)
55+
result.should.have.property('body', "Hello world")
56+
done()
57+
58+
it 'should be able to load all broadcast emails for a team', (done) ->
59+
teamsnap.loadBroadcastEmails {teamId: team.id}, (err, result) ->
60+
expect(err).to.be.null
61+
result.should.be.an('array')
62+
result.should.have.property('length', 1)
63+
done()
64+
65+
it 'should be able to load a single broadcast email', (done) ->
66+
teamsnap.loadBroadcastEmails email.id, (err, result) ->
67+
expect(err).to.be.null
68+
result.should.be.an('array')
69+
result.should.have.property('length', 1)
70+
result[0].should.have.property('id', email.id)
71+
done()
72+
73+
74+
it 'should be able to delete a broadcast email', (done) ->
75+
teamsnap.deleteBroadcastEmail email, (err, result) ->
76+
expect(err).to.be.null
77+
done()
78+

0 commit comments

Comments
 (0)