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 CHANGED
@@ -1,2 +1,19 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
1
18
  test/fixtures/vcr_cassettes/
2
19
  test/aws.yml
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- all_seeing_pi (0.0.1)
4
+ all_seeing_pi (0.0.2)
5
5
  aws-sdk
6
6
 
7
7
  GEM
@@ -1,14 +1,14 @@
1
1
  require "all_seeing_pi/version"
2
- require "all_seeing_pi/palantir"
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
- palantir = AllSeeingPi::Palantir.new
8
+ golem = AllSeeingPi::Golem.new
9
9
 
10
10
  loop do
11
- palantir.spy
11
+ golem.spy
12
12
  end
13
13
  end
14
14
  end
@@ -2,7 +2,7 @@ require 'all_seeing_pi/camera'
2
2
  require 'all_seeing_pi/uploader'
3
3
 
4
4
  module AllSeeingPi
5
- class Palantir
5
+ class Golem
6
6
  attr_reader :camera, :uploader
7
7
 
8
8
  def initialize
@@ -2,7 +2,7 @@ require 'aws-sdk'
2
2
 
3
3
  module AllSeeingPi
4
4
  class Uploader
5
- BUCKET = 'all_seeing_pi'
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
- buckets.create(BUCKET) unless buckets[BUCKET].exists?
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[BUCKET].objects[filename].write(:file => image_path)
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
@@ -1,3 +1,3 @@
1
1
  module AllSeeingPi
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
@@ -1,32 +1,32 @@
1
1
  require 'test_helper'
2
2
 
3
- class PalantirTest < MiniTest::Unit::TestCase
3
+ class GolemTest < MiniTest::Unit::TestCase
4
4
  def setup
5
5
  @fixture = 'test/fixtures/eye_of_sauron.jpg'
6
- @palantir = AllSeeingPi::Palantir.new
6
+ @golem = AllSeeingPi::Golem.new
7
7
  end
8
8
 
9
9
  def test_spy_sends_capture_to_the_camera
10
- @palantir.stubs(:store_image)
10
+ @golem.stubs(:store_image)
11
11
  FileUtils.stubs(:rm)
12
12
 
13
- @palantir.camera.expects(:capture).returns(@fixture)
14
- @palantir.spy
13
+ @golem.camera.expects(:capture).returns(@fixture)
14
+ @golem.spy
15
15
  end
16
16
 
17
17
  def test_store_image
18
- @palantir.camera.stubs(:capture).returns(@fixture)
18
+ @golem.camera.stubs(:capture).returns(@fixture)
19
19
  FileUtils.stubs(:rm)
20
20
 
21
- @palantir.uploader.expects(:upload).with(@fixture)
22
- @palantir.spy
21
+ @golem.uploader.expects(:upload).with(@fixture)
22
+ @golem.spy
23
23
  end
24
24
 
25
25
  def test_spy_deletes_the_image
26
- @palantir.camera.stubs(:capture).returns(@fixture)
27
- @palantir.stubs(:store_image)
26
+ @golem.camera.stubs(:capture).returns(@fixture)
27
+ @golem.stubs(:store_image)
28
28
 
29
29
  FileUtils.expects(:rm).with(@fixture)
30
- @palantir.spy
30
+ @golem.spy
31
31
  end
32
32
  end
@@ -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('uploader') do
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.1
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-02 00:00:00.000000000 Z
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/palantir.rb
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