Class: Unifi::Client
- Inherits:
-
Object
- Object
- Unifi::Client
- Defined in:
- lib/unifi/client.rb,
lib/unifi/client/main.rb,
lib/unifi/client/wlan.rb,
lib/unifi/client/sites.rb,
lib/unifi/client/guests.rb,
lib/unifi/client/vouchers.rb
Defined Under Namespace
Modules: Guests, Main, Sites, Vouchers, Wlan
Instance Method Summary collapse
- #adopt_device(mac) ⇒ Object
- #block_sta(mac) ⇒ Object
-
#initialize(options = {}) ⇒ Client
constructor
A new instance of Client.
- #login ⇒ Object
- #logout ⇒ Object
Methods included from Main
#add_usergroup, #count_alarms, #create_hotspotop, #delete_usergroup, #disable_ap, #edit_usergroup, #led_override, #list_admins, #list_alarms, #list_clients, #list_current_channels, #list_dashboard, #list_devices, #list_dpi_stats, #list_dynamicdns, #list_events, #list_extension, #list_health, #list_hotspotop, #list_networkconf, #list_portconf, #list_portforward_stats, #list_rogueaps, #list_self, #list_settings, #list_usergroups, #list_users, #locate_ap, #reconnect_sta, #rename_ap, #restart_ap, #set_ap_radiosettings, #set_sta_name, #set_sta_note, #set_usergroup, #site_leds, #spectrum_scan, #spectrum_scan_state, #stat_allusers, #stat_auths, #stat_client, #stat_daily_aps, #stat_daily_site, #stat_hourly_aps, #stat_hourly_site, #stat_payment, #stat_sessions, #stat_sta_sessions_latest, #unblock_sta, #upgrade_device, #upgrade_device_external
Methods included from Wlan
#create_wlan, #delete_wlan, #list_wlan_groups, #list_wlanconf, #set_wlansettings
Methods included from Guests
#authorize_guest, #extend_guest_validity, #list_guests, #set_guestlogin_settings, #unauthorize_guest
Methods included from Sites
#add_site, #delete_site, #list_sites, #stat_sites, #stat_sysinfo
Methods included from Vouchers
#create_voucher, #revoke_voucher, #stat_voucher
Constructor Details
#initialize(options = {}) ⇒ Client
Returns a new instance of Client.
19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/unifi/client.rb', line 19 def initialize( = {}) [:url] ||= ENV["UNIFI_URL"] self.class.base_uri "https://#{[:url]}/api" @site = [:site] || ENV["UNIFI_SITE"] || "default" @username = [:username] || ENV["UNIFI_USERNAME"] @password = [:password] || ENV["UNIFI_PASSWORD"] self.class..merge!(headers: { 'Content-Type': 'application/json', 'Accept': 'application/json' }, verify: false) login self.class..merge!(headers: { 'Cookie': @cookies } ) end |
Instance Method Details
#adopt_device(mac) ⇒ Object
332 333 334 335 336 |
# File 'lib/unifi/client/main.rb', line 332 def adopt_device(mac) body = { cmd: 'adopt', mac: mac.downcase } response = self.class.post("/s/#{@site}/cmd/stamgr", { body: body.to_json }) response.parsed_response end |
#block_sta(mac) ⇒ Object
326 327 328 329 330 |
# File 'lib/unifi/client/main.rb', line 326 def block_sta(mac) body = { cmd: 'block-sta', mac: mac.downcase } response = self.class.post("/s/#{@site}/cmd/stamgr", { body: body.to_json }) response.parsed_response end |
#login ⇒ Object
32 33 34 35 36 |
# File 'lib/unifi/client.rb', line 32 def login response = self.class.post("/login", body: "{'username': '#{@username}', 'password': '#{@password}'}") @cookies = response.headers['set-cookie'] end |
#logout ⇒ Object
38 39 40 41 |
# File 'lib/unifi/client.rb', line 38 def logout self.class.get("/logout") @cookies = '' end |