Skip to content

Commit

Permalink
Update readme file.
Browse files Browse the repository at this point in the history
  • Loading branch information
dcu committed Mar 27, 2016
1 parent 172a9f0 commit cd614fb
Showing 1 changed file with 50 additions and 25 deletions.
75 changes: 50 additions & 25 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,34 @@

A go library for using the Authy public API.

**This API is not stable yet. Use it at your own risk.**

## Installation

If you don't have `$GOPATH` configured please type the following commands:

$ export GOPATH=$HOME/GoCode
$ mkdir -p $GOPATH/src
$ echo 'export GOPATH=$HOME/GoCode' >> ~/.bashrc

```shell
$ export GOPATH=$HOME/GoCode
$ mkdir -p $GOPATH/src
$ echo 'export GOPATH=$HOME/GoCode' >> ~/.bashrc
```

If you already have `$GOPATH` configured then install the package:

$ go get github.com/dcu/go-authy
```shell
$ go get github.com/dcu/go-authy
```

## Usage

To use this client you just need to import `go-authy` package and initialize it with your API KEY

import(
"github.com/dcu/go-authy"
)
authy_api := authy.NewAuthyApi("#your_api_key")
```go
import(
"github.com/dcu/go-authy"
)
authyAPI := authy.NewAuthyAPI("#your_api_key")
```

Now that you have an Authy API object you can start sending requests.

Expand All @@ -32,7 +38,9 @@ Now that you have an Authy API object you can start sending requests.
By default, most operations and errors are logged to `stderr`. You can
access `authy.Logger` to replace the logger. Example:

authy.Logger = log.New(...)
```go
authy.Logger = log.New(...)
```

## Creating Users

Expand All @@ -41,20 +49,26 @@ A cellphone is uniquely associated with an authy_id.__

Creating users is very easy, you need to pass an email, a cellphone and a country code:

user, err := authy_api.RegisterUser("[email protected]", 44, "405-342-5699", url.Values{})
```go
user, err := authyAPI.RegisterUser("[email protected]", 44, "405-342-5699", url.Values{})
```

in this case `44` is the country code(UK), use `1` for USA or Canada.

You can easily see if the user was created by calling `user.Valid()`.
If request went right, you need to store the `authy id` in your database. Use `user.Id` to get this `id` in your database.

if user.Valid() {
# store userResponse.User.Id in your user database
}
```go
if user.Valid() {
# store userResponse.User.Id in your user database
}
```

If something goes wrong `user.Valid()` will return `false` and you can see the errors using the following code

user.Errors
```go
user.Errors
```

it returns a `map[string]string` explaining what went wrong with the request.

Expand All @@ -64,20 +78,25 @@ it returns a `map[string]string` explaining what went wrong with the request.

To verify users you need the user id and a token. The token you get from the user through your login form.

verification,err := authy_api.VerifyToken(authy-id, "token-entered-by-the-user", url.Values{"ip":{"<user ip>"}})
```go
verification, err := authyAPI.VerifyToken(authy-id, "token-entered-by-the-user", url.Values{"ip":{"<user ip>"}})
```

Once again you can use `verification.Valid` to verify whether the token was valid or not.

if verification.Valid() {
# the user is valid
}

```go
if verification.Valid() {
# the user is valid
}
```

## Requesting SMS Tokens

To request a SMS token you only need the user id.

sms,err := authy_api.RequestSms("authy-id", url.Values{})
```go
sms, err := authyAPI.RequestSMS("authy-id", url.Values{})
```

As always, you can use `sms.Valid()` to verify if the token was sent. To be able to use this method you need to have activated the SMS plugin for your Authy App.

Expand All @@ -87,7 +106,9 @@ You should force this request to ensure the user will get a token even if it's u

To request a token via Phone Call you only need the user id.

phoneCall,err := authy_api.RequestPhoneCall("authy-id", url.Values{"force":{"true"}})
```go
phoneCall, err := authyAPI.RequestPhoneCall("authy-id", url.Values{"force":{"true"}})
```

As always, you can use `phoneCall.Valid()` to verify if the token was sent. To be able to use this method you need to have activated the Phone Call plugin for your Authy App.

Expand All @@ -98,16 +119,20 @@ You should force this request to ensure the user will get a token even if it's u

Get the code:

$ go get -u github.com/dcu/go-authy
$ cd $GOPATH/src/github.com/dcu/go-authy
```shell
$ go get -u github.com/dcu/go-authy
$ cd $GOPATH/src/github.com/dcu/go-authy
```

and start coding.

### Tests

To run the test just type:

make test
```shell
make test
```

### More...

Expand Down

0 comments on commit cd614fb

Please sign in to comment.