Skip to content

Commit

Permalink
adds gitignore
Browse files Browse the repository at this point in the history
  • Loading branch information
nickescallon committed Feb 21, 2015
1 parent f46368d commit f059ae4
Show file tree
Hide file tree
Showing 10 changed files with 308 additions and 0 deletions.
16 changes: 16 additions & 0 deletions .gitignore
@@ -0,0 +1,16 @@
### OSX ###
.DS_Store
.AppleDouble
.LSOverride
Icon

# Files that might appear on external disk
.Spotlight-V100
.Trashes

### NPM ###
npm-debug.log
node_modules

### Bower ###
**/bower_components/
26 changes: 26 additions & 0 deletions ne.swapi/endpoints/endpoints.constants.js
@@ -0,0 +1,26 @@
(function() {
angular.module('ne.swapi.endpoints.constants', [])
.constant('ENDPOINTS', ENDPOINTS())
.constant('PAGE_PARAM', '?people=');

function ENDPOINTS() {
var root = 'https://swapi.co/api/',
people = 'people/',
films = 'films/',
starships = 'starships/',
vehicles = 'vehicles/',
species = 'species/',
planets = 'planets/'

return {
ROOT: root,
PEOPLE: root + people,
FILMS: root + films,
STARSHIPS: root + starships,
VEHICLES: root + vehicles,
SPECIES: root + species,
PLANETS: root + planets
};
}

})();
30 changes: 30 additions & 0 deletions ne.swapi/endpoints/endpoints.films.service.js
@@ -0,0 +1,30 @@
(function() {
angular.module('ne.swapi.endpoints.films', ['ne.swapi.endpoints.helpers', 'ne.swapi.endpoints.constants'])
.factory('swapiFilms', swapiFilms);

swapiFilms.$inject = ['apiHelpers', 'ENDPOINTS'];
function swapiFilms(apiHelpers, ENDPOINTS) {

var service = {
byId: byId,
byPage: byPage,
all: all
};

return service;

function byId(id) {
return apiHelpers.getRecord(ENPOINTS.FILMS, id);
}

function byPage(pageNumber) {
return apiHelpers.getPaged(ENDPOINTS.FILMS, pageNumber);
}

function all() {
return apiHelpers.getAll(ENDPOINTS.FILMS);
}

}

})();
59 changes: 59 additions & 0 deletions ne.swapi/endpoints/endpoints.helpers.service.js
@@ -0,0 +1,59 @@
(function() {
angular.module('ne.swapi.endpoints.helpers', [])
.factory('apiHelpers', apiHelpers)

apiHelpers.$inject = ['$http', '$q'];
function apiHelpers($http, $q) {
var service = {
get: get,
getRecord: getRecord,
getPaged: getPaged,
getSchema: getSchema,
getAll: getAll
};

return service;

function get(url) {
return $http.get(url);
}

function getPaged(url, page) {
return $http.get( url + '?page=' + (page || '') );
}

function getRecord(url, id) {
return $http.get( url + 'id/' + id + '/' );
}

function getSchema(url) {
return $http.get( url + 'schema')
}

function getAll(url) {
var service = this,
deferred = $q.defer(),
results = [];

fetchRecords(url);
return deferred.promise;

function fetchRecords(url) {
service.get(url)
.then(function(response) {
results = results.concat(response.data.results);
if (typeof response.data.next === 'string') {
fetchRecords(response.data.next)
} else {
deferred.resolve({count: results.length, results: results})
}
})
.catch(function(error) {
deferred.reject(error);
});
}
}

}

})();
30 changes: 30 additions & 0 deletions ne.swapi/endpoints/endpoints.people.service.js
@@ -0,0 +1,30 @@
(function() {
angular.module('ne.swapi.endpoints.people', ['ne.swapi.endpoints.helpers', 'ne.swapi.endpoints.constants'])
.factory('swapiPeople', swapiPeople);

swapiPeople.$inject = ['apiHelpers', 'ENDPOINTS'];
function swapiPeople(apiHelpers, ENDPOINTS) {

var service = {
byId: byId,
byPage: byPage,
all: all
};

return service;

function byId(id) {
return apiHelpers.getRecord(ENPOINTS.PEOPLE, id);
}

function byPage(pageNumber) {
return apiHelpers.getPaged(ENDPOINTS.PEOPLE, pageNumber);
}

function all() {
return apiHelpers.getAll(ENDPOINTS.PEOPLE);
}

}

})();
30 changes: 30 additions & 0 deletions ne.swapi/endpoints/endpoints.planets.service.js
@@ -0,0 +1,30 @@
(function() {
angular.module('ne.swapi.endpoints.planets', ['ne.swapi.endpoints.helpers', 'ne.swapi.endpoints.constants'])
.factory('swapiPlanets', swapiPlanets);

swapiPlanets.$inject = ['apiHelpers', 'ENDPOINTS'];
function swapiPlanets(apiHelpers, ENDPOINTS) {

var service = {
byId: byId,
byPage: byPage,
all: all
};

return service;

function byId(id) {
return apiHelpers.getRecord(ENPOINTS.PLANETS, id);
}

function byPage(pageNumber) {
return apiHelpers.getPaged(ENDPOINTS.PLANETS, pageNumber);
}

function all() {
return apiHelpers.getAll(ENDPOINTS.PLANETS);
}

}

})();
30 changes: 30 additions & 0 deletions ne.swapi/endpoints/endpoints.species.service.js
@@ -0,0 +1,30 @@
(function() {
angular.module('ne.swapi.endpoints.species', ['ne.swapi.endpoints.helpers', 'ne.swapi.endpoints.constants'])
.factory('swapiSpecies', swapiSpecies);

swapiSpecies.$inject = ['apiHelpers', 'ENDPOINTS'];
function swapiSpecies(apiHelpers, ENDPOINTS) {

var service = {
byId: byId,
byPage: byPage,
all: all
};

return service;

function byId(id) {
return apiHelpers.getRecord(ENPOINTS.SPECIES, id);
}

function byPage(pageNumber) {
return apiHelpers.getPaged(ENDPOINTS.SPECIES, pageNumber);
}

function all() {
return apiHelpers.getAll(ENDPOINTS.SPECIES);
}

}

})();
30 changes: 30 additions & 0 deletions ne.swapi/endpoints/endpoints.starships.service.js
@@ -0,0 +1,30 @@
(function() {
angular.module('ne.swapi.endpoints.starships', ['ne.swapi.endpoints.helpers', 'ne.swapi.endpoints.constants'])
.factory('swapiStarships', swapiStarships);

swapiStarships.$inject = ['apiHelpers', 'ENDPOINTS'];
function swapiStarships(apiHelpers, ENDPOINTS) {

var service = {
byId: byId,
byPage: byPage,
all: all
};

return service;

function byId(id) {
return apiHelpers.getRecord(ENPOINTS.STARSHIPS, id);
}

function byPage(pageNumber) {
return apiHelpers.getPaged(ENDPOINTS.STARSHIPS, pageNumber);
}

function all() {
return apiHelpers.getAll(ENDPOINTS.STARSHIPS);
}

}

})();
30 changes: 30 additions & 0 deletions ne.swapi/endpoints/endpoints.vehicles.service.js
@@ -0,0 +1,30 @@
(function() {
angular.module('ne.swapi.endpoints.vehicles', ['ne.swapi.endpoints.helpers', 'ne.swapi.endpoints.constants'])
.factory('swapiVehicles', swapiVehicles);

swapiVehicles.$inject = ['apiHelpers', 'ENDPOINTS'];
function swapiVehicles(apiHelpers, ENDPOINTS) {

var service = {
byId: byId,
byPage: byPage,
all: all
};

return service;

function byId(id) {
return apiHelpers.getRecord(ENPOINTS.VEHICLES, id);
}

function byPage(pageNumber) {
return apiHelpers.getPaged(ENDPOINTS.VEHICLES, pageNumber);
}

function all() {
return apiHelpers.getAll(ENDPOINTS.VEHICLES);
}

}

})();
27 changes: 27 additions & 0 deletions ne.swapi/index.js
@@ -0,0 +1,27 @@
(function() {
angular.module('ne.swapi.api', [
'ne.swapi.endpoints.people',
'ne.swapi.endpoints.films',
'ne.swapi.endpoints.starships',
'ne.swapi.endpoints.vehicles',
'ne.swapi.endpoints.species',
'ne.swapi.endpoints.planets'
])
.factory('swapi', swapi);

swapi.$inject = ['swapiPeople', 'swapiFilms', 'swapiStarships', 'swapiVehicles', 'swapiSpecies', 'swapiPlanets'];
function swapi(swapiPeople, swapiFilms, swapiStarships, swapiVehicles, swapiSpecies, swapiPlanets) {

var service = {
people: swapiPeople,
films: swapiFilms,
starships: swapiStarships,
vehicles: swapiVehicles,
species: swapiSpecies,
planets: swapiPlanets
};

return service;
}

})();

0 comments on commit f059ae4

Please sign in to comment.