module UnifiGem::Client::Main

Public Instance Methods

add_usergroup(group_name, group_dn = -1, group_up = -1) click to toggle source
# 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) click to toggle source
# 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 = '') click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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_admins() click to toggle source
# 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_alarms() click to toggle source
# 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 = '') click to toggle source
# 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_channels() click to toggle source
# 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_dashboard() click to toggle source
# 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 = '') click to toggle source
# 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_stats() click to toggle source
# 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_dynamicdns() click to toggle source
# 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 = {}) click to toggle source
# 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_extension() click to toggle source
# 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_health() click to toggle source
# 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_hotspotop() click to toggle source
# 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_networkconf() click to toggle source
# 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_portconf() click to toggle source
# 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_stats() click to toggle source
# 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) click to toggle source
# 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_self() click to toggle source
# File lib/unifi_gem/client/main.rb, line 77
def list_self
  response = self.class.get("/s/#{@site}/self")
  response.parsed_response
end
list_settings() click to toggle source
# 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_usergroups() click to toggle source
# 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_users() click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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 = '') click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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 = '') click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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