class UnifiGem::Client
Public Class Methods
new(options = {})
click to toggle source
# File lib/unifi_gem/client.rb, line 21 def initialize(options = {}) # @logger = ::Logger.new STDOUT, :debug, :curl options[:url] ||= ENV["UNIFI_URL"] self.class.base_uri "https://#{options[:url]}/api" @selfbaseuri = "https://#{options[:url]}" @site = options[:site] || ENV["UNIFI_SITE"] || "default" @username = options[:username] || ENV["UNIFI_USERNAME"] @password = options[:password] || ENV["UNIFI_PASSWORD"] self.class.default_options.merge!(headers: { 'Content-Type'=>'application/json', 'Accept'=>'application/json' }, verify: false) login self.class.default_options.merge!(headers: { 'Cookie'=>@cookies } ) end
Public Instance Methods
adopt_device(mac)
click to toggle source
# 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)
click to toggle source
# 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()
click to toggle source
# File lib/unifi_gem/client.rb, line 36 def login options = { headers: { Referer: "#{@selfbaseuri}/login" }, body: JSON.generate({ username: "#{@username}", password: "#{@password}" }) } response = self.class.post("/login", options) puts response @cookies = response.headers['set-cookie'] end
logout()
click to toggle source
# File lib/unifi_gem/client.rb, line 51 def logout self.class.get("/logout") @cookies = '' end