Class: Shove::Client
- Inherits:
-
Object
- Object
- Shove::Client
- Defined in:
- lib/shove/client.rb
Instance Method Summary collapse
-
#authorize(uid, channel = "*", &block) ⇒ Object
authorize a user on a private channel
uid
the users idchannel
the channel to authorize them on. -
#broadcast(channel, event, message, &block) ⇒ Object
broadcast a message
channel
the channel to broadcast onevent
the event to triggermessage
the message to send, UTF-8 encoded kthx. -
#direct(uid, event, message, &block) ⇒ Object
direct a message to a specific user
uid
the users idevent
the event to triggermessage
the message to send, UTF-8 encoded kthx. -
#initialize(network, key, opts = {}) ⇒ Client
constructor
create an API client
network
the network idkey
the api access keyopts
hash with a few options, such as: :secure true or false :host leave as default unless you are given a private cluster.
Constructor Details
#initialize(network, key, opts = {}) ⇒ Client
create an API client network
the network id key
the api access key opts
hash with a few options, such as: :secure true or false :host leave as default unless you are given a private cluster
10 11 12 13 14 15 16 |
# File 'lib/shove/client.rb', line 10 def initialize network, key, opts={} @network = network @key = key @auth_header = { "api-key" => key } @secure = opts[:secure] || false @host = opts[:host] || "api.shove.io" end |
Instance Method Details
#authorize(uid, channel = "*", &block) ⇒ Object
authorize a user on a private channel uid
the users id channel
the channel to authorize them on
37 38 39 |
# File 'lib/shove/client.rb', line 37 def uid, channel="*", &block Request.new("#{uri}/#{@network}/authorize/#{channel}/#{uid}", @auth_header).post(&block) end |
#broadcast(channel, event, message, &block) ⇒ Object
broadcast a message channel
the channel to broadcast on event
the event to trigger message
the message to send, UTF-8 encoded kthx
22 23 24 |
# File 'lib/shove/client.rb', line 22 def broadcast channel, event, , &block Request.new("#{uri}/#{@network}/broadcast/#{channel}/#{event}", @auth_header).post(, &block) end |
#direct(uid, event, message, &block) ⇒ Object
direct a message to a specific user uid
the users id event
the event to trigger message
the message to send, UTF-8 encoded kthx
30 31 32 |
# File 'lib/shove/client.rb', line 30 def direct uid, event, , &block Request.new("#{uri}/#{@network}/direct/#{event}/#{uid}", @auth_header).post(, &block) end |