Skip to content

Commit 000f9fe

Browse files
authored
v.0.2.3 (#16)
* chore: Add credits and thanks * fix(docs): update version * fix: change the sample user * chore: add sample test env * fix: set props on package.json * fix: move dependencies * fix: circle ci (#1) * fix: remove filter on config * fix: back filters * fix: add .env.testing - circleci * chore: remove plans (#2) Remove plans * feature: add seeds on migrations (#3) * chore: remove plans * feature: add seeds on migrations * fix: change precommit script * fix: update script * fix: add adonijs on circleci * fix: add adonisjs on circleci * fix: add .env.testing * chore: add seed instructions * feat: add patreon button (#7) feat: add patreon button * v.0.2.1 * fix: set node version * fix: remove unused nodemon * feat: posting new homepage * chore: ignore file * v0.2.2 * v0.2.2 * chore: remove unused dependencie * fix: copy and menu links on homepage (#11) * fix: copy and menu links on homepage * fix: link on readme * feat: add requests stats (#12) * feat: add requests stats * fix: requests test * v0.2.3 * chore: update version * fix: logger tests (#13) v.0.2.3 * feat: add requests stats * fix: requests test * chore: update version * fix: request tests * v0.2.3 * fix: requests logger (#14) * feat: add requests stats * fix: requests test * v0.2.3 * chore: update version * fix: request tests * fix: request tests * fix: remove requests tests (#15) * feat: add requests stats * fix: requests test * v0.2.3 * chore: update version
1 parent 452acaf commit 000f9fe

26 files changed

Lines changed: 350 additions & 31178 deletions

CHANGELOG.md

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,40 @@
1-
## [0.2.2](https://github.com/marciovsena/bibleapi/compare/0.2.0...0.2.2) (2018-11-30)
1+
## [0.2.3](https://github.com/marciovsena/bibleapi/compare/v0.2.2...v0.2.3) (2018-12-26)
2+
23

34
### Bug Fixes
45

5-
- remove unused nodemon ([4b1ca0e](https://github.com/marciovsena/bibleapi/commit/4b1ca0e))
6+
* copy and menu links on homepage ([#11](https://github.com/marciovsena/bibleapi/issues/11)) ([3fdad7a](https://github.com/marciovsena/bibleapi/commit/3fdad7a))
7+
* requests test ([ebd597e](https://github.com/marciovsena/bibleapi/commit/ebd597e))
8+
69

710
### Features
811

9-
- posting new homepage ([acb2332](https://github.com/marciovsena/bibleapi/commit/acb2332))
12+
* add requests stats ([68697e6](https://github.com/marciovsena/bibleapi/commit/68697e6))
13+
14+
15+
16+
## [0.2.2](https://github.com/marciovsena/bibleapi/compare/0.2.0...v0.2.2) (2018-11-30)
1017

11-
# 0.2.1 (2018-11-30)
1218

1319
### Bug Fixes
1420

15-
- **docs:** update version ([098832e](https://github.com/marciovsena/bibleapi/commit/098832e))
16-
- change the sample user ([256be0d](https://github.com/marciovsena/bibleapi/commit/256be0d))
17-
- circle ci ([#1](https://github.com/marciovsena/bibleapi/issues/1)) ([b58afe5](https://github.com/marciovsena/bibleapi/commit/b58afe5))
18-
- move dependencies ([1783b1f](https://github.com/marciovsena/bibleapi/commit/1783b1f))
19-
- set node version ([3dfb7e0](https://github.com/marciovsena/bibleapi/commit/3dfb7e0))
20-
- set props on package.json ([c6f37ca](https://github.com/marciovsena/bibleapi/commit/c6f37ca))
21+
* **docs:** update version ([098832e](https://github.com/marciovsena/bibleapi/commit/098832e))
22+
* change the sample user ([256be0d](https://github.com/marciovsena/bibleapi/commit/256be0d))
23+
* circle ci ([#1](https://github.com/marciovsena/bibleapi/issues/1)) ([b58afe5](https://github.com/marciovsena/bibleapi/commit/b58afe5))
24+
* move dependencies ([1783b1f](https://github.com/marciovsena/bibleapi/commit/1783b1f))
25+
* remove unused nodemon ([4b1ca0e](https://github.com/marciovsena/bibleapi/commit/4b1ca0e))
26+
* set node version ([3dfb7e0](https://github.com/marciovsena/bibleapi/commit/3dfb7e0))
27+
* set props on package.json ([c6f37ca](https://github.com/marciovsena/bibleapi/commit/c6f37ca))
28+
2129

2230
### Features
2331

24-
- add patreon button ([#7](https://github.com/marciovsena/bibleapi/issues/7)) ([13f301e](https://github.com/marciovsena/bibleapi/commit/13f301e))
32+
* add patreon button ([#7](https://github.com/marciovsena/bibleapi/issues/7)) ([13f301e](https://github.com/marciovsena/bibleapi/commit/13f301e))
33+
* posting new homepage ([acb2332](https://github.com/marciovsena/bibleapi/commit/acb2332))
34+
35+
2536

2637
# 0.2.0 (2018-11-25)
2738

28-
- Init project
39+
40+

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,5 +78,5 @@ Visite our [trello](https://trello.com/b/VPGRzM36/biblieapi) board
7878
Created and maintained by:
7979

8080
<!-- prettier-ignore -->
81-
| [<img src="https://avatars0.githubusercontent.com/u/3450717?s=460&v=4" width="60px;"/><br /><sub><b>Márcio Sena</b></sub>](https://github.com/marciovsena)<br />[💻](https://github.com/marciovsena/bibleapi/commits?author=marciovsena "Code") [📖](https://github.com/marciovsena/bibleapi/commits?author=marciovsena "Documentation") [🐛](https://github.com/marciovsena/bibleapi/issues?q=author%marciovsena "Bug reports")
81+
| [<img src="https://avatars0.githubusercontent.com/u/3450717?s=460&v=4" width="60px;"/><br /><sub><b>Márcio Sena</b></sub>](https://github.com/marciovsena)<br />[💻](https://github.com/marciovsena/bibleapi/commits?author=marciovsena "Code") [📖](https://github.com/marciovsena/bibleapi/commits?author=marciovsena "Documentation") [🐛](https://github.com/marciovsena/bibleapi/issues?q=author%3Amarciovsena "Bug reports")
8282
| :---: |

apidoc/api_data.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

apidoc/api_data.json

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

apidoc/api_project.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

apidoc/api_project.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{ "name": "bibleAPI", "version": "0.2.0", "description": "A RESTful API for Bible", "title": "bibleAPI", "url": "https://bibleapi.co/", "header": { "title": "bibleAPI", "index": "Home", "indexHref": "https://bibleapi.co" }, "template": { "forceLanguage": "en" }, "sampleUrl": false, "defaultVersion": "0.0.0", "apidoc": "0.3.0", "generator": { "name": "apidoc", "time": "2018-11-25T04:02:19.553Z", "url": "http://apidocjs.com", "version": "0.17.6" }}
1+
{ "name": "bibleAPI", "version": "0.2.0", "description": "A RESTful API for Bible", "title": "bibleAPI", "url": "https://bibleapi.co/", "header": { "title": "bibleAPI", "index": "Home", "indexHref": "https://bibleapi.co" }, "template": { "forceLanguage": "en" }, "sampleUrl": false, "defaultVersion": "0.0.0", "apidoc": "0.3.0", "generator": { "name": "apidoc", "time": "2018-12-08T23:25:23.298Z", "url": "http://apidocjs.com", "version": "0.17.6" }}
Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
'use strict'
2+
3+
const Database = use('Database')
4+
const Request = use('App/Models/Request')
5+
const moment = require('moment')
6+
const { newRequest } = use('App/utils')
7+
8+
const getPeriod = period => {
9+
switch (period) {
10+
case 'month':
11+
return moment().subtract(30, 'days')
12+
case 'week':
13+
return moment().subtract(7, 'days')
14+
default:
15+
return moment().subtract(1, 'days')
16+
}
17+
}
18+
19+
class RequestController {
20+
/**
21+
* @api {get} api/requests/:period? Get Requests
22+
* @apiVersion 0.2.0
23+
* @apiName show
24+
* @apiGroup Requests
25+
*
26+
*
27+
* @apiParam {String} period [month, week, day]
28+
*
29+
* @apiSuccess {String} url Requisition url
30+
* @apiSuccess {String} data Requisition date
31+
*
32+
* @apiExample Example usage:
33+
* curl -i https://bibleapi.co/api/requests/month
34+
*
35+
* @apiSuccessExample {json} Success-Response:
36+
* HTTP/1.1 200 OK
37+
* [{
38+
* "url": "/api/books/gn",
39+
* "date": "2018-12-08T22:16:52.000Z"
40+
* }]
41+
*
42+
* @apiError TooManyRequests When performing more than 3 requests at the same endpoint in an interval less than 5 minutes
43+
*
44+
* @apiErrorExample {text} Error-Response:
45+
* HTTP/1.1 429 Too Many Requests
46+
*
47+
*
48+
*/
49+
50+
async show({ request, params }) {
51+
newRequest(request.url())
52+
const { period } = params
53+
const date = getPeriod(period)
54+
const requests = date
55+
? await Request.query().where('created_at', '>', date)
56+
: await Request.query()
57+
return await requests.map(request => ({
58+
url: request.url,
59+
date: request.created_at
60+
}))
61+
}
62+
63+
/**
64+
* @api {get} api/requests/count/:period? Get Count Requests
65+
* @apiVersion 0.2.0
66+
* @apiName count
67+
* @apiGroup Requests
68+
*
69+
*
70+
* @apiParam {String} period [month, week, day]
71+
*
72+
* @apiSuccess {String} url Requisition url
73+
* @apiSuccess {String} count Number of requisitions in the period
74+
*
75+
* @apiExample Example usage:
76+
* curl -i https://bibleapi.co/api/requests/count/month
77+
*
78+
* @apiSuccessExample {json} Success-Response:
79+
* HTTP/1.1 200 OK
80+
* [{
81+
* "url": "/api/books/gn",
82+
* "count": "3",
83+
* }]
84+
*
85+
* @apiError TooManyRequests When performing more than 3 requests at the same endpoint in an interval less than 5 minutes
86+
*
87+
* @apiErrorExample {text} Error-Response:
88+
* HTTP/1.1 429 Too Many Requests
89+
*
90+
*
91+
*/
92+
93+
async count({ request, params }) {
94+
newRequest(request.url())
95+
const { period } = params
96+
const date = getPeriod(period)
97+
const requests = date
98+
? await Database.count()
99+
.select('url')
100+
.from('requests')
101+
.where('created_at', '>', date)
102+
.groupBy('url')
103+
.orderBy('count', 'desc')
104+
: await Database.count()
105+
.select('url')
106+
.from('requests')
107+
.groupBy('url')
108+
.orderBy('count', 'desc')
109+
return requests
110+
}
111+
}
112+
113+
module.exports = RequestController

app/Controllers/Http/SearchController.js

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
const Book = use('App/Models/Book')
44
const Verse = use('App/Models/Verse')
5-
const { notFound, badRequest } = use('App/utils')
5+
const { notFound, badRequest, newRequest } = use('App/utils')
66

77
class SearchController {
88
/**
@@ -62,7 +62,8 @@ class SearchController {
6262
*
6363
*/
6464

65-
async getVerse({ params, response }) {
65+
async getVerse({ request, params, response }) {
66+
newRequest(request.url())
6667
const { chapter, number, book, version } = params
6768
const bookData = await Book.query().where('abbrev', book)
6869
if (bookData.length > 0) {
@@ -178,7 +179,8 @@ class SearchController {
178179
*
179180
*/
180181

181-
async getChapter({ params, response }) {
182+
async getChapter({ request, params, response }) {
183+
newRequest(request.url())
182184
const { chapter, book, version } = params
183185
const bookData = await Book.query().where('abbrev', book)
184186
if (bookData.length > 0) {
@@ -277,7 +279,8 @@ class SearchController {
277279
* HTTP/1.1 429 Too Many Requests
278280
*/
279281

280-
async getBooks() {
282+
async getBooks({ request }) {
283+
newRequest(request.url())
281284
const books = await Book.query()
282285
return books.map(book => ({
283286
abbrev: book.abbrev,
@@ -335,7 +338,8 @@ class SearchController {
335338
*
336339
*/
337340

338-
async getBook({ params, response }) {
341+
async getBook({ request, params, response }) {
342+
newRequest(request.url())
339343
const book = await Book.findBy('abbrev', params.book)
340344
return book
341345
? {
@@ -417,7 +421,8 @@ class SearchController {
417421
* }
418422
*/
419423

420-
async search({ response, request }) {
424+
async search({ request, response }) {
425+
newRequest(request.url())
421426
const { version, search } = request.all()
422427
if (!version || !search) {
423428
return badRequest(

app/Models/Request.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
'use strict'
2+
3+
/** @type {typeof import('@adonisjs/lucid/src/Lucid/Model')} */
4+
const Model = use('Model')
5+
6+
class Request extends Model {
7+
}
8+
9+
module.exports = Request

app/utils.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
const Request = use('App/Models/Request')
2+
13
const notFound = response => {
24
response.status(404)
35
return {
@@ -18,7 +20,17 @@ const badRequest = (response, message) => {
1820
}
1921
}
2022

23+
const newRequest = async url => {
24+
const req = { url }
25+
try {
26+
await Request.create(req)
27+
} catch (err) {
28+
console.log(err)
29+
}
30+
}
31+
2132
module.exports = {
2233
badRequest,
23-
notFound
34+
notFound,
35+
newRequest
2436
}

0 commit comments

Comments
 (0)