Created
December 28, 2011 22:22
-
-
Save KushalP/1530108 to your computer and use it in GitHub Desktop.
CoffeeScript API Example
This file contains hidden or 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 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