class Snapme::Snapper

Attributes

auth_token[R]
command[R]
host[R]
interval[R]

Public Class Methods

new(host, interval, auth_token, command = ImagesnapCommand.new) click to toggle source
# File lib/snapme/snapper.rb, line 7
def initialize(host, interval, auth_token, command = ImagesnapCommand.new)
  @auth_token = auth_token
  @command    = command
  @host       = host
  @interval   = interval
end

Public Instance Methods

auth_token_field_name() click to toggle source
# File lib/snapme/snapper.rb, line 27
def auth_token_field_name
  'auth_token'
end
endpoint_url() click to toggle source
# File lib/snapme/snapper.rb, line 23
def endpoint_url
  "#{host}/snapshot"
end
file_field_name() click to toggle source
# File lib/snapme/snapper.rb, line 31
def file_field_name
  'snapshot'
end
filename() click to toggle source
# File lib/snapme/snapper.rb, line 35
def filename
  '/tmp/snapshot.jpg'
end
run(looping = true) click to toggle source
# File lib/snapme/snapper.rb, line 14
def run(looping = true)
  loop do
    take_snapshot
    post_snapshot
    break unless looping
    sleep(interval)
  end
end

Private Instance Methods

auth_token_field() click to toggle source
# File lib/snapme/snapper.rb, line 55
def auth_token_field
  Curl::PostField.content(auth_token_field_name, auth_token)
end
curl() click to toggle source
# File lib/snapme/snapper.rb, line 49
def curl
  @curl ||= Curl::Easy.new(endpoint_url).tap do |curl|
    curl.multipart_form_post = true
  end
end
file_field() click to toggle source
# File lib/snapme/snapper.rb, line 59
def file_field
  Curl::PostField.file(file_field_name, filename)
end
post_snapshot() click to toggle source
# File lib/snapme/snapper.rb, line 45
def post_snapshot
  curl.http_post(file_field, auth_token_field)
end
take_snapshot() click to toggle source
# File lib/snapme/snapper.rb, line 41
def take_snapshot
  command.call(filename)
end