Class: UnifiGem::Client
- Inherits:
-
Object
- Object
- UnifiGem::Client
- Defined in:
- lib/unifi_gem/client.rb,
lib/unifi_gem/client/main.rb,
lib/unifi_gem/client/wlan.rb,
lib/unifi_gem/client/sites.rb,
lib/unifi_gem/client/guests.rb,
lib/unifi_gem/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.
21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/unifi_gem/client.rb', line 21 def initialize( = {}) # @logger = ::Logger.new STDOUT, :debug, :curl [:url] ||= ENV["UNIFI_URL"] self.class.base_uri "https://#{[:url]}/api" @selfbaseuri = "https://#{[:url]}" @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_gem/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_gem/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
36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/unifi_gem/client.rb', line 36 def login = { headers: { Referer: "#{@selfbaseuri}/login" }, body: JSON.generate({ username: "#{@username}", password: "#{@password}" }) } response = self.class.post("/login", ) puts response @cookies = response.headers['set-cookie'] end |
#logout ⇒ Object
51 52 53 54 |
# File 'lib/unifi_gem/client.rb', line 51 def logout self.class.get("/logout") @cookies = '' end |