Class: Shove::App

Inherits:
Object
  • Object
show all
Defined in:
lib/shove/app.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config = Confstruct::Configuration.new, &block) ⇒ App

create an API client config optional Confstruct &block config block Example: Shove::App.new do

app_id "myappid"
app_key "myappkey"

end



14
15
16
17
# File 'lib/shove/app.rb', line 14

def initialize config=Confstruct::Configuration.new, &block
  @config = config
  configure(&block)
end

Instance Attribute Details

#configObject

Returns the value of attribute config.



4
5
6
# File 'lib/shove/app.rb', line 4

def config
  @config
end

Instance Method Details

#channel(name) ⇒ Object

create a channel context for acting on a channel name the name of the channel



51
52
53
# File 'lib/shove/app.rb', line 51

def channel name
  Http::ChannelContext.new(self, name)
end

#client(id) ⇒ Object

create a cleint context for acting on a client id the id of the client



57
58
59
# File 'lib/shove/app.rb', line 57

def client id
  Http::ClientContext.new(self, id)
end

#configure(params = {}, &block) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/shove/app.rb', line 19

def configure params={}, &block

  @config.configure do
    api_url Shove.config.api_url || "https://api.shove.io"
  end

  if params
    @config.configure params
  end
  
  if block
    @config.configure(&block)
  end

  unless @config.app_id
    raise ShoveException.new("App ID required")
  end
end

#connect(id = nil) ⇒ Object

Connect to shove as a client in the current process id optional shove id to supply



76
77
78
79
80
# File 'lib/shove/app.rb', line 76

def connect id=nil
  client = Client::Connection.new(self, id)
  client.connect
  client
end

#hostsObject

get a list of websocket hosts



45
46
47
# File 'lib/shove/app.rb', line 45

def hosts
  request("hosts").exec_sync(:get).parse
end

#request(path) ⇒ Object

Create a default request object with the base URL path extra path info



68
69
70
# File 'lib/shove/app.rb', line 68

def request path
  Http::Request.new("#{url}/#{path}", @config)
end

#urlObject

the base URL based on the settings



62
63
64
# File 'lib/shove/app.rb', line 62

def url
  "#{@config.api_url}/apps/#{@config.app_id}"
end

#valid?Boolean

is the app valid? do the app_id and app_key work with the remote

Returns:

  • (Boolean)


40
41
42
# File 'lib/shove/app.rb', line 40

def valid?
  !request("validate").exec_sync(:get).error?
end