maygion-ipcam 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (2) hide show
  1. data/lib/maygion-ipcam.rb +55 -0
  2. metadata +55 -0
@@ -0,0 +1,55 @@
1
+ #!/usr/bin/ruby
2
+
3
+ # file: maygion-ipcam.rb
4
+
5
+ require 'net/http'
6
+ require 'open-uri'
7
+
8
+ class MayGionIPCam
9
+
10
+ attr_reader :resp
11
+
12
+ def initialize(opt)
13
+ o = {username: 'user', password: 'user', address: '192.168.1.14', port: 80}.merge(opt)
14
+ @addr, @port = o[:address], o[:port]
15
+ @raw_url = "http://#{@addr}/cgi.cmd?cmd=moveptz&tick=100&user=user&pwd=user"
16
+ @resp, data = login(o[:username], o[:password])
17
+ @cookie = @resp.response['set-cookie'].scan(/\w+\=[^=]+(?=;)/).join(';')
18
+ end
19
+
20
+ def left(i=1)
21
+ move_camera '&dir=btnPtzLeft&nPtzTimes=' + i.to_s
22
+ end
23
+
24
+ def right(i=1)
25
+ move_camera '&dir=btnPtzRight&nPtzTimes=' + i.to_s
26
+ end
27
+
28
+ def up(i=1)
29
+ move_camera '&dir=btnPtzUp&nPtzTimes=' + i.to_s
30
+ end
31
+
32
+ def down(i=1)
33
+ move_camera '&dir=btnPtzDown&nPtzTimes=' + i.to_s
34
+ end
35
+
36
+ def login(username, password)
37
+
38
+ http = Net::HTTP.new(@addr, @port)
39
+ path = '/cgi-bin/cgicmd'
40
+
41
+ # POST request -> logging in
42
+ data = 'szAccount=user&szPassword=user&cmd=Login&urlOnSuccess=/mobile.asp'
43
+ headers = {
44
+ 'Referer' => "http://#{@addr}/login.asp",
45
+ 'Content-Type' => 'application/x-www-form-urlencoded'
46
+ }
47
+
48
+ http.post(path, data, headers)
49
+ end
50
+
51
+ def move_camera(instruction)
52
+ url = @raw_url + instruction
53
+ open(url, 'UserAgent' => 'Ruby IPCO (IP Camera Operator)', 'Cookie' => @cookie).read
54
+ end
55
+ end
metadata ADDED
@@ -0,0 +1,55 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: maygion-ipcam
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors: []
7
+
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2010-08-17 00:00:00 +01:00
13
+ default_executable:
14
+ dependencies: []
15
+
16
+ description:
17
+ email:
18
+ executables: []
19
+
20
+ extensions: []
21
+
22
+ extra_rdoc_files: []
23
+
24
+ files:
25
+ - lib/maygion-ipcam.rb
26
+ has_rdoc: true
27
+ homepage:
28
+ licenses: []
29
+
30
+ post_install_message:
31
+ rdoc_options: []
32
+
33
+ require_paths:
34
+ - lib
35
+ required_ruby_version: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ">="
38
+ - !ruby/object:Gem::Version
39
+ version: "0"
40
+ version:
41
+ required_rubygems_version: !ruby/object:Gem::Requirement
42
+ requirements:
43
+ - - ">="
44
+ - !ruby/object:Gem::Version
45
+ version: "0"
46
+ version:
47
+ requirements: []
48
+
49
+ rubyforge_project:
50
+ rubygems_version: 1.3.5
51
+ signing_key:
52
+ specification_version: 3
53
+ summary: maygion-ipcam
54
+ test_files: []
55
+