-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This is more JavaScript class idiomatic. It also allows for future abstractions like removing the hard coded URLs. The original file used tabs so I kept that even though the .vimrc seems to contradict this. This also uses UMD for encapsulation which makes it more universal to be pulled into other websites.
- Loading branch information
Showing
1 changed file
with
50 additions
and
34 deletions.
There are no files selected for viewing
This file contains 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 |
---|---|---|
@@ -1,38 +1,54 @@ | ||
'use strict'; | ||
|
||
var Meetup = function(meetupURL) { | ||
this.meetupURL = (typeof meetupURL!=='undefined') ? meetupURL : | ||
"https://api.meetup.com/2/events?offset=0&format=json&limited_events=False&group_urlname=techcorridorio&page=200&fields=&order=time&desc=false&status=upcoming&sig_id=168857872&sig=e659cc6038d27adf6eae600a44905c69196c77df"; | ||
|
||
this.getEvents = function(callback) { | ||
$.ajax({ | ||
url: this.meetupURL, | ||
dataType: 'jsonp' | ||
}) | ||
.done(function(data) { | ||
callback(data); | ||
|
||
}) | ||
.fail(function(error) { | ||
console.log("Meetup API Request Failed"); | ||
/* globals define */ | ||
(function(root, factory) { | ||
if (typeof define === 'function' && define.amd) { | ||
// AMD. Register as an anonymous module. | ||
define([], function() { | ||
// Also create a global in case some scripts | ||
// that are loaded still are looking for | ||
// a global even when an AMD loader is in use. | ||
return (root.Meetup = factory()); | ||
}); | ||
} else { | ||
// Browser globals | ||
root.Meetup = factory(); | ||
} | ||
}(this, function() { | ||
'use strict'; | ||
|
||
// TODO: These URLs should not be hard coded here. | ||
var EVENTS_URL = 'https://api.meetup.com/2/events?offset=0&format=json&' + | ||
'limited_events=False&group_urlname=techcorridorio&page=200&fields=&' + | ||
'order=time&desc=false&status=upcoming&sig_id=168857872&' + | ||
'sig=e659cc6038d27adf6eae600a44905c69196c77df'; | ||
|
||
var DEVELOPERS_URL = 'https://api.meetup.com/2/members?format=json&' + | ||
'group_urlname=techcorridorio&photo-host=public&order=name&' + | ||
'sig_id=70201382&sig=5b77206251c64989f61e8f45580e0d200221f5d4&' + | ||
'page=20&offset={{offset}}'; | ||
|
||
function getMeetupEndpoint(url) { | ||
return $.ajax({url: url, dataType: 'jsonp'}); | ||
} | ||
|
||
function Meetup() { | ||
var requestedPage = window.location.search.match(/page=(\d+)/); | ||
var offset = (requestedPage == null ? 0 : parseInt(requestedPage[1]) - 1); | ||
this.offset = (offset < 0 ? 0 : offset); | ||
this.meetupURL = this._urlFor(EVENTS_URL); | ||
this.developersURL = this._urlFor(DEVELOPERS_URL); | ||
} | ||
|
||
Meetup.prototype._urlFor = function(urlTemplate) { | ||
return urlTemplate.replace('{{offset}}', this.offset); | ||
}; | ||
|
||
var requested_page = window.location.search.match(/page=(\d+)/); | ||
var offset = (requested_page == null ? 0 : parseInt(requested_page[1]) - 1); | ||
offset = (offset < 0 ? 0 : offset); | ||
this.developersURL = "https://api.meetup.com/2/members?format=json&group_urlname=techcorridorio&photo-host=public&order=name&sig_id=70201382&sig=5b77206251c64989f61e8f45580e0d200221f5d4&page=20" + | ||
"&offset=" + offset; | ||
this.getDevelopers = function(callback) { | ||
$.ajax({ | ||
url: this.developersURL, | ||
dataType: 'jsonp' | ||
}) | ||
.done(function(data) { | ||
callback(data); | ||
}) | ||
.fail(function(error) { | ||
console.log("Meetup API Request Failed"); | ||
}); | ||
Meetup.prototype.getEvents = function() { | ||
return getMeetupEndpoint(this.meetupURL); | ||
}; | ||
|
||
Meetup.prototype.getDevelopers = function() { | ||
return getMeetupEndpoint(this.developersURL); | ||
}; | ||
}; | ||
|
||
return Meetup; | ||
})); |