Class: Shove::App
- Inherits:
-
Object
- Object
- Shove::App
- Defined in:
- lib/shove/app.rb
Instance Attribute Summary collapse
-
#api_url ⇒ Object
Returns the value of attribute api_url.
-
#app_id ⇒ Object
Returns the value of attribute app_id.
-
#app_key ⇒ Object
Returns the value of attribute app_key.
-
#ws_url ⇒ Object
Returns the value of attribute ws_url.
Instance Method Summary collapse
-
#channel(name) ⇒ Object
create a channel context for acting on a channel
name
the name of the channel. -
#channel_key(channel) ⇒ Object
Generate a channel key for a client to self authorize publish and subscribe actions.
-
#client(id) ⇒ Object
create a cleint context for acting on a client
id
the id of the client. -
#connect(connect_key = nil) ⇒ Object
Connect to shove as a client in the current process
id
optional shove id to supply. -
#connect_key ⇒ Object
Generate a connect key for a client to self authorize publish and subscribe actions.
-
#hosts ⇒ Object
get a list of websocket hosts.
-
#initialize(config = {}) ⇒ App
constructor
create an API client
config
optional Confstruct &block config block Example: Shove::App.new( app_id: “myappid” app_key: “myappkey” ). -
#publish_key(channel) ⇒ Object
Generate a channel key for a client to self authorize publish and subscribe actions.
-
#request(path) ⇒ Object
Create a default request object with the base URL
path
extra path info. -
#subscribe_key(channel) ⇒ Object
Generate a channel key for a client to self authorize subscribe actions.
-
#url ⇒ Object
the base URL based on the settings.
-
#valid? ⇒ Boolean
is the app valid? do the app_id and app_key work with the remote.
Constructor Details
#initialize(config = {}) ⇒ App
create an API client config
optional Confstruct &block config block Example: Shove::App.new(
app_id: "myappid"
app_key: "myappkey"
)
14 15 16 17 18 19 20 21 22 |
# File 'lib/shove/app.rb', line 14 def initialize config={} @config = config @app_id = config[:app_id] @app_key = config[:app_key] @api_url = config[:api_url] || "https://api.shove.io" @ws_url = config[:ws_url] raise ShoveException.new("App ID required") unless @app_id end |
Instance Attribute Details
#api_url ⇒ Object
Returns the value of attribute api_url.
4 5 6 |
# File 'lib/shove/app.rb', line 4 def api_url @api_url end |
#app_id ⇒ Object
Returns the value of attribute app_id.
4 5 6 |
# File 'lib/shove/app.rb', line 4 def app_id @app_id end |
#app_key ⇒ Object
Returns the value of attribute app_key.
4 5 6 |
# File 'lib/shove/app.rb', line 4 def app_key @app_key end |
#ws_url ⇒ Object
Returns the value of attribute ws_url.
4 5 6 |
# File 'lib/shove/app.rb', line 4 def ws_url @ws_url end |
Instance Method Details
#channel(name) ⇒ Object
create a channel context for acting on a channel name
the name of the channel
37 38 39 |
# File 'lib/shove/app.rb', line 37 def channel name Http::ChannelContext.new(self, name) end |
#channel_key(channel) ⇒ Object
Generate a channel key for a client to self authorize publish and subscribe actions. channel
the name of the channel
61 62 63 |
# File 'lib/shove/app.rb', line 61 def channel_key channel Digest::SHA1.hexdigest "#{@app_key}-#{channel}!" end |
#client(id) ⇒ Object
create a cleint context for acting on a client id
the id of the client
43 44 45 |
# File 'lib/shove/app.rb', line 43 def client id Http::ClientContext.new(self, id) end |
#connect(connect_key = nil) ⇒ Object
Connect to shove as a client in the current process id
optional shove id to supply
90 91 92 93 94 |
# File 'lib/shove/app.rb', line 90 def connect connect_key=nil client = Client::Connection.new(self) client.connect connect_key client end |
#connect_key ⇒ Object
Generate a connect key for a client to self authorize publish and subscribe actions. channel
the name of the channel
82 83 84 |
# File 'lib/shove/app.rb', line 82 def connect_key Digest::SHA1.hexdigest "#{@app_key}-connect" end |
#hosts ⇒ Object
get a list of websocket hosts
31 32 33 |
# File 'lib/shove/app.rb', line 31 def hosts @hosts ||= request("hosts").exec_sync(:get).parse end |
#publish_key(channel) ⇒ Object
Generate a channel key for a client to self authorize publish and subscribe actions. channel
the name of the channel
68 69 70 |
# File 'lib/shove/app.rb', line 68 def publish_key channel channel_key channel end |
#request(path) ⇒ Object
Create a default request object with the base URL path
extra path info
54 55 56 |
# File 'lib/shove/app.rb', line 54 def request path Http::Request.new("#{url}/#{path}", self) end |
#subscribe_key(channel) ⇒ Object
Generate a channel key for a client to self authorize subscribe actions. channel
the name of the channel
75 76 77 |
# File 'lib/shove/app.rb', line 75 def subscribe_key channel Digest::SHA1.hexdigest "#{@app_key}-#{channel}" end |
#url ⇒ Object
the base URL based on the settings
48 49 50 |
# File 'lib/shove/app.rb', line 48 def url "#{@api_url}/apps/#{@app_id}" end |
#valid? ⇒ Boolean
is the app valid? do the app_id and app_key work with the remote
26 27 28 |
# File 'lib/shove/app.rb', line 26 def valid? !request("validate").exec_sync(:get).error? end |