-
-
Notifications
You must be signed in to change notification settings - Fork 114
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: add requests stats * fix: requests test * v0.2.3 * chore: update version
- Loading branch information
1 parent
3fdad7a
commit 303aca9
Showing
19 changed files
with
334 additions
and
31,157 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,40 @@ | ||
## [0.2.2](https://github.com/marciovsena/bibleapi/compare/0.2.0...0.2.2) (2018-11-30) | ||
## [0.2.3](https://github.com/marciovsena/bibleapi/compare/v0.2.2...v0.2.3) (2018-12-26) | ||
|
||
|
||
### Bug Fixes | ||
|
||
- remove unused nodemon ([4b1ca0e](https://github.com/marciovsena/bibleapi/commit/4b1ca0e)) | ||
* copy and menu links on homepage ([#11](https://github.com/marciovsena/bibleapi/issues/11)) ([3fdad7a](https://github.com/marciovsena/bibleapi/commit/3fdad7a)) | ||
* requests test ([ebd597e](https://github.com/marciovsena/bibleapi/commit/ebd597e)) | ||
|
||
|
||
### Features | ||
|
||
- posting new homepage ([acb2332](https://github.com/marciovsena/bibleapi/commit/acb2332)) | ||
* add requests stats ([68697e6](https://github.com/marciovsena/bibleapi/commit/68697e6)) | ||
|
||
|
||
|
||
## [0.2.2](https://github.com/marciovsena/bibleapi/compare/0.2.0...v0.2.2) (2018-11-30) | ||
|
||
# 0.2.1 (2018-11-30) | ||
|
||
### Bug Fixes | ||
|
||
- **docs:** update version ([098832e](https://github.com/marciovsena/bibleapi/commit/098832e)) | ||
- change the sample user ([256be0d](https://github.com/marciovsena/bibleapi/commit/256be0d)) | ||
- circle ci ([#1](https://github.com/marciovsena/bibleapi/issues/1)) ([b58afe5](https://github.com/marciovsena/bibleapi/commit/b58afe5)) | ||
- move dependencies ([1783b1f](https://github.com/marciovsena/bibleapi/commit/1783b1f)) | ||
- set node version ([3dfb7e0](https://github.com/marciovsena/bibleapi/commit/3dfb7e0)) | ||
- set props on package.json ([c6f37ca](https://github.com/marciovsena/bibleapi/commit/c6f37ca)) | ||
* **docs:** update version ([098832e](https://github.com/marciovsena/bibleapi/commit/098832e)) | ||
* change the sample user ([256be0d](https://github.com/marciovsena/bibleapi/commit/256be0d)) | ||
* circle ci ([#1](https://github.com/marciovsena/bibleapi/issues/1)) ([b58afe5](https://github.com/marciovsena/bibleapi/commit/b58afe5)) | ||
* move dependencies ([1783b1f](https://github.com/marciovsena/bibleapi/commit/1783b1f)) | ||
* remove unused nodemon ([4b1ca0e](https://github.com/marciovsena/bibleapi/commit/4b1ca0e)) | ||
* set node version ([3dfb7e0](https://github.com/marciovsena/bibleapi/commit/3dfb7e0)) | ||
* set props on package.json ([c6f37ca](https://github.com/marciovsena/bibleapi/commit/c6f37ca)) | ||
|
||
|
||
### Features | ||
|
||
- add patreon button ([#7](https://github.com/marciovsena/bibleapi/issues/7)) ([13f301e](https://github.com/marciovsena/bibleapi/commit/13f301e)) | ||
* add patreon button ([#7](https://github.com/marciovsena/bibleapi/issues/7)) ([13f301e](https://github.com/marciovsena/bibleapi/commit/13f301e)) | ||
* posting new homepage ([acb2332](https://github.com/marciovsena/bibleapi/commit/acb2332)) | ||
|
||
|
||
|
||
# 0.2.0 (2018-11-25) | ||
|
||
- Init project | ||
|
||
|
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
'use strict' | ||
|
||
const Database = use('Database') | ||
const Request = use('App/Models/Request') | ||
const moment = require('moment') | ||
const { newRequest } = use('App/utils') | ||
|
||
const getPeriod = period => { | ||
switch (period) { | ||
case 'month': | ||
return moment().subtract(30, 'days') | ||
case 'week': | ||
return moment().subtract(7, 'days') | ||
default: | ||
return moment().subtract(1, 'days') | ||
} | ||
} | ||
|
||
class RequestController { | ||
/** | ||
* @api {get} api/requests/:period? Get Requests | ||
* @apiVersion 0.2.0 | ||
* @apiName show | ||
* @apiGroup Requests | ||
* | ||
* | ||
* @apiParam {String} period [month, week, day] | ||
* | ||
* @apiSuccess {String} url Requisition url | ||
* @apiSuccess {String} data Requisition date | ||
* | ||
* @apiExample Example usage: | ||
* curl -i https://bibleapi.co/api/requests/month | ||
* | ||
* @apiSuccessExample {json} Success-Response: | ||
* HTTP/1.1 200 OK | ||
* [{ | ||
* "url": "/api/books/gn", | ||
* "date": "2018-12-08T22:16:52.000Z" | ||
* }] | ||
* | ||
* @apiError TooManyRequests When performing more than 3 requests at the same endpoint in an interval less than 5 minutes | ||
* | ||
* @apiErrorExample {text} Error-Response: | ||
* HTTP/1.1 429 Too Many Requests | ||
* | ||
* | ||
*/ | ||
|
||
async show({ request, params }) { | ||
newRequest(request.url()) | ||
const { period } = params | ||
const date = getPeriod(period) | ||
const requests = date | ||
? await Request.query().where('created_at', '>', date) | ||
: await Request.query() | ||
return await requests.map(request => ({ | ||
url: request.url, | ||
date: request.created_at | ||
})) | ||
} | ||
|
||
/** | ||
* @api {get} api/requests/count/:period? Get Count Requests | ||
* @apiVersion 0.2.0 | ||
* @apiName count | ||
* @apiGroup Requests | ||
* | ||
* | ||
* @apiParam {String} period [month, week, day] | ||
* | ||
* @apiSuccess {String} url Requisition url | ||
* @apiSuccess {String} count Number of requisitions in the period | ||
* | ||
* @apiExample Example usage: | ||
* curl -i https://bibleapi.co/api/requests/count/month | ||
* | ||
* @apiSuccessExample {json} Success-Response: | ||
* HTTP/1.1 200 OK | ||
* [{ | ||
* "url": "/api/books/gn", | ||
* "count": "3", | ||
* }] | ||
* | ||
* @apiError TooManyRequests When performing more than 3 requests at the same endpoint in an interval less than 5 minutes | ||
* | ||
* @apiErrorExample {text} Error-Response: | ||
* HTTP/1.1 429 Too Many Requests | ||
* | ||
* | ||
*/ | ||
|
||
async count({ request, params }) { | ||
newRequest(request.url()) | ||
const { period } = params | ||
const date = getPeriod(period) | ||
const requests = date | ||
? await Database.count() | ||
.select('url') | ||
.from('requests') | ||
.where('created_at', '>', date) | ||
.groupBy('url') | ||
.orderBy('count', 'desc') | ||
: await Database.count() | ||
.select('url') | ||
.from('requests') | ||
.groupBy('url') | ||
.orderBy('count', 'desc') | ||
return requests | ||
} | ||
} | ||
|
||
module.exports = RequestController |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
'use strict' | ||
|
||
/** @type {typeof import('@adonisjs/lucid/src/Lucid/Model')} */ | ||
const Model = use('Model') | ||
|
||
class Request extends Model { | ||
} | ||
|
||
module.exports = Request |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
const requests = [ | ||
{ | ||
url: '/api/books/gn' | ||
}, | ||
{ | ||
url: '/api/books' | ||
}, | ||
{ | ||
url: '/api/requests/count/week' | ||
}, | ||
{ | ||
url: '/api/requests/count/week' | ||
}, | ||
{ | ||
url: '/api/requests/count/month' | ||
}, | ||
{ | ||
url: '/api/requests/' | ||
}, | ||
{ | ||
url: '/api/requests/week' | ||
}, | ||
{ | ||
url: '/api/requests/count/month' | ||
} | ||
] | ||
|
||
module.exports = requests |
Oops, something went wrong.