-
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
3 changed files
with
86 additions
and
63 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
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
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,52 @@ | ||
'use strict'; | ||
/* 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'; | ||
|
||
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"; | ||
var MISSING_REOURCE_MSG = 'resourceUrl not defined. Please see ' + | ||
'http://www.meetup.com/meetup_api/auth/#keysign ' + | ||
'to see how to create a signed resource URL.'; | ||
|
||
this.getEvents = function(callback) { | ||
$.ajax({ | ||
url: this.meetupURL, | ||
dataType: 'jsonp' | ||
}) | ||
.done(function(data) { | ||
callback(data); | ||
function Meetup(resourceUrl) { | ||
var requestedPage = parseInt(URI().getQuery('page'), 10); | ||
this.offset = Math.max(0, (requestedPage - 1) || 0); | ||
this.resourceUrl = resourceUrl; | ||
} | ||
|
||
}) | ||
.fail(function(error) { | ||
console.log("Meetup API Request Failed"); | ||
}); | ||
}; | ||
Meetup.prototype.fetch = function(limit) { | ||
if (!this.resourceUrl) { | ||
return $.Deferred() | ||
.reject(new Error(MISSING_REOURCE_MSG)) | ||
.promise(); | ||
} | ||
|
||
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"); | ||
}); | ||
var url = URI(this.resourceUrl) | ||
.setQuery({ | ||
offset: this.offset, | ||
format: 'json' | ||
}) | ||
.toString(); | ||
|
||
return $.ajax({url: url, dataType: 'jsonp'}) | ||
.then(function(data) { | ||
if (!limit) { return data.results; } | ||
return $.grep(data.results, function(item_, index) { | ||
return index <= limit; | ||
}); | ||
}); | ||
}; | ||
}; | ||
|
||
return Meetup; | ||
})); |