Skip to content

Instantly share code, notes, and snippets.

@zo0m
Last active November 21, 2015 22:07
Show Gist options
  • Save zo0m/a4f9e8852dc574654423 to your computer and use it in GitHub Desktop.
Save zo0m/a4f9e8852dc574654423 to your computer and use it in GitHub Desktop.
abstract service ACS
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
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