Skip to content

Instantly share code, notes, and snippets.

@KushalP
Created December 28, 2011 22:22
Show Gist options
  • Save KushalP/1530108 to your computer and use it in GitHub Desktop.
Save KushalP/1530108 to your computer and use it in GitHub Desktop.
CoffeeScript API Example
class Server
constructor: (@name = "Base Server", @host = "", @port = 80, @uri = "/") ->
parse: (json) ->
false
url: ->
@host + ":" @port + @uri
toString: ->
"#{@name} server, running on: #{@url()}"
class Hudson extends Server
# Handling our default values as we're running on Hudson.
constructor: (name = null, host = null, port = 88, uri = null)
console.log @toString
name = "Hudson" if not name?
host = "localhost" if not host?
uri = "/" if not uri?
super name, host, port, uri
# Overriding for the implementation-specific model.
parse: (json = null) ->
return false if not json?
result:
jobs = {}
$.each json.jobs, (id, job) ->
result.jobs[id] =
name: job.name
url: job.url
color: color
result
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment