snapme 0.2.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c37aefde28b96f4f670041ca1ecd9485d2761fd7
4
- data.tar.gz: b261506d6c38a79484cbc6c80262bcfb647ac7eb
3
+ metadata.gz: abdae2cc364480149efdfdc721b199aa8678a01c
4
+ data.tar.gz: 4683b97c1f6429fdb24026d7527247e609238dce
5
5
  SHA512:
6
- metadata.gz: 327af7600aba44c960e8f41de9e9d46afede5151ab991e2875c989d0bad00b3678aadf93aea5c9bb0e31309b12f112ffb962a3816257820e747633778350a390
7
- data.tar.gz: 384851802554a71b7b56c412e4d15206a79afb13a74ec11c8fd3a604674df09d912aefd3738034387bb3a761cf626f89289421d31cb6b352aaa601828088b084
6
+ metadata.gz: 6b29d82a52e106bbeaaab70c60be2b20b6244a5bce533f68add7e409db4b3331b5e735b1f8c484487d805191657d5976ee00521dbd39ee0af8b125bc4dafa354
7
+ data.tar.gz: 95b86e4d1131b28d5e35566393159a8aa882c15299916bf07d66ae9e07ede085b57b96be84cd3dfd6edc762ef37f60000359e3883bd19b3cc5d33bcb0b4f7238
@@ -2,12 +2,13 @@ require 'curb'
2
2
 
3
3
  module Snapme
4
4
  class Snapper
5
- attr_reader :command, :host, :interval
5
+ attr_reader :auth_token, :command, :host, :interval
6
6
 
7
- def initialize(host, interval, command = ImagesnapCommand.new)
8
- @command = command
9
- @host = host
10
- @interval = interval
7
+ def initialize(host, interval, auth_token = ENV['SNAPME_AUTH_TOKEN'], command = ImagesnapCommand.new)
8
+ @auth_token = auth_token
9
+ @command = command
10
+ @host = host
11
+ @interval = interval
11
12
  end
12
13
 
13
14
  def run(looping = true)
@@ -23,6 +24,14 @@ module Snapme
23
24
  "#{host}/snapshot"
24
25
  end
25
26
 
27
+ def auth_token_field_name
28
+ 'auth_token'
29
+ end
30
+
31
+ def file_field_name
32
+ 'snapshot'
33
+ end
34
+
26
35
  def filename
27
36
  '/tmp/snapshot.jpg'
28
37
  end
@@ -34,7 +43,7 @@ module Snapme
34
43
  end
35
44
 
36
45
  def post_snapshot
37
- curl.http_post(file, auth_token)
46
+ curl.http_post(file_field, auth_token_field)
38
47
  end
39
48
 
40
49
  def curl
@@ -43,12 +52,12 @@ module Snapme
43
52
  end
44
53
  end
45
54
 
46
- def auth_token
47
- Curl::PostField.content('auth_token', ENV['AUTH_TOKEN'])
55
+ def auth_token_field
56
+ Curl::PostField.content(auth_token_field_name, auth_token)
48
57
  end
49
58
 
50
- def file
51
- Curl::PostField.file('snapshot', filename)
59
+ def file_field
60
+ Curl::PostField.file(file_field_name, filename)
52
61
  end
53
62
  end
54
63
  end
@@ -2,7 +2,7 @@ module Snapme
2
2
  module Version
3
3
  MAJOR = 0
4
4
  MINOR = 2
5
- PATCH = 0
5
+ PATCH = 1
6
6
  PRE = nil
7
7
 
8
8
  def self.to_s
@@ -1,11 +1,12 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Snapme::Snapper do
4
- let(:host) { 'http://example.com' }
5
- let(:interval){ double :interval }
6
- let(:command) { double :command }
4
+ let(:host) { 'http://example.com' }
5
+ let(:interval) { double :interval }
6
+ let(:auth_token){ double :auth_token }
7
+ let(:command) { double :command }
7
8
 
8
- subject(:snapper){ described_class.new(host, interval, command) }
9
+ subject(:snapper){ described_class.new(host, interval, auth_token, command) }
9
10
 
10
11
  describe '#run' do
11
12
  it 'takes a snapshot' do
@@ -15,17 +16,21 @@ describe Snapme::Snapper do
15
16
 
16
17
  it 'posts the snapshot to the web' do
17
18
  allow(command).to receive(:call)
18
- curl = double 'Curl::Easy'
19
- file = double 'Curl::PostField'
19
+ curl = double 'Curl::Easy'
20
+ file = double 'Curl::PostField - file'
21
+ token = double 'Curl::PostField - token'
20
22
 
21
23
  # Hint: The number of mocks here is probably a hint that we're missing an
22
24
  # object. I'm willing to accept this for now...
23
25
  expect(Curl::Easy).to receive(:new).with(snapper.endpoint_url).and_return(curl)
24
26
  expect(Curl::PostField).to receive(:file)
25
- .with(snapper.field_name, snapper.filename)
27
+ .with(snapper.file_field_name, snapper.filename)
26
28
  .and_return(file)
29
+ expect(Curl::PostField).to receive(:content)
30
+ .with(snapper.auth_token_field_name, auth_token)
31
+ .and_return(token)
27
32
  expect(curl).to receive(:multipart_form_post=).with(true)
28
- expect(curl).to receive(:http_post).with(file)
33
+ expect(curl).to receive(:http_post).with(file, token)
29
34
 
30
35
  snapper.run(false)
31
36
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: snapme
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jay Hayes