foscam-ruby 0.0.3 → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,15 +1,7 @@
1
1
  ---
2
- !binary "U0hBMQ==":
3
- metadata.gz: !binary |-
4
- NTM1YTU4NzIxZDQ1OTVhM2M5NWRhMDczZmFmY2ZlNDJkMjlkM2Q4Zg==
5
- data.tar.gz: !binary |-
6
- MGRiZTRmZWQyZDk2ODg1YWJlOTVhZTBiNGU5ZjQ5MWUyZjc2Yjg0NQ==
7
- !binary "U0hBNTEy":
8
- metadata.gz: !binary |-
9
- ZTIzN2ZiYTFhODg4NzE0YjZiNGU2MjQ2ODljNTNjNTQ1ZjdkYTUyY2RhNmJj
10
- YzQyOWZmNjcyZjU4MjkwZGEyYmNkYWNjOTUxY2I3ODk2YTM2NjU4ZGIyYmE5
11
- NWNhZGRjZDQ5YmM1N2Y1NWIzYmY3YmEzZjNiZmExYjdjZDQ5ZWU=
12
- data.tar.gz: !binary |-
13
- M2UxMTgxNmVlNTgyMzM3YWYwYzIxYzRhNTJlYTQ5MTA4MWQ5ZWNkZmVjYTZj
14
- MjlmZTJlMzU1OGFkYmI4ZmNiMmVkNThkYjdlNmY0Y2Q3NmZlMTBiNTMyMDBk
15
- ZGU3MWE3NjdiM2RkZjhkNmMyN2E0Yzc5MDgyZWU2NmVkY2VlNmE=
2
+ SHA1:
3
+ metadata.gz: 07206c44423faf623a2bf523367d0e07ebd87456
4
+ data.tar.gz: f035164cea711af91542b19fd2cbf2c559c1fadc
5
+ SHA512:
6
+ metadata.gz: 683e4c6829e42cdca0ff3bab2c89022f921d6f9f572a1b310fdd1beaf2dfd503e96bfc0679a2327672f7999ae8c214b333f71b3972a671e722bce0e9d5dc319d
7
+ data.tar.gz: 2d0c567f0c6e0b8f20042d96abffc3e8c47a85065e9edabc98673e8bd90b108636732eee9c54b4bd46329678843e047300372aeee8a79df09491f1f5f943d644
@@ -3,4 +3,4 @@ before_install:
3
3
  language: ruby
4
4
  rvm:
5
5
  - 1.9.3
6
- - 1.8.7
6
+ - 2.0.0
@@ -21,6 +21,7 @@ Gem::Specification.new do |spec|
21
21
  spec.add_dependency 'faraday'
22
22
  spec.add_dependency 'mini_magick'
23
23
  spec.add_dependency 'active_support'
24
+ spec.add_dependency 'activemodel'
24
25
 
25
26
  spec.add_development_dependency "bundler", "~> 1.3"
26
27
  spec.add_development_dependency "rake"
@@ -2,8 +2,28 @@ require "foscam/version"
2
2
  require "faraday"
3
3
  require "mini_magick"
4
4
  require "active_support/core_ext/object/to_query"
5
+ require "active_support/core_ext/class/attribute_accessors"
5
6
  require "date"
7
+ require "date"
8
+ require "active_model"
9
+ require 'singleton'
10
+
11
+ require 'foscam/model/base'
6
12
 
7
13
  module Foscam
8
14
  autoload :Client, 'foscam/client'
15
+ module Model
16
+ autoload :User, 'foscam/model/user'
17
+ autoload :Device, 'foscam/model/device'
18
+ autoload :FtpServer, 'foscam/model/ftp_server'
19
+ autoload :MailServer, 'foscam/model/mail_server'
20
+ autoload :AlarmConfig, 'foscam/model/alarm_config'
21
+ autoload :Network, 'foscam/model/network'
22
+ end
23
+
24
+ module Schedule
25
+ autoload :Week, 'foscam/schedule/week'
26
+ autoload :Day, 'foscam/schedule/day'
27
+ autoload :ThirdOfADay, 'foscam/schedule/third_of_a_day'
28
+ end
9
29
  end
@@ -1,145 +1,6 @@
1
+ require "foscam/constants"
1
2
  module Foscam
2
3
 
3
- # DDNS_STATUS
4
- DDNS_STATUS = {
5
- 0 => "No Action",
6
- 1 => "It's connecting...",
7
- 2 => "Can't connect to the Server",
8
- 3 => "Dyndns Succeed",
9
- 4 => "DynDns Failed: Dyndns.org Server Error",
10
- 5 => "DynDns Failed: Incorrect User or Password",
11
- 6 => "DynDns Failed: Need Credited User",
12
- 7 => "DynDns Failed: Illegal Host Format",
13
- 8 => "DynDns Failed: The Host Does not Exist",
14
- 9 => "DynDns Failed: The Host Does not Belong to You",
15
- 10 => "DynDns Failed: Too Many or Too Few Hosts",
16
- 11 => "DynDns Failed: The Host is Blocked for Abusing",
17
- 12 => "DynDns Failed: Bad Reply from Server",
18
- 13 => "DynDns Failed: Bad Reply from Server",
19
- 14 => "Oray Failed: Bad Reply from Server",
20
- 15 => "Oray Failed: Incorrect User or Password",
21
- 16 => "Oray Failed: Incorrect Hostname",
22
- 17 => "Oray Succeed"
23
- }
24
-
25
- # UPNP_STATUS
26
- UPNP_STATUS = {
27
- 0 => "No Action",
28
- 1 => "Succeed",
29
- 2 => "Device System Error",
30
- 3 => "Errors in Network Communication",
31
- 4 => "Errors in Chat with UPnP Device",
32
- 5 => "Rejected by UPnP Device, Maybe Port Conflict"
33
- }
34
-
35
- # ALARM_STATUS
36
- ALARM_STATUS = {
37
- 0 => "No alarm",
38
- 1 => "Motion alarm",
39
- 2 => "Input Alarm"
40
- }
41
-
42
- # CAMERA_PARAMS_MODE
43
- CAMERA_PARAMS_MODE = {
44
- 0 => "50hz",
45
- 1 => "60hz",
46
- 2 => "outdoor"
47
- }
48
-
49
- # CAMERA_CONTROL_MODE
50
- CAMERA_CONTROL_MODE = CAMERA_PARAMS_MODE.inject({}){|memo,(k,v)| memo[v.to_sym] = k; memo}
51
-
52
- # CAMERA_PARAMS_ORIENTATION
53
- CAMERA_PARAMS_ORIENTATION = {
54
- 0 => "default",
55
- 1 => "flip",
56
- 2 => "mirror",
57
- 3 => "flip+mirror"
58
- }
59
-
60
- # CAMERA_CONTROL_ORIENTATION
61
- CAMERA_CONTROL_ORIENTATION = CAMERA_PARAMS_ORIENTATION.inject({}){|memo,(k,v)| memo[v.to_sym] = k; memo}
62
-
63
- # CAMERA_PARAMS_RESOLUTION
64
- CAMERA_PARAMS_RESOLUTION = {
65
- 8 => "qvga",
66
- 32 => "vga"
67
- }
68
-
69
- # CAMERA_CONTROL_RESOLUTION
70
- CAMERA_CONTROL_RESOLUTION = CAMERA_PARAMS_RESOLUTION.inject({}){|memo,(k,v)| memo[v.to_sym] = k; memo}
71
-
72
- # CAMERA_CONTROLS
73
- CAMERA_CONTROLS = {
74
- :resolution => 0,
75
- :brightness => 1,
76
- :contrast => 2,
77
- :mode => 3,
78
- :flip => 5
79
- }
80
-
81
- # DECODER_CONTROLS
82
- DECODER_CONTROLS = {
83
- :up => 0,
84
- :stop => 1,
85
- :stop_up => 1,
86
- :down => 2,
87
- :stop_down => 3,
88
- :left => 4,
89
- :stop_left => 5,
90
- :right => 6,
91
- :stop_right => 7,
92
- :center => 25,
93
- :vertical_patrol => 26,
94
- :stop_vertical_patrol => 27,
95
- :horizon_patrol => 28,
96
- :stop_horizon_patrol => 29,
97
- :io_output_high => 94,
98
- :io_output_low => 95,
99
- }
100
-
101
- # USER_PERMISSIONS
102
- USER_PERMISSIONS = {
103
- 0 => :visitor,
104
- 1 => :operator,
105
- 2 => :administrator
106
- }
107
-
108
- # PTZ_AUTO_PATROL_TYPE
109
- PTZ_AUTO_PATROL_TYPE = {
110
- 0 => :none,
111
- 1 => :horizontal,
112
- 2 => :vertical,
113
- 3 => :"horizontal+vertical"
114
- }
115
-
116
- # PTZ_AUTO_PATROL_TYPE_ID
117
- PTZ_AUTO_PATROL_TYPE_ID = PTZ_AUTO_PATROL_TYPE.invert
118
-
119
- # LED_MODE
120
- LED_MODE = {
121
- 0 => :mode1,
122
- 1 => :mode2,
123
- 2 => :disabled
124
- }
125
-
126
- # LED_MODE_ID
127
- LED_MODE_ID = LED_MODE.invert
128
-
129
- # DECODER_BAUD
130
- DECODER_BAUD = {
131
- 9 => :B1200,
132
- 11 => :B2400,
133
- 12 => :B4800,
134
- 13 => :B9600,
135
- 14 => :B19200,
136
- 15 => :B38400,
137
- 4097 => :B57600,
138
- 4098 => :B115200
139
- }
140
- # DECODER_BAUD_ID
141
- DECODER_BAUD_ID = DECODER_BAUD.invert
142
-
143
4
  # TODO: put in some documentation for this class
144
5
  class Client
145
6
 
@@ -167,7 +28,6 @@ module Foscam
167
28
 
168
29
  ##
169
30
  # Connects to the foscam webcam
170
-
171
31
  # @param url [String] The address to your camera
172
32
  # @param username [String] username to authorize with the camera
173
33
  # @param password [String] password to authorize with the camera
@@ -342,7 +202,7 @@ module Foscam
342
202
  # @return [Hash] If the request is unsuccessful the hash will be empty. Otherwise it contains the following fields:
343
203
  # * :id (String) The device id.
344
204
  # * :sys_ver (String) Firmware version number.
345
- # * :resolution (String) Web UI version number.
205
+ # * :app_ver (String) Web UI version number.
346
206
  # * :alias (String) The assigned camera name.
347
207
  # * :now (DateTime) The camera's time.
348
208
  # * :tz (String) The camera time zone.
@@ -419,27 +279,7 @@ module Foscam
419
279
  # * :ftp_filename (String)
420
280
  # * :ftp_numberoffiles (Fixnum)
421
281
  # * :ftp_schedule_enable (FalseClass, TrueClass)
422
- # * :ftp_schedule_sun_0 (Fixnum)
423
- # * :ftp_schedule_sun_1 (Fixnum)
424
- # * :ftp_schedule_sun_2 (Fixnum)
425
- # * :ftp_schedule_mon_0 (Fixnum)
426
- # * :ftp_schedule_mon_1 (Fixnum)
427
- # * :ftp_schedule_mon_2 (Fixnum)
428
- # * :ftp_schedule_tue_0 (Fixnum)
429
- # * :ftp_schedule_tue_1 (Fixnum)
430
- # * :ftp_schedule_tue_2 (Fixnum)
431
- # * :ftp_schedule_wed_0 (Fixnum)
432
- # * :ftp_schedule_wed_1 (Fixnum)
433
- # * :ftp_schedule_wed_2 (Fixnum)
434
- # * :ftp_schedule_thu_0 (Fixnum)
435
- # * :ftp_schedule_thu_1 (Fixnum)
436
- # * :ftp_schedule_thu_2 (Fixnum)
437
- # * :ftp_schedule_fri_0 (Fixnum)
438
- # * :ftp_schedule_fri_1 (Fixnum)
439
- # * :ftp_schedule_fri_2 (Fixnum)
440
- # * :ftp_schedule_sat_0 (Fixnum)
441
- # * :ftp_schedule_sat_1 (Fixnum)
442
- # * :ftp_schedule_sat_2 (Fixnum)
282
+ # * :ftp_schedule (Schedule::Week)
443
283
  # * :alarm_motion_armed (FalseClass, TrueClass)
444
284
  # * :alarm_motion_sensitivity (Fixnum)
445
285
  # * :alarm_motion_compensation (Fixnum)
@@ -454,27 +294,7 @@ module Foscam
454
294
  # * :alarm_msn (FalseClass, TrueClass)
455
295
  # * :alarm_http_url (String)
456
296
  # * :alarm_schedule_enable (FalseClass, TrueClass)
457
- # * :alarm_schedule_sun_0 (Fixnum)
458
- # * :alarm_schedule_sun_1 (Fixnum)
459
- # * :alarm_schedule_sun_2 (Fixnum)
460
- # * :alarm_schedule_mon_0 (Fixnum)
461
- # * :alarm_schedule_mon_1 (Fixnum)
462
- # * :alarm_schedule_mon_2 (Fixnum)
463
- # * :alarm_schedule_tue_0 (Fixnum)
464
- # * :alarm_schedule_tue_1 (Fixnum)
465
- # * :alarm_schedule_tue_2 (Fixnum)
466
- # * :alarm_schedule_wed_0 (Fixnum)
467
- # * :alarm_schedule_wed_1 (Fixnum)
468
- # * :alarm_schedule_wed_2 (Fixnum)
469
- # * :alarm_schedule_thu_0 (Fixnum)
470
- # * :alarm_schedule_thu_1 (Fixnum)
471
- # * :alarm_schedule_thu_2 (Fixnum)
472
- # * :alarm_schedule_fri_0 (Fixnum)
473
- # * :alarm_schedule_fri_1 (Fixnum)
474
- # * :alarm_schedule_fri_2 (Fixnum)
475
- # * :alarm_schedule_sat_0 (Fixnum)
476
- # * :alarm_schedule_sat_1 (Fixnum)
477
- # * :alarm_schedule_sat_2 (Fixnum)
297
+ # * :alarm_schedule (Schedule::Week)
478
298
  # * :decoder_baud (Fixnum)
479
299
  # * :msn_user (String)
480
300
  # * :msn_pwd (String)
@@ -492,26 +312,32 @@ module Foscam
492
312
  response = @connection.get("get_params.cgi")
493
313
  response = response.success? ? parse_response(response) : {}
494
314
  unless response.empty?
315
+ alarm_schedule = {}
316
+ ftp_schedule = {}
317
+ response.keys.each do |field|
318
+ ftp_match = field.to_s.match(/ftp_schedule_(.+)_(\d)/)
319
+ unless ftp_match.nil?
320
+ value = response.delete(field)
321
+ ftp_schedule.merge!("#{ftp_match[1]}_#{ftp_match[2]}".to_sym => value.to_i)
322
+ end
323
+
324
+ alarm_match = field.to_s.match(/alarm_schedule_(.+)_(\d)/)
325
+ unless alarm_match.nil?
326
+ value = response.delete(field)
327
+ alarm_schedule.merge!("#{alarm_match[1]}_#{alarm_match[2]}".to_sym => value.to_i)
328
+ end
329
+ end
330
+
331
+ response[:ftp_schedule] = ::Foscam::Schedule::Week.new(ftp_schedule)
332
+
333
+ response[:alarm_schedule] = ::Foscam::Schedule::Week.new(alarm_schedule)
334
+
495
335
  response[:now] = ::DateTime.strptime(response[:now],'%s')
496
336
  [:ntp_enable, :wifi_enable, :pppoe_enable, :upnp_enable, :alarm_schedule_enable, :ftp_schedule_enable].each do |field|
497
337
  response[field] = response[field].to_i > 0
498
338
  end
499
- [
500
- :ftp_schedule_sun_0, :ftp_schedule_sun_1, :ftp_schedule_sun_2,
501
- :ftp_schedule_mon_0, :ftp_schedule_mon_1, :ftp_schedule_mon_2,
502
- :ftp_schedule_tue_0, :ftp_schedule_tue_1, :ftp_schedule_tue_2,
503
- :ftp_schedule_wed_0, :ftp_schedule_wed_1, :ftp_schedule_wed_2,
504
- :ftp_schedule_thu_0, :ftp_schedule_thu_1, :ftp_schedule_thu_2,
505
- :ftp_schedule_fri_0, :ftp_schedule_fri_1, :ftp_schedule_fri_2,
506
- :ftp_schedule_sat_0, :ftp_schedule_sat_1, :ftp_schedule_sat_2,
507
- :alarm_schedule_sun_0, :alarm_schedule_sun_1, :alarm_schedule_sun_2,
508
- :alarm_schedule_mon_0, :alarm_schedule_mon_1, :alarm_schedule_mon_2,
509
- :alarm_schedule_tue_0, :alarm_schedule_tue_1, :alarm_schedule_tue_2,
510
- :alarm_schedule_wed_0, :alarm_schedule_wed_1, :alarm_schedule_wed_2,
511
- :alarm_schedule_thu_0, :alarm_schedule_thu_1, :alarm_schedule_thu_2,
512
- :alarm_schedule_fri_0, :alarm_schedule_fri_1, :alarm_schedule_fri_2,
513
- :alarm_schedule_sat_0, :alarm_schedule_sat_1, :alarm_schedule_sat_2,
514
- :daylight_savings_time, :ddns_proxy_port, :ftp_port, :mail_port, :port, :dev2_port, :dev3_port, :dev4_port, :dev5_port, :dev6_port, :dev7_port, :dev8_port, :dev9_port].each do |field|
339
+
340
+ [:daylight_savings_time, :ddns_proxy_port, :ftp_port, :mail_port, :port, :dev2_port, :dev3_port, :dev4_port, :dev5_port, :dev6_port, :dev7_port, :dev8_port, :dev9_port].each do |field|
515
341
  response[field] = response[field].to_i
516
342
  end
517
343
  [:user1_pri, :user2_pri, :user3_pri, :user4_pri, :user5_pri, :user6_pri, :user7_pri, :user8_pri].each do |key|
@@ -560,11 +386,23 @@ module Foscam
560
386
  ##
561
387
  # Set usernames, passwords and privilages
562
388
  # @param [Hash] params
389
+ # @option params [String] :user1 Username of user1.
390
+ # @option params [String] :pwd1 Password of user1.
391
+ # @option params [String] :pri1 Privilages of user1.
392
+ # @option params [String] ...
393
+ # @option params [String] :user8 Username of user8.
394
+ # @option params [String] :pwd8 Password of user8.
395
+ # @option params [String] :pri8 Privilages of user8.
563
396
  # @return [FalseClass,TrueClass] whether the request was successful.
564
397
  def set_users(params)
565
398
  [:user1, :pwd1, :user2, :pwd2, :user3, :pwd3, :user4, :pwd4, :user5, :pwd5, :user6, :pwd6, :user7, :pwd7, :user8, :pwd8].each do |key|
566
399
  throw "invalid parameter value" if params.has_key?(key) && params[key].length > 12
567
400
  end
401
+ # if it is one of the matching symbols then set it to the corresponding integer
402
+ [:pri1, :pri2, :pri3, :pri4, :pri5, :pri6, :pri7, :pri8].each do |key|
403
+ params[key] = USER_PERMISSIONS_ID[key] if params.has_key?(key) && params[key].is_a?(Symbol)
404
+ end
405
+
568
406
  response = @connection.get("set_users.cgi?#{params.to_query}")
569
407
  response.success?
570
408
  end
@@ -576,6 +414,11 @@ module Foscam
576
414
  ##
577
415
  # Set usernames, passwords and privilages
578
416
  # @param [Hash] params
417
+ # @option params [String] :ip if ip set to "",The device will DHCP Ip
418
+ # @option params [String] :mask mask
419
+ # @option params [String] :gateway gateway
420
+ # @option params [String] :dns dns server
421
+ # @option params [Fixnum] :port port number
579
422
  # @return [FalseClass,TrueClass] whether the request was successful.
580
423
  def set_network(params)
581
424
  response = @connection.get("set_network.cgi?#{params.to_query}")
@@ -702,61 +545,39 @@ module Foscam
702
545
 
703
546
  ##
704
547
  # Set Forbidden
705
- # @param [Hash] params
706
- # @option params [Fixnum] :schedule_fri_0
707
- # @option params [Fixnum] :schedule_fri_1
708
- # @option params [Fixnum] :schedule_fri_2
709
- # @option params [Fixnum] :schedule_mon_0
710
- # @option params [Fixnum] :schedule_mon_1
711
- # @option params [Fixnum] :schedule_mon_2
712
- # @option params [Fixnum] :schedule_sat_0
713
- # @option params [Fixnum] :schedule_sat_1
714
- # @option params [Fixnum] :schedule_sat_2
715
- # @option params [Fixnum] :schedule_sun_0
716
- # @option params [Fixnum] :schedule_sun_1
717
- # @option params [Fixnum] :schedule_sun_2
718
- # @option params [Fixnum] :schedule_thu_0
719
- # @option params [Fixnum] :schedule_thu_1
720
- # @option params [Fixnum] :schedule_thu_2
721
- # @option params [Fixnum] :schedule_tue_0
722
- # @option params [Fixnum] :schedule_tue_1
723
- # @option params [Fixnum] :schedule_tue_2
724
- # @option params [Fixnum] :schedule_wed_0
725
- # @option params [Fixnum] :schedule_wed_1
726
- # @option params [Fixnum] :schedule_wed_2
548
+ # @param [Schedule::Week] week
727
549
  # @return [FalseClass,TrueClass] whether the request was successful.
728
- def set_forbidden(params)
729
- response = @connection.get("set_forbidden.cgi?#{params.to_query}")
730
- response.success?
550
+ def set_forbidden(week)
551
+ if week.is_a?(Schedule::Week)
552
+ params = {}
553
+ week.to_param.each_pair do |key, value|
554
+ params.merge!("schedule_#{key}" => value)
555
+ end
556
+ response = @connection.get("set_forbidden.cgi?#{params.to_query}")
557
+ response.success?
558
+ else
559
+ false
560
+ end
731
561
  end
732
562
 
733
563
  ##
734
564
  # Returns the forbidden schedule for the camera
735
- # @return [Hash] If the request is unsuccessful the hash will be empty. Otherwise it contains the following fields:
736
- # * :schedule_sun_0 (Fixnum)
737
- # * :schedule_sun_1 (Fixnum)
738
- # * :schedule_sun_2 (Fixnum)
739
- # * :schedule_mon_0 (Fixnum)
740
- # * :schedule_mon_1 (Fixnum)
741
- # * :schedule_mon_2 (Fixnum)
742
- # * :schedule_tue_0 (Fixnum)
743
- # * :schedule_tue_1 (Fixnum)
744
- # * :schedule_tue_2 (Fixnum)
745
- # * :schedule_wed_0 (Fixnum)
746
- # * :schedule_wed_1 (Fixnum)
747
- # * :schedule_wed_2 (Fixnum)
748
- # * :schedule_thu_0 (Fixnum)
749
- # * :schedule_thu_1 (Fixnum)
750
- # * :schedule_thu_2 (Fixnum)
751
- # * :schedule_fri_0 (Fixnum)
752
- # * :schedule_fri_1 (Fixnum)
753
- # * :schedule_fri_2 (Fixnum)
754
- # * :schedule_sat_0 (Fixnum)
755
- # * :schedule_sat_1 (Fixnum)
756
- # * :schedule_sat_2 (Fixnum)
565
+ # @return [Schedule::Week, nil] If the request is unsuccessful then nil is returned.
757
566
  def get_forbidden
758
567
  response = @connection.get("get_forbidden.cgi")
759
- response.success? ? parse_response(response) : {}
568
+ params = response.success? ? parse_response(response) : {}
569
+ schedule = {}
570
+ unless params.empty?
571
+ params.keys.each do |field|
572
+ match = field.to_s.match(/schedule_(.+)_(\d)/)
573
+ unless match.nil?
574
+ schedule.merge!("#{match[1]}_#{match[2]}".to_sym => params[field].to_i)
575
+ end
576
+ end
577
+ ::Foscam::Schedule::Week.new(schedule)
578
+ else
579
+ nil
580
+ end
760
581
  end
761
582
 
762
583
  ##