Giter VIP home page Giter VIP logo

talker.rb's Introduction

Talker Ruby Client

A real-time Talker Ruby client.

Usage

  1. Get a Talker account at https://talkerapp.com/signup

  2. Get your Talker Token on https://myaccount.talkerapp.com/settings

  3. Serve hot and enjoy

    Talker.connect(:room => "Room name", :token => YOUR_TALKER_TOKEN) do |client| client.on_connected do client.send_message "hello!" end

    client.on_message do |user, message| puts user["name"] + ": " + message end

    trap("INT") { client.close } end

Callbacks

All arguments are optional.

on_connected(user)

Called when the user is authenticated and ready to receive events. "user" is a Hash containing your user info: {"id"=>1, "name"=>"macournoyer", "email"=>"[email protected]"}.

on_presence(users)

Called after on_connected with the list of connected users. With users being something like this:

[{"id"=>1, "name"=>"macournoyer", "email"=>"[email protected]"},
 {"id"=>2, "name"=>"gary", "email"=>"[email protected]"}]

on_message(user, message)

Called when a new message is received. user is the sender.

on_private_message(user, message)

Called when a new private message is received. user is the sender.

on_join(user)

Called when a user joins the room.

on_idle(user)

Called when a user becomes idle (closed connection without leaving).

on_back(user)

Called when a user is back from idle.

on_leave(user)

Called when a user leaves.

on_close

Called when the connection is closed.

on_error(error_message)

Called when an error is received from the Talker server.

on_event(event)

Called when any kind of event (all of the above) is received. "event" is a Hash: {"type":"event type","id":"unique ID",... event specific attributes}.

Methods

Methods of an instance of Talker class.

current_user

Info about the user currently connected, nil if not yet connected:

{"id"=>1, "name"=>"macournoyer", "email"=>"[email protected]"}

users

Array of users currently in the room. In the form:

[{"id"=>1, "name"=>"macournoyer", "email"=>"[email protected]"},
 {"id"=>2, "name"=>"gary", "email"=>"[email protected]"}]

leave

Leave the room and close the connection.

close

Close the connection without leaving the room.

send_message(message)

Send a message.

send_private_message(user_name, message)

Send a private message to user_name.

Running the specs

Howdy brave lil' one! To run the specs you'll need courage, hard work and some luck:

  1. Install from source my "special" fork of em-spec at http://github.com/macournoyer/em-spec.

  2. Edit the file spec/talker.example.yml with your info and rename it to spec/talker.yml.

  3. Run rake and everything should be green, birds should start signing and someone will make you a chocolate cake

(results may vary).

Credits & License

Released under the Ruby License, (c) Talker

Thanks to http://github.com/raggi for kicking this off.

talker.rb's People

Contributors

brianmario avatar macournoyer avatar raggi avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  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.