all_seeing_pi 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +17 -0
- data/Gemfile.lock +1 -1
- data/lib/all_seeing_pi.rb +3 -3
- data/lib/all_seeing_pi/{palantir.rb → golem.rb} +1 -1
- data/lib/all_seeing_pi/uploader.rb +18 -3
- data/lib/all_seeing_pi/version.rb +1 -1
- data/test/test_palantir.rb +11 -11
- data/test/test_uploader.rb +11 -1
- metadata +3 -3
data/.gitignore
CHANGED
data/Gemfile.lock
CHANGED
data/lib/all_seeing_pi.rb
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
require "all_seeing_pi/version"
|
2
|
-
require "all_seeing_pi/
|
2
|
+
require "all_seeing_pi/golem"
|
3
3
|
require "all_seeing_pi/camera"
|
4
4
|
require "all_seeing_pi/uploader"
|
5
5
|
|
6
6
|
module AllSeeingPi
|
7
7
|
def self.watch
|
8
|
-
|
8
|
+
golem = AllSeeingPi::Golem.new
|
9
9
|
|
10
10
|
loop do
|
11
|
-
|
11
|
+
golem.spy
|
12
12
|
end
|
13
13
|
end
|
14
14
|
end
|
@@ -2,7 +2,7 @@ require 'aws-sdk'
|
|
2
2
|
|
3
3
|
module AllSeeingPi
|
4
4
|
class Uploader
|
5
|
-
|
5
|
+
BUCKET_PREFIX = 'all_seeing_pi'
|
6
6
|
|
7
7
|
attr_reader :s3
|
8
8
|
|
@@ -12,10 +12,25 @@ module AllSeeingPi
|
|
12
12
|
|
13
13
|
def upload(image_path)
|
14
14
|
buckets = s3.buckets
|
15
|
-
|
15
|
+
|
16
|
+
bucket_name = fetch_or_create_bucket_name(buckets)
|
17
|
+
buckets.create(bucket_name) unless buckets[bucket_name].exists?
|
16
18
|
|
17
19
|
filename = File.basename(image_path)
|
18
|
-
buckets[
|
20
|
+
buckets[bucket_name].objects[filename].write(:file => image_path)
|
21
|
+
end
|
22
|
+
|
23
|
+
def fetch_or_create_bucket_name(buckets)
|
24
|
+
bucket_name = buckets.map do |bucket|
|
25
|
+
name = bucket.name
|
26
|
+
name if name.match /all_seeing_pi/
|
27
|
+
end.compact.first
|
28
|
+
|
29
|
+
bucket_name ||= "#{BUCKET_PREFIX}_#{bucket_id}"
|
30
|
+
end
|
31
|
+
|
32
|
+
def bucket_id
|
33
|
+
Time.now.to_f.to_s.split('.').join.to_i
|
19
34
|
end
|
20
35
|
end
|
21
36
|
end
|
data/test/test_palantir.rb
CHANGED
@@ -1,32 +1,32 @@
|
|
1
1
|
require 'test_helper'
|
2
2
|
|
3
|
-
class
|
3
|
+
class GolemTest < MiniTest::Unit::TestCase
|
4
4
|
def setup
|
5
5
|
@fixture = 'test/fixtures/eye_of_sauron.jpg'
|
6
|
-
@
|
6
|
+
@golem = AllSeeingPi::Golem.new
|
7
7
|
end
|
8
8
|
|
9
9
|
def test_spy_sends_capture_to_the_camera
|
10
|
-
@
|
10
|
+
@golem.stubs(:store_image)
|
11
11
|
FileUtils.stubs(:rm)
|
12
12
|
|
13
|
-
@
|
14
|
-
@
|
13
|
+
@golem.camera.expects(:capture).returns(@fixture)
|
14
|
+
@golem.spy
|
15
15
|
end
|
16
16
|
|
17
17
|
def test_store_image
|
18
|
-
@
|
18
|
+
@golem.camera.stubs(:capture).returns(@fixture)
|
19
19
|
FileUtils.stubs(:rm)
|
20
20
|
|
21
|
-
@
|
22
|
-
@
|
21
|
+
@golem.uploader.expects(:upload).with(@fixture)
|
22
|
+
@golem.spy
|
23
23
|
end
|
24
24
|
|
25
25
|
def test_spy_deletes_the_image
|
26
|
-
@
|
27
|
-
@
|
26
|
+
@golem.camera.stubs(:capture).returns(@fixture)
|
27
|
+
@golem.stubs(:store_image)
|
28
28
|
|
29
29
|
FileUtils.expects(:rm).with(@fixture)
|
30
|
-
@
|
30
|
+
@golem.spy
|
31
31
|
end
|
32
32
|
end
|
data/test/test_uploader.rb
CHANGED
@@ -3,12 +3,22 @@ require 'test_helper'
|
|
3
3
|
class UploaderTest < MiniTest::Unit::TestCase
|
4
4
|
def setup
|
5
5
|
@fixture = 'test/fixtures/eye_of_sauron.jpg'
|
6
|
+
@filename = File.basename(@fixture)
|
6
7
|
@uploader = AllSeeingPi::Uploader.new
|
8
|
+
@bucket_name = AllSeeingPi::Uploader::BUCKET_PREFIX
|
7
9
|
end
|
8
10
|
|
9
11
|
def test_upload
|
10
|
-
VCR.use_cassette('
|
12
|
+
VCR.use_cassette('uploader_test_upload') do
|
11
13
|
@uploader.upload(@fixture)
|
14
|
+
assert @uploader.s3.buckets[@bucket_name].objects[@filename].exists?, "#{@fixture} was not uploaded."
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def test_fetch_or_create_bucket_name
|
19
|
+
VCR.use_cassette('uploader_test_fetch_or_create_bucket_name') do
|
20
|
+
name = @uploader.fetch_or_create_bucket_name(@uploader.s3.buckets)
|
21
|
+
assert_match /#{@bucket_name}/, name
|
12
22
|
end
|
13
23
|
end
|
14
24
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: all_seeing_pi
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2014-11-
|
12
|
+
date: 2014-11-03 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|
@@ -141,7 +141,7 @@ files:
|
|
141
141
|
- capture.sh
|
142
142
|
- lib/all_seeing_pi.rb
|
143
143
|
- lib/all_seeing_pi/camera.rb
|
144
|
-
- lib/all_seeing_pi/
|
144
|
+
- lib/all_seeing_pi/golem.rb
|
145
145
|
- lib/all_seeing_pi/uploader.rb
|
146
146
|
- lib/all_seeing_pi/version.rb
|
147
147
|
- test/fixtures/eye_of_sauron.jpg
|