summaryrefslogtreecommitdiffstats
path: root/vendor/github.com/mrexodia/wray
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/github.com/mrexodia/wray')
-rw-r--r--vendor/github.com/mrexodia/wray/README.markdown113
-rw-r--r--vendor/github.com/mrexodia/wray/go_faye.go140
-rw-r--r--vendor/github.com/mrexodia/wray/http_transport.go55
-rw-r--r--vendor/github.com/mrexodia/wray/response.go61
-rw-r--r--vendor/github.com/mrexodia/wray/schedular.go22
-rw-r--r--vendor/github.com/mrexodia/wray/transport.go21
-rw-r--r--vendor/github.com/mrexodia/wray/utils.go10
7 files changed, 0 insertions, 422 deletions
diff --git a/vendor/github.com/mrexodia/wray/README.markdown b/vendor/github.com/mrexodia/wray/README.markdown
deleted file mode 100644
index 64c1e833..00000000
--- a/vendor/github.com/mrexodia/wray/README.markdown
+++ /dev/null
@@ -1,113 +0,0 @@
-# Wray, faye client for Go
-
-Wray is a client for the [Faye](http://faye.jcoglan.com) publish-subscribe messaging service by [James Coglan](https://twitter.com/jcoglan).
-
-## Current status
-
-In progress.
-
-## Getting Started
-
-Wray is only a client for Faye. You will need to setup a server using Ruby or Node.js first. Instructions that can be found on the [Faye project pages](http://faye.jcoglan.com/).
-
-###Subscribing to channels
-
-```
-package main
-
-import "github.com/pythonandchips/wray"
-import "fmt"
-
-func main() {
- //register the types of transport you want available. Only long-polling is currently supported
- wray.RegisterTransports([]gofaye.Transport{ &gofaye.HttpTransport{} })
-
- //create a new client
- client := wray.NewFayeClient("http://localhost:5000/faye")
-
- //subscribe to the channels you want to listen to
- client.Subscribe("/foo", false, func(message wray.Message) {
- fmt.Println("-------------------------------------------")
- fmt.Println(message.Data)
- })
-
- //wildcards can be used to subscribe to multipule channels
- client.Subscribe("/foo/*", false, func(message wray.Message) {
- fmt.Println("-------------------------------------------")
- fmt.Println(message.Data)
- })
-
- //start listening on all subscribed channels and hold the process open
- client.Listen()
-}
-```
-
-###Publishing to channels
-```
-package main
-
-import "github.com/pythonandchips/wray"
-import "fmt"
-
-func main() {
- //register the types of transport you want available. Only long-polling is currently supported
- wray.RegisterTransports([]wray.Transport{ &gofaye.HttpTransport{} })
-
- //create a new client
- client := wray.NewFayeClient("http://localhost:5000/faye")
-
- params := map[string]interface{}{"hello": "from golang"}
-
- //send message to server
- client.Publish("/foo", params)
-}
-```
-
-Simple examples are availabe in the examples folder.
-
-##Future Work
-There is still a lot to do to bring Wray in line with Faye functionality. This is a less than exhaustive list of work to be completed:-
-
-- web socket support
-- eventsource support
-- logging
-- middleware additions
-- correctly handle disconnect and server down
-- promises for subscription and publishing
-- automated integrations test to ensure Wray continues to work with Faye
-
-## Bugs/Features/Prase
-
-It you find any bugs or have some feature requests please add an issue on the repository. Or if you just want to get in touch and tell me how awesome wray is you can get me on twitter @colin_gemmell or drop me an email at pythonandchips{at}gmail.com.
-
-## Contributing to Wray
-
-* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
-* Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
-* Fork the project
-* Start a feature/bugfix branch
-* Commit and push until you are happy with your contribution
-* Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
-
-## Copyright
-
-Copyright (c) 2014 Colin Gemmell
-
-Permission is hereby granted, free of charge, to any person obtaining
-a copy of this software and associated documentation files (the
-"Software"), to deal in the Software without restriction, including
-without limitation the rights to use, copy, modify, merge, publish,
-distribute, sublicense, and/or sell copies of the Software, and to
-permit persons to whom the Software is furnished to do so, subject to
-the following conditions:
-
-The above copyright notice and this permission notice shall be
-included in all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
-LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
-OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
-WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
diff --git a/vendor/github.com/mrexodia/wray/go_faye.go b/vendor/github.com/mrexodia/wray/go_faye.go
deleted file mode 100644
index ab78eed7..00000000
--- a/vendor/github.com/mrexodia/wray/go_faye.go
+++ /dev/null
@@ -1,140 +0,0 @@
-package wray
-
-import (
- "fmt"
- "path/filepath"
- "strings"
- "time"
-)
-
-const (
- UNCONNECTED = 1
- CONNECTING = 2
- CONNECTED = 3
- DISCONNECTED = 4
-
- HANDSHAKE = "handshake"
- RETRY = "retry"
- NONE = "none"
-
- CONNECTION_TIMEOUT = 60.0
- DEFAULT_RETRY = 5.0
- MAX_REQUEST_SIZE = 2048
-)
-
-var (
- MANDATORY_CONNECTION_TYPES = []string{"long-polling"}
- registeredTransports = []Transport{}
-)
-
-type FayeClient struct {
- state int
- url string
- subscriptions []Subscription
- transport Transport
- clientId string
- schedular Schedular
-}
-
-type Subscription struct {
- channel string
- callback func(Message)
-}
-
-type SubscriptionPromise struct {
- subscription Subscription
-}
-
-func NewFayeClient(url string) *FayeClient {
- schedular := ChannelSchedular{}
- client := &FayeClient{url: url, state: UNCONNECTED, schedular: schedular}
- return client
-}
-
-func (self *FayeClient) handshake() {
- t, err := SelectTransport(self, MANDATORY_CONNECTION_TYPES, []string{})
- if err != nil {
- panic("No usable transports available")
- }
- self.transport = t
- self.transport.setUrl(self.url)
- self.state = CONNECTING
- handshakeParams := map[string]interface{}{"channel": "/meta/handshake",
- "version": "1.0",
- "supportedConnectionTypes": []string{"long-polling"}}
- response, err := self.transport.send(handshakeParams)
- if err != nil {
- fmt.Println("Handshake failed. Retry in 10 seconds")
- self.state = UNCONNECTED
- self.schedular.wait(10*time.Second, func() {
- fmt.Println("retying handshake")
- self.handshake()
- })
- return
- }
- self.clientId = response.clientId
- self.state = CONNECTED
- self.transport, err = SelectTransport(self, response.supportedConnectionTypes, []string{})
- if err != nil {
- panic("Server does not support any available transports. Supported transports: " + strings.Join(response.supportedConnectionTypes, ","))
- }
-}
-
-func (self *FayeClient) Subscribe(channel string, force bool, callback func(Message)) SubscriptionPromise {
- if self.state == UNCONNECTED {
- self.handshake()
- }
- subscriptionParams := map[string]interface{}{"channel": "/meta/subscribe", "clientId": self.clientId, "subscription": channel, "id": "1"}
- subscription := Subscription{channel: channel, callback: callback}
- //TODO: deal with subscription failures
- self.transport.send(subscriptionParams)
- self.subscriptions = append(self.subscriptions, subscription)
- return SubscriptionPromise{subscription}
-}
-
-func (self *FayeClient) handleResponse(response Response) {
- for _, message := range response.messages {
- for _, subscription := range self.subscriptions {
- matched, _ := filepath.Match(subscription.channel, message.Channel)
- if matched {
- go subscription.callback(message)
- }
- }
- }
-}
-
-func (self *FayeClient) connect() {
- connectParams := map[string]interface{}{"channel": "/meta/connect", "clientId": self.clientId, "connectionType": self.transport.connectionType()}
- responseChannel := make(chan Response)
- go func() {
- response, _ := self.transport.send(connectParams)
- responseChannel <- response
- }()
- self.listen(responseChannel)
-}
-
-func (self *FayeClient) listen(responseChannel chan Response) {
- response := <-responseChannel
- if response.successful == true {
- go self.handleResponse(response)
- } else {
- }
-}
-
-func (self *FayeClient) Listen() {
- for {
- self.connect()
- }
-}
-
-func (self *FayeClient) Publish(channel string, data map[string]interface{}) {
- if self.state != CONNECTED {
- self.handshake()
- }
- publishParams := map[string]interface{}{"channel": channel, "data": data, "clientId": self.clientId}
- self.transport.send(publishParams)
-}
-
-func RegisterTransports(transports []Transport) {
- registeredTransports = transports
-}
diff --git a/vendor/github.com/mrexodia/wray/http_transport.go b/vendor/github.com/mrexodia/wray/http_transport.go
deleted file mode 100644
index f9465832..00000000
--- a/vendor/github.com/mrexodia/wray/http_transport.go
+++ /dev/null
@@ -1,55 +0,0 @@
-package wray
-
-import (
- "bytes"
- "encoding/json"
- "errors"
- "io/ioutil"
- "net/http"
- "net/url"
-)
-
-type HttpTransport struct {
- url string
- SendHook func(data map[string]interface{})
-}
-
-func (self HttpTransport) isUsable(clientUrl string) bool {
- parsedUrl, err := url.Parse(clientUrl)
- if err != nil {
- return false
- }
- if parsedUrl.Scheme == "http" || parsedUrl.Scheme == "https" {
- return true
- }
- return false
-}
-
-func (self HttpTransport) connectionType() string {
- return "long-polling"
-}
-
-func (self HttpTransport) send(data map[string]interface{}) (Response, error) {
- if self.SendHook != nil {
- self.SendHook(data)
- }
- dataBytes, _ := json.Marshal(data)
- buffer := bytes.NewBuffer(dataBytes)
- responseData, err := http.Post(self.url, "application/json", buffer)
- if err != nil {
- return Response{}, err
- }
- if responseData.StatusCode != 200 {
- return Response{}, errors.New(responseData.Status)
- }
- readData, _ := ioutil.ReadAll(responseData.Body)
- responseData.Body.Close()
- var jsonData []interface{}
- json.Unmarshal(readData, &jsonData)
- response := newResponse(jsonData)
- return response, nil
-}
-
-func (self *HttpTransport) setUrl(url string) {
- self.url = url
-}
diff --git a/vendor/github.com/mrexodia/wray/response.go b/vendor/github.com/mrexodia/wray/response.go
deleted file mode 100644
index e9815c3f..00000000
--- a/vendor/github.com/mrexodia/wray/response.go
+++ /dev/null
@@ -1,61 +0,0 @@
-package wray
-
-type Response struct {
- id string
- channel string
- successful bool
- clientId string
- supportedConnectionTypes []string
- messages []Message
- error error
-}
-
-type Message struct {
- Channel string
- Id string
- Data map[string]interface{}
-}
-
-func newResponse(data []interface{}) Response {
- headerData := data[0].(map[string]interface{})
- messagesData := data[1.:]
- messages := parseMessages(messagesData)
- var id string
- if headerData["id"] != nil {
- id = headerData["id"].(string)
- }
- supportedConnectionTypes := []string{}
- if headerData["supportedConnectionTypes"] != nil {
- d := headerData["supportedConnectionTypes"].([]interface{})
- for _, sct := range(d) {
- supportedConnectionTypes = append(supportedConnectionTypes, sct.(string))
- }
- }
- var clientId string
- if headerData["clientId"] != nil {
- clientId = headerData["clientId"].(string)
- }
- return Response{id: id,
- clientId: clientId,
- channel: headerData["channel"].(string),
- successful: headerData["successful"].(bool),
- messages: messages,
- supportedConnectionTypes: supportedConnectionTypes}
-}
-
-func parseMessages(data []interface{}) []Message {
- messages := []Message{}
- for _, messageData := range(data) {
- m := messageData.(map[string]interface{})
- var id string
- if m["id"] != nil {
- id = m["id"].(string)
- }
- message := Message{Channel: m["channel"].(string),
- Id: id,
- Data: m["data"].(map[string]interface{})}
- messages = append(messages, message)
- }
- return messages
-}
-
diff --git a/vendor/github.com/mrexodia/wray/schedular.go b/vendor/github.com/mrexodia/wray/schedular.go
deleted file mode 100644
index 3453fd61..00000000
--- a/vendor/github.com/mrexodia/wray/schedular.go
+++ /dev/null
@@ -1,22 +0,0 @@
-package wray
-
-import "time"
-
-type Schedular interface {
- wait(time.Duration, func())
- delay() time.Duration
-}
-
-type ChannelSchedular struct {
-}
-
-func (self ChannelSchedular) wait(delay time.Duration, callback func()) {
- go func() {
- time.Sleep(delay)
- callback()
- }()
-}
-
-func (self ChannelSchedular) delay() time.Duration {
- return (1 * time.Minute)
-}
diff --git a/vendor/github.com/mrexodia/wray/transport.go b/vendor/github.com/mrexodia/wray/transport.go
deleted file mode 100644
index 82f4d4d3..00000000
--- a/vendor/github.com/mrexodia/wray/transport.go
+++ /dev/null
@@ -1,21 +0,0 @@
-package wray
-
-import (
- "errors"
-)
-
-type Transport interface {
- isUsable(string) bool
- connectionType() string
- send(map[string]interface{}) (Response, error)
- setUrl(string)
-}
-
-func SelectTransport(client *FayeClient, transportTypes []string, disabled []string) (Transport, error) {
- for _, transport := range registeredTransports {
- if contains(transport.connectionType(), transportTypes) && transport.isUsable(client.url) {
- return transport, nil
- }
- }
- return nil, errors.New("No usable transports available")
-}
diff --git a/vendor/github.com/mrexodia/wray/utils.go b/vendor/github.com/mrexodia/wray/utils.go
deleted file mode 100644
index c587f7c6..00000000
--- a/vendor/github.com/mrexodia/wray/utils.go
+++ /dev/null
@@ -1,10 +0,0 @@
-package wray
-
-func contains(target string, slice []string) bool {
- for _, t := range(slice) {
- if t == target {
- return true
- }
- }
- return false
-}