class Dimma::Session
Missing method calls are delegated to the underlying RestClient::Resource
Public Class Methods
new(key, secret = nil, options = {})
click to toggle source
Initialize the Beacon API resource; you get both your API key and secret key from beaconpush.com/account/settings.
@example
# Specify that no requests must take longer than 10 seconds. dimma = Dimma::Session.new "key", "secret", :timeout => 10
@param [#to_s] key API key. @param [nil, to_s] secret Secret key. Set to nil if you have turned off authentication. @param [Hash] options (see RestClient#initialize)
# File lib/dimma.rb, line 38 def initialize(key, secret = nil, options = {}) url = "http://api.beaconpush.com/#{Dimma::API_VERSION}/#{key.to_s}/" options[:headers] ||= {} options[:headers].merge!({"X-Beacon-Secret-Key" => secret.to_s}) unless secret.nil? __setobj__ RestClient::Resource.new(url, options) end
Public Instance Methods
channel(name = 'default')
click to toggle source
Retrieve a channel by name, bound to this Session
.
@param [#to_s] name @return (see Channel#initialize)
# File lib/dimma.rb, line 73 def channel(name = 'default') Channel.new(name, __getobj__) end
message(message)
click to toggle source
Send a message to the ‘default’ channel.
@param (see Channel#message
) @return (see Channel#message
) @see Channel#message
# File lib/dimma.rb, line 57 def message(message) channel.message(message) end
user(name)
click to toggle source
Retrieve a user by name, bound to this Session
.
@param [#to_s] name @return (see User#initialize)
# File lib/dimma.rb, line 65 def user(name) User.new(name, __getobj__) end
users()
click to toggle source
Retrieve number of online users.
@return [Fixnum]
# File lib/dimma.rb, line 48 def users JSON.parse(self['users'].get.body)["online"] end