add github.com/stvp/flowdock to Godeps
This commit is contained in:
parent
5cab5e7e00
commit
160f45b0a6
3 changed files with 162 additions and 0 deletions
4
Godeps/Godeps.json
generated
4
Godeps/Godeps.json
generated
|
@ -174,6 +174,10 @@
|
|||
"Comment": "1.5.0-168-g2abea07",
|
||||
"Rev": "2abea075ec076abf0572d29bdb28ae7da64cfb7a"
|
||||
},
|
||||
{
|
||||
"ImportPath": "github.com/stvp/flowdock",
|
||||
"Rev": "50362abeabebf40b0f56a326d62f17e61a59302b"
|
||||
},
|
||||
{
|
||||
"ImportPath": "launchpad.net/goyaml",
|
||||
"Comment": "51",
|
||||
|
|
53
Godeps/_workspace/src/github.com/stvp/flowdock/README.md
generated
vendored
Normal file
53
Godeps/_workspace/src/github.com/stvp/flowdock/README.md
generated
vendored
Normal file
|
@ -0,0 +1,53 @@
|
|||
flowdock
|
||||
========
|
||||
|
||||
A Flowdock client for Golang. See the [Flowdock API docs][api_docs] for more
|
||||
information on the individual attributes.
|
||||
|
||||
[Go API Documentation][godocs]
|
||||
|
||||
Examples
|
||||
--------
|
||||
|
||||
You can set global defaults and use `flowdock.Inbox()` directly:
|
||||
|
||||
```go
|
||||
import (
|
||||
"github.com/stvp/flowdock"
|
||||
)
|
||||
|
||||
func main() {
|
||||
flowdock.Token = "732da505d0284d5b1d909b1a32426345"
|
||||
flowdock.Source = "My Cool App"
|
||||
flowdock.FromAddress = "cool@dudes.com"
|
||||
// See API docs for more variables
|
||||
|
||||
go flowdock.Inbox("My subject", "My content goes here.")
|
||||
}
|
||||
```
|
||||
|
||||
Or you can create a `flowdock.Client` to use different Flowdock message
|
||||
settings in the same app:
|
||||
|
||||
```go
|
||||
import (
|
||||
"github.com/stvp/flowdock"
|
||||
)
|
||||
|
||||
func main() {
|
||||
client := flowdock.Client{
|
||||
Token: "732da505d0284d5b1d909b1a32426345",
|
||||
Source: "App A",
|
||||
FromAddress: "email@stovepipestudios.com",
|
||||
FromName: "Client A",
|
||||
ReplyTo: "app_a@stovepipestudios.com",
|
||||
Tags: []string{"app_a"},
|
||||
}
|
||||
|
||||
go client.Inbox("Subject", "Content")
|
||||
}
|
||||
```
|
||||
|
||||
[api_docs]: https://www.flowdock.com/api/team-inbox
|
||||
[godocs]: http://godoc.org/github.com/stvp/flowdock
|
||||
|
105
Godeps/_workspace/src/github.com/stvp/flowdock/flowdock.go
generated
vendored
Normal file
105
Godeps/_workspace/src/github.com/stvp/flowdock/flowdock.go
generated
vendored
Normal file
|
@ -0,0 +1,105 @@
|
|||
package flowdock
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
const (
|
||||
ENDPOINT = "https://api.flowdock.com/v1/messages/team_inbox/"
|
||||
)
|
||||
|
||||
var (
|
||||
// Required default client settings
|
||||
Token = ""
|
||||
Source = ""
|
||||
FromAddress = ""
|
||||
|
||||
// Optional default client settings
|
||||
FromName = ""
|
||||
ReplyTo = ""
|
||||
Project = ""
|
||||
Link = ""
|
||||
Tags = []string{}
|
||||
)
|
||||
|
||||
type Client struct {
|
||||
// Required
|
||||
Token string
|
||||
Source string
|
||||
FromAddress string
|
||||
Subject string
|
||||
Content string
|
||||
|
||||
// Optional
|
||||
FromName string
|
||||
ReplyTo string
|
||||
Project string
|
||||
Link string
|
||||
Tags []string
|
||||
}
|
||||
|
||||
func (c *Client) Inbox(subject, content string) error {
|
||||
return send(c.Token, c.Source, c.FromAddress, subject, content, c.FromName, c.ReplyTo, c.Project, c.Link, c.Tags)
|
||||
}
|
||||
|
||||
func Inbox(subject, content string) error {
|
||||
return send(Token, Source, FromAddress, subject, content, FromName, ReplyTo, Project, Link, Tags)
|
||||
}
|
||||
|
||||
func send(token, source, fromAddress, subject, content, fromName, replyTo, project, link string, tags []string) error {
|
||||
// Required validation
|
||||
if len(token) == 0 {
|
||||
return fmt.Errorf(`"Token" is required`)
|
||||
}
|
||||
if len(source) == 0 {
|
||||
return fmt.Errorf(`"Source" is required`)
|
||||
}
|
||||
if len(fromAddress) == 0 {
|
||||
return fmt.Errorf(`"FromAddress" is required`)
|
||||
}
|
||||
if len(subject) == 0 {
|
||||
return fmt.Errorf(`"Subject" is required`)
|
||||
}
|
||||
|
||||
// Build payload
|
||||
payload := map[string]interface{}{
|
||||
"source": source,
|
||||
"from_address": fromAddress,
|
||||
"subject": subject,
|
||||
"content": content,
|
||||
}
|
||||
if len(fromName) > 0 {
|
||||
payload["from_name"] = fromName
|
||||
}
|
||||
if len(replyTo) > 0 {
|
||||
payload["reply_to"] = replyTo
|
||||
}
|
||||
if len(project) > 0 {
|
||||
payload["project"] = project
|
||||
}
|
||||
if len(link) > 0 {
|
||||
payload["link"] = link
|
||||
}
|
||||
if len(tags) > 0 {
|
||||
payload["tags"] = tags
|
||||
}
|
||||
jsonPayload, err := json.Marshal(payload)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// Send to Flowdock
|
||||
resp, err := http.Post(ENDPOINT+token, "application/json", bytes.NewReader(jsonPayload))
|
||||
defer resp.Body.Close()
|
||||
|
||||
if resp.StatusCode == 200 {
|
||||
return nil
|
||||
} else {
|
||||
bodyBytes, _ := ioutil.ReadAll(resp.Body)
|
||||
return fmt.Errorf("Unexpected response from Flowdock: %s %s", resp.Status, string(bodyBytes))
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue