diff --git a/CHANGELOG.md b/CHANGELOG.md index 2021b66..d675aae 100755 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,10 @@ + +## 1.1.0 (2015-07-16) + +### Features + +- Added ability to limit the number of items to return + ### 1.0.2 (2015-07-16) diff --git a/README.md b/README.md index 347a386..b96c060 100644 --- a/README.md +++ b/README.md @@ -39,6 +39,21 @@ Use the service whenever you want it: }); } + +By default, all items are return but you can limit the number of items you want by specifying a limit in your `getFeed` call: + + function controller(Climb) { + var vm = this; + + var FEED_ID = '7216e32607f244179f5c51350a2ee2c8'; + var limit = 3; + + Climb.getFeed(FEED_ID, limit).then(function(items) { + vm.social = items; + }); + + } + ### Example diff --git a/bower.json b/bower.json index 78a49b9..d808bc5 100755 --- a/bower.json +++ b/bower.json @@ -5,9 +5,9 @@ ], "name": "angular-climb", "description": "Angular module for interacting with the Climb.social public API", - "version": "1.0.2", + "version": "1.1.0", "main": [ - "dist/angular-climb-1.0.2.js" + "dist/angular-climb-1.1.0.js" ], "homepage": "https://github.com/Climb-social/angular-climb.git", "repository": { diff --git a/dist/angular-climb-1.0.2.min.js b/dist/angular-climb-1.0.2.min.js deleted file mode 100644 index c30b8e0..0000000 --- a/dist/angular-climb-1.0.2.min.js +++ /dev/null @@ -1 +0,0 @@ -!function(a,b){"use strict";if("function"==typeof define&&define.amd)define(["angular"],b);else{if("undefined"==typeof module||"object"!=typeof module.exports)return b(a.angular);module.exports=b(require("angular"))}}(this,function(a){"use strict";function b(a,b){return{getFeed:function(c){if(!c)throw new Error("Please specify a feedId");var d=[b,c,"?callback=JSON_CALLBACK"].join("");return a.jsonp(d).then(function(a){return a.data})}}}var c="angular-climb",d=a.module(c,["ng"]);return d.constant("CLIMB_BASE_URL","http://app.climb.social/api/v1/collections/").factory("ClimbFactory",["$http","CLIMB_BASE_URL",b]),c}); \ No newline at end of file diff --git a/dist/angular-climb-1.0.2.js b/dist/angular-climb-1.1.0.js similarity index 88% rename from dist/angular-climb-1.0.2.js rename to dist/angular-climb-1.1.0.js index 9c4147f..eb8d919 100644 --- a/dist/angular-climb-1.0.2.js +++ b/dist/angular-climb-1.1.0.js @@ -24,7 +24,7 @@ ]); function ClimbFactory($http, CLIMB_BASE_URL) { return { - getFeed: function (FEED_ID) { + getFeed: function (FEED_ID, limit) { if (!FEED_ID) { throw new Error('Please specify a feedId'); } @@ -34,7 +34,11 @@ '?callback=JSON_CALLBACK' ].join(''); return $http.jsonp(climbFeedUrl).then(function success(response) { - return response.data; + var items = response.data; + if (items) { + return items.slice(0, limit); + } + return items; }); } }; diff --git a/dist/angular-climb-1.1.0.min.js b/dist/angular-climb-1.1.0.min.js new file mode 100644 index 0000000..23838e3 --- /dev/null +++ b/dist/angular-climb-1.1.0.min.js @@ -0,0 +1 @@ +!function(a,b){"use strict";if("function"==typeof define&&define.amd)define(["angular"],b);else{if("undefined"==typeof module||"object"!=typeof module.exports)return b(a.angular);module.exports=b(require("angular"))}}(this,function(a){"use strict";function b(a,b){return{getFeed:function(c,d){if(!c)throw new Error("Please specify a feedId");var e=[b,c,"?callback=JSON_CALLBACK"].join("");return a.jsonp(e).then(function(a){var b=a.data;return b?b.slice(0,d):b})}}}var c="angular-climb",d=a.module(c,["ng"]);return d.constant("CLIMB_BASE_URL","http://app.climb.social/api/v1/collections/").factory("ClimbFactory",["$http","CLIMB_BASE_URL",b]),c}); \ No newline at end of file diff --git a/package.json b/package.json index 59ee2cd..cf0f60a 100644 --- a/package.json +++ b/package.json @@ -1,8 +1,8 @@ { "name": "angular-climb", - "version": "1.0.2", + "version": "1.1.0", "description": "Angular module for interacting with the Climb.social public API.", - "main": "dist/angular-climb-1.0.2.js", + "main": "dist/angular-climb-1.1.0.js", "directories": { "test": "test" }, diff --git a/src/component.js b/src/component.js index eb1dcf1..d5d2f41 100755 --- a/src/component.js +++ b/src/component.js @@ -30,7 +30,7 @@ function ClimbFactory($http, CLIMB_BASE_URL) { return ({ - getFeed: function(FEED_ID) { + getFeed: function(FEED_ID, limit) { if (!FEED_ID) { throw new Error('Please specify a feedId'); @@ -40,7 +40,12 @@ return $http.jsonp(climbFeedUrl) .then(function success(response) { - return response.data; + var items = response.data; + + if(items) { + return items.slice(0, limit); + } + return items; }); } diff --git a/test/unit/componentSpec.js b/test/unit/componentSpec.js index 0cde7e2..4e66ab9 100755 --- a/test/unit/componentSpec.js +++ b/test/unit/componentSpec.js @@ -13,10 +13,15 @@ describe('When testing the climb module,', function () { var service; var $httpBackend; + var $q; + var deferred; - beforeEach(inject(function (_ClimbFactory_, _$httpBackend_) { + beforeEach(inject(function (_ClimbFactory_, _$httpBackend_, _$q_) { service = _ClimbFactory_; $httpBackend = _$httpBackend_; + $q = _$q_; + + deferred = $q.defer(); })); it('should have a method getFeed().', function () { @@ -52,6 +57,52 @@ describe('When testing the climb module,', function () { $httpBackend.flush(); }); + it('should accept a limit for the number of items to return', function () { + var limit = 3; + + var url = 'http://app.climb.social/api/v1/collections/' + FEED_ID + '?callback=JSON_CALLBACK'; + $httpBackend + .expectJSONP(url) + .respond([ + {title: 'a'}, + {title: 'b'}, + {title: 'c'}, + {title: 'd'}, + {title: 'e'}, + {title: 'f'} + ]); + + service.getFeed(FEED_ID, limit).then(function (items) { + expect(items.length).toBe(limit); + }); + + $httpBackend.flush(); + + }); + + it('should accept a different limit for the number of items to return', function () { + var limit = 4; + + var url = 'http://app.climb.social/api/v1/collections/' + FEED_ID + '?callback=JSON_CALLBACK'; + $httpBackend + .expectJSONP(url) + .respond([ + {title: 'a'}, + {title: 'b'}, + {title: 'c'}, + {title: 'd'}, + {title: 'e'}, + {title: 'f'} + ]); + + service.getFeed(FEED_ID, limit).then(function (items) { + expect(items.length).toBe(limit); + }); + + $httpBackend.flush(); + + }); + });