|
1 |
| -'use strict'; |
| 1 | +/* globals define */ |
| 2 | +(function(root, factory) { |
| 3 | + if (typeof define === 'function' && define.amd) { |
| 4 | + // AMD. Register as an anonymous module. |
| 5 | + define([], function() { |
| 6 | + // Also create a global in case some scripts |
| 7 | + // that are loaded still are looking for |
| 8 | + // a global even when an AMD loader is in use. |
| 9 | + return (root.Meetup = factory()); |
| 10 | + }); |
| 11 | + } else { |
| 12 | + // Browser globals |
| 13 | + root.Meetup = factory(); |
| 14 | + } |
| 15 | +}(this, function() { |
| 16 | + 'use strict'; |
2 | 17 |
|
3 |
| -var Meetup = function(meetupURL) { |
4 |
| - this.meetupURL = (typeof meetupURL!=='undefined') ? meetupURL : |
5 |
| - "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"; |
| 18 | + function Meetup(resourceUrl) { |
| 19 | + var requestedPage = window.location.search.match(/page=(\d+)/); |
| 20 | + var offset = (requestedPage == null ? 0 : parseInt(requestedPage[1]) - 1); |
| 21 | + this.offset = (offset < 0 ? 0 : offset); |
| 22 | + this._uri = URI(resourceUrl); |
| 23 | + } |
6 | 24 |
|
7 |
| - this.getEvents = function(callback) { |
8 |
| - $.ajax({ |
9 |
| - url: this.meetupURL, |
10 |
| - dataType: 'jsonp' |
11 |
| - }) |
12 |
| - .done(function(data) { |
13 |
| - callback(data); |
| 25 | + Meetup.prototype.fetch = function(limit) { |
| 26 | + var url = this._uri.setQuery({ |
| 27 | + offset: this.offset, |
| 28 | + format: 'json' |
| 29 | + }).toString(); |
| 30 | + var promise = $.ajax({url: url, dataType: 'jsonp'}); |
14 | 31 |
|
15 |
| - }) |
16 |
| - .fail(function(error) { |
17 |
| - console.log("Meetup API Request Failed"); |
| 32 | + return promise.then(function(data) { |
| 33 | + if (!limit) { return data.results; } |
| 34 | + return $.grep(data.results, function(item_, index) { |
| 35 | + return index <= limit; |
| 36 | + }); |
18 | 37 | });
|
19 | 38 | };
|
20 | 39 |
|
21 |
| - var requested_page = window.location.search.match(/page=(\d+)/); |
22 |
| - var offset = (requested_page == null ? 0 : parseInt(requested_page[1]) - 1); |
23 |
| - offset = (offset < 0 ? 0 : offset); |
24 |
| - 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" + |
25 |
| - "&offset=" + offset; |
26 |
| - this.getDevelopers = function(callback) { |
27 |
| - $.ajax({ |
28 |
| - url: this.developersURL, |
29 |
| - dataType: 'jsonp' |
30 |
| - }) |
31 |
| - .done(function(data) { |
32 |
| - callback(data); |
33 |
| - }) |
34 |
| - .fail(function(error) { |
35 |
| - console.log("Meetup API Request Failed"); |
36 |
| - }); |
37 |
| - }; |
38 |
| -}; |
| 40 | + return Meetup; |
| 41 | +})); |
0 commit comments