snapme 0.2.0 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/snapme/snapper.rb +19 -10
- data/lib/snapme/version.rb +1 -1
- data/spec/lib/snapme/snapper_spec.rb +13 -8
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: abdae2cc364480149efdfdc721b199aa8678a01c
|
4
|
+
data.tar.gz: 4683b97c1f6429fdb24026d7527247e609238dce
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6b29d82a52e106bbeaaab70c60be2b20b6244a5bce533f68add7e409db4b3331b5e735b1f8c484487d805191657d5976ee00521dbd39ee0af8b125bc4dafa354
|
7
|
+
data.tar.gz: 95b86e4d1131b28d5e35566393159a8aa882c15299916bf07d66ae9e07ede085b57b96be84cd3dfd6edc762ef37f60000359e3883bd19b3cc5d33bcb0b4f7238
|
data/lib/snapme/snapper.rb
CHANGED
@@ -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
|
-
@
|
9
|
-
@
|
10
|
-
@
|
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(
|
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
|
47
|
-
Curl::PostField.content(
|
55
|
+
def auth_token_field
|
56
|
+
Curl::PostField.content(auth_token_field_name, auth_token)
|
48
57
|
end
|
49
58
|
|
50
|
-
def
|
51
|
-
Curl::PostField.file(
|
59
|
+
def file_field
|
60
|
+
Curl::PostField.file(file_field_name, filename)
|
52
61
|
end
|
53
62
|
end
|
54
63
|
end
|
data/lib/snapme/version.rb
CHANGED
@@ -1,11 +1,12 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Snapme::Snapper do
|
4
|
-
let(:host)
|
5
|
-
let(:interval){ double :interval }
|
6
|
-
let(:
|
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
|
19
|
-
file
|
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.
|
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
|