Last active
November 21, 2015 22:07
-
-
Save zo0m/a4f9e8852dc574654423 to your computer and use it in GitHub Desktop.
abstract service ACS
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
class AbstractService | |
constructor: (@cloud)-> | |
defaultSearchCondition: (searchCondition = {})-> | |
searchCondition.response_json_depth or= 3 | |
searchCondition | |
buildArrowQueryString: (methodName)=> "/v1/#{@apiName}/#{methodName}.json" | |
getObjectsFromResponse: (response)=> response?.response?[@apiName] or [] | |
get: (methodName, searchCondition)=> | |
@cloud.getAsync @buildArrowQueryString(methodName), searchCondition | |
.then (response)-> | |
if response?.body?.meta?.code is 200 | |
response.body | |
else | |
error = new Error "Call to cloud was failed" | |
error.status = 500 | |
throw error | |
.then (response)=> | |
@getObjectsFromResponse(response) | |
.catch (error)-> | |
console.log "ERROR #{error}" | |
throw error | |
show: (searchCondition = @defaultSearchCondition searchCondition)=> | |
#default settings | |
@get "show", searchCondition | |
query: (searchCondition = @defaultSearchCondition searchCondition)=> | |
#default settings | |
searchCondition.isArray = yes | |
searchCondition.limit or= 250 | |
@get "query", searchCondition | |
module.exports = AbstractService |
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
AbstractService = require "./abstract" | |
class CustomObjects extends AbstractService | |
constructor: (@cloud)-> | |
@apiName = "objects" | |
buildArrowQueryString: (methodName)=> "/v1/#{@apiName}/#{@className}/#{methodName}.json" | |
getObjectsFromResponse: (response)=> | |
response?.response?[@className] or [] | |
show: (searchCondition)-> | |
searchCondition.classname or= @className | |
super(searchCondition) | |
query: (searchCondition)=> | |
searchCondition.classname or= @className | |
super(searchCondition) | |
module.exports = CustomObjects |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment