Class: Dropcam::Dropcam

Inherits:
Base
  • Object
show all
Defined in:
lib/dropcam.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(username, password) ⇒ Dropcam

Returns a new instance of Dropcam.



9
10
11
12
13
# File 'lib/dropcam.rb', line 9

def initialize(username, password)
  @session = Session.new(username, password)
  @session.authenticate
  ## 
end

Instance Attribute Details

#sessionObject (readonly)

Returns the value of attribute session.



8
9
10
# File 'lib/dropcam.rb', line 8

def session
  @session
end

Instance Method Details

#camera(uuid) ⇒ Object



14
15
16
17
18
19
20
# File 'lib/dropcam.rb', line 14

def camera(uuid)
  c = Camera.new(uuid)
  c.cookies = @session.cookies
  c.session_token = @session.session_token
  c.properties = c.info      
  c
end

#camerasObject



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/dropcam.rb', line 49

def cameras      
  response = get(::CAMERAS_GET_VISIBLE, {"group_cameras" => true}, @session.cookies)
  cameras = []
  if response.success?
    response_json = JSON.parse(response.body)
    owned = response_json["items"][0]["owned"]
    owned.each{|camera|
      c = Camera.new(camera["uuid"], camera)
      c.cookies = @session.cookies
      c.session_token = @session.session_token
      cameras.push(c)
    }
  end
  return cameras
end

#get_public_camera(token) ⇒ Object



22
23
24
25
26
27
28
29
30
31
# File 'lib/dropcam.rb', line 22

def get_public_camera(token)
  response = get(::CAMERAS_GET_BY_PUBLIC_TOKEN, {"token"=>token, "return_deleted"=>true}, @session.cookies)      
  if response.success?
    return response.body
  elsif response.not_authorized?
    raise AuthorizationError 
  else 
    raise CameraNotFoundError 
  end
end

#public_camerasObject



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

def public_cameras      
  response = get(::CAMERAS_GET_PUBLIC, {}, @session.cookies)
  cameras = []
  if response.success?
    response_json = JSON.parse(response.body)
    owned = response_json["items"][0]["owned"]
    owned.each{|camera|
      c = Camera.new(camera["uuid"], camera)
      c.cookies = @session.cookies
      c.session_token = @session.session_token
      cameras.push(c)
    }
  end
  return cameras
end