Skip to content

bamarni/digits

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

21 Commits
 
 
 
 
 
 
 
 
 
 
 
 

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

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages