├── .eslintrc
├── .gitignore
├── .travis.yml
├── README.md
├── api
├── index.js
├── instructors.js
├── keys.js
├── models
│ ├── index.js
│ ├── instructors.js
│ ├── keys.js
│ ├── operations.js
│ └── student.js
├── operations.js
├── students.js
└── utils.js
├── example.html
├── gulpfile.js
├── importer.js
├── package.json
├── server.js
├── tests
└── routes
│ ├── instructors.js
│ ├── keys.js
│ ├── operations.js
│ └── students.js
└── travis-startup.js
/.eslintrc:
--------------------------------------------------------------------------------
1 | {
2 | "env": {
3 | "node": true,
4 | "es6": true
5 | }
6 | }
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | node_modules
--------------------------------------------------------------------------------
/.travis.yml:
--------------------------------------------------------------------------------
1 | language: node_js
2 | node_js: 4.2
3 | services: mongodb
4 | before_script:
5 | - npm install -g gulp
6 | - node travis-startup.js
7 | script: gulp tests
8 | env:
9 | - CXX=g++-4.8
10 | addons:
11 | apt:
12 | sources:
13 | - ubuntu-toolchain-r-test
14 | packages:
15 | - gcc-4.8
16 | - g++-4.8
17 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # HackerYou API [](https://travis-ci.org/HackerYou/hackeryou-api)
2 | A simple API for the HackerYou community. It contains all the alumni, instructors and operations staff information.
3 |
4 | # Why?
5 | Mostly this is for learning purposes. Allowing students to practice AJAX using the data, and ultimately allowing students the ability to contribute to the API. For example the API key process is not the most robust, but it allows students a way to practice passing data to an API.
6 |
7 | ### Authorization
8 | In order to make requests to the HackerYou API you need to first obtain an API key. Getting a key is easy, you need to make a POST request to `/key` and provide your email address, you will then be returned an `key` that you can use for your requests!
9 |
10 | ## Routes
11 |
12 | All requests need to be prefixed with `http://api.hackeryou.com/v1/`.
13 |
14 | ### Key
15 | #### `/key`
16 | **POST** or **GET** _Return or register an api key for use based on email provided_
17 |
18 | Params | Value | Description
19 | ------ | ---- | ------
20 | `email` : string | `your-email` | Api key to make requests
21 |
22 | **Examples:** `http://api.hackeryou.com/v1/key?email=snickers@example.com`
23 |
24 | #### Sample Response
25 |
26 | *New Key*
27 |
28 | {
29 | "response": {
30 | "key": "$2a$10$ifelhq/xoaa3t0TTWsrz2eXx.6VyV26z92zuN.e68SosdHwnuyF/q",
31 | "email": "tes@tes.com",
32 | }
33 | }
34 |
35 | *Key Exists*
36 |
37 | {
38 | "response": {
39 | "key": "$2a$10$ifelhq/xoaa3t0TTWsrz2eXx.6VyV26z92zuN.e68SosdHwnuyF/q",
40 | "email": "tes@tes.com"
41 | },
42 | "message": "Key for email already exists"
43 | }
44 |
45 |
46 |
47 | ### Students
48 | ### `/students`
49 | GET _Return all students_
50 |
51 | Params | Value | Description
52 | ------ | ---- | ------
53 | `key` : string | `your-api-key` | Api key to make requests
54 | `order` : string | `desc`
`asc` | Used to sort the order of students based on name
55 |
56 | ####Sample Response
57 |
58 | {
59 | "students": [
60 | {
61 | "_id": "562e98353f0007bf9713d9d0",
62 | "name": "Adam Kendal",
63 | "photo": "http://hackeryou.com/wp-content/uploads/2015/07/AdamKendal-230x230.jpg",
64 | "location": "Toronto, Ontario",
65 | "cohort": {
66 | "year": 2015,
67 | "season": "Summer"
68 | },
69 | "social": {
70 | "website": "http://adamkendal.ca",
71 | "github": "http://github.com/abkendal",
72 | "twitter": "http://twitter.com/abkendal"
73 | },
74 | "job": {
75 | "position": "Jr. Front-End Developer (contract) ",
76 | "location": "Nurun"
77 | }
78 | }
79 | ],
80 | "count": 1
81 | }
82 |
83 | ### `/students/:cohort/:year`
84 | GET _Return all students by cohort and year_
85 |
86 | Params | Value | Description
87 | ------ | ------ | ------
88 | `key` : string | `your-api-key` | Api key to make requests
89 | `order` : string | `desc`
`asc` | Used to sort the order of students based on name
90 |
91 | **Examples:** `http://api.hackeryou.com/v1/students/summer/2015?key=yourkey`
92 |
93 | #### Sample Response
94 | Same as the above
95 |
96 | ### Operations
97 | ### `/operations`
98 | GET _Return all operations staff_
99 |
100 | Params | Value | Description
101 | ------ | ------ | ------
102 | `key` : string | `your-api-key` | Api key to make requests
103 | `order` : string | `desc`
`asc` | Used to sort the order of students based on name
104 |
105 | #### Sample Response
106 |
107 | {
108 | "operations": [
109 | {
110 | "_id": "562e98353f0007bf9713d9d1",
111 | "name": "Heather Payne",
112 | "role": "CEO",
113 | "photo": "http://hackeryou.com/wp-content/uploads/2014/11/team-heatherpayne-@2x1-530x462.jpg",
114 | "social": {
115 | "twitter": "http://twitter.com/heatherpayne",
116 | "website": "http://heatherpayne.ca",
117 | "email": "heather@hackeryou.com"
118 | }
119 | }
120 | ],
121 | "count": 1
122 | }
123 |
124 |
125 | ### Instructors
126 | ### `/instructors`
127 | GET _Return all instructors_
128 |
129 | Params | Value | Description
130 | ------ | ------ | ------
131 | `key` : string | `your-api-key` | Api key to make requests
132 | `order` : string | `desc`
`asc` | Used to sort the order of students based on name
133 |
134 | #### Sample Response
135 |
136 | {
137 | "instructors": [
138 | {
139 | "_id": "562e98353f0007bf9713d9cf",
140 | "name": "Anne Thomas",
141 | "role": "Lead Instructor, Web Development",
142 | "photo": "http://hackeryou.com/wp-content/uploads/2014/12/Anne-530x462.jpg",
143 | "social": {
144 | "twitter": "http://twitter.com/AlfalfaAnne",
145 | "github": "http://github.com/AlfalfaAnne"
146 | }
147 | }
148 | ],
149 | "count": 1
150 | }
151 |
152 |
153 | ## Importer
154 |
155 | Used to scrape the HackerYou website to gather students information
156 |
157 | ## TODO
158 | Get current students/not just alumni
159 | Add deploy step after Travis CI pass. Either with a simple bash script or [shipit](https://github.com/shipitjs/shipit) file.
160 |
161 | ## Contributing
162 | Please fork the repo and make pull requests!
163 | To get started run `npm install`, start an instance of mongoDB. In order to get the initial data you will have to run `node importer.js` with either `team` or `students` as an argument.
164 |
165 | node importer.js team
166 |
167 |
168 |
--------------------------------------------------------------------------------
/api/index.js:
--------------------------------------------------------------------------------
1 | 'use strict';
2 |
3 | let mongoose = require('mongoose');
4 | mongoose.connect('mongodb://localhost/hackeryou-api');
5 |
6 | let keys = require('./keys.js');
7 | let students = require('./students.js');
8 | let operations = require('./operations.js');
9 | let instructors = require('./instructors.js');
10 |
11 | module.exports = {
12 | keys: keys,
13 | students: students,
14 | operations: operations,
15 | instructors: instructors
16 | };
--------------------------------------------------------------------------------
/api/instructors.js:
--------------------------------------------------------------------------------
1 | 'use strict';
2 |
3 | let models = require('./models/index.js');
4 |
5 | let instructors = {};
6 |
7 | instructors.getInstructors = (req,res) => {
8 | let order = req.query.order || 1;
9 | if(order !== 1) {
10 | order = order.toLowerCase() === 'asc' ? 1 : -1;
11 | }
12 | models.instructors.find({},{'__v' : 0}, (err,docs) => {
13 | if(err) {
14 | res.send({
15 | error: err
16 | });
17 | }
18 | else {
19 | res.send({
20 | instructors: docs,
21 | count: docs.length
22 | });
23 | }
24 | }).sort({name: order});
25 | };
26 |
27 |
28 | module.exports = instructors;
--------------------------------------------------------------------------------
/api/keys.js:
--------------------------------------------------------------------------------
1 | 'use strict';
2 |
3 | let key = {};
4 | let models = require('./models/index.js');
5 | let bcrypt = require('bcrypt');
6 |
7 | key.getKey = (req,res) => {
8 | var query = Object.keys(req.query).length > 0 ? req.query : req.body;
9 | if(query.email === undefined) {
10 | res.send({
11 | error: 'Missing email parameter.'
12 | });
13 | return;
14 | }
15 | let apiKey = bcrypt.hashSync(query.email,10);
16 | models.keys.find({email: query.email}, {__v:0,_id:0}, (err,doc) => {
17 | if(err) {
18 | res.send({
19 | error: err
20 | });
21 | }
22 | else if (doc.length > 0) {
23 | res.send({
24 | response:doc[0],
25 | message: 'Key for email already exists'
26 | });
27 | }
28 | else {
29 | new models.keys({
30 | key: apiKey,
31 | email: query.email
32 | }).save().then((doc) => {
33 | res.send({
34 | response: {
35 | key: apiKey,
36 | email: query.email
37 | }
38 | });
39 | });
40 | }
41 | });
42 | };
43 |
44 | module.exports = key;
45 |
46 |
47 |
48 |
49 |
50 |
--------------------------------------------------------------------------------
/api/models/index.js:
--------------------------------------------------------------------------------
1 | 'use strict';
2 |
3 | let Students = require('./student.js');
4 | let Operations = require('./operations.js');
5 | let Instructors = require('./instructors.js');
6 | let Keys = require('./keys.js');
7 |
8 | module.exports = {
9 | students: Students,
10 | operations: Operations,
11 | instructors: Instructors,
12 | keys: Keys
13 | };
--------------------------------------------------------------------------------
/api/models/instructors.js:
--------------------------------------------------------------------------------
1 | 'use strict';
2 |
3 | let mongoose = require('mongoose');
4 |
5 | let schema = new mongoose.Schema({
6 | name: String,
7 | role: String,
8 | social: {
9 | twitter: String,
10 | website: String,
11 | github: String,
12 | emai: String
13 | },
14 | photo: String
15 | });
16 |
17 | module.exports = mongoose.model('Instructor',schema);
--------------------------------------------------------------------------------
/api/models/keys.js:
--------------------------------------------------------------------------------
1 | 'use strict';
2 |
3 | let mongoose = require('mongoose');
4 |
5 | let schema = new mongoose.Schema({
6 | key: String,
7 | email: String
8 | });
9 |
10 | module.exports = mongoose.model('Key', schema);
--------------------------------------------------------------------------------
/api/models/operations.js:
--------------------------------------------------------------------------------
1 | 'use strict';
2 |
3 | let mongoose = require('mongoose');
4 |
5 | let schema = new mongoose.Schema({
6 | name: String,
7 | role: String,
8 | social: {
9 | twitter: String,
10 | website: String,
11 | email: String
12 | },
13 | photo: String
14 | });
15 |
16 | module.exports = mongoose.model('Operation', schema);
--------------------------------------------------------------------------------
/api/models/student.js:
--------------------------------------------------------------------------------
1 | 'use strict';
2 |
3 | let mongoose = require('mongoose');
4 |
5 | let schema = new mongoose.Schema({
6 | name: String,
7 | location: String,
8 | job: {
9 | position: String,
10 | location: String,
11 | website: String
12 | },
13 | photo: String,
14 | social: {
15 | linkedIn: String,
16 | github: String,
17 | twitter: String,
18 | website: String
19 | },
20 | cohort: {
21 | season: String,
22 | year: Number
23 | }
24 | });
25 |
26 | module.exports = mongoose.model('Student', schema);
27 |
28 |
29 |
--------------------------------------------------------------------------------
/api/operations.js:
--------------------------------------------------------------------------------
1 | 'use strict';
2 |
3 | let operations = {};
4 | let models = require('./models/index.js');
5 |
6 | operations.getOperations = (req,res) => {
7 | let order = req.query.order || 1;
8 | if(order !== 1) {
9 | order = order.toLowerCase() === 'asc' ? 1 : -1;
10 | }
11 | models.operations.find({},{'__v':0}, function(err,docs) {
12 | if(err) {
13 | res.send({
14 | error: err
15 | });
16 | }
17 | else {
18 | res.send({
19 | operations: docs,
20 | count: docs.length
21 | });
22 | };
23 | }).sort({name: order});
24 | };
25 |
26 |
27 | module.exports = operations;
--------------------------------------------------------------------------------
/api/students.js:
--------------------------------------------------------------------------------
1 | 'use strict';
2 |
3 | let models = require('./models/index.js');
4 | let student = {};
5 | let utils = require('./utils.js');
6 |
7 | student.getStudents = (req, res) => {
8 | let order = req.query.order || 1;
9 | if(order !== 1) {
10 | order = order.toLowerCase() === 'asc' ? 1 : -1;
11 | }
12 | models.students.find({},{'__v': 0},(err,docs) => {
13 | if(err) {
14 | res.send({
15 | error: err
16 | });
17 | }
18 | else {
19 | res.send({
20 | students: docs,
21 | count: docs.length
22 | });
23 | }
24 | }).sort({name: order});
25 | };
26 |
27 | student.getByCohort = (req,res) => {
28 | let params = req.params;
29 | let order = req.query.order || 1;
30 | if(order !== 1) {
31 | order = order.toLowerCase() === 'asc' ? 1 : -1;
32 | }
33 | models.students.find({
34 | 'cohort.year': params.year,
35 | 'cohort.season': utils.capitalize(params.cohort)
36 | }, (err,docs) => {
37 | if(err) {
38 | res.send({
39 | error: err
40 | });
41 | }
42 | else {
43 | res.send({
44 | students: docs,
45 | count: docs.length
46 | });
47 | }
48 | }).sort({name:order});
49 | };
50 |
51 | module.exports = student;
--------------------------------------------------------------------------------
/api/utils.js:
--------------------------------------------------------------------------------
1 | 'use strict';
2 |
3 | module.exports = {
4 | capitalize: (str) => {
5 | return str[0].toUpperCase() + str.substring(1);
6 | }
7 | };
--------------------------------------------------------------------------------
/example.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |