lib/snapme/snapper.rb in snapme-0.2.0 vs lib/snapme/snapper.rb in snapme-0.2.1
- old
+ new
@@ -1,15 +1,16 @@
require 'curb'
module Snapme
class Snapper
- attr_reader :command, :host, :interval
+ attr_reader :auth_token, :command, :host, :interval
- def initialize(host, interval, command = ImagesnapCommand.new)
- @command = command
- @host = host
- @interval = interval
+ def initialize(host, interval, auth_token = ENV['SNAPME_AUTH_TOKEN'], command = ImagesnapCommand.new)
+ @auth_token = auth_token
+ @command = command
+ @host = host
+ @interval = interval
end
def run(looping = true)
loop do
take_snapshot
@@ -21,10 +22,18 @@
def endpoint_url
"#{host}/snapshot"
end
+ def auth_token_field_name
+ 'auth_token'
+ end
+
+ def file_field_name
+ 'snapshot'
+ end
+
def filename
'/tmp/snapshot.jpg'
end
private
@@ -32,23 +41,23 @@
def take_snapshot
command.call(filename)
end
def post_snapshot
- curl.http_post(file, auth_token)
+ curl.http_post(file_field, auth_token_field)
end
def curl
@curl ||= Curl::Easy.new(endpoint_url).tap do |curl|
curl.multipart_form_post = true
end
end
- def auth_token
- Curl::PostField.content('auth_token', ENV['AUTH_TOKEN'])
+ def auth_token_field
+ Curl::PostField.content(auth_token_field_name, auth_token)
end
- def file
- Curl::PostField.file('snapshot', filename)
+ def file_field
+ Curl::PostField.file(file_field_name, filename)
end
end
end