snapme 0.1.0

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: d4d44dde969d381544e81572d3c00fff16106200
4
+ data.tar.gz: 1955f8dd7c68818c2efaafb4e2d7f6542a97680b
5
+ SHA512:
6
+ metadata.gz: 9863d5d1c37cbf3b964e8ed8524bf41ac98f4ec3f5166eec62e8137ad6604cf7ba3be219276d6ccf71bf4a4c64a782e8101a289f776836d4012467794f0688e2
7
+ data.tar.gz: f94ba67de95e43e497e2a9e1a8db5b6d81844e19fcbc4033103b2beec4d8e7260d523841a3c3e3eac0794786e8465f14e2cb01f13fca43aa300e385f8ef20cf0
data/.gitignore ADDED
@@ -0,0 +1,3 @@
1
+ .ruby-gemset
2
+ .ruby-version
3
+ Gemfile.lock
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
data/Gemfile ADDED
@@ -0,0 +1,2 @@
1
+ source 'https://rubygems.org'
2
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Jay Hayes
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,30 @@
1
+ snapme
2
+ ======
3
+
4
+ A small daemon process that takes a snapshot of you at a given interval and
5
+ posts it to Snapme for all your team to see!
6
+
7
+ Requrirements
8
+ -------------
9
+
10
+ * Mac OS X
11
+ * Image capture devise (ex. iSight camera)
12
+ * Ruby 2.0 *
13
+
14
+ \* Note: I got fancy with Ruby 2.0's keyword arguments... This was probably a
15
+ bad choice for a general purchase library. Complain at me and it will be fixed.
16
+
17
+ Installation
18
+ ------------
19
+
20
+ ```bash
21
+ gem install snapme
22
+ ```
23
+
24
+ Usage
25
+ -----
26
+
27
+ ```bash
28
+ $ snapme # process will be daemonized
29
+ $ snapme -h # to print the command line options
30
+ ```
data/bin/imagesnap ADDED
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env ruby
2
+ `vendor/imagesnap`
data/bin/snapme ADDED
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'snapme'
4
+ Snapme::CLI::Command.start(ARGV.dup)
@@ -0,0 +1,11 @@
1
+ module Snapme
2
+ module CLI
3
+ class Command
4
+ def self.start(args)
5
+ options = Options.parse(args)
6
+ Process.daemon(true) if options.daemon
7
+ Snapper.new(options.host, options.interval).run
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,45 @@
1
+ require 'optparse'
2
+
3
+ module Snapme
4
+ module CLI
5
+ class Options
6
+ DEFAULT_HOST = 'http://snapme.herokuapp.com'
7
+ DEFAULT_INTERVAL = 30 #seconds
8
+
9
+ attr_reader :daemon, :host, :interval
10
+
11
+ def initialize(daemon: true, host: DEFAULT_HOST, interval: DEFAULT_INTERVAL)
12
+ @daemon = !!(daemon)
13
+ @host = host
14
+ @interval = interval.to_i
15
+ end
16
+
17
+ def self.parse(args)
18
+ options = {}
19
+
20
+ OptionParser.new do |opts|
21
+ opts.banner = 'Usage: snapme [options]'
22
+
23
+ opts.on('-h', '--help', 'Show this message') do
24
+ puts opts
25
+ exit
26
+ end
27
+
28
+ opts.on('-H', '--host [URL]', 'Snapme service web address') do |url|
29
+ options[:host] = url
30
+ end
31
+
32
+ opts.on('-d', '--[no-]daemon', 'Daemonize process') do |daemon|
33
+ options[:daemon] = daemon
34
+ end
35
+
36
+ opts.on('-i', '--interval [SECONDS]', 'Snapshot interval') do |seconds|
37
+ options[:interval] = seconds
38
+ end
39
+ end.parse!(args)
40
+
41
+ new(options)
42
+ end
43
+ end
44
+ end
45
+ end
data/lib/snapme/cli.rb ADDED
@@ -0,0 +1,2 @@
1
+ require 'snapme/cli/command'
2
+ require 'snapme/cli/options'
@@ -0,0 +1,13 @@
1
+ module Snapme
2
+ class ImagesnapCommand
3
+ def call(filename)
4
+ `#{command_name} #{filename}`
5
+ end
6
+
7
+ private
8
+
9
+ def command_name
10
+ 'imagesnap'
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,52 @@
1
+ require 'curb'
2
+
3
+ module Snapme
4
+ class Snapper
5
+ attr_reader :command, :host, :interval
6
+
7
+ def initialize(host, interval, command = ImagesnapCommand.new)
8
+ @command = command
9
+ @host = host
10
+ @interval = interval
11
+ end
12
+
13
+ def run(looping = true)
14
+ loop do
15
+ take_snapshot
16
+ post_snapshot
17
+ break unless looping
18
+ sleep(interval)
19
+ end
20
+ end
21
+
22
+ def endpoint_url
23
+ "#{host}/users/1/snapshot"
24
+ end
25
+
26
+ def field_name
27
+ 'snapshot'
28
+ end
29
+
30
+ def filename
31
+ '/tmp/snapshot.jpg'
32
+ end
33
+
34
+ private
35
+
36
+ def take_snapshot
37
+ command.call(filename)
38
+ end
39
+
40
+ def post_snapshot
41
+ curl.http_post(file)
42
+ end
43
+
44
+ def curl
45
+ @curl ||= Curl::Easy.new(endpoint_url)
46
+ end
47
+
48
+ def file
49
+ Curl::PostField.file(field_name, filename)
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,12 @@
1
+ module Snapme
2
+ module Version
3
+ MAJOR = 0
4
+ MINOR = 1
5
+ PATCH = 0
6
+ PRE = nil
7
+
8
+ def self.to_s
9
+ [MAJOR, MINOR, PATCH, PRE].compact.join('.')
10
+ end
11
+ end
12
+ end
data/lib/snapme.rb ADDED
@@ -0,0 +1,4 @@
1
+ require 'snapme/cli'
2
+ require 'snapme/imagesnap_command'
3
+ require 'snapme/snapper'
4
+ require 'snapme/version'
data/snapme.gemspec ADDED
@@ -0,0 +1,22 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $LOAD_PATH.unshift File.expand_path("../lib", __FILE__)
3
+ require 'snapme/version'
4
+
5
+ Gem::Specification.new do |gem|
6
+ gem.name = 'snapme'
7
+ gem.version = Snapme::Version
8
+ gem.authors = ['Jay Hayes']
9
+ gem.email = ['ur@iamvery.com']
10
+ gem.description = %q{Share yourself with your team}
11
+ gem.summary = %q{Share yourself with your team}
12
+ gem.homepage = 'https://github.com/iamvery/snapme'
13
+ gem.license = 'MIT'
14
+
15
+ gem.files = `git ls-files`.split($/)
16
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
17
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
+ gem.require_paths = %w(lib)
19
+
20
+ gem.add_dependency 'curb', '~>0.8'
21
+ gem.add_development_dependency 'rspec', '~>2.14'
22
+ end
@@ -0,0 +1,44 @@
1
+ require 'spec_helper'
2
+ require 'ostruct'
3
+
4
+ describe Snapme::CLI::Command do
5
+ describe '.start' do
6
+ let(:args) { double :args }
7
+ let(:options){ OpenStruct.new }
8
+ let(:snapper){ double('Snapme::Snapper').as_null_object }
9
+
10
+ before do
11
+ allow(Snapme::CLI::Options).to receive(:parse).and_return(options)
12
+ allow(Snapme::Snapper).to receive(:new).and_return(snapper)
13
+ end
14
+
15
+ it 'parses options from the arguments' do
16
+ expect(Snapme::CLI::Options).to receive(:parse).with(args)
17
+ described_class.start(args)
18
+ end
19
+
20
+ it 'daemonizes the process if option is true' do
21
+ options.daemon = true
22
+ expect(Process).to receive(:daemon).with(true)
23
+ described_class.start(args)
24
+ end
25
+
26
+ it 'does not daemonize the process if option is false' do
27
+ expect(Process).to_not receive(:daemon)
28
+ described_class.start(args)
29
+ end
30
+
31
+ it 'runs a snapper' do
32
+ host = double :host
33
+ interval = double :interval
34
+ options.host = host
35
+ options.interval = interval
36
+ snapper = double 'Snapme::Snapper'
37
+
38
+ expect(Snapme::Snapper).to receive(:new).with(host, interval).and_return(snapper)
39
+ expect(snapper).to receive(:run)
40
+
41
+ described_class.start(args)
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,94 @@
1
+ require 'spec_helper'
2
+
3
+ describe Snapme::CLI::Options do
4
+ describe 'default values' do
5
+ subject(:options){ described_class.new }
6
+
7
+ it 'set daemon to true' do
8
+ expect(options.daemon).to be_true
9
+ end
10
+
11
+ it 'has default host' do
12
+ expect(options.host).to eq(described_class::DEFAULT_HOST)
13
+ end
14
+
15
+ it 'has default interval' do
16
+ expect(options.interval).to eq(described_class::DEFAULT_INTERVAL)
17
+ end
18
+ end
19
+
20
+ describe 'intialization' do
21
+ it 'sets daemon to truthy value' do
22
+ options = described_class.new(daemon: 'something truthy')
23
+ expect(options.daemon).to be_true
24
+ end
25
+
26
+ it 'sets the host' do
27
+ host = double :host
28
+ options = described_class.new(host: host)
29
+ expect(options.host).to eq(host)
30
+ end
31
+
32
+ it 'sets the interval to integer value' do
33
+ integer = 123
34
+ interval = "#{integer}abc"
35
+ options = described_class.new(interval: interval)
36
+ expect(options.interval).to eq(integer)
37
+ end
38
+ end
39
+
40
+ describe '.parse' do
41
+ it 'handles --host option' do
42
+ host = 'http://example.com'
43
+ args = %W(--host #{host})
44
+ options = described_class.parse(args)
45
+
46
+ expect(options.host).to eq(host)
47
+ end
48
+
49
+ it 'handles -H (host alias) option' do
50
+ host = 'http://example.com'
51
+ args = %W(-H #{host})
52
+ options = described_class.parse(args)
53
+
54
+ expect(options.host).to eq(host)
55
+ end
56
+
57
+ it 'handles --daemon option' do
58
+ args = %w(--daemon)
59
+ options = described_class.parse(args)
60
+
61
+ expect(options.daemon).to be_true
62
+ end
63
+
64
+ it 'handles --no-daemon option' do
65
+ args = %w(--no-daemon)
66
+ options = described_class.parse(args)
67
+
68
+ expect(options.daemon).to be_false
69
+ end
70
+
71
+ it 'handles -d (daemon alias) option' do
72
+ args = %w(-d)
73
+ options = described_class.parse(args)
74
+
75
+ expect(options.daemon).to be_true
76
+ end
77
+
78
+ it 'handles --interval option' do
79
+ interval = 123
80
+ args = %W(--interval #{interval})
81
+ options = described_class.parse(args)
82
+
83
+ expect(options.interval).to eq(interval)
84
+ end
85
+
86
+ it 'handles -i (interval alias) option' do
87
+ interval = 123
88
+ args = %W(-i #{interval})
89
+ options = described_class.parse(args)
90
+
91
+ expect(options.interval).to eq(interval)
92
+ end
93
+ end
94
+ end
@@ -0,0 +1,32 @@
1
+ require 'spec_helper'
2
+
3
+ describe Snapme::Snapper do
4
+ let(:host) { 'http://example.com' }
5
+ let(:interval){ double :interval }
6
+ let(:command) { double :command }
7
+
8
+ subject(:snapper){ described_class.new(host, interval, command) }
9
+
10
+ describe '#run' do
11
+ it 'takes a snapshot' do
12
+ expect(command).to receive(:call).with(snapper.filename)
13
+ snapper.run(false) # do not loop
14
+ end
15
+
16
+ it 'posts the snapshot to the web' do
17
+ allow(command).to receive(:call)
18
+ curl = double 'Curl::Easy'
19
+ file = double 'Curl::PostField'
20
+
21
+ # Hint: The number of mocks here is probably a hint that we're missing an
22
+ # object. I'm willing to accept this for now...
23
+ expect(Curl::Easy).to receive(:new).with(snapper.endpoint_url).and_return(curl)
24
+ expect(Curl::PostField).to receive(:file)
25
+ .with(snapper.field_name, snapper.filename)
26
+ .and_return(file)
27
+ expect(curl).to receive(:http_post).with(file)
28
+
29
+ snapper.run(false)
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,6 @@
1
+ $:.unshift '../lib'
2
+ require 'snapme'
3
+
4
+ RSpec.configure do |config|
5
+ config.order = 'random'
6
+ end
data/vendor/imagesnap ADDED
Binary file
metadata ADDED
@@ -0,0 +1,98 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: snapme
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Jay Hayes
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-07-17 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: curb
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '0.8'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '0.8'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rspec
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: '2.14'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: '2.14'
41
+ description: Share yourself with your team
42
+ email:
43
+ - ur@iamvery.com
44
+ executables:
45
+ - imagesnap
46
+ - snapme
47
+ extensions: []
48
+ extra_rdoc_files: []
49
+ files:
50
+ - .gitignore
51
+ - .rspec
52
+ - Gemfile
53
+ - LICENSE
54
+ - README.md
55
+ - bin/imagesnap
56
+ - bin/snapme
57
+ - lib/snapme.rb
58
+ - lib/snapme/cli.rb
59
+ - lib/snapme/cli/command.rb
60
+ - lib/snapme/cli/options.rb
61
+ - lib/snapme/imagesnap_command.rb
62
+ - lib/snapme/snapper.rb
63
+ - lib/snapme/version.rb
64
+ - snapme.gemspec
65
+ - spec/lib/snapme/cli/command_spec.rb
66
+ - spec/lib/snapme/cli/options_spec.rb
67
+ - spec/lib/snapme/snapper_spec.rb
68
+ - spec/spec_helper.rb
69
+ - vendor/imagesnap
70
+ homepage: https://github.com/iamvery/snapme
71
+ licenses:
72
+ - MIT
73
+ metadata: {}
74
+ post_install_message:
75
+ rdoc_options: []
76
+ require_paths:
77
+ - lib
78
+ required_ruby_version: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ required_rubygems_version: !ruby/object:Gem::Requirement
84
+ requirements:
85
+ - - '>='
86
+ - !ruby/object:Gem::Version
87
+ version: '0'
88
+ requirements: []
89
+ rubyforge_project:
90
+ rubygems_version: 2.0.3
91
+ signing_key:
92
+ specification_version: 4
93
+ summary: Share yourself with your team
94
+ test_files:
95
+ - spec/lib/snapme/cli/command_spec.rb
96
+ - spec/lib/snapme/cli/options_spec.rb
97
+ - spec/lib/snapme/snapper_spec.rb
98
+ - spec/spec_helper.rb