Code Monkey home page Code Monkey logo

pusher-http-go's Introduction

Pusher Go Library

##Triggering Events

client := pusher.Client{
    AppId:  app_id,
    Key:    app_key,
    Secret: app_secret,
}

data := map[string]string{"message": "hello world"}

client.Trigger("test_channel", "my_event", data)

Excluding Recipients

In place of the "" in the last example, we enter the socket_id of the connection we wish to exclude from receiving the event:

client.Trigger("test_channel", "my_event", data, "1234.5678")

##Info From All Channels

channelParams := map[string]string{
    "filter_by_prefix": "presence-",
    "info":             "user_count"}

channels, err := client.Channels(channelParams)

fmt.Printf(channels)

// => &{Channels:map[presence-chatroom:{UserCount:4} private-notifications:{UserCount:31}  ]}

##Info From One Channel

channelParams := map[string]string{
    "info": "user_count"}

channel, err := client.Channel("presence-chatroom", channelParams)

###Gettings Users From Presence Channel

users, err := client.GetChannelUsers("presence-chatroom")

Channel Authentication

Private Channels

func pusherAuth(res http.ResponseWriter, req *http.Request) {

    params, _ := ioutil.ReadAll(req.Body)
    auth := client.AuthenticateChannel(params)
    fmt.Fprintf(res, auth)

}

func main() {
    http.HandleFunc("/", root)
    http.HandleFunc("/pusher/auth", pusherAuth)

    http.ListenAndServe(":5000", nil)
}

Presence Channels

Like private channels, but one passes in user data to be associated with the member.

params, _ := ioutil.ReadAll(req.Body)

presenceData := pusher.MemberData{
    UserId: "1", 
    UserInfo: map[string]string{"twitter": "jamiepatel"}}

auth := client.AuthenticateChannel(params, presenceData)

fmt.Fprintf(res, auth)

Webhooks

body, _ := ioutil.ReadAll(req.Body)

webhook, err := client.Webhook(req.Header, body)

if err != nil {
    fmt.Println("Webhook is invalid :(")
} else {
    fmt.Printf("%+v\n", webhook)
}

Feature Support

Feature Supported
Trigger event on single channel
Trigger event on multiple channels
Limit channels Per trigger to 10
Limit channel/event name length
Validates channel names
Excluding recipients from events
Authenticating private channels
Authenticating presence channels
Get the list of channels in an application
Get the state of a single channel
Get a list of users in a presence channel
WebHook validation
Can instantiate from URL/ENV
Debugging & Logging
Cluster configuration
Timeouts
HTTPS
HTTP Proxy configuration
HTTP KeepAlive

##TODO:

  • Finish feature support
  • More thorough error-handling.
  • Asynchronous requests(?)
  • General refactoring

##Running The Tests

$ go test

pusher-http-go's People

Contributors

jpatel531 avatar zimbatm avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.