foscam-ruby 0.0.2 → 0.0.3

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,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- NTkyMzY0NmMwMWI2ZWRmNjIxMTQ0N2UyNjRjMjY1NTEyODRkNmNiNQ==
4
+ NTM1YTU4NzIxZDQ1OTVhM2M5NWRhMDczZmFmY2ZlNDJkMjlkM2Q4Zg==
5
5
  data.tar.gz: !binary |-
6
- ZmNhMjVjODY5MDVmOGVkNzExZmQ2OGFjMWRkNDExYTA4YjU4NDk3Mw==
6
+ MGRiZTRmZWQyZDk2ODg1YWJlOTVhZTBiNGU5ZjQ5MWUyZjc2Yjg0NQ==
7
7
  !binary "U0hBNTEy":
8
8
  metadata.gz: !binary |-
9
- NjE5ZmVkYWY4NDZiZjE5MTRmMDg3NjE4ZjBmNjJkN2E3YTVlODVmNmFiNWMy
10
- MmIwNTI0Njc5MWVlYWEyODAwNzY2OTcyNjAyODEwYThmOTlhMjEwNzgxYTI5
11
- MzAxZWZiNjU4YWZiNzBlMWM5OGZmMzM4MjhlZTZjZDNkODRmZjQ=
9
+ ZTIzN2ZiYTFhODg4NzE0YjZiNGU2MjQ2ODljNTNjNTQ1ZjdkYTUyY2RhNmJj
10
+ YzQyOWZmNjcyZjU4MjkwZGEyYmNkYWNjOTUxY2I3ODk2YTM2NjU4ZGIyYmE5
11
+ NWNhZGRjZDQ5YmM1N2Y1NWIzYmY3YmEzZjNiZmExYjdjZDQ5ZWU=
12
12
  data.tar.gz: !binary |-
13
- OWQxY2NlYTYyODFkZGQxZGE1ZThmM2QyN2M2ZjVjMGFhZTk2ODViZWQ3YzY4
14
- YWVmYjVmZmZkMjhhZjc3N2ZkMTY1MTljMzMxYzA0YjFjMzUzODRkNGU5ZGVl
15
- ODgzMjI4YTdkOWEyNDYzMTFmMzhlMWI2MmIxMGMyN2RhNjc2MTk=
13
+ M2UxMTgxNmVlNTgyMzM3YWYwYzIxYzRhNTJlYTQ5MTA4MWQ5ZWNkZmVjYTZj
14
+ MjlmZTJlMzU1OGFkYmI4ZmNiMmVkNThkYjdlNmY0Y2Q3NmZlMTBiNTMyMDBk
15
+ ZGU3MWE3NjdiM2RkZjhkNmMyN2E0Yzc5MDgyZWU2NmVkY2VlNmE=
@@ -1,3 +1,5 @@
1
+ before_install:
2
+ - gem install bundler
1
3
  language: ruby
2
4
  rvm:
3
5
  - 1.9.3
data/README.md CHANGED
@@ -1,6 +1,9 @@
1
1
  # Foscam::Ruby
2
+ [![Gem Version](https://badge.fury.io/rb/foscam-ruby.png)](http://badge.fury.io/rb/foscam-ruby)
3
+ [![Build Status](https://travis-ci.org/cwadding/foscam-ruby.png)](https://travis-ci.org/cwadding/foscam-ruby)
4
+ [![Code Climate](https://codeclimate.com/github/cwadding/foscam-ruby.png)](https://codeclimate.com/github/cwadding/foscam-ruby)
2
5
 
3
- A client library written in ruby to communicate to your [foscam webcam](http://www.foscam.com/) using the [foscam SDK](http://site.usajumping.com/Download/ipcam_cgi_sdk.pdf).
6
+ A client library written in ruby to communicate to your [foscam webcam](http://www.amazon.com/gp/product/B006ZP8UOW/ref=as_li_qf_sp_asin_tl?ie=UTF8&camp=1789&creative=9325&creativeASIN=B006ZP8UOW&linkCode=as2&tag=foscamruby-20) using the [foscam SDK](http://site.usajumping.com/Download/ipcam_cgi_sdk.pdf).
4
7
 
5
8
  ## Installation
6
9
 
data/Rakefile CHANGED
@@ -1,4 +1,5 @@
1
1
  require "bundler/gem_tasks"
2
2
 
3
3
  require 'rspec/core/rake_task'
4
- RSpec::Core::RakeTask.new('spec')
4
+ task :default => :spec
5
+ RSpec::Core::RakeTask.new
@@ -2,6 +2,7 @@ require "foscam/version"
2
2
  require "faraday"
3
3
  require "mini_magick"
4
4
  require "active_support/core_ext/object/to_query"
5
+ require "date"
5
6
 
6
7
  module Foscam
7
8
  autoload :Client, 'foscam/client'
@@ -1,5 +1,6 @@
1
1
  module Foscam
2
2
 
3
+ # DDNS_STATUS
3
4
  DDNS_STATUS = {
4
5
  0 => "No Action",
5
6
  1 => "It's connecting...",
@@ -21,6 +22,7 @@ module Foscam
21
22
  17 => "Oray Succeed"
22
23
  }
23
24
 
25
+ # UPNP_STATUS
24
26
  UPNP_STATUS = {
25
27
  0 => "No Action",
26
28
  1 => "Succeed",
@@ -30,19 +32,24 @@ module Foscam
30
32
  5 => "Rejected by UPnP Device, Maybe Port Conflict"
31
33
  }
32
34
 
35
+ # ALARM_STATUS
33
36
  ALARM_STATUS = {
34
37
  0 => "No alarm",
35
38
  1 => "Motion alarm",
36
39
  2 => "Input Alarm"
37
40
  }
38
41
 
42
+ # CAMERA_PARAMS_MODE
39
43
  CAMERA_PARAMS_MODE = {
40
44
  0 => "50hz",
41
45
  1 => "60hz",
42
46
  2 => "outdoor"
43
47
  }
48
+
49
+ # CAMERA_CONTROL_MODE
44
50
  CAMERA_CONTROL_MODE = CAMERA_PARAMS_MODE.inject({}){|memo,(k,v)| memo[v.to_sym] = k; memo}
45
51
 
52
+ # CAMERA_PARAMS_ORIENTATION
46
53
  CAMERA_PARAMS_ORIENTATION = {
47
54
  0 => "default",
48
55
  1 => "flip",
@@ -50,15 +57,19 @@ module Foscam
50
57
  3 => "flip+mirror"
51
58
  }
52
59
 
60
+ # CAMERA_CONTROL_ORIENTATION
53
61
  CAMERA_CONTROL_ORIENTATION = CAMERA_PARAMS_ORIENTATION.inject({}){|memo,(k,v)| memo[v.to_sym] = k; memo}
54
62
 
63
+ # CAMERA_PARAMS_RESOLUTION
55
64
  CAMERA_PARAMS_RESOLUTION = {
56
65
  8 => "qvga",
57
66
  32 => "vga"
58
67
  }
59
68
 
69
+ # CAMERA_CONTROL_RESOLUTION
60
70
  CAMERA_CONTROL_RESOLUTION = CAMERA_PARAMS_RESOLUTION.inject({}){|memo,(k,v)| memo[v.to_sym] = k; memo}
61
71
 
72
+ # CAMERA_CONTROLS
62
73
  CAMERA_CONTROLS = {
63
74
  :resolution => 0,
64
75
  :brightness => 1,
@@ -67,6 +78,7 @@ module Foscam
67
78
  :flip => 5
68
79
  }
69
80
 
81
+ # DECODER_CONTROLS
70
82
  DECODER_CONTROLS = {
71
83
  :up => 0,
72
84
  :stop => 1,
@@ -86,26 +98,35 @@ module Foscam
86
98
  :io_output_low => 95,
87
99
  }
88
100
 
101
+ # USER_PERMISSIONS
89
102
  USER_PERMISSIONS = {
90
103
  0 => :visitor,
91
104
  1 => :operator,
92
105
  2 => :administrator
93
106
  }
94
107
 
108
+ # PTZ_AUTO_PATROL_TYPE
95
109
  PTZ_AUTO_PATROL_TYPE = {
96
110
  0 => :none,
97
111
  1 => :horizontal,
98
112
  2 => :vertical,
99
113
  3 => :"horizontal+vertical"
100
114
  }
115
+
116
+ # PTZ_AUTO_PATROL_TYPE_ID
101
117
  PTZ_AUTO_PATROL_TYPE_ID = PTZ_AUTO_PATROL_TYPE.invert
102
118
 
119
+ # LED_MODE
103
120
  LED_MODE = {
104
121
  0 => :mode1,
105
122
  1 => :mode2,
106
123
  2 => :disabled
107
124
  }
125
+
126
+ # LED_MODE_ID
108
127
  LED_MODE_ID = LED_MODE.invert
128
+
129
+ # DECODER_BAUD
109
130
  DECODER_BAUD = {
110
131
  9 => :B1200,
111
132
  11 => :B2400,
@@ -116,13 +137,26 @@ module Foscam
116
137
  4097 => :B57600,
117
138
  4098 => :B115200
118
139
  }
119
-
140
+ # DECODER_BAUD_ID
120
141
  DECODER_BAUD_ID = DECODER_BAUD.invert
121
142
 
122
-
143
+ # TODO: put in some documentation for this class
123
144
  class Client
124
145
 
125
- attr_accessor :url, :username, :password, :connection
146
+
147
+ # @!attribute [rw] url
148
+ # @return [String] the url to the camera
149
+ attr_accessor :url
150
+ # @!attribute [rw] username
151
+ # @return [String] The username for authentication to the camera
152
+ attr_accessor :username
153
+ # @!attribute [rw] password
154
+ # @return [String] The password for authentication to the camera
155
+ attr_accessor :password
156
+
157
+ # @!attribute [rw] connection
158
+ # @return [Faraday] The HTTP connection object to the camera
159
+ attr_accessor :connection
126
160
 
127
161
  def initialize(args = {})
128
162
  @url = args.delete(:url)
@@ -131,6 +165,15 @@ module Foscam
131
165
  connect(@url, @username, @password)
132
166
  end
133
167
 
168
+ ##
169
+ # Connects to the foscam webcam
170
+
171
+ # @param url [String] The address to your camera
172
+ # @param username [String] username to authorize with the camera
173
+ # @param password [String] password to authorize with the camera
174
+ # @example connect to a camera
175
+ # client = Foscam::Client.new
176
+ # client.connect('http://192.168.0.1', 'foobar', 'secret')
134
177
  def connect(url, username = nil, password = nil)
135
178
  @url = url
136
179
  @username = username
@@ -139,11 +182,30 @@ module Foscam
139
182
  @connection.basic_auth(@username, @password) unless @username.nil? && @password.nil?
140
183
  end
141
184
 
185
+ ##
186
+ # Obtains a snapshot of the current image
187
+ # @return [nil, ::MiniMagick::Image]
188
+ # @example Save a captured image
189
+ # client = Foscam::Client.new(url: 'http://192.168.0.1', username: 'foobar', password: 'secret')
190
+ # image = client.snapshot
191
+ # unless image.nil?
192
+ # image.write('image_filename.jpg')
193
+ # end
142
194
  def snapshot
143
195
  response = @connection.get('snapshot.cgi')
144
196
  response.success? ? ::MiniMagick::Image.read(response.body) : nil
145
197
  end
146
198
 
199
+ ##
200
+ # Obtains the cameras status information
201
+ # @see DDNS_STATUS
202
+ # @see UPNP_STATUS
203
+ # @see ALARM_STATUS
204
+ # @return [Hash] The cameras status
205
+ # * :now (DateTime) The current time on the camera
206
+ # * :alarm_status (String) Returns an Alarm status
207
+ # * :ddns_status (String) Returns an UPNP status
208
+ # * :upnp_status (String) Returns an DDNS status
147
209
  def get_status
148
210
  response = @connection.get('get_status.cgi')
149
211
  response = response.success? ? parse_response(response) : {}
@@ -151,11 +213,23 @@ module Foscam
151
213
  response[:ddns_status] = DDNS_STATUS[response[:ddns_status].to_i]
152
214
  response[:upnp_status] = UPNP_STATUS[response[:upnp_status].to_i]
153
215
  response[:alarm_status] = ALARM_STATUS[response[:alarm_status].to_i]
154
- response[:now] = DateTime.strptime(response[:now],'%s')
216
+ response[:now] = ::DateTime.strptime(response[:now],'%s')
155
217
  end
156
218
  response
157
219
  end
158
220
 
221
+
222
+ ##
223
+ # Obtains the cameras parameters (orientation, resolution, contrast, brightness)
224
+ # @see CAMERA_PARAMS_ORIENTATION
225
+ # @see CAMERA_PARAMS_MODE
226
+ # @see CAMERA_PARAMS_RESOLUTION
227
+ # @return [Hash] The cameras parameters
228
+ # * :flip (String) The camera orientation.
229
+ # * :mode (String) The camera mode.
230
+ # * :resolution (String) The camera resolution.
231
+ # * :brightness (Fixnum) The camera brightness.
232
+ # * :contrast (Fixnum) The camera contrast.
159
233
  def get_camera_params
160
234
  response = @connection.get('get_camera_params.cgi')
161
235
  response = response.success? ? parse_response(response) : {}
@@ -168,6 +242,11 @@ module Foscam
168
242
  response
169
243
  end
170
244
 
245
+ ##
246
+ # Controls the pan and tilt of the camera
247
+ # @see DECODER_CONTROLS
248
+ # @param action [Symbol] A symbol corresponding to the desired action.
249
+ # @return [FalseClass,TrueClass] whether the request was successful.
171
250
  def decoder_control(action)
172
251
  case action
173
252
  when Symbol || String
@@ -179,6 +258,18 @@ module Foscam
179
258
  response.success?
180
259
  end
181
260
 
261
+ ##
262
+ # Sets the camera sensor parameters
263
+ # @see CAMERA_CONTROL_MODE
264
+ # @see CAMERA_CONTROL_ORIENTATION
265
+ # @see CAMERA_PARAMS_RESOLUTION
266
+ # @param [Hash] params Parameters to set
267
+ # @option params [Symbol,String] :resolution Set to one of the keys or values in CAMERA_PARAMS_RESOLUTION
268
+ # @option params [Fixnum] :brightness Value between 0 and 255
269
+ # @option params [Fixnum] :contrast Value between 0 and 6
270
+ # @option params [Symbol, Integer] :mode Value between 0 and 2 or option in CAMERA_CONTROL_MODE
271
+ # @option params [Symbol, Integer] :flip Value between 0 and 3 or option in CAMERA_CONTROL_ORIENTATION
272
+ # @return [FalseClass,TrueClass] whether the request was successful.
182
273
  def camera_control(params)
183
274
  params.all? do |key, value|
184
275
  # validation
@@ -230,39 +321,197 @@ module Foscam
230
321
  end
231
322
  end
232
323
 
324
+ ##
325
+ # Reboots the camera
326
+ # @return [FalseClass,TrueClass] whether the request was successful.
233
327
  def reboot
234
328
  response = @connection.get("reboot.cgi")
235
329
  response.success?
236
330
  end
237
331
 
332
+ ##
333
+ # Restore settings to the factory defaults
334
+ # @return [FalseClass,TrueClass] whether the request was successful.
238
335
  def restore_factory
239
336
  response = @connection.get("restore_factory.cgi")
240
337
  response.success?
241
338
  end
242
339
 
340
+ ##
341
+ # Returns all the parameters for the camera
342
+ # @return [Hash] If the request is unsuccessful the hash will be empty. Otherwise it contains the following fields:
343
+ # * :id (String) The device id.
344
+ # * :sys_ver (String) Firmware version number.
345
+ # * :resolution (String) Web UI version number.
346
+ # * :alias (String) The assigned camera name.
347
+ # * :now (DateTime) The camera's time.
348
+ # * :tz (String) The camera time zone.
349
+ # * :ntp_enable (FalseClass, TrueClass) Whether the ntp server is enabled.
350
+ # * :ntp_svr (String) Address to the ntp server.
351
+ # * :user1_name (String) Username of user1.
352
+ # * :user1_pwd (String) Password of user1.
353
+ # * :user1_pri (String) Privilages of user1.
354
+ # * ...
355
+ # * :user8_name (String) Username of user8.
356
+ # * :user8_pwd (String) Password of user8.
357
+ # * :user8_pri (String) Privilages of user8.
358
+ # * :dev2_alias (String) The 2nd Device alias
359
+ # * :dev2_host (String) The 2nd Device host(IP or Domain name)
360
+ # * :dev2_port (String) The 2nd Device port.
361
+ # * :dev2_user (String) The 2nd Device user name .
362
+ # * :dev2_pwd (String) The 2nd Device password.
363
+ # * ...
364
+ # * :dev9_alias (String) The 9th Device alias
365
+ # * :dev9_host (String) The 9th Device host(IP or Domain name)
366
+ # * :dev9_port (Fixnum) The 9th Device port.
367
+ # * :dev9_user (String) The 9th Device user name .
368
+ # * :dev9_pwd (String) The 9th Device password.
369
+ # * :ip_address (String) The network ip address of the camera.
370
+ # * :mask (String) The network mask of the camera.
371
+ # * :gateway (String) The network gateway of the camera.
372
+ # * :dns (String) The address of the dns server.
373
+ # * :port (Fixnum) The network port.
374
+ # * :wifi_enable (FalseClass, TrueClass) Whether wifi is enabled or not.
375
+ # * :wifi_ssid (String) Your WIFI SSID
376
+ # * :wifi_encrypt (FalseClass, TrueClass) Whether wifi is encrypted or not.
377
+ # * :wifi_defkey (String) Wep Default TX Key
378
+ # * :wifi_key1 (String) Key1
379
+ # * :wifi_key2 (String) Key2
380
+ # * :wifi_key3 (String) Key3
381
+ # * :wifi_key4 (String) Key4
382
+ # * :wifi_autht (String) ype The Authetication type 0:open 1:share
383
+ # * :wifi_keyfo (String) rmat Keyformat 0:Hex 1:ASCII
384
+ # * :wifi_key1_bits (String) 0:64 bits; 1:128 bits
385
+ # * :wifi_key2_bits (String) 0:64 bits; 1:128 bits
386
+ # * :wifi_key3_bits (String) 0:64 bits; 1:128 bits
387
+ # * :wifi_key4_bits (String) 0:64 bits; 1:128 bits
388
+ # * :wifi_channel (String) Channel (default 6)
389
+ # * :wifi_mode (String) Mode (default 0)
390
+ # * :wifi_wpa_psk (String) wpa_psk
391
+ # * :pppoe_enable (FalseClass, TrueClass)
392
+ # * :pppoe_user (String)
393
+ # * :pppoe_pwd (String)
394
+ # * :upnp_enable (FalseClass, TrueClass)
395
+ # * :ddns_service (String)
396
+ # * :ddns_user (String)
397
+ # * :ddns_pwd (String)
398
+ # * :ddns_host (String)
399
+ # * :ddns_proxy_svr (String)
400
+ # * :ddns_proxy_port (Fixnum)
401
+ # * :mail_svr (String)
402
+ # * :mail_port (Fixnum)
403
+ # * :mail_tls (String)
404
+ # * :mail_user (String)
405
+ # * :mail_pwd (String)
406
+ # * :mail_sender (String)
407
+ # * :mail_receiver1 (String)
408
+ # * :mail_receiver2 (String)
409
+ # * :mail_receiver3 (String)
410
+ # * :mail_receiver4 (String)
411
+ # * :mail_inet_ip (String)
412
+ # * :ftp_svr (String)
413
+ # * :ftp_port (String)
414
+ # * :ftp_user (String)
415
+ # * :ftp_pwd (String)
416
+ # * :ftp_dir (String)
417
+ # * :ftp_mode (String)
418
+ # * :ftp_upload_interval (String)
419
+ # * :ftp_filename (String)
420
+ # * :ftp_numberoffiles (Fixnum)
421
+ # * :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)
443
+ # * :alarm_motion_armed (FalseClass, TrueClass)
444
+ # * :alarm_motion_sensitivity (Fixnum)
445
+ # * :alarm_motion_compensation (Fixnum)
446
+ # * :alarm_input_armed (FalseClass, TrueClass]
447
+ # * :alarm_ioin_level (Fixnum)
448
+ # * :alarm_iolinkage (Fixnum)
449
+ # * :alarm_preset (Fixnum)
450
+ # * :alarm_ioout_level (Fixnum)
451
+ # * :alarm_mail (FalseClass, TrueClass)
452
+ # * :alarm_upload_interval (Fixnum)
453
+ # * :alarm_http (FalseClass, TrueClass)
454
+ # * :alarm_msn (FalseClass, TrueClass)
455
+ # * :alarm_http_url (String)
456
+ # * :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)
478
+ # * :decoder_baud (Fixnum)
479
+ # * :msn_user (String)
480
+ # * :msn_pwd (String)
481
+ # * :msn_friend1 (String)
482
+ # * :msn_friend2 (String)
483
+ # * :msn_friend3 (String)
484
+ # * :msn_friend4 (String)
485
+ # * :msn_friend5 (String)
486
+ # * :msn_friend6 (String)
487
+ # * :msn_friend7 (String)
488
+ # * :msn_friend8 (String)
489
+ # * :msn_friend9 (String)
490
+ # * :msn_friend10 (String)
243
491
  def get_params
244
492
  response = @connection.get("get_params.cgi")
245
493
  response = response.success? ? parse_response(response) : {}
246
494
  unless response.empty?
247
- response[:now] = DateTime.strptime(response[:now],'%s')
495
+ response[:now] = ::DateTime.strptime(response[:now],'%s')
248
496
  [:ntp_enable, :wifi_enable, :pppoe_enable, :upnp_enable, :alarm_schedule_enable, :ftp_schedule_enable].each do |field|
249
497
  response[field] = response[field].to_i > 0
250
498
  end
251
- [:ftp_schedule_sun_0, :ftp_schedule_sun_1, :ftp_schedule_sun_2,
252
- :ftp_schedule_mon_0, :ftp_schedule_mon_1, :ftp_schedule_mon_2,
253
- :ftp_schedule_tue_0, :ftp_schedule_tue_1, :ftp_schedule_tue_2,
254
- :ftp_schedule_wed_0, :ftp_schedule_wed_1, :ftp_schedule_wed_2,
255
- :ftp_schedule_thu_0, :ftp_schedule_thu_1, :ftp_schedule_thu_2,
256
- :ftp_schedule_fri_0, :ftp_schedule_fri_1, :ftp_schedule_fri_2,
257
- :ftp_schedule_sat_0, :ftp_schedule_sat_1, :ftp_schedule_sat_2,
258
- :alarm_schedule_sun_0, :alarm_schedule_sun_1, :alarm_schedule_sun_2,
259
- :alarm_schedule_mon_0, :alarm_schedule_mon_1, :alarm_schedule_mon_2,
260
- :alarm_schedule_tue_0, :alarm_schedule_tue_1, :alarm_schedule_tue_2,
261
- :alarm_schedule_wed_0, :alarm_schedule_wed_1, :alarm_schedule_wed_2,
262
- :alarm_schedule_thu_0, :alarm_schedule_thu_1, :alarm_schedule_thu_2,
263
- :alarm_schedule_fri_0, :alarm_schedule_fri_1, :alarm_schedule_fri_2,
264
- :alarm_schedule_sat_0, :alarm_schedule_sat_1, :alarm_schedule_sat_2,
265
- :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|
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|
266
515
  response[field] = response[field].to_i
267
516
  end
268
517
  [:user1_pri, :user2_pri, :user3_pri, :user4_pri, :user5_pri, :user6_pri, :user7_pri, :user8_pri].each do |key|
@@ -272,20 +521,35 @@ module Foscam
272
521
  response
273
522
  end
274
523
 
524
+ ##
525
+ # Upgrade the camera firmware
526
+ # @return [FalseClass,TrueClass] whether the request was successful.
275
527
  def upgrade_firmware
276
528
  response = @connection.post("upgrade_firmware.cgi")
277
529
  end
278
530
 
531
+ ##
532
+ # Upgrade the cameras html pages.
533
+ # @return [FalseClass,TrueClass] whether the request was successful.
279
534
  def upgrade_htmls
280
535
  response = @connection.post("upgrade_htmls.cgi")
281
536
  end
282
537
 
538
+
539
+ ##
540
+ # Set the name of the camera
541
+ # @param [String] name The name of the camera which is 20 characters or less.
542
+ # @return [FalseClass,TrueClass] whether the request was successful.
283
543
  def set_alias(name)
284
544
  throw "invalid parameter value" if name.length > 20
285
545
  response = @connection.get("set_alias.cgi?alias=#{name}")
286
546
  response.success?
287
547
  end
288
548
 
549
+ ##
550
+ # Set the datetime of the camera
551
+ # @param [Hash] params
552
+ # @return [FalseClass,TrueClass] whether the request was successful.
289
553
  def set_datetime(params)
290
554
  # Extract the time zone
291
555
  throw "invalid parameter value" if params.has_key?(:ntp_svr) && params[:ntp_svr].length > 64
@@ -293,6 +557,10 @@ module Foscam
293
557
  response.success?
294
558
  end
295
559
 
560
+ ##
561
+ # Set usernames, passwords and privilages
562
+ # @param [Hash] params
563
+ # @return [FalseClass,TrueClass] whether the request was successful.
296
564
  def set_users(params)
297
565
  [:user1, :pwd1, :user2, :pwd2, :user3, :pwd3, :user4, :pwd4, :user5, :pwd5, :user6, :pwd6, :user7, :pwd7, :user8, :pwd8].each do |key|
298
566
  throw "invalid parameter value" if params.has_key?(key) && params[key].length > 12
@@ -305,16 +573,34 @@ module Foscam
305
573
  # response = @connection.get("set_devices.cgi?#{params.to_query}")
306
574
  # end
307
575
 
576
+ ##
577
+ # Set usernames, passwords and privilages
578
+ # @param [Hash] params
579
+ # @return [FalseClass,TrueClass] whether the request was successful.
308
580
  def set_network(params)
309
581
  response = @connection.get("set_network.cgi?#{params.to_query}")
310
582
  response.success?
311
583
  end
312
-
584
+ ##
585
+ # Set the wifi parameters
586
+ # @param [Hash] params
587
+ # @option params [FalseClass, TrueClass] :enable Whether wifi is enabled or not.
588
+ # @option params [String] :ssid Your WIFI SSID
589
+ # @option params [FalseClass, TrueClass] :encrypt Whether wifi is encrypted or not.
590
+ # @option params [String] :wpa_psk wpa_psk
591
+ # @return [FalseClass,TrueClass] whether the request was successful.
313
592
  def set_wifi(params)
314
593
  response = @connection.get("set_wifi.cgi?#{params.to_query}")
315
594
  response.success?
316
595
  end
317
-
596
+
597
+ ##
598
+ # Set the pppoe parameters
599
+ # @param [Hash] params
600
+ # @option params [FalseClass, TrueClass] :enable
601
+ # @option params [String] :user
602
+ # @option params [String] :pwd
603
+ # @return [FalseClass,TrueClass] whether the request was successful.
318
604
  def set_pppoe(params)
319
605
  throw "invalid parameter value" if params.has_key?(:user) && params[:user].length > 20
320
606
  throw "invalid parameter value" if params.has_key?(:pwd) && params[:pwd].length > 20
@@ -322,11 +608,24 @@ module Foscam
322
608
  response.success?
323
609
  end
324
610
 
611
+ ##
612
+ # Enable or disable upnp
613
+ # @param [FalseClass, TrueClass] flag A boolean for whether to enable or disable upnp.
614
+ # @return [FalseClass,TrueClass] whether the request was successful.
325
615
  def set_upnp(flag)
326
616
  response = @connection.get("set_upnp.cgi?enable=#{handle_boolean(flag)}")
327
617
  response.success?
328
618
  end
329
619
 
620
+
621
+ ##
622
+ # Set the ddns parameters
623
+ # @param [Hash] params
624
+ # @option params [String] :user
625
+ # @option params [String] :pwd
626
+ # @option params [String] :host
627
+ # @option params [String] :service
628
+ # @return [FalseClass,TrueClass] whether the request was successful.
330
629
  def set_ddns(params)
331
630
  throw "invalid parameter value" if params.has_key?(:user) && params[:user].length > 20
332
631
  throw "invalid parameter value" if params.has_key?(:pwd) && params[:pwd].length > 20
@@ -335,11 +634,34 @@ module Foscam
335
634
  response.success?
336
635
  end
337
636
 
637
+ ##
638
+ # Set the ftp parameters
639
+ # @param [Hash] params
640
+ # @option params [String] :dir
641
+ # @option params [String] :user
642
+ # @option params [String] :pwd
643
+ # @option params [String] :svr
644
+ # @option params [Fixnum] :port
645
+ # @option params [Fixnum] :upload_interval in seconds
646
+ # @return [FalseClass,TrueClass] whether the request was successful.
338
647
  def set_ftp(params)
339
648
  response = @connection.get("set_ftp.cgi?#{params.to_query}")
340
649
  response.success?
341
650
  end
342
651
 
652
+ ##
653
+ # Set the smtp server mail notification parameters
654
+ # @param [Hash] params
655
+ # @option params [String] :user must be less than 20 characters
656
+ # @option params [String] :pwd must be less than 20 characters
657
+ # @option params [String] :svr
658
+ # @option params [Fixnum] :port
659
+ # @option params [String] :sender must be less than 40 characters
660
+ # @option params [String] :receiver1 must be less than 40 characters
661
+ # @option params [String] :receiver2 must be less than 40 characters
662
+ # @option params [String] :receiver3 must be less than 40 characters
663
+ # @option params [String] :receiver4 must be less than 40 characters
664
+ # @return [FalseClass,TrueClass] whether the request was successful.
343
665
  def set_mail(params)
344
666
  throw "invalid parameter value" if params.has_key?(:user) && params[:user].length > 20
345
667
  throw "invalid parameter value" if params.has_key?(:pwd) && params[:pwd].length > 20
@@ -350,26 +672,110 @@ module Foscam
350
672
  response.success?
351
673
  end
352
674
 
675
+ ##
676
+ # Set alarm parameters
677
+ # @param [Hash] params
678
+ # @option params [TrueClass, FalseClass] :motion_armed Whether the motion is enabled or disabled
679
+ # @option params [TrueClass, FalseClass] :input_armed Whether the motion is enabled or disabled
680
+ # @option params [TrueClass, FalseClass] :mail whether to send email on alarm
681
+ # @option params [TrueClass, FalseClass] :iolinkage whether to send email on alarm
682
+ # @option params [Fixnum] :motion_sensitivity
683
+ # @option params [Fixnum] :upload_interval in seconds
684
+ # @return [FalseClass,TrueClass] whether the request was successful.
353
685
  def set_alarm(params)
354
686
  response = @connection.get("set_alarm.cgi?#{params.to_query}")
355
687
  response.success?
356
688
  end
357
689
 
690
+ ##
691
+ # Write to comm
692
+ # @param [Hash] params
693
+ # @option params [Fixnum] :baud
694
+ # @option params [String] :bytes
695
+ # @option params [String] :data
696
+ # @option params [Fixnum] :port
697
+ # @return [FalseClass,TrueClass] whether the request was successful.
358
698
  def comm_write(params)
359
699
  response = @connection.get("comm_write.cgi?#{params.to_query}")
360
700
  response.success?
361
701
  end
362
702
 
703
+ ##
704
+ # 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
727
+ # @return [FalseClass,TrueClass] whether the request was successful.
363
728
  def set_forbidden(params)
364
729
  response = @connection.get("set_forbidden.cgi?#{params.to_query}")
365
730
  response.success?
366
731
  end
367
732
 
733
+ ##
734
+ # 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)
368
757
  def get_forbidden
369
758
  response = @connection.get("get_forbidden.cgi")
370
759
  response.success? ? parse_response(response) : {}
371
760
  end
372
761
 
762
+ ##
763
+ # Set miscellaneous parameters
764
+ # @param [Hash] params
765
+ # @option params [Fixnum] :led_mode
766
+ # @option params [Fixnum] :ptz_auto_patrol_interval
767
+ # @option params [Fixnum] :ptz_auto_patrol_type
768
+ # @option params [Fixnum] :ptz_patrol_down_rate
769
+ # @option params [Fixnum] :ptz_patrol_h_rounds
770
+ # @option params [Fixnum] :ptz_patrol_left_rate
771
+ # @option params [Fixnum] :ptz_patrol_rate
772
+ # @option params [Fixnum] :ptz_patrol_right_rate
773
+ # @option params [Fixnum] :ptz_patrol_up_rate
774
+ # @option params [Fixnum] :ptz_patrol_v_rounds
775
+ # @option params [FalseClass,TrueClass] :ptz_preset_onstart
776
+ # @option params [FalseClass,TrueClass] :ptz_center_onstart
777
+ # @option params [FalseClass,TrueClass] :ptz_disable_preset
778
+ # @return [FalseClass,TrueClass] whether the request was successful.
373
779
  def set_misc(params)
374
780
  url_params = params.clone
375
781
  [:ptz_patrol_rate, :ptz_patrol_up_rate, :ptz_patrol_down_rate, :ptz_patrol_left_rate, :ptz_patrol_right_rate].each do |key|
@@ -387,6 +793,23 @@ module Foscam
387
793
  response.success?
388
794
  end
389
795
 
796
+
797
+ ##
798
+ # Get miscellaneous parameters
799
+ # @return [Hash] If the request is unsuccessful the hash will be empty. Otherwise it contains the following fields:
800
+ # * :led_mode (Fixnum)
801
+ # * :ptz_auto_patrol_interval (Fixnum)
802
+ # * :ptz_auto_patrol_type (Fixnum)
803
+ # * :ptz_patrol_down_rate (Fixnum)
804
+ # * :ptz_patrol_h_rounds (Fixnum)
805
+ # * :ptz_patrol_left_rate (Fixnum)
806
+ # * :ptz_patrol_rate (Fixnum)
807
+ # * :ptz_patrol_right_rate (Fixnum)
808
+ # * :ptz_patrol_up_rate (Fixnum)
809
+ # * :ptz_patrol_v_rounds (Fixnum)
810
+ # * :ptz_preset_onstart (FalseClass,TrueClass)
811
+ # * :ptz_center_onstart (FalseClass,TrueClass)
812
+ # * :ptz_disable_preset (FalseClass,TrueClass)
390
813
  def get_misc
391
814
  response = @connection.get("get_misc.cgi")
392
815
  response = response.success? ? parse_response(response) : {}
@@ -404,6 +827,11 @@ module Foscam
404
827
  response
405
828
  end
406
829
 
830
+
831
+ ##
832
+ # Set decoder baud
833
+ # @param [String,Symbol] baud
834
+ # @return [FalseClass,TrueClass] whether the request was successful.
407
835
  def set_decoder(baud)
408
836
  baud = DECODER_BAUD_ID[baud.to_sym] if baud.is_a?(String) || baud.is_a?(Symbol)
409
837
  response = @connection.get("set_decoder.cgi?baud=#{baud}")
@@ -1,3 +1,4 @@
1
1
  module Foscam
2
- VERSION = "0.0.2"
2
+ # Gem Version number
3
+ VERSION = "0.0.3"
3
4
  end
@@ -270,7 +270,7 @@ http_interactions:
270
270
 
271
271
  var ftp_user=''my_username'';
272
272
 
273
- var ftp_pwd=''RscCh63'';
273
+ var ftp_pwd=''secret'';
274
274
 
275
275
  var ftp_dir=''R2D2'';
276
276
 
@@ -4,9 +4,10 @@ require 'bundler/setup'
4
4
  require 'vcr'
5
5
  require 'foscam-ruby' # and any other gems you need
6
6
 
7
- FOSCAM_USERNAME = 'my_username'
8
- FOSCAM_PASSWORD = 'my_password'
9
- FOSCAM_URL = "http://192.168.0.117/"
7
+
8
+ FOSCAM_USERNAME = 'my_username' #:nodoc:all
9
+ FOSCAM_PASSWORD = 'my_password' #:nodoc:all
10
+ FOSCAM_URL = "http://192.168.0.117/" #:nodoc:all
10
11
 
11
12
  VCR.configure do |c|
12
13
  c.cassette_library_dir = 'spec/fixtures/vcr'
@@ -14,9 +15,15 @@ VCR.configure do |c|
14
15
  # c.allow_http_connections_when_no_cassette = true
15
16
  end
16
17
 
17
- module Boolean; end
18
- class TrueClass; include Boolean; end
19
- class FalseClass; include Boolean; end
18
+
19
+ module Boolean #:nodoc:all
20
+ end
21
+ class TrueClass #:nodoc:all
22
+ include Boolean
23
+ end
24
+ class FalseClass #:nodoc:all
25
+ include Boolean
26
+ end
20
27
 
21
28
  RSpec.configure do |config|
22
29
  # some (optional) config here
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: foscam-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chris Waddington
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-03-08 00:00:00.000000000 Z
11
+ date: 2013-03-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -242,4 +242,3 @@ test_files:
242
242
  - spec/fixtures/vcr/foscam_upgrade_htmls.yml
243
243
  - spec/foscam/client_spec.rb
244
244
  - spec/spec_helper.rb
245
- has_rdoc: