Module: UnifiGem::Client::Main

Included in:
UnifiGem::Client
Defined in:
lib/unifi_gem/client/main.rb

Instance Method Summary collapse

Instance Method Details

#add_usergroup(group_name, group_dn = -1,, group_up = -1)) ⇒ Object



231
232
233
234
235
# File 'lib/unifi_gem/client/main.rb', line 231

def add_usergroup(group_name, group_dn = -1, group_up = -1)
  body = { name: group_name, qos_rate_max_down: group_dn, qos_rate_max_up: group_up }
  response = self.class.get("/s/#{@site}/rest/usergroup", { body: body.to_json })
  response.parsed_response
end

#count_alarms(archived) ⇒ Object



280
281
282
283
# File 'lib/unifi_gem/client/main.rb', line 280

def count_alarms(archived)
  response = self.class.get("/s/#{@site}/cnt/alarm#{archived ? '' : '?archived=false'}")
  response.parsed_response
end

#create_hotspotop(name, x_password, note = '') ⇒ Object



312
313
314
315
316
317
# File 'lib/unifi_gem/client/main.rb', line 312

def create_hotspotop(name, x_password, note = '')
  body = { name: name, x_password: x_password }
  body[:note] = note if note
  response = self.class.post("/s/#{@site}/rest/hotspotop", { body: body.to_json })
  response.parsed_response
end

#delete_usergroup(group_id) ⇒ Object



226
227
228
229
# File 'lib/unifi_gem/client/main.rb', line 226

def delete_usergroup(group_id)
  response = self.class.delete("/s/#{@site}/rest/usergroup/#{group_id}")
  response.parsed_response
end

#disable_ap(ap_id, disable) ⇒ Object



306
307
308
309
310
# File 'lib/unifi_gem/client/main.rb', line 306

def disable_ap(ap_id, disable)
  body = { disabled: disable }
  response = self.class.put("/s/#{@site}/rest/device/#{ap_id}", { body: body.to_json })
  response.parsed_response
end

#edit_usergroup(group_id, site_id, group_name, group_dn = -1,, group_up = -1)) ⇒ Object



237
238
239
240
241
242
243
244
245
# File 'lib/unifi_gem/client/main.rb', line 237

def edit_usergroup(group_id, site_id, group_name, group_dn = -1, group_up = -1)
  body = { _id: group_id,
           name: group_name,
           qos_rate_max_down: group_dn,
           qos_rate_max_up: group_up,
           site_id: site_id }
  response = self.class.put("/s/#{@site}/rest/usergroup/#{group_id}", { body: body.to_json })
  response.parsed_response
end

#led_override(device_id, override_mode) ⇒ Object



296
297
298
299
300
301
302
303
304
# File 'lib/unifi_gem/client/main.rb', line 296

def led_override(device_id, override_mode)
  body = { led_override: override_mode }
  if ['off', 'on', 'default'].include?(override_mode)
    response = self.class.put("/s/#{@site}/rest/device/#{device_id}", { body: body.to_json })
    response.parsed_response
  else
    false
  end
end

#list_adminsObject



290
291
292
293
294
# File 'lib/unifi_gem/client/main.rb', line 290

def list_admins
  body = { cmd: 'get-admins' }
  response = self.class.post("/s/#{@site}/cmd/sitemgr", { body: body.to_json })
  response.parsed_response
end

#list_alarmsObject



285
286
287
288
# File 'lib/unifi_gem/client/main.rb', line 285

def list_alarms
  response = self.class.get("/s/#{@site}/list/alarm")
  response.parsed_response
end

#list_clients(mac = '') ⇒ Object



12
13
14
15
# File 'lib/unifi_gem/client/main.rb', line 12

def list_clients(mac = '')
  response = self.class.get("/s/#{@site}/stat/sta/#{mac.delete(" :")}")
  response.parsed_response
end

#list_current_channelsObject



97
98
99
100
# File 'lib/unifi_gem/client/main.rb', line 97

def list_current_channels
  response = self.class.get("/s/#{@site}/stat/current-channel")
  response.parsed_response
end

#list_dashboardObject



7
8
9
10
# File 'lib/unifi_gem/client/main.rb', line 7

def list_dashboard
  response = self.class.get("/s/#{@site}/stat/dashboard")
  response.parsed_response
end

#list_devices(mac = '') ⇒ Object



22
23
24
25
# File 'lib/unifi_gem/client/main.rb', line 22

def list_devices(mac = '')
  response = self.class.get("/s/#{@site}/stat/device/#{mac.delete(" :")}")
  response.parsed_response
end

#list_dpi_statsObject



102
103
104
105
# File 'lib/unifi_gem/client/main.rb', line 102

def list_dpi_stats
  response = self.class.get("/s/#{@site}/stat/dpi")
  response.parsed_response
end

#list_dynamicdnsObject



27
28
29
30
# File 'lib/unifi_gem/client/main.rb', line 27

def list_dynamicdns
  response = self.class.get("/s/#{@site}/list/dynamicdns")
  response.parsed_response
end

#list_events(options = {}) ⇒ Object



32
33
34
35
36
37
38
39
# File 'lib/unifi_gem/client/main.rb', line 32

def list_events(options = {})
  body = { _sort: '-time', }
  body[:within] = options[:historyhours] || 720
  body[:_start] = options[:start] || 0
  body[:_limit] = options[:limit] || 3000
  response = self.class.get("/s/#{@site}/stat/event", { body: body.to_json })
  response.parsed_response
end

#list_extensionObject



41
42
43
44
# File 'lib/unifi_gem/client/main.rb', line 41

def list_extension
  response = self.class.get("/s/#{@site}/list/extension")
  response.parsed_response
end

#list_healthObject



46
47
48
49
# File 'lib/unifi_gem/client/main.rb', line 46

def list_health
  response = self.class.get("/s/#{@site}/stat/health")
  response.parsed_response
end

#list_hotspotopObject



51
52
53
54
# File 'lib/unifi_gem/client/main.rb', line 51

def list_hotspotop
  response = self.class.get("/s/#{@site}/list/hotspotop")
  response.parsed_response
end

#list_networkconfObject



56
57
58
59
# File 'lib/unifi_gem/client/main.rb', line 56

def list_networkconf
  response = self.class.get("/s/#{@site}/list/networkconf")
  response.parsed_response
end

#list_portconfObject



61
62
63
64
# File 'lib/unifi_gem/client/main.rb', line 61

def list_portconf
  response = self.class.get("/s/#{@site}/list/portconf")
  response.parsed_response
end

#list_portforward_statsObject



66
67
68
69
# File 'lib/unifi_gem/client/main.rb', line 66

def list_portforward_stats
  response = self.class.get("/s/#{@site}/stat/portforward")
  response.parsed_response
end

#list_rogueaps(within = 24) ⇒ Object



71
72
73
74
75
# File 'lib/unifi_gem/client/main.rb', line 71

def list_rogueaps(within = 24)
  body = { within: within }
  response = self.class.get("/s/#{@site}/stat/rogueap", { body: body.to_json })
  response.parsed_response
end

#list_selfObject



77
78
79
80
# File 'lib/unifi_gem/client/main.rb', line 77

def list_self
  response = self.class.get("/s/#{@site}/self")
  response.parsed_response
end

#list_settingsObject



82
83
84
85
# File 'lib/unifi_gem/client/main.rb', line 82

def list_settings
  response = self.class.get("/s/#{@site}/get/setting")
  response.parsed_response
end

#list_usergroupsObject



87
88
89
90
# File 'lib/unifi_gem/client/main.rb', line 87

def list_usergroups
  response = self.class.get("/s/#{@site}/list/usergroup")
  response.parsed_response
end

#list_usersObject



92
93
94
95
# File 'lib/unifi_gem/client/main.rb', line 92

def list_users
  response = self.class.get("/s/#{@site}/list/user")
  response.parsed_response
end

#locate_ap(mac, enable) ⇒ Object



266
267
268
269
270
# File 'lib/unifi_gem/client/main.rb', line 266

def locate_ap(mac, enable)
  body = { cmd: enable ? 'set-locate' : 'unset-locate', mac: mac.downcase }
  response = self.class.get("/s/#{@site}/cmd/devmgr", { body: body.to_json })
  response.parsed_response
end

#reconnect_sta(mac) ⇒ Object



107
108
109
110
111
# File 'lib/unifi_gem/client/main.rb', line 107

def reconnect_sta(mac)
  body = { cmd: 'kick-sta', mac: mac.downcase }
  response = self.class.post("/s/#{@site}/cmd/stamgr", { body: body.to_json })
  response.parsed_response
end

#rename_ap(ap_id, apname) ⇒ Object



113
114
115
116
117
# File 'lib/unifi_gem/client/main.rb', line 113

def rename_ap(ap_id, apname)
  body = { name: apname }
  response = self.class.get("/s/#{@site}/upd/device/#{ap_id.delete(" ")}", { body: body.to_json })
  response.parsed_response
end

#restart_ap(mac) ⇒ Object



119
120
121
122
123
# File 'lib/unifi_gem/client/main.rb', line 119

def restart_ap(mac)
  body = { cmd: 'restart', mac: mac.downcase }
  response = self.class.get("/s/#{@site}/cmd/devmgr", { body: body.to_json })
  response.parsed_response
end

#set_ap_radiosettings(ap_id, radio, channel, ht, tx_power_mode, tx_power) ⇒ Object



272
273
274
275
276
277
278
# File 'lib/unifi_gem/client/main.rb', line 272

def set_ap_radiosettings(ap_id, radio, channel, ht, tx_power_mode, tx_power)
  body = { radio_table: { radio: radio,
                          channel: channel,
                          ht: ht,
                          tx_power_mode: tx_power_mode,
                          tx_power: tx_power } }
end

#set_sta_name(user_id, name = '') ⇒ Object



260
261
262
263
264
# File 'lib/unifi_gem/client/main.rb', line 260

def set_sta_name(user_id, name = '')
  body = { name: name }
  response = self.class.get("/s/#{@site}/upd/user/#{user_id}", { body: body.to_json })
  response.parsed_response
end

#set_sta_note(user_id, note = nil) ⇒ Object



253
254
255
256
257
258
# File 'lib/unifi_gem/client/main.rb', line 253

def set_sta_note(user_id, note = nil)
  body = { noted: note ? true : false }
  body[:note] = note if note
  response = self.class.get("/s/#{@site}/upd/user/#{user_id}", { body: body.to_json })
  response.parsed_response
end

#set_usergroup(user_id, group_id) ⇒ Object



247
248
249
250
251
# File 'lib/unifi_gem/client/main.rb', line 247

def set_usergroup(user_id, group_id)
  body = { usergroup_id: group_id }
  response = self.class.get("/s/#{@site}/upd/user/#{user_id}", { body: body.to_json })
  response.parsed_response
end

#site_leds(enable) ⇒ Object



220
221
222
223
224
# File 'lib/unifi_gem/client/main.rb', line 220

def site_leds(enable)
  body = { led_enabled: enable }
  response = self.class.post("/s/#{@site}/set/setting/mgmt", { body: body.to_json })
  response.parsed_response
end

#spectrum_scan(mac) ⇒ Object



202
203
204
205
206
# File 'lib/unifi_gem/client/main.rb', line 202

def spectrum_scan(mac)
  body = { cmd: 'spectrum-scan', mac: mac }
  response = self.class.post("/s/#{@site}/cmd/devmgr", { body: body.to_json })
  response.parsed_response
end

#spectrum_scan_state(mac) ⇒ Object



197
198
199
200
# File 'lib/unifi_gem/client/main.rb', line 197

def spectrum_scan_state(mac)
  response = self.class.get("/s/#{@site}/stat/spectrum-scan/#{mac.delete(': ')}")
  response.parsed_response
end

#stat_allusers(historyhours = 8760) ⇒ Object



191
192
193
194
195
# File 'lib/unifi_gem/client/main.rb', line 191

def stat_allusers(historyhours = 8760)
  body = { type: 'all', conn: 'all', within: historyhours}
  response = self.class.get("/s/#{@site}/stat/alluser", { body: body.to_json })
  response.parsed_response
end

#stat_auths(start_time = nil, end_time = Time.now.to_i) ⇒ Object



184
185
186
187
188
189
# File 'lib/unifi_gem/client/main.rb', line 184

def stat_auths(start_time = nil, end_time = Time.now.to_i)
  body = { start: start_time ? start_time : end_time - (7 * 24 * 3600),
           end: end_time }
  response = self.class.get("/s/#{@site}/stat/authorization", { body: body.to_json })
  response.parsed_response
end

#stat_client(mac = '') ⇒ Object



17
18
19
20
# File 'lib/unifi_gem/client/main.rb', line 17

def stat_client(mac = '')
  response = self.class.get("/s/#{@site}/stat/user/#{mac.delete(" :")}")
  response.parsed_response
end

#stat_daily_aps(start_time = nil, end_time = Time.now.to_i * 1000) ⇒ Object



161
162
163
164
165
166
167
# File 'lib/unifi_gem/client/main.rb', line 161

def stat_daily_aps(start_time = nil, end_time = Time.now.to_i * 1000)
  body = { start: start_time ? start_time : end_time - (7 * 24 * 3600 * 1000),
           end: end_time,
           attrs: ['bytes', 'num_sta', 'time'] }
  response = self.class.get("/s/#{@site}/stat/report/daily.ap", { body: body.to_json })
  response.parsed_response
end

#stat_daily_site(start_time = nil, end_time = Time.now.to_i - (Time.now.to_i % 3600) * 1000) ⇒ Object



169
170
171
172
173
174
175
176
177
178
179
180
181
182
# File 'lib/unifi_gem/client/main.rb', line 169

def stat_daily_site(start_time = nil, end_time = Time.now.to_i - (Time.now.to_i % 3600) * 1000)
  body = { start: start_time ? start_time : end_time - (52 * 7 * 24 * 3600 * 1000),
           end: end_time,
           attributes: ['bytes',
                        'wan-tx_bytes',
                        'wan-rx_bytes',
                        'wlan_bytes',
                        'num_sta',
                        'lan-num_sta',
                        'wlan-num_sta',
                        'time'] }
  response = self.class.get("/s/#{@site}/stat/report/daily.site", { body: body.to_json })
  response.parsed_response
end

#stat_hourly_aps(start_time = nil, end_time = Time.now.to_i * 1000) ⇒ Object



153
154
155
156
157
158
159
# File 'lib/unifi_gem/client/main.rb', line 153

def stat_hourly_aps(start_time = nil, end_time = Time.now.to_i * 1000)
  body = { start: start_time ? start_time : end_time - (7 * 24 * 3600 * 1000),
           end: end_time,
           attrs: ['bytes', 'num_sta', 'time'] }
  response = self.class.get("/s/#{@site}/stat/report/hourly.ap", { body: body.to_json })
  response.parsed_response
end

#stat_hourly_site(start_time = nil, end_time = Time.now.to_i * 1000) ⇒ Object



143
144
145
146
147
148
149
150
151
# File 'lib/unifi_gem/client/main.rb', line 143

def stat_hourly_site(start_time = nil, end_time = Time.now.to_i * 1000)
  body = { start: start_time ? start_time : end_time - (7 * 24 * 3600 * 1000),
           end: end_time,
           attributes: ['bytes',
                        'wan-tx_bytes',
                        'wan-rx_bytes', 'wlan_bytes', 'num_sta', 'lan-num_sta', 'wlan-num_sta', 'time'] }
  response = self.class.get("/s/#{@site}/stat/report/hourly.site", { body: body.to_json })
  response.parsed_response
end

#stat_payment(within = nil) ⇒ Object



138
139
140
141
# File 'lib/unifi_gem/client/main.rb', line 138

def stat_payment(within = nil)
  response = self.class.get("/s/#{@site}/stat/payment#{within ? "?within=#{within}" : '' }")
  response.parsed_response
end

#stat_sessions(start_time = nil, end_time = Time.now.to_i, mac = nil) ⇒ Object



131
132
133
134
135
136
# File 'lib/unifi_gem/client/main.rb', line 131

def stat_sessions(start_time = nil, end_time = Time.now.to_i, mac = nil)
  body = { start: start_time ? start_time : end_time - (7 * 24 * 3600), end: end_time, type: 'all' }
  body[:mac] = mac if mac
  response = self.class.get("/s/#{@site}/stat/session", { body: body.to_json })
  response.parsed_response
end

#stat_sta_sessions_latest(mac, limit = 5) ⇒ Object



125
126
127
128
129
# File 'lib/unifi_gem/client/main.rb', line 125

def stat_sta_sessions_latest(mac, limit = 5)
  body = { mac: mac.downcase, _limit: limit, _sort: '-assoc_time' }
  response = self.class.get("/s/#{@site}/stat/session", { body: body.to_json })
  response.parsed_response
end

#unblock_sta(mac) ⇒ Object



319
320
321
322
323
# File 'lib/unifi_gem/client/main.rb', line 319

def unblock_sta(mac)
  body = { cmd: 'unblock-sta', mac: mac.downcase }
  response = self.class.post("/s/#{@site}/cmd/stamgr", { body: body.to_json })
  response.parsed_response
end

#upgrade_device(mac) ⇒ Object



214
215
216
217
218
# File 'lib/unifi_gem/client/main.rb', line 214

def upgrade_device(mac)
  body = { mac: mac }
  response = self.class.get("/s/#{@site}/cmd/devmgr/upgrade", { body: body.to_json })
  response.parsed_response
end

#upgrade_device_external(firmware_url, device_mac) ⇒ Object



208
209
210
211
212
# File 'lib/unifi_gem/client/main.rb', line 208

def upgrade_device_external(firmware_url, device_mac)
  body = { url: firmware_url, mac: device_mac }
  response = self.class.get("/s/#{@site}/cmd/devmgr/upgrade-external", { body: body.to_json })
  response.parsed_response
end