landline-api

command module
v0.0.0-...-e00079b Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 24, 2015 License: AGPL-3.0 Imports: 6 Imported by: 0

README

Landline API

Open Tasks Build Status

Drop in chat for your app

This is a product being built by the Assembly community. You can help push this idea forward by visiting https://assembly.com/landline.

Development

With Docker

The easiest way to run the API locally is with Compose. First make sure Docker and Compose are installed. Then run:

docker-compose up -d
# Create postgres databases
./dc-setup
# Run database migrations
docker exec -t landlineapi_web_1 goose up
# Insert test data
docker exec -t landlineapi_web_1 go run db/test-data.go
Without Docker

If you want to run it outside Docker, make sure postgres and go version 1.4 are installed, then run

go get bitbucket.org/liamstask/goose/cmd/goose
go get github.com/codegangsta/gin
godep restore
./db/setup
./db/migrate
forego run go run db/test-data.go
gin
Testing with a client

In order to get the landline web client working with your local instance of the API, you will first need to run the test id provider located at example/identity_provider.go. The program takes in two parameters:

  1. a secret key shared between the landline API and the id provider
  2. IP address of the server to redirect a client to after authentication (default: localhost:3000)

To run it with the default redirect URL:

go run example/identity_provider.go 41fe7589256fd058b3f56bc71a56ebad3b1d6b86e027a73a02db0e3a0524f9d4

Next, from the landline-web directory, run:

cp .env.sample .env
npm start

And open a browser to http://localhost:8080 after webpack is running.

If using boot2docker:

go run example/identity_provider.go 41fe7589256fd058b3f56bc71a56ebad3b1d6b86e027a73a02db0e3a0524f9d4 $(boot2docker ip):3000

# in landline-web directory:
echo LANDLINE_API_URL=http://$(boot2docker ip):3000 > .env
npm start
Authentication flow
# Start up the test id provider
$ go run example/identity_provider.go 41fe7589256fd058b3f56bc71a56ebad3b1d6b86e027a73a02db0e3a0524f9d4

# Grab the sso endpoint with nonce from landline
$ curl -i 'localhost:3000/sessions/new?team=test-dev'
HTTP/1.1 302 Found
Location: http://localhost:8989/sso?payload=...&sig=....

# Hit the identity provider with payload landline redirect, this needs to return a user payload
$ curl -i http://localhost:8989/sso?payload=...&sig=....
HTTP/1.1 302 Found
Location: http://localhost:3000/sessions/sso?payload=...&sig=...

# hit landline with the user payload to receive a session token for the api
$ curl -i http://localhost:3000/sessions/sso?payload=...&sig=...
{"token":"..."}

# now you can make requests with your jwt token
$ curl -H "Authorization: Bearer $TOKEN" localhost:3000/rooms
{"rooms":[]}
Easily test the api using JavaScript

If you're running the example identity provider at port 8989, you can go to localhost:8989/debug. You'll find an empty page, but when you open up the javascript console in your browser of choice, you'll see that there are a bunch of handy Javascript objects and functions to help you debug your changes to the api.

Promises

The javascript on this page uses Promises. If you're not familiar with them, check out this html5rocks article on them, they're awesome.

The Session object

The session object helps you make authenticated calls to the API. You don't construct them using the new keyword, but by calling Session.create(). This function returns a promise, which will resolve to a session as soon as we've obtained a session token from the API server.

Session.create(function(sess){
    // You can use 'sess' as the session in here.
});
Session.immediate()

When you're writing scripts, it's handy to know when your session token has been obtained, and your session is ready to use. But when you're just testing stuff in the javascript console, the request will probably be completed multiple seconds before you're done typing your next command. Session.immediate allows you to treat session creation as if it's asynchronous.

sess = Session.immediate();
// You can 'immediately' start using the session object.
session.makeCall(method, path, data)

On a session object, you can call session.makeCall to make an api call. method is the HTTP request method, path is the path you'd like to request, including query parameters. If data is given, it'll be json serialized, and sent as the request body. This method returns a promise, which will resolve to the JSON parsed response text.

Session.create(function(sess){
    sess.makeCall("GET", "/rooms").then(roomsResponse){
        // use the response in here.
    }
});

boundLog

the boundLog function does exactly the same thing as console.log, but it is already bound to the console object, so you can easily pass it as a callback.

//within the javascript console:
sess = Session.immediate();
sess.makeCall("GET", "/rooms").then(boundLog);

This will log the javascript object returned by the /rooms endpoint to the console.

How Assembly Works

Assembly products are like open-source and made with contributions from the community. Assembly handles the boring stuff like hosting, support, financing, legal, etc. Once the product launches we collect the revenue and split the profits amongst the contributors.

Visit https://assembly.com to learn more.

Documentation

Overview

+build heroku

Directories

Path Synopsis
Godeps
_workspace/src/code.google.com/p/go-uuid/uuid
The uuid package generates and inspects UUIDs.
The uuid package generates and inspects UUIDs.
_workspace/src/github.com/dgrijalva/jwt-go
Package jwt is a Go implementation of JSON Web Tokens: http://self-issued.info/docs/draft-jones-json-web-token.html See README.md for more info.
Package jwt is a Go implementation of JSON Web Tokens: http://self-issued.info/docs/draft-jones-json-web-token.html See README.md for more info.
A useful example app.
_workspace/src/github.com/googollee/go-socket.io
go-socket.io is the implement of socket.io in golang.
go-socket.io is the implement of socket.io in golang.
_workspace/src/github.com/gorilla/websocket
Package websocket implements the WebSocket protocol defined in RFC 6455.
Package websocket implements the WebSocket protocol defined in RFC 6455.
_workspace/src/github.com/gorilla/websocket/examples/autobahn
Command server is a test server for the Autobahn WebSockets Test Suite.
Command server is a test server for the Autobahn WebSockets Test Suite.
_workspace/src/github.com/julienschmidt/httprouter
Package httprouter is a trie based high performance HTTP request router.
Package httprouter is a trie based high performance HTTP request router.
_workspace/src/github.com/kylelemons/go-gypsy/yaml
Gypsy is a simplified YAML parser written in Go.
Gypsy is a simplified YAML parser written in Go.
_workspace/src/github.com/lib/pq
Package pq is a pure Go Postgres driver for the database/sql package.
Package pq is a pure Go Postgres driver for the database/sql package.
_workspace/src/github.com/lib/pq/listen_example
Below you will find a self-contained Go program which uses the LISTEN / NOTIFY mechanism to avoid polling the database while waiting for more work to arrive.
Below you will find a self-contained Go program which uses the LISTEN / NOTIFY mechanism to avoid polling the database while waiting for more work to arrive.
_workspace/src/github.com/lib/pq/oid
Package oid contains OID constants as defined by the Postgres server.
Package oid contains OID constants as defined by the Postgres server.
_workspace/src/github.com/microcosm-cc/bluemonday
Package bluemonday provides a way of describing a whitelist of HTML elements and attributes as a policy, and for that policy to be applied to untrusted strings from users that may contain markup.
Package bluemonday provides a way of describing a whitelist of HTML elements and attributes as a policy, and for that policy to be applied to untrusted strings from users that may contain markup.
_workspace/src/github.com/russross/blackfriday
Blackfriday markdown processor.
Blackfriday markdown processor.
_workspace/src/github.com/shurcooL/sanitized_anchor_name
Package sanitized_anchor_name provides a func to create sanitized anchor names.
Package sanitized_anchor_name provides a func to create sanitized anchor names.
_workspace/src/github.com/ziutek/mymysql/godrv
MySQL driver for Go database/sql package
MySQL driver for Go database/sql package
_workspace/src/github.com/ziutek/mymysql/mysql
MySQL Client API written entirely in Go without any external dependences.
MySQL Client API written entirely in Go without any external dependences.
_workspace/src/github.com/ziutek/mymysql/native
Thread unsafe engine for MyMySQL
Thread unsafe engine for MyMySQL
_workspace/src/golang.org/x/net/html
Package html implements an HTML5-compliant tokenizer and parser.
Package html implements an HTML5-compliant tokenizer and parser.
_workspace/src/golang.org/x/net/html/atom
Package atom provides integer codes (also known as atoms) for a fixed set of frequently occurring HTML strings: tag names and attribute keys such as "p" and "id".
Package atom provides integer codes (also known as atoms) for a fixed set of frequently occurring HTML strings: tag names and attribute keys such as "p" and "id".
_workspace/src/golang.org/x/net/html/charset
Package charset provides common text encodings for HTML documents.
Package charset provides common text encodings for HTML documents.
_workspace/src/gopkg.in/gorp.v1
Package gorp provides a simple way to marshal Go structs to and from SQL databases.
Package gorp provides a simple way to marshal Go structs to and from SQL databases.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL