Skip to content

Commit 9139efb

Browse files
committed
new function, bumped to 0.5.2
1 parent df68bcc commit 9139efb

File tree

7 files changed

+105
-52
lines changed

7 files changed

+105
-52
lines changed

README.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,21 @@ githubFactory.getUser({
4242
});
4343
```
4444

45+
```js
46+
//https://developer.github.com/v3/search/#search-users
47+
48+
githubFactory.getUsers({
49+
q:"<SEARCH_STRING>", // (optional)
50+
sort:"<SORT_STRING>", // (optional) 'followers', 'repositories', 'joined'
51+
order:"<SORT_ORDER>", // (optional) 'desc', 'asc'
52+
per_page:"<ITEMS_PER_PAGE>", // (optional) valid values: 1-100 | default: 30
53+
}).then(function(_data){
54+
//on success
55+
}).catch(function (_data) {
56+
//on error
57+
});
58+
```
59+
4560
#### getRepo
4661
```js
4762
githubFactory.getRepoByUserAndName({

bower.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "angular-github-api-factory",
33
"description": "angularjs factory for github json rest api requests",
4-
"version": "0.5.1",
4+
"version": "0.5.2",
55
"main": "dist/angular-github-api-factory.js",
66
"authors": [
77
"Jonathan Hornung"

demo/js/app.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,17 @@ app.controller('controller', ['$scope', 'githubFactory', function($scope, github
77
console.info("user", _data);
88
});
99

10+
githubFactory.getUsers({
11+
q:"Johnny",
12+
per_page: 100,
13+
}).then(function(_data){
14+
console.info("users", _data);
15+
});
1016

1117
githubFactory.getReposByUser({
1218
user:"JohnnyTheTank",
1319
per_page: 100,
14-
}).success(function(_data){
20+
}).then(function(_data){
1521
console.info("repos by user", _data);
1622
});
1723

dist/angular-github-api-factory.js

Lines changed: 40 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,28 @@
11
/**
22
@name: angular-github-api-factory
3-
@version: 0.5.1 (01-06-2016)
3+
@version: 0.5.2 (30-08-2018)
44
@author: Jonathan Hornung
55
@url: https://github.com/JohnnyTheTank/angular-github-api-factory#readme
66
@license: MIT
77
*/
8-
"use strict";
8+
'use strict';
99

10-
angular.module("jtt_github", [])
10+
angular.module('jtt_github', [])
1111
.factory('githubFactory', ['$http', 'githubSearchDataService', function ($http, githubSearchDataService) {
1212

1313
var githubFactory = {};
1414

15+
githubFactory.getUsers = function (_params) {
16+
var searchData = githubSearchDataService.getNew('users', _params);
17+
return $http({
18+
method: 'GET',
19+
url: searchData.url,
20+
params: searchData.object,
21+
});
22+
};
23+
1524
githubFactory.getUser = function (_params) {
16-
var searchData = githubSearchDataService.getNew("user", _params);
25+
var searchData = githubSearchDataService.getNew('user', _params);
1726
return $http({
1827
method: 'GET',
1928
url: searchData.url,
@@ -22,7 +31,7 @@ angular.module("jtt_github", [])
2231
};
2332

2433
githubFactory.getReposByUser = function (_params) {
25-
var searchData = githubSearchDataService.getNew("reposByUser", _params);
34+
var searchData = githubSearchDataService.getNew('reposByUser', _params);
2635
return $http({
2736
method: 'GET',
2837
url: searchData.url,
@@ -31,7 +40,7 @@ angular.module("jtt_github", [])
3140
};
3241

3342
githubFactory.getReposByName = function (_params) {
34-
var searchData = githubSearchDataService.getNew("reposByName", _params);
43+
var searchData = githubSearchDataService.getNew('reposByName', _params);
3544
return $http({
3645
method: 'GET',
3746
url: searchData.url,
@@ -40,7 +49,7 @@ angular.module("jtt_github", [])
4049
};
4150

4251
githubFactory.getRepoByUserAndName = function (_params) {
43-
var searchData = githubSearchDataService.getNew("repoByUserAndName", _params);
52+
var searchData = githubSearchDataService.getNew('repoByUserAndName', _params);
4453
return $http({
4554
method: 'GET',
4655
url: searchData.url,
@@ -49,7 +58,7 @@ angular.module("jtt_github", [])
4958
};
5059

5160
githubFactory.getEventsByUser = function (_params) {
52-
var searchData = githubSearchDataService.getNew("eventsByUser", _params);
61+
var searchData = githubSearchDataService.getNew('eventsByUser', _params);
5362
return $http({
5463
method: 'GET',
5564
url: searchData.url,
@@ -58,7 +67,7 @@ angular.module("jtt_github", [])
5867
};
5968

6069
githubFactory.getEventsFromRepoByUserAndName = function (_params) {
61-
var searchData = githubSearchDataService.getNew("eventsFromRepoByUserAndName", _params);
70+
var searchData = githubSearchDataService.getNew('eventsFromRepoByUserAndName', _params);
6271
return $http({
6372
method: 'GET',
6473
url: searchData.url,
@@ -69,8 +78,8 @@ angular.module("jtt_github", [])
6978
return githubFactory;
7079
}])
7180
.service('githubSearchDataService', function () {
72-
this.getApiBaseUrl = function (_params) {
73-
return "https://api.github.com/";
81+
this.getApiBaseUrl = function () {
82+
return 'https://api.github.com/';
7483
};
7584

7685
this.fillDataInObjectByList = function (_object, _params, _list) {
@@ -87,7 +96,7 @@ angular.module("jtt_github", [])
8796
this.getNew = function (_type, _params) {
8897
var githubSearchData = {
8998
object: {},
90-
url: "",
99+
url: '',
91100
};
92101

93102
if (angular.isDefined(_params.per_page)) {
@@ -99,48 +108,55 @@ angular.module("jtt_github", [])
99108
}
100109

101110
switch (_type) {
102-
case "user":
111+
case 'user':
103112
githubSearchData.object.per_page = undefined;
104113
githubSearchData = this.fillDataInObjectByList(githubSearchData, _params, []);
105-
githubSearchData.url = this.getApiBaseUrl() + "users/" + _params.user;
114+
githubSearchData.url = this.getApiBaseUrl() + 'users/' + _params.user;
115+
break;
116+
117+
case 'users':
118+
githubSearchData = this.fillDataInObjectByList(githubSearchData, _params, [
119+
'sort', 'order', 'page'
120+
]);
121+
githubSearchData.url = this.getApiBaseUrl() + 'search/users?q=' + _params.q;
106122
break;
107123

108-
case "reposByUser":
124+
case 'reposByUser':
109125
githubSearchData = this.fillDataInObjectByList(githubSearchData, _params, [
110126
'q', 'sort', 'order', 'page'
111127
]);
112-
githubSearchData.url = this.getApiBaseUrl() + "users/" + _params.user + "/repos";
128+
githubSearchData.url = this.getApiBaseUrl() + 'users/' + _params.user + '/repos';
113129
break;
114130

115-
case "reposByName":
131+
case 'reposByName':
116132
githubSearchData = this.fillDataInObjectByList(githubSearchData, _params, [
117133
'sort', 'order', 'page'
118134
]);
119-
githubSearchData.url = this.getApiBaseUrl() + "search/repositories?q=" + _params.q;
135+
githubSearchData.url = this.getApiBaseUrl() + 'search/repositories?q=' + _params.q;
120136
break;
121137

122-
case "repoByUserAndName":
138+
case 'repoByUserAndName':
123139
githubSearchData.object = {
124140
access_token: _params.access_token,
125141
};
126142

127143
githubSearchData = this.fillDataInObjectByList(githubSearchData, _params, []);
128144

129-
githubSearchData.url = this.getApiBaseUrl() + "repos/" + _params.user + "/" + _params.repo;
145+
githubSearchData.url = this.getApiBaseUrl() + 'repos/' + _params.user + '/' + _params.repo;
130146
break;
131147

132-
case "eventsByUser":
148+
case 'eventsByUser':
133149
githubSearchData = this.fillDataInObjectByList(githubSearchData, _params, [
134150
'q', 'sort', 'order', 'page'
135151
]);
136-
githubSearchData.url = this.getApiBaseUrl() + "users/" + _params.user + "/events";
152+
githubSearchData.url = this.getApiBaseUrl() + 'users/' + _params.user + '/events';
137153
break;
138154

139-
case "eventsFromRepoByUserAndName":
155+
case 'eventsFromRepoByUserAndName':
140156
githubSearchData = this.fillDataInObjectByList(githubSearchData, _params, [
141157
'q', 'sort', 'order', 'page'
142158
]);
143-
githubSearchData.url = this.getApiBaseUrl() + "repos/" + _params.user + "/" + _params.repo + "/events";
159+
githubSearchData.url = this.getApiBaseUrl() + 'repos/' + _params.user + '/' + _params.repo + '/events';
144160
break;
145161
}
146162
return githubSearchData;

dist/angular-github-api-factory.min.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "angular-github-api-factory",
3-
"version": "0.5.1",
3+
"version": "0.5.2",
44
"description": "angularjs factory for github json rest api requests",
55
"main": "dist/angular-github-api-factory.js",
66
"scripts": {

0 commit comments

Comments
 (0)