Class: Grandstream::Client
- Inherits:
-
Object
- Object
- Grandstream::Client
- Defined in:
- lib/grandstream/client.rb
Instance Attribute Summary collapse
-
#camera_ip ⇒ Object
Returns the value of attribute camera_ip.
Instance Method Summary collapse
- #base_url ⇒ Object
- #get(path) ⇒ Object
- #get_snapshot(image_path) ⇒ Object
- #http_request(url) ⇒ Object
-
#initialize(camera_ip) ⇒ Client
constructor
A new instance of Client.
- #load_options(path) ⇒ Object
- #set(path, params) ⇒ Object
- #set_options(path, options) ⇒ Object
- #snapshot_url ⇒ Object
Constructor Details
#initialize(camera_ip) ⇒ Client
Returns a new instance of Client.
9 10 11 |
# File 'lib/grandstream/client.rb', line 9 def initialize(camera_ip) @camera_ip = camera_ip end |
Instance Attribute Details
#camera_ip ⇒ Object
Returns the value of attribute camera_ip.
7 8 9 |
# File 'lib/grandstream/client.rb', line 7 def camera_ip @camera_ip end |
Instance Method Details
#base_url ⇒ Object
17 18 19 |
# File 'lib/grandstream/client.rb', line 17 def base_url "http://#{camera_ip}" end |
#get(path) ⇒ Object
25 26 27 28 |
# File 'lib/grandstream/client.rb', line 25 def get(path) url = "#{base_url}/goform/#{path}?cmd=get" open(url).read end |
#get_snapshot(image_path) ⇒ Object
21 22 23 |
# File 'lib/grandstream/client.rb', line 21 def get_snapshot(image_path) File.write(image_path, open(snapshot_url).read, {mode: 'wb'}) end |
#http_request(url) ⇒ Object
48 49 50 51 52 53 |
# File 'lib/grandstream/client.rb', line 48 def http_request(url) uri = URI url Net::HTTP.start(uri.host, uri.port) do |http| yield(http, uri) end end |
#load_options(path) ⇒ Object
39 40 41 42 43 44 45 46 |
# File 'lib/grandstream/client.rb', line 39 def (path) = {} get(path).split("\n").each do |line| vals = line.split('=') [vals[0]] = vals[1].chomp if vals[1] end end |
#set(path, params) ⇒ Object
30 31 32 33 34 35 36 37 |
# File 'lib/grandstream/client.rb', line 30 def set(path, params) url = "#{base_url}/goform/#{path}?cmd=set&#{params.map{|k,v| "#{k}=#{v}"}.join("&")}" http_request(url) do |http, uri| req = Net::HTTP::Get.new(uri) req.basic_auth 'admin', 'admin' response = http.request(req) end end |
#set_options(path, options) ⇒ Object
55 56 57 |
# File 'lib/grandstream/client.rb', line 55 def (path, ) set(path, ) end |
#snapshot_url ⇒ Object
13 14 15 |
# File 'lib/grandstream/client.rb', line 13 def snapshot_url "#{base_url}/snapshot/view0.jpg" end |