class Grandstream::Client

Attributes

camera_ip[RW]

Public Class Methods

new(camera_ip) click to toggle source
# File lib/grandstream/client.rb, line 9
def initialize(camera_ip)
    @camera_ip  = camera_ip
end

Public Instance Methods

base_url() click to toggle source
# File lib/grandstream/client.rb, line 17
def base_url 
    "http://#{camera_ip}"
end
get(path) click to toggle source
# 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) click to toggle source
# 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) { |http, uri| ... } click to toggle source
# 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) click to toggle source
# File lib/grandstream/client.rb, line 39
def load_options(path)
    options_hash = {}
    get(path).split("\n").each do |line|
        vals = line.split('=')
        options_hash[vals[0]] = vals[1].chomp if vals[1]
    end
    options_hash
end
set(path, params) click to toggle source
# 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) click to toggle source
# File lib/grandstream/client.rb, line 55
def set_options(path, options)
    set(path, options)
end
snapshot_url() click to toggle source
# File lib/grandstream/client.rb, line 13
def snapshot_url
    "#{base_url}/snapshot/view0.jpg"
end