Module: Appboard
- Defined in:
- lib/appboard/version.rb,
lib/appboard.rb,
lib/appboard/widget.rb,
lib/appboard/rest_api.rb,
lib/appboard/bootstrap.rb,
lib/appboard/exceptions.rb,
lib/appboard/widgetpusher.rb,
lib/appboard/dashboardsetup.rb
Overview
:nodoc:
Defined Under Namespace
Modules: Bootstrap, RestAPI, Version Classes: DashboardSetup, Error, Widget, WidgetPusher
Constant Summary collapse
- @@dashboards =
{}
Class Method Summary collapse
-
.apiKey(value = nil) ⇒ Object
Define API key.
- .handle_error(e) ⇒ Object
- .log ⇒ Object
- .log=(log) ⇒ Object
-
.push(options = {}, &block) ⇒ Object
Push on dashboard all defined widgets in block.
-
.setup(options = {}, &block) ⇒ Object
Creates new or updates existing dashboard with defined widgets in block.
-
.widget(widget_name) ⇒ Object
Define a widget.
Methods included from RestAPI
default_headers, send_data, send_setup
Methods included from Bootstrap
default_settings, settings, settings=
Class Method Details
.apiKey(value = nil) ⇒ Object
Define API key
24 25 26 27 |
# File 'lib/appboard.rb', line 24 def apiKey(value = nil) @apiKey = value unless value.nil? @apiKey end |
.handle_error(e) ⇒ Object
167 168 169 170 171 172 |
# File 'lib/appboard.rb', line 167 def handle_error(e) log.error "#{e.class}: #{e.}"#, :exception => e e.backtrace.each do |line| log.error line end end |
.log ⇒ Object
174 175 176 |
# File 'lib/appboard.rb', line 174 def log @@log ||= Logger.new($stdout) end |
.log=(log) ⇒ Object
178 179 180 |
# File 'lib/appboard.rb', line 178 def log=(log) @@log = log end |
.push(options = {}, &block) ⇒ Object
Push on dashboard all defined widgets in block
appboard.push {
() {
uid "..."
data {
# Data is here
}
}
}
Options
-
:apiKey => ‘API key’
-
:logging => false
Refer to default config below for how to set these as defaults
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 |
# File 'lib/appboard.rb', line 96 def push( = {}, &block) config = settings.update() if block_given? pusher = WidgetPusher.new.instance_eval(&block) pusher..each do || dashboard = nil if .name @@dashboards.each do |name, db| dashboard = db if db.(.name) break if dashboard end if dashboard = dashboard.(.name) .uid(.uid) end end raise ArgumentError, "Widget 'uid' and 'name' are not defined" if .uid.nil? && .name.nil? apiKey = pusher.apiKey || config[:apiKey] url = "#{config[:url]}/#{config[:version]}/#{apiKey}/data/#{.uid}" send_data url, .get_data end else raise ArgumentError, "Block is expected as argument for Appboard.push()" end end |
.setup(options = {}, &block) ⇒ Object
Creates new or updates existing dashboard with defined widgets in block
appboard.setup {
dashboard('name') {
width 5
('widget 1') {
type "..."
size "..."
}
('widget 2') {
# Widget configuration is here
}
}
}
Options
-
:apiKey => ‘API key’
-
:logging => false
-
:debug => false
Refer to default config below for how to set these as defaults
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/appboard.rb', line 53 def setup( = {}, &block) config = settings.update() if block_given? ds = DashboardSetup.new.instance_eval(&block) apiKey = ds.apiKey || config[:apiKey] url = "#{config[:url]}/#{config[:version]}/#{apiKey}/setup" result = send_setup url, ds if result && config[:debug] puts "Dashboard with name '#{ds.get_dashboard.name}' has been set, and following widgets have been added:" ds.get_dashboard..each do || puts " * #{.name}, with uid '#{.uid}'" end end @@dashboards[ds.get_dashboard.name] = ds if result else raise ArgumentError, "Block is expected as argument for Appboard.setup()" end end |
.widget(widget_name) ⇒ Object
Define a widget. May be called inside push loop or separately
widget(‘name’) {
data {
# Data is here
}
}
137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 |
# File 'lib/appboard.rb', line 137 def () config = settings dashboard = nil @@dashboards.each do |name, db| dashboard = db if db.() break if dashboard end raise ArgumentError, "Widget '#{}' is not defined, to use this method setup dashboard with Appboard.setup()" if dashboard.nil? if block_given? block = Proc.new apiKey = dashboard.apiKey || config[:apiKey] uid = dashboard.().uid url = "#{config[:url]}/#{config[:version]}/#{apiKey}/data/#{uid}" = Widget.new(, &block) send_data url, .get_data else block = Proc.new {} = Widget.new(, &block) .uid(dashboard.().uid) end end |