-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
51 changed files
with
3,050 additions
and
1,504 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 |
---|---|---|
|
@@ -26,6 +26,7 @@ | |
*.sql | ||
*.sqlite | ||
*.xml | ||
data/ | ||
|
||
# OS generated files # | ||
###################### | ||
|
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,8 +1,6 @@ | ||
const responseMessages = [ | ||
module.exports = [ | ||
{code: 200, message: 'Success'}, | ||
{code: 400, message: 'Bad Request'}, | ||
{code: 404, message: 'Not Found'}, | ||
{code: 500, message: 'Internal Server Error'} | ||
]; | ||
|
||
module.exports = responseMessages; | ||
]; |
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 |
---|---|---|
@@ -1,3 +1,40 @@ | ||
const Utils = require('../utils.js'); | ||
// api v1 | ||
const Utils = require('../utils'); | ||
const Schema = require('../schema.js'); | ||
const ResponseMessages = require('../../responseMessages') | ||
|
||
module.exports = Utils.facets('authors'); | ||
module.exports = { | ||
plugin: { | ||
name: 'authors', | ||
register: async function(server, options) { | ||
|
||
server.route([ | ||
{ | ||
path: '/authors/{term?}', | ||
method: 'GET', | ||
config: { | ||
description: 'retrieve all authors starting with the provided letters', | ||
tags: ['authors', 'api'], | ||
plugins: { | ||
'hapi-swagger': { | ||
order: 6, | ||
responseMessages: ResponseMessages | ||
} | ||
}, | ||
validate: Schema.authors, | ||
notes: [ | ||
'This route fetches authors starting with the provided letters.' | ||
] | ||
}, | ||
handler: async function(request, h) { | ||
|
||
if (request.params.term) { | ||
return Utils.find(request.params.term, 'authors'); | ||
} | ||
|
||
} | ||
} | ||
]); | ||
}, | ||
}, | ||
}; |
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,54 +1,64 @@ | ||
const Wreck = require('wreck'); | ||
const Config = require('../../../config.js'); | ||
const ResponseMessages = require('../../response-messages'); | ||
const Utils = require('../utils.js'); | ||
const Cache = Utils.cache('root'); | ||
|
||
const uri = Config.uri + 'communities/biosyslit'; | ||
const cacheKey = Utils.createCacheKey(uri); | ||
|
||
const biosyslit = { | ||
const ResponseMessages = require('../../responseMessages'); | ||
const Utils = require('../utils.js'); | ||
const Cache = Utils.cache('root') | ||
|
||
method: 'GET', | ||
path: '/', | ||
const getResult = async function(uri, cacheKey) { | ||
|
||
handler: async function(request, h) { | ||
const { res, payload } = await Wreck.get(uri); | ||
|
||
let result = Cache.getSync(cacheKey); | ||
if (result) { | ||
if (payload) { | ||
|
||
return result; | ||
} | ||
else { | ||
|
||
const { res, payload } = await Wreck.get(uri); | ||
if (payload) { | ||
|
||
result = JSON.parse(payload); | ||
Cache.putSync(cacheKey, result); | ||
return result; | ||
} | ||
else { | ||
|
||
return Utils.errorMsg; | ||
} | ||
let result = JSON.parse(payload); | ||
if (Cache.getSync(cacheKey)) { | ||
Cache.deleteSync(cacheKey) | ||
} | ||
}, | ||
|
||
config: { | ||
description: "The API root of the 'biosyslit' community at Zenodo", | ||
tags: ['biosyslit', 'communities', 'api'], | ||
plugins: { | ||
'hapi-swagger': { | ||
order: 1, | ||
responseMessages: ResponseMessages | ||
} | ||
}, | ||
validate: {}, | ||
notes: [ | ||
'A community to share publications related to bio-systematics. The goal is to provide open access to publications cited in publications or in combination with scientific names a digital object identifier (DOI) to enable citation of the publications including direct access to its digital representation. For additional search functionality can be used. This includes also searches in CrossRef, DataCite, PubMed, RefBank, GNUB and Mendeley.', | ||
] | ||
Cache.putSync(cacheKey, result) | ||
return result; | ||
} | ||
else { | ||
|
||
return Utils.errorMsg; | ||
} | ||
|
||
}; | ||
|
||
module.exports = biosyslit; | ||
module.exports = { | ||
plugin: { | ||
name: 'biosyslit', | ||
register: async function(server, options) { | ||
|
||
server.route([{ | ||
path: '/', | ||
method: 'GET', | ||
config: { | ||
description: "The API root of the 'biosyslit' community at Zenodo", | ||
tags: ['biosyslit', 'communities', 'api'], | ||
plugins: { | ||
'hapi-swagger': { | ||
order: 1, | ||
responseMessages: ResponseMessages | ||
} | ||
}, | ||
validate: {}, | ||
notes: [ | ||
'A community to share publications related to bio-systematics. The goal is to provide open access to publications cited in publications or in combination with scientific names a digital object identifier (DOI) to enable citation of the publications including direct access to its digital representation. For additional search functionality can be used. This includes also searches in CrossRef, DataCite, PubMed, RefBank, GNUB and Mendeley.', | ||
] | ||
}, | ||
handler: async function(request, h) { | ||
|
||
const [ cacheKey, uri ] = Utils.makeUriAndCacheKey(request, '/') | ||
|
||
if (request.query.refreshCache) { | ||
return getResult(uri, cacheKey) | ||
} | ||
else { | ||
return (Cache.getSync(cacheKey) || getResult(uri, cacheKey)) | ||
} | ||
|
||
} | ||
}]); | ||
}, | ||
}, | ||
}; |
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,3 +1,39 @@ | ||
const Utils = require('../utils.js'); | ||
const Utils = require('../utils'); | ||
const Schema = require('../schema.js'); | ||
const ResponseMessages = require('../../responseMessages') | ||
|
||
module.exports = Utils.facets('families'); | ||
module.exports = { | ||
plugin: { | ||
name: 'families', | ||
register: async function(server, options) { | ||
|
||
server.route([ | ||
{ | ||
path: '/families/{term?}', | ||
method: 'GET', | ||
config: { | ||
description: 'retrieve all families starting with the provided letters', | ||
tags: ['families', 'api'], | ||
plugins: { | ||
'hapi-swagger': { | ||
order: 7, | ||
responseMessages: ResponseMessages | ||
} | ||
}, | ||
validate: Schema.families, | ||
notes: [ | ||
'This route fetches the families starting with the provided letters.' | ||
] | ||
}, | ||
handler: async function(request, h) { | ||
|
||
if (request.params.term) { | ||
return Utils.find(request.params.term, 'families'); | ||
} | ||
|
||
} | ||
} | ||
]); | ||
}, | ||
}, | ||
}; |
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,93 +1,65 @@ | ||
const Wreck = require('wreck'); | ||
const Schema = require('../schema.js'); | ||
const Config = require('../../../config.js'); | ||
const ResponseMessages = require('../../response-messages'); | ||
|
||
const ResponseMessages = require('../../responseMessages'); | ||
const Utils = require('../utils.js'); | ||
const Cache = Utils.cache('files'); | ||
const Cache = Utils.cache('files') | ||
|
||
const getResult = async function(uri) { | ||
const getResult = async function(uri, cacheKey) { | ||
|
||
const { res, payload } = await Wreck.get(uri); | ||
const result = JSON.parse(payload); | ||
return result; | ||
}; | ||
|
||
const files = { | ||
if (payload) { | ||
|
||
method: 'GET', | ||
path: '/files/{file_id}', | ||
|
||
handler: function(request, h) { | ||
let result = JSON.parse(payload); | ||
if (Cache.getSync(cacheKey)) { | ||
Cache.deleteSync(cacheKey) | ||
} | ||
Cache.putSync(cacheKey, result) | ||
return result; | ||
} | ||
else { | ||
|
||
return Utils.errorMsg; | ||
} | ||
|
||
// construct the URI | ||
const uri = Config.uri + 'files/' + encodeURIComponent(request.params.file_id); | ||
}; | ||
|
||
// construct the cacheKey | ||
const cacheKey = Utils.createCacheKey(uri); | ||
module.exports = { | ||
plugin: { | ||
name: 'files', | ||
register: async function(server, options) { | ||
|
||
let result; | ||
if (request.query.refreshCache) { | ||
server.route([{ | ||
path: '/files/{file_id}', | ||
method: 'GET', | ||
config: { | ||
description: "fetch files from Zenodo", | ||
tags: ['file', 'api'], | ||
plugins: { | ||
'hapi-swagger': { | ||
order: 4, | ||
responseMessages: ResponseMessages | ||
} | ||
}, | ||
validate: Schema.files, | ||
notes: [ | ||
'Files inside Zenodo records', | ||
] | ||
}, | ||
handler: async function(request, h) { | ||
|
||
result = getResult(uri) | ||
if (result) { | ||
|
||
// getResult succeeded | ||
utils.updateCache(Cache, cacheKey, result); | ||
return result; | ||
} | ||
else { | ||
|
||
// getResult failed, so check if result | ||
// exists in cache | ||
result = Cache.getSync(cacheKey) | ||
if (result) { | ||
|
||
// return result from cache | ||
return result; | ||
} | ||
else { | ||
|
||
// no result in cache | ||
return Utils.errorMsg; | ||
} | ||
} | ||
} | ||
else { | ||
|
||
result = Cache.getSync(cacheKey); | ||
if (result) { | ||
|
||
// return result from cache | ||
return result; | ||
} | ||
else { | ||
const [ cacheKey, uri ] = Utils.makeUriAndCacheKey(request, 'files') | ||
|
||
result = getResult(uri) | ||
if (result) { | ||
updateCache(Cache, cacheKey, result); | ||
return result; | ||
} | ||
else { | ||
return Utils.errorMsg; | ||
if (request.query.refreshCache) { | ||
return getResult(uri, cacheKey) | ||
} | ||
else { | ||
return (Cache.getSync(cacheKey) || getResult(uri, cacheKey)) | ||
} | ||
|
||
} | ||
} | ||
} | ||
}, | ||
|
||
config: { | ||
description: "fetch files from Zenodo", | ||
tags: ['file', 'api'], | ||
plugins: { | ||
'hapi-swagger': { | ||
order: 4, | ||
responseMessages: ResponseMessages | ||
} | ||
}]); | ||
}, | ||
validate: Schema.files, | ||
notes: [ | ||
'Files inside Zenodo records', | ||
] | ||
}, | ||
}; | ||
|
||
module.exports = files; | ||
}; |
Oops, something went wrong.