Skip to content

Commit

Permalink
Added ability to limit the number of items returned fixes #2
Browse files Browse the repository at this point in the history
  • Loading branch information
mmmoli committed Jul 16, 2015
1 parent b8835fa commit 55e5670
Show file tree
Hide file tree
Showing 9 changed files with 92 additions and 10 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
<a name"1.1.0"></a>
## 1.1.0 (2015-07-16)

### Features

- Added ability to limit the number of items to return

<a name"1.0.2"></a>
### 1.0.2 (2015-07-16)

Expand Down
15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 2 additions & 2 deletions bower.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
1 change: 0 additions & 1 deletion dist/angular-climb-1.0.2.min.js

This file was deleted.

8 changes: 6 additions & 2 deletions dist/angular-climb-1.0.2.js → dist/angular-climb-1.1.0.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}
Expand All @@ -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;
});
}
};
Expand Down
1 change: 1 addition & 0 deletions dist/angular-climb-1.1.0.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -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"
},
Expand Down
9 changes: 7 additions & 2 deletions src/component.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -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;
});

}
Expand Down
53 changes: 52 additions & 1 deletion test/unit/componentSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 () {
Expand Down Expand Up @@ -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();

});

});


Expand Down

0 comments on commit 55e5670

Please sign in to comment.