Skip to content


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

more idiomatic CoffeeScript examples in the README

Trailing lines containing nothing but `)()` is *so* JavaScript...
  • Loading branch information...
commit a921239baca1f89367f4f8a07146c13c60325590 1 parent 17e2352
@michaelficarra michaelficarra authored
Showing with 19 additions and 21 deletions.
  1. +19 −21
@@ -8,29 +8,28 @@ All examples are written in [CoffeeScript](, but Octo.js
## Quick Example
-``` coffeescript
api = octo.api()
-api.get('/events').on('success', (res) ->
+do api.get('/events').on 'success', (res) ->
pubevents = res.body
`api.get` sets up a closure, so you'll need to invoke it before the request is sent.
-``` coffeescript
events = api.get('/events').perpage(50)
.on 'end', (res) ->
console.log api.limit()
console.log #1
+do events
## Using in the browser
Download both [superagent]( and octo.js and include them in the `<head>` of your document.
-``` html
<script src="superagent.js"></script>
<script src="octo.js"></script>
@@ -38,7 +37,7 @@ Download both [superagent]( and octo.j
## Using in node.js
Install using `npm`.
-``` shell
npm install octo
Require octo in your node.js script
@@ -50,8 +49,8 @@ octo = require 'octo'
## Paging
One goal of octo.js was to make paging very simple. Paging is built right into the library.
-``` coffeescript
-events = api.get('/events').on('success', (res) ->
+events = api.get('/events').on 'success', (res) ->
# the current page
@@ -60,15 +59,15 @@ events = api.get('/events').on('success', (res) ->
# requests the previous page
+do events
What if you want to start on a different page and limit the number of results per page?
# Start on page 5 only returning 10 results per page
+do api.get('/events').page(5).perpage(10)
## Events
@@ -79,16 +78,16 @@ Octo.js supports three events: `"success"`, `"error"` and `"end"`. These callba
* *`end`* - Fired at the end of every request, regarldess of status.
-events = api.get('/events')
+do api.get('/events')
.on('success', (res) -> console.log(res.body))
.on('error', (res) -> console.log(res.body))
- .on('end', (res) -> console.log(res.body))()
+ .on('end', (res) -> console.log(res.body))
## Basic Auth
``` coffeescript
api = octo.api().username('foo').password('bar')
-api.get('/user').on('success', (res) -> console.log(res.body))()
+do api.get('/user').on 'success', (res) -> console.log res.body
## OAuth2
@@ -96,7 +95,7 @@ If you've [registered your script or app](
api = octo.api().token('MY APP TOKEN')
-api.get('/user').on('success', (res) -> console.log(res.body))()
+do api.get('/user').on 'success', (res) -> console.log res.body
This will work with any registered OAuth application, but will return *unauthorized* if you've not registered your application with GitHub.
@@ -106,28 +105,27 @@ GitHub APIv3 allows you to programmatically fetch a token for use in scripts tha
api = octo.api().username('foo').password('bar')'/authorizations', {note: 'my script', scopes: ['public_repo']})
- .on('success', (res) -> console.log(res.body))()
+do'/authorizations', {note: 'my script', scopes: ['public_repo']})
+ .on 'success', (res) -> console.log res.body
## Checking Rate limits
The GitHub API has a rate limit that's returned with the headers of every request. You can easily access this info to see your limit and how many requests you have left
-api.get('/users/caged/repos').on('success', ->
+do api.get('/users/caged/repos').on 'success', ->
# Your limit per hour
console.log api.limit()
# Amount you have remaining in that hour
console.log api.remaining()
### More examples
There are some interactive examples in ./examples. You can fire up the server to play with these:
node examples.js
Examples available at http://localhost:9292
Please sign in to comment.
Something went wrong with that request. Please try again.