class Sonycam::CLI

Constants

DD_PATH

Public Instance Methods

api(method, *params) click to toggle source
# File lib/sonycam/cli.rb, line 48
def api method, *params
  puts api_client.request(method, *params).to_json
end
api_client() click to toggle source
# File lib/sonycam/cli.rb, line 61
def api_client
  return @api_client if @api_client.is_a? API
  unless File.exist?(DD_PATH)
    puts "Can not find #{DD_PATH}, start scanning..."
    invoke :scan, []
  end
  @api_client = API.new DeviceDescription.new(DD_PATH).api_url(:camera)
end
list(query = nil) click to toggle source
# File lib/sonycam/cli.rb, line 32
def list query = nil
  apis = api_client.request(:getAvailableApiList).first
  apis.select!{|method| method =~ /#{query}/i } if query
  puts apis
end
liveview() click to toggle source
# File lib/sonycam/cli.rb, line 53
def liveview
  liveview_url = api_client.request('startLiveview').first
  Liveview.stream(liveview_url) do |packet|
    puts packet[:payload_data][:jpeg_data]
  end
end
scan(ip = nil) click to toggle source
# File lib/sonycam/cli.rb, line 19
def scan ip = nil
  location = Scanner.scan(ip).first
  puts "Found location: #{location}"
  File.write File.join(DD_PATH), open(location).read
  puts "Device description file saved to #{DD_PATH}"
end