Class: Dropcam::Camera

Inherits:
Base
  • Object
show all
Defined in:
lib/dropcam/camera.rb

Instance Attribute Summary collapse

Attributes inherited from Base

#cookies, #session_token

Instance Method Summary collapse

Methods inherited from Base

#delete, #get, #post

Constructor Details

#initialize(uuid, properties = {}) ⇒ Camera

Returns a new instance of Camera.



20
21
22
23
24
# File 'lib/dropcam/camera.rb', line 20

def initialize(uuid, properties={})
  @uuid = uuid
  @settings = {}
  self.properties = properties
end

Instance Attribute Details

#descriptionObject (readonly)

Returns the value of attribute description.



15
16
17
# File 'lib/dropcam/camera.rb', line 15

def description
  @description
end

#download_hostObject (readonly)

Returns the value of attribute download_host.



14
15
16
# File 'lib/dropcam/camera.rb', line 14

def download_host
  @download_host
end

#download_server_liveObject (readonly)

Returns the value of attribute download_server_live.



14
15
16
# File 'lib/dropcam/camera.rb', line 14

def download_server_live
  @download_server_live
end

#hours_of_recording_maxObject (readonly)

Returns the value of attribute hours_of_recording_max.



15
16
17
# File 'lib/dropcam/camera.rb', line 15

def hours_of_recording_max
  @hours_of_recording_max
end

#idObject (readonly)

Returns the value of attribute id.



16
17
18
# File 'lib/dropcam/camera.rb', line 16

def id
  @id
end

#is_connectedObject (readonly)

Returns the value of attribute is_connected.



15
16
17
# File 'lib/dropcam/camera.rb', line 15

def is_connected
  @is_connected
end

#is_onlineObject (readonly)

Returns the value of attribute is_online.



15
16
17
# File 'lib/dropcam/camera.rb', line 15

def is_online
  @is_online
end

#is_publicObject (readonly)

Returns the value of attribute is_public.



15
16
17
# File 'lib/dropcam/camera.rb', line 15

def is_public
  @is_public
end

#is_streamingObject (readonly)

Returns the value of attribute is_streaming.



14
15
16
# File 'lib/dropcam/camera.rb', line 14

def is_streaming
  @is_streaming
end

#notification_devicesObject (readonly)

Returns the value of attribute notification_devices.



14
15
16
# File 'lib/dropcam/camera.rb', line 14

def notification_devices
  @notification_devices
end

#owner_idObject (readonly)

Returns the value of attribute owner_id.



16
17
18
# File 'lib/dropcam/camera.rb', line 16

def owner_id
  @owner_id
end

#public_tokenObject (readonly)

Returns the value of attribute public_token.



14
15
16
# File 'lib/dropcam/camera.rb', line 14

def public_token
  @public_token
end

#settings(force = false) ⇒ Object

Returns the value of attribute settings.



17
18
19
# File 'lib/dropcam/camera.rb', line 17

def settings
  @settings
end

#timezoneObject (readonly)

Returns the value of attribute timezone.



15
16
17
# File 'lib/dropcam/camera.rb', line 15

def timezone
  @timezone
end

#timezone_utc_offsetObject (readonly)

Returns the value of attribute timezone_utc_offset.



15
16
17
# File 'lib/dropcam/camera.rb', line 15

def timezone_utc_offset
  @timezone_utc_offset
end

#titleObject (readonly)

Returns the value of attribute title.



14
15
16
# File 'lib/dropcam/camera.rb', line 14

def title
  @title
end

#typeObject (readonly)

Returns the value of attribute type.



16
17
18
# File 'lib/dropcam/camera.rb', line 16

def type
  @type
end

#uuidObject (readonly)

Returns the value of attribute uuid.



14
15
16
# File 'lib/dropcam/camera.rb', line 14

def uuid
  @uuid
end

Instance Method Details

#all_notification_devicesObject

API for Notifications doesn’t include email notifcations The code below parses an HTML Partial to get all notifcation values



224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
# File 'lib/dropcam/camera.rb', line 224

def all_notification_devices
  request_path = ::CAMERA_HTML_SETTINGS_BASE + @uuid
  response = get(request_path, {}, @cookies)      
  if response.success?
    raw_html = response.body
    doc = Hpricot.parse(raw_html)

    notifications = []
    doc.search("//div[@class='notification_target']").each { |notification_target|
      puts notification_target
      data_id =  notification_target.get_attribute("data-id")
      puts data_id
      name =  notification_target.at("div/span").inner_text
      
      input =  notification_target.at("div/input")

      attributes = input.attributes.to_hash
      data_type = attributes["data-type"]
      data_value = attributes["data-value"]
      checked = attributes.has_key?("checked")
      

      notifications.push(note)
    }
    return notifications
  elsif response.not_authorized?
    raise AuthorizationError 
  else 
    raise CameraNotFoundError 
  end
end

#clipsObject



51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/dropcam/camera.rb', line 51

def clips
  response = get(::CLIP_GET_ALL, {}, @cookies)      
  if response.success?
    return response.body ## returns a zip
    clips = []
    all_clips = JSON.parse(response.body)["items"]
    for clip in all_clips
      c = Clip.new(self, clip)
      if c.camera_id == self.id
        clips.push c
      end
    end
    return clips
  elsif response.not_authorized?
    raise AuthorizationError 
  else 
    raise CameraNotFoundError 
  end
end

#create_clip(length, start_date, title, description) ⇒ Object



72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/dropcam/camera.rb', line 72

def create_clip(length, start_date, title, description)
  params = {"uuid"=>@uuid, "length" => length, "start_date" => start_date, "title" => title, "description" => description}
  response = post(::VIDEOS_REQUEST, params, @cookies)      
  if response.success?
    clip_info = JSON.parse(response.body)["items"][0]
    return Clip.new(self, clip_info)
  elsif response.not_authorized?
    raise AuthorizationError 
  else 
    raise CameraNotFoundError 
  end
end

#current_image(width = 1200) ⇒ Object



47
48
49
# File 'lib/dropcam/camera.rb', line 47

def current_image(width=1200)
  return get_image(width)
end

#get_all_cuepoints(limit = 2500) ⇒ Object



110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
# File 'lib/dropcam/camera.rb', line 110

def get_all_cuepoints(limit=2500)
  params = {"uuid"=>@uuid, "max_results"=>limit}
  response = get(::NEXUS_GET_REVERSE_PAGINATED_CUEPOINTS_PATH, params, @cookies, true)      
  if response.success?
    cuepoints = []
    all_cuepoints = JSON.parse(response.body)
    for cuepoint in all_cuepoints
      cuepoints.push Cuepoint.new(cuepoint)
    end
    
    return cuepoints
  elsif response.not_authorized?
    raise AuthorizationError 
  else 
    raise CameraNotFoundError 
  end
end

#get_cuepoint(start_time) ⇒ Object



128
129
130
131
132
133
134
135
136
137
138
# File 'lib/dropcam/camera.rb', line 128

def get_cuepoint(start_time)
  params = {"uuid"=>@uuid, "start_time" => start_time}
  response = get(::NEXUS_GET_CUEPOINT_PATH, params, @cookies, true)      
  if response.success?
    return Cuepoint.new(JSON.parse(response.body)[0])        
  elsif response.not_authorized?
    raise AuthorizationError 
  else 
    raise CameraNotFoundError 
  end
end

#get_event_clip_image_archive(cuepoint_id, number_of_frames, width) ⇒ Object



86
87
88
89
90
91
92
93
94
95
96
# File 'lib/dropcam/camera.rb', line 86

def get_event_clip_image_archive(cuepoint_id, number_of_frames, width)      
  params = {"uuid"=>@uuid, "width" => width, "cuepoint_id" => cuepoint_id, "num_frames" => number_of_frames, "format" => "TAR_JPG"}
  response = get(::NEXUS_GET_EVENT_CLIP_PATH, params, @cookies, true)      
  if response.success?
    return response.body ## returns a zip
  elsif response.not_authorized?
    raise AuthorizationError 
  else 
    raise CameraNotFoundError 
  end
end

#get_event_clip_video(cuepoint_id, number_of_frames, width) ⇒ Object



98
99
100
101
102
103
104
105
106
107
108
# File 'lib/dropcam/camera.rb', line 98

def get_event_clip_video(cuepoint_id, number_of_frames, width)      
  params = {"uuid"=>@uuid, "width" => width, "cuepoint_id" => cuepoint_id, "num_frames" => number_of_frames, "format" => "h264"}
  response = get(::NEXUS_GET_EVENT_CLIP_PATH, params, @cookies, true)      
  if response.success?
    return response.body ## returns a zip
  elsif response.not_authorized?
    raise AuthorizationError 
  else 
    raise CameraNotFoundError 
  end
end

#get_image(width = 1200, timestamp = nil) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/dropcam/camera.rb', line 33

def get_image(width=1200, timestamp=nil)
  params = {"uuid"=>@uuid, "width" => width}
  params["time"] = timestamp if timestamp
  
  response = get(::IMAGE_PATH, params, @cookies, true)      
  if response.success?
    return response.body
  elsif response.not_authorized?
    raise AuthorizationError 
  else 
    raise CameraNotFoundError 
  end
end

#properties=(properties) ⇒ Object



26
27
28
29
30
# File 'lib/dropcam/camera.rb', line 26

def properties=(properties)
  properties.each{|key, value|
    instance_variable_set("@#{key}", value)
  }
end

#public=(is_public) ⇒ Object



153
154
155
156
157
158
159
160
161
162
# File 'lib/dropcam/camera.rb', line 153

def public=(is_public)
  response = post(::CAMERAS_UPDATE, {"uuid"=>@uuid, "is_public"=>is_public, "accepted_public_terms_at" => "true"}, @cookies)      
  if response.success?
    self.properties = JSON.parse(response.body)["items"][0]
  elsif response.not_authorized?
    raise AuthorizationError 
  else 
    raise CameraNotFoundError 
  end
end

#public?Boolean

Returns:

  • (Boolean)


164
165
166
# File 'lib/dropcam/camera.rb', line 164

def public?
  @is_public
end

#set_public_token(token) ⇒ Object



168
169
170
171
172
173
174
175
176
177
178
# File 'lib/dropcam/camera.rb', line 168

def set_public_token(token)
  response = post(::CAMERAS_UPDATE, {"uuid"=>@uuid, "token"=>token}, @cookies)      
  if response.success?
    self.properties = JSON.parse(response.body)["items"][0]
    return true
  elsif response.not_authorized?
    raise AuthorizationError 
  else 
    raise CameraNotFoundError 
  end
end

#streamObject



258
259
260
# File 'lib/dropcam/camera.rb', line 258

def stream
  Stream.new self
end

#update_infoObject



140
141
142
143
144
145
146
147
148
149
# File 'lib/dropcam/camera.rb', line 140

def update_info
  response = get(::CAMERAS_GET, {"id"=>@uuid}, @cookies)      
  if response.success?
    self.properties = JSON.parse(response.body)["items"][0]
  elsif response.not_authorized?
    raise AuthorizationError 
  else 
    raise CameraNotFoundError 
  end
end