Skip to content

Latest commit

 

History

21 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

digits Build Status

Library for Twitter Digits, it acts as a delegator (for more information : https://dev.twitter.com/oauth/echo).

This package requires Go +1.7

Usage

Standalone

package main

import (
	"net/http"

	"gopkg.in/bamarni/digits.v1"
)

func main() {
	identity, err := digits.Verify(
		"https://api.digits.com/1.1/sdk/account.json",
		"OAuth oauth_consumer_key=[...] oauth_*=[...]",
		nil,
	)
	// println(identity.PhoneNumber)
	// ...
}

Negroni middleware

The default handler throws a HTTP 401 response in case of authentication failure. Otherwise, user identity can be retrieved through the request context :

package main

import (
	"net/http"

	"github.com/urfave/negroni"
	"gopkg.in/bamarni/digits.v1"
)

func main() {
	mux := http.NewServeMux()
	mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
		identity := r.Context().Value(digits.Key).(*digits.Identity)
		fmt.Fprintf(w, "Can I reach you at %s?", identity.PhoneNumber)
	})

	n := negroni.Classic()
	n.Use(digits.Default())
	n.UseHandler(mux)

	http.ListenAndServe(":3000", n)
}

In dev environment, you can skip authentication to Digits API and use a static phone number instead :

digitsMiddleware := digits.New(digits.Options{
	PhoneNumber: "+33123456789",
})
n := negroni.New(digitsMiddleware)
// ...

About

Library for Twitter Digits

Resources

Stars

2 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages