all_seeing_pi 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -16,4 +16,4 @@ test/tmp
16
16
  test/version_tmp
17
17
  tmp
18
18
  test/fixtures/vcr_cassettes/
19
- test/aws.yml
19
+ test/all_seeing_pi.yml
@@ -2,8 +2,22 @@ require "all_seeing_pi/version"
2
2
  require "all_seeing_pi/golem"
3
3
  require "all_seeing_pi/camera"
4
4
  require "all_seeing_pi/uploader"
5
+ require "all_seeing_pi/configuration"
5
6
 
6
7
  module AllSeeingPi
8
+ class << self
9
+ attr_accessor :config
10
+ end
11
+
12
+ def self.config
13
+ @config ||= Configuration.new
14
+ end
15
+
16
+ def self.configure
17
+ self.config ||= Configuration.new
18
+ yield(config)
19
+ end
20
+
7
21
  def self.watch
8
22
  golem = AllSeeingPi::Golem.new
9
23
 
@@ -0,0 +1,41 @@
1
+ module AllSeeingPi
2
+ class Configuration
3
+ attr_accessor :aws_key, :aws_secret, :redis_host, :redis_password
4
+
5
+ def initialize
6
+ reset!
7
+ load_config_from_file
8
+ end
9
+
10
+ def reset!
11
+ instance_variables.each do |var|
12
+ instance_variable_set(var, nil)
13
+ end
14
+ end
15
+
16
+ def [](key)
17
+ send(key)
18
+ end
19
+
20
+ def []=(key, value)
21
+ send("#{key}=", value)
22
+ end
23
+
24
+ def load_config_from_file(filename = 'all_seeing_pi.yml')
25
+ paths = [
26
+ "#{filename}",
27
+ "config/#{filename}"
28
+ ]
29
+
30
+ config = {}
31
+
32
+ paths.each do |filepath|
33
+ config = YAML.load_file(filepath) if File.exists?(filepath)
34
+ end
35
+
36
+ config.each do |key, value|
37
+ send("#{key}=", value)
38
+ end
39
+ end
40
+ end
41
+ end
@@ -8,6 +8,7 @@ module AllSeeingPi
8
8
 
9
9
  def initialize
10
10
  @s3 = AWS::S3.new
11
+ require 'pry'; binding.pry if $debug
11
12
  end
12
13
 
13
14
  def upload(image_path)
@@ -1,3 +1,3 @@
1
1
  module AllSeeingPi
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
@@ -0,0 +1,42 @@
1
+ require 'test_helper'
2
+
3
+ class AllSeeingPiTest < MiniTest::Unit::TestCase
4
+ def setup
5
+ @config = AllSeeingPi.config
6
+ end
7
+
8
+ def teardown
9
+ AllSeeingPi.config.reset!
10
+ end
11
+
12
+ def test_config_with_block
13
+ AllSeeingPi.configure do |config|
14
+ config.aws_key = 'test_config_with_block_aws_key'
15
+ end
16
+
17
+ assert_equal 'test_config_with_block_aws_key', AllSeeingPi.config[:aws_key]
18
+ end
19
+
20
+ def test_setting_config_directly
21
+ AllSeeingPi.config.aws_key = 'test_setting_config_directly_key'
22
+
23
+ assert_equal 'test_setting_config_directly_key', AllSeeingPi.config[:aws_key]
24
+ end
25
+
26
+ def test_resetting_config
27
+ AllSeeingPi.config.aws_key = 'test_resetting_config_key'
28
+ AllSeeingPi.config.reset!
29
+
30
+ assert_nil AllSeeingPi.config[:aws_key]
31
+ end
32
+
33
+ def test_that_config_merges_local_configuration_from_all_seeing_pi_yml
34
+ filename = 'all_seeing_pi.yml'
35
+ File.write(filename, "aws_key: 'test_config_merge_key'")
36
+ AllSeeingPi.config.load_config_from_file
37
+
38
+ assert_equal 'test_config_merge_key', AllSeeingPi.config[:aws_key]
39
+ ensure
40
+ FileUtils.rm(filename)
41
+ end
42
+ end
@@ -0,0 +1,18 @@
1
+ require 'test_helper'
2
+
3
+ class ConfigurationTest < MiniTest::Unit::TestCase
4
+ def setup
5
+ @config = AllSeeingPi.config
6
+ end
7
+
8
+ def test_load_config_from_file
9
+ filename = 'test_config.yml'
10
+ File.write(filename, "aws_key: totally_fake")
11
+
12
+ @config.load_config_from_file('test_config.yml')
13
+
14
+ assert_equal 'totally_fake', AllSeeingPi.config[:aws_key]
15
+ ensure
16
+ FileUtils.rm(filename)
17
+ end
18
+ end
@@ -10,6 +10,10 @@ VCR.configure do |c|
10
10
  c.hook_into :webmock
11
11
  end
12
12
 
13
- AWS.config(YAML.load_file('test/aws.yml'))
13
+ AllSeeingPi.config.load_config_from_file('test/all_seeing_pi.yml')
14
14
 
15
+ AWS.config(
16
+ access_key_id: AllSeeingPi.config[:aws_key],
17
+ secret_access_key: AllSeeingPi.config[:aws_secret]
18
+ )
15
19
  ENV['ALL_SEEING_PI_ENV'] = 'test'
@@ -21,4 +21,13 @@ class UploaderTest < MiniTest::Unit::TestCase
21
21
  assert_match /#{@bucket_name}/, name
22
22
  end
23
23
  end
24
+
25
+ def test_uploader_uses_credentials_from_config
26
+ AllSeeingPi.config[:aws_key] = 'test_key'
27
+ AllSeeingPi.config[:aws_secret] = 'test_secret'
28
+ uploader = AllSeeingPi::Uploader.new
29
+
30
+ key, secret = AllSeeingPi.config[:aws_key], AllSeeingPi.config[:aws_secret]
31
+ assert_equal ['test_key', 'test_secret'], [key, secret]
32
+ end
24
33
  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.2
4
+ version: 0.0.3
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-03 00:00:00.000000000 Z
12
+ date: 2014-11-05 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler
@@ -141,11 +141,14 @@ 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/configuration.rb
144
145
  - lib/all_seeing_pi/golem.rb
145
146
  - lib/all_seeing_pi/uploader.rb
146
147
  - lib/all_seeing_pi/version.rb
147
148
  - test/fixtures/eye_of_sauron.jpg
149
+ - test/test_all_seeing_pi.rb
148
150
  - test/test_camera.rb
151
+ - test/test_configuration.rb
149
152
  - test/test_helper.rb
150
153
  - test/test_palantir.rb
151
154
  - test/test_uploader.rb
@@ -176,7 +179,9 @@ specification_version: 3
176
179
  summary: A gem to capture images with a Raspberry Pi camera.
177
180
  test_files:
178
181
  - test/fixtures/eye_of_sauron.jpg
182
+ - test/test_all_seeing_pi.rb
179
183
  - test/test_camera.rb
184
+ - test/test_configuration.rb
180
185
  - test/test_helper.rb
181
186
  - test/test_palantir.rb
182
187
  - test/test_uploader.rb