Ably
A Ruby client library for ably.io, the real-time messaging service.
Installation
The client library is available as a gem from RubyGems.org.
Add this line to your application's Gemfile:
gem 'ably'
And then execute:
$ bundle
Or install it yourself as:
$ gem install ably
Using the Realtime API
Subscribing to a channel
Given:
client = Ably::Realtime.new(api_key: "xxxxx")
channel = client.channel("test")
Subscribe to all events:
channel.subscribe do ||
[:name] #=> "greeting"
[:data] #=> "Hello World!"
end
Only certain events:
channel.subscribe("myEvent") do ||
[:name] #=> "myEvent"
[:data] #=> "myData"
end
Publishing to a channel
client = Ably::Realtime.new(api_key: "xxxxx")
channel = client.channel("test")
channel.publish("greeting", "Hello World!")
Using the REST API
Publishing a message to a channel
client = Ably::Rest.new(api_key: "xxxxx")
channel = client.channel("test")
channel.publish("myEvent", "Hello!") #=> true
Fetching a channel's history
client = Ably::Rest.new(api_key: "xxxxx")
channel = client.channel("test")
channel.history #=> [{:name=>"test", :data=>"payload"}]
Authentication with a token
client = Ably::Rest.new(api_key: "xxxxx")
client.auth. # creates a token and will use token authentication moving forwards
client.auth.current_token #=> #<Ably::Token>
channel.publish("myEvent", "Hello!") #=> true, sent using token authentication
Fetching your application's stats
client = Ably::Rest.new(api_key: "xxxxx")
client.stats #=> [{:channels=>..., :apiRequests=>..., ...}]
Fetching the Ably service time
client = Ably::Rest.new(api_key: "xxxxx")
client.time #=> 2013-12-12 14:23:34 +0000
Contributing
- Fork it
- Create your feature branch (
git checkout -b my-new-feature) - Commit your changes (
git commit -am 'Add some feature') - Push to the branch (
git push origin my-new-feature) - Create new Pull Request