Class: MayGionIPCam
- Inherits:
-
Object
- Object
- MayGionIPCam
- Defined in:
- lib/maygion-ipcam.rb
Constant Summary collapse
- Factor =
500
Instance Attribute Summary collapse
-
#cookie ⇒ Object
readonly
Returns the value of attribute cookie.
-
#resp ⇒ Object
readonly
Returns the value of attribute resp.
Instance Method Summary collapse
- #down(i = 1) ⇒ Object
-
#initialize(opt) ⇒ MayGionIPCam
constructor
A new instance of MayGionIPCam.
- #left(i = 1) ⇒ Object
- #login(username, password) ⇒ Object
- #move_camera(instruction) ⇒ Object
- #right(i = 1) ⇒ Object
- #snap ⇒ Object
- #up(i = 1) ⇒ Object
Constructor Details
#initialize(opt) ⇒ MayGionIPCam
Returns a new instance of MayGionIPCam.
13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/maygion-ipcam.rb', line 13 def initialize(opt) o = {username: 'user', password: 'user', address: '192.168.1.14', \ port: 80, cookie: ''}.merge(opt) @addr, @port = o[:address], o[:port] @raw_url = "http://#{@addr}/cgi.cmd?cmd=moveptz&user=" + o[:username] \ + "&pwd=" + o[:password] @cookie = o[:cookie] if @cookie.empty? then @resp, data = login(o[:username], o[:password]) @cookie = @resp.response['set-cookie'].scan(/\w+\=[^=]+(?=;)/).join(';') end end |
Instance Attribute Details
#cookie ⇒ Object (readonly)
Returns the value of attribute cookie.
10 11 12 |
# File 'lib/maygion-ipcam.rb', line 10 def @cookie end |
#resp ⇒ Object (readonly)
Returns the value of attribute resp.
10 11 12 |
# File 'lib/maygion-ipcam.rb', line 10 def resp @resp end |
Instance Method Details
#down(i = 1) ⇒ Object
40 41 42 |
# File 'lib/maygion-ipcam.rb', line 40 def down(i=1) move_camera "&dir=btnPtzDown&tick=%s&nPtzTimes=1" % [i * Factor] end |
#left(i = 1) ⇒ Object
28 29 30 |
# File 'lib/maygion-ipcam.rb', line 28 def left(i=1) move_camera "&dir=btnPtzLeft&tick=%s&nPtzTimes=1" % [i * Factor] end |
#login(username, password) ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/maygion-ipcam.rb', line 44 def login(username, password) http = Net::HTTP.new(@addr, @port) path = '/cgi-bin/cgicmd' # POST request -> logging in data = "szAccount=#{username}&szPassword=" + password + "&cmd=Login&urlOnSuccess=/mobile.asp" headers = { 'Referer' => "http://#{@addr}/login.asp", 'Content-Type' => 'application/x-www-form-urlencoded' } http.post(path, data, headers) end |
#move_camera(instruction) ⇒ Object
60 61 62 63 64 |
# File 'lib/maygion-ipcam.rb', line 60 def move_camera(instruction) url = @raw_url + instruction URI.open(url, 'UserAgent' => 'Ruby IPCO (IP Camera Operator)', \ 'Cookie' => @cookie){|x| x.read} end |
#right(i = 1) ⇒ Object
32 33 34 |
# File 'lib/maygion-ipcam.rb', line 32 def right(i=1) move_camera "&dir=btnPtzRight&tick=%s&nPtzTimes=1" % [i * Factor] end |
#snap ⇒ Object
66 67 68 69 70 71 72 |
# File 'lib/maygion-ipcam.rb', line 66 def snap() url = "http://#{@addr}/snap.jpg" URI.open(url, 'UserAgent' => 'Ruby IPCO (IP Camera Operator)', \ 'Cookie' => @cookie){|x| x.read} end |
#up(i = 1) ⇒ Object
36 37 38 |
# File 'lib/maygion-ipcam.rb', line 36 def up(i=1) move_camera "&dir=btnPtzUp&tick=%s&nPtzTimes=1" % [i * Factor] end |