arduino_build_notifier 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1 @@
1
+ pkg/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source :rubygems
2
+
3
+ gemspec
4
+
data/Gemfile.lock ADDED
@@ -0,0 +1,44 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ arduino_build_notifier (0.0.1)
5
+ celluloid
6
+ dino
7
+ gli
8
+ httparty
9
+ nokogiri
10
+
11
+ GEM
12
+ remote: http://rubygems.org/
13
+ specs:
14
+ celluloid (0.12.3)
15
+ facter (>= 1.6.12)
16
+ timers (>= 1.0.0)
17
+ diff-lcs (1.1.3)
18
+ dino (0.8)
19
+ serialport
20
+ facter (1.6.14)
21
+ gli (2.4.1)
22
+ httparty (0.9.0)
23
+ multi_json (~> 1.0)
24
+ multi_xml
25
+ multi_json (1.3.7)
26
+ multi_xml (0.5.1)
27
+ nokogiri (1.5.5)
28
+ rspec (2.11.0)
29
+ rspec-core (~> 2.11.0)
30
+ rspec-expectations (~> 2.11.0)
31
+ rspec-mocks (~> 2.11.0)
32
+ rspec-core (2.11.1)
33
+ rspec-expectations (2.11.3)
34
+ diff-lcs (~> 1.1.3)
35
+ rspec-mocks (2.11.3)
36
+ serialport (1.1.0)
37
+ timers (1.0.1)
38
+
39
+ PLATFORMS
40
+ ruby
41
+
42
+ DEPENDENCIES
43
+ arduino_build_notifier!
44
+ rspec
data/README.md ADDED
@@ -0,0 +1,26 @@
1
+ # Arduino Build Notifier
2
+
3
+ A Continuous Integration Server Monitor made it over an Arduino board
4
+
5
+ # Installation
6
+
7
+ 1. Install the ruby gem
8
+
9
+ gem install arduino_build_notifier
10
+
11
+ 2. Wire your Arduino (Picks later)
12
+ - Success led: pin 13
13
+ - Failure led: pin 12
14
+ - Building led: pin 11
15
+ - Error led: pin 10
16
+ 3. Plug the Arduino board to the computer
17
+ 4. If you don't have your arduino ready to work with ruby, follow the [dino gem instructions](https://github.com/austinbv/dino#get-started-in-no-time)
18
+ 5. run the command ard-notifier
19
+
20
+ Usage: ard-notifier --server 'http://...' --project foo --user foo --password bar
21
+ -s, --server SERVER CI server URL
22
+ -j, --project PROJECT Project name
23
+ -u, --user USER CI server username
24
+ -p, --password PASS CI server password
25
+ -t, --time [TIME] Request frequency (secs)
26
+ -h, --help Show this message
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,22 @@
1
+ Gem::Specification.new do |s|
2
+ s.name = 'arduino_build_notifier'
3
+ s.version = '0.0.1'
4
+ s.date = '2012-11-08'
5
+ s.summary = "An Integration server notifier"
6
+ s.description = "like ccmenu but with Arduino"
7
+ s.authors = ["Herman Moreno"]
8
+ s.email = 'herman.moreno@crowdint.com'
9
+ s.files = `git ls-files`.split("\n")
10
+ s.homepage = 'https://github.com/supherman/arduino_build_notifier'
11
+
12
+ s.executables = ['ard-notifier']
13
+
14
+ s.add_development_dependency('rspec')
15
+
16
+ s.add_dependency('celluloid')
17
+ s.add_dependency('dino')
18
+ s.add_dependency('gli')
19
+ s.add_dependency('httparty')
20
+ s.add_dependency('nokogiri')
21
+ end
22
+
data/bin/ard-notifier ADDED
@@ -0,0 +1,60 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'bundler'
4
+ Bundler.require
5
+ require 'optparse'
6
+
7
+ options = {}
8
+ options[:time] = 10
9
+
10
+ optparse = OptionParser.new do |opts|
11
+ opts.banner = "Usage: ard-notifier --server 'http://...' --project foo --user foo --password bar"
12
+
13
+ opts.on '-s SERVER', '--server SERVER', 'CI server URL' do |url|
14
+ options[:server] = url
15
+ end
16
+
17
+ opts.on '-j PROJECT', '--project PROJECT', 'Project name' do |project|
18
+ options[:project] = project
19
+ end
20
+
21
+ opts.on '-u USER', '--user USER', 'CI server username' do |user|
22
+ options[:user] = user
23
+ end
24
+
25
+ opts.on '-p PASS', '--password PASS', 'CI server password' do |pass|
26
+ options[:pass] = pass
27
+ end
28
+
29
+ opts.on '-t [TIME]', '--time [TIME]', 'Request frequency (secs)' do |time|
30
+ options[:time] = time
31
+ end
32
+
33
+ opts.on_tail("-h", "--help", "Show this message") do
34
+ puts opts
35
+ exit
36
+ end
37
+
38
+ end
39
+
40
+ begin
41
+ optparse.parse!
42
+ mandatory = [:server, :project, :user, :pass]
43
+ missing = mandatory.select{ |param| options[param].nil? }
44
+ if not missing.empty?
45
+ puts "Missing options: #{missing.join(', ')}"
46
+ puts optparse
47
+ exit
48
+ end
49
+ rescue OptionParser::InvalidOption, OptionParser::MissingArgument
50
+ puts $!.to_s
51
+ puts optparse
52
+ exit
53
+ end
54
+
55
+ build = ArduinoBuildNotifier::CruiseControlBuild.new options[:server], options[:project], { username: options[:user], password: options[:pass] }
56
+ arduino = ArduinoBuildNotifier::ArduinoBoard.new
57
+ notifier = ArduinoBuildNotifier::Notifier.new build, arduino, options[:time]
58
+ notifier.start_notifications
59
+ sleep
60
+
@@ -0,0 +1,41 @@
1
+ require 'dino'
2
+
3
+ module ArduinoBuildNotifier
4
+ class ArduinoBoard
5
+ def initialize
6
+ @board = Dino::Board.new(Dino::TxRx.new)
7
+ @success_led = Dino::Components::Led.new(pin: 13, board: @board)
8
+ @failure_led = Dino::Components::Led.new(pin: 12, board: @board)
9
+ @building_led = Dino::Components::Led.new(pin: 11, board: @board)
10
+ @error_led = Dino::Components::Led.new(pin: 10, board: @board)
11
+ @leds = [@success_led, @failure_led, @building_led, @error_led]
12
+ end
13
+
14
+ def success
15
+ turn_off_leds
16
+ @success_led.on
17
+ end
18
+
19
+ def failure
20
+ turn_off_leds
21
+ @failure_led.on
22
+ end
23
+
24
+ def building
25
+ turn_off_leds
26
+ @building_led.on
27
+ end
28
+
29
+ def error
30
+ turn_off_leds
31
+ @error_led.on
32
+ end
33
+
34
+ private
35
+
36
+ def turn_off_leds
37
+ @leds.each { |led| led.off }
38
+ end
39
+
40
+ end
41
+ end
@@ -0,0 +1,41 @@
1
+ require 'httparty'
2
+ require 'nokogiri'
3
+
4
+ module ArduinoBuildNotifier
5
+ class CruiseControlBuild
6
+ attr_reader :status
7
+
8
+ def initialize(url, project, auth = {})
9
+ @url = "#{url}/XmlStatusReport.aspx"
10
+ @project = project
11
+ @auth = auth
12
+ end
13
+
14
+ def request_status
15
+ begin
16
+ response = HTTParty.get @url, basic_auth: @auth
17
+ response = parse(response)
18
+ set_status(response)
19
+ rescue
20
+ @status = :error
21
+ end
22
+ end
23
+
24
+ private
25
+
26
+ def parse(response)
27
+ @response = Nokogiri.XML(response).
28
+ xpath(%(//Projects/Project[@name="#{@project}"])).first
29
+ end
30
+
31
+ def set_status(response)
32
+ @status = if response[:activity] == 'Building'
33
+ :building
34
+ else
35
+ response[:lastBuildStatus].downcase.to_sym
36
+ end
37
+ end
38
+
39
+ end
40
+ end
41
+
@@ -0,0 +1,23 @@
1
+ require 'celluloid'
2
+
3
+ module ArduinoBuildNotifier
4
+ class Notifier
5
+ include Celluloid
6
+
7
+ def initialize(build, arduino, time = 10)
8
+ @time = time
9
+ @build = build
10
+ @arduino = arduino
11
+ end
12
+
13
+ def notify(status)
14
+ @arduino.send status
15
+ end
16
+
17
+ def start_notifications
18
+ every @time do
19
+ notify @build.request_status
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,3 @@
1
+ module ArduinoBuildNotifier
2
+ VERSION = '0.0.1'
3
+ end
@@ -0,0 +1,8 @@
1
+ require 'arduino_build_notifier/arduino_board'
2
+ require 'arduino_build_notifier/notifier'
3
+ require 'arduino_build_notifier/cruise_control_build'
4
+ require 'arduino_build_notifier/version'
5
+
6
+ module ArduinoBuildNotifier
7
+
8
+ end
@@ -0,0 +1,75 @@
1
+ require 'spec_helper'
2
+
3
+ describe ArduinoBuildNotifier::ArduinoBoard do
4
+ let(:txrx) { stub }
5
+ let(:board) { stub }
6
+ let(:success) { stub }
7
+ let(:failure) { stub }
8
+ let(:building) { stub }
9
+ let(:error) { stub }
10
+
11
+ before do
12
+ Dino::TxRx.should_receive(:new).and_return txrx
13
+ Dino::Board.should_receive(:new).with(txrx).and_return board
14
+ Dino::Components::Led.should_receive(:new).with(pin: 13, board: board).and_return success
15
+ Dino::Components::Led.should_receive(:new).with(pin: 12, board: board).and_return failure
16
+ Dino::Components::Led.should_receive(:new).with(pin: 11, board: board).and_return building
17
+ Dino::Components::Led.should_receive(:new).with(pin: 10, board: board).and_return error
18
+ end
19
+
20
+ describe '#success' do
21
+ before do
22
+ subject.should_receive(:turn_off_leds)
23
+ success.should_receive :on
24
+ end
25
+
26
+ it 'turns on success led' do
27
+ subject.success
28
+ end
29
+ end
30
+
31
+ describe '#failure' do
32
+ before do
33
+ subject.should_receive(:turn_off_leds)
34
+ failure.should_receive :on
35
+ end
36
+
37
+ it 'turns on failure led' do
38
+ subject.failure
39
+ end
40
+ end
41
+
42
+ describe '#building' do
43
+ before do
44
+ subject.should_receive(:turn_off_leds)
45
+ building.should_receive :on
46
+ end
47
+
48
+ it 'turns on building led' do
49
+ subject.building
50
+ end
51
+ end
52
+
53
+
54
+ describe '#error' do
55
+ before do
56
+ subject.should_receive(:turn_off_leds)
57
+ error.should_receive :on
58
+ end
59
+
60
+ it 'turns on error led' do
61
+ subject.error
62
+ end
63
+ end
64
+
65
+ describe '#turn_off_leds' do
66
+ it 'turns off all the leds' do
67
+ success.should_receive :off
68
+ failure.should_receive :off
69
+ building.should_receive :off
70
+ error.should_receive :off
71
+ subject.send :turn_off_leds
72
+ end
73
+ end
74
+
75
+ end
@@ -0,0 +1,42 @@
1
+ require 'spec_helper'
2
+
3
+ describe ArduinoBuildNotifier::CruiseControlBuild do
4
+ let(:url) { 'foo url' }
5
+ let(:project) { 'foo' }
6
+ let(:auth) { stub }
7
+ let(:response) { stub }
8
+
9
+ subject { ArduinoBuildNotifier::CruiseControlBuild.new url,project, auth }
10
+
11
+ describe '#request_status' do
12
+ before do
13
+ HTTParty.should_receive(:get).with("#{url}/XmlStatusReport.aspx", basic_auth: auth).and_return response
14
+ subject.should_receive(:parse).with(response).and_return response
15
+ subject.should_receive(:set_status).with(response)
16
+ end
17
+
18
+ it 'request for a build status' do
19
+ subject.request_status
20
+ end
21
+ end
22
+
23
+ describe '#set_status' do
24
+ context 'When building' do
25
+ let(:response) { { activity: 'Building' } }
26
+
27
+ it 'returns :building' do
28
+ subject.send(:set_status, response).should eq(:building)
29
+ end
30
+ end
31
+
32
+ context 'When build finished' do
33
+ let(:response) { { activity: 'Waiting', lastBuildStatus: :success } }
34
+
35
+ it 'returns the build result' do
36
+ subject.send(:set_status, response).should eq(:success)
37
+ end
38
+ end
39
+ end
40
+
41
+ end
42
+
@@ -0,0 +1,21 @@
1
+ require 'spec_helper'
2
+
3
+ describe ArduinoBuildNotifier::Notifier do
4
+ let(:build) { stub }
5
+ let(:board) { stub }
6
+
7
+ subject { ArduinoBuildNotifier::Notifier.new build, board }
8
+
9
+ describe '#notify' do
10
+ it 'prints the build status' do
11
+ board.should_receive(:status)
12
+ subject.notify(:status)
13
+ end
14
+ end
15
+
16
+ describe '#start_notifications' do
17
+ it 'request for the build status each given time' do
18
+ # TODO: Find a way to test celluloid methods
19
+ end
20
+ end
21
+ end
@@ -0,0 +1 @@
1
+ require 'arduino_build_notifier'
metadata ADDED
@@ -0,0 +1,157 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: arduino_build_notifier
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Herman Moreno
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-11-08 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rspec
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: celluloid
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: dino
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :runtime
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ - !ruby/object:Gem::Dependency
63
+ name: gli
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ type: :runtime
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ - !ruby/object:Gem::Dependency
79
+ name: httparty
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ! '>='
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ type: :runtime
87
+ prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ - !ruby/object:Gem::Dependency
95
+ name: nokogiri
96
+ requirement: !ruby/object:Gem::Requirement
97
+ none: false
98
+ requirements:
99
+ - - ! '>='
100
+ - !ruby/object:Gem::Version
101
+ version: '0'
102
+ type: :runtime
103
+ prerelease: false
104
+ version_requirements: !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ! '>='
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ description: like ccmenu but with Arduino
111
+ email: herman.moreno@crowdint.com
112
+ executables:
113
+ - ard-notifier
114
+ extensions: []
115
+ extra_rdoc_files: []
116
+ files:
117
+ - .gitignore
118
+ - Gemfile
119
+ - Gemfile.lock
120
+ - README.md
121
+ - Rakefile
122
+ - arduino_build_notifier.gemspec
123
+ - bin/ard-notifier
124
+ - lib/arduino_build_notifier.rb
125
+ - lib/arduino_build_notifier/arduino_board.rb
126
+ - lib/arduino_build_notifier/cruise_control_build.rb
127
+ - lib/arduino_build_notifier/notifier.rb
128
+ - lib/arduino_build_notifier/version.rb
129
+ - spec/lib/arduino_board_spec.rb
130
+ - spec/lib/cruise_control_build_spec.rb
131
+ - spec/lib/notifier_spec.rb
132
+ - spec/spec_helper.rb
133
+ homepage: https://github.com/supherman/arduino_build_notifier
134
+ licenses: []
135
+ post_install_message:
136
+ rdoc_options: []
137
+ require_paths:
138
+ - lib
139
+ required_ruby_version: !ruby/object:Gem::Requirement
140
+ none: false
141
+ requirements:
142
+ - - ! '>='
143
+ - !ruby/object:Gem::Version
144
+ version: '0'
145
+ required_rubygems_version: !ruby/object:Gem::Requirement
146
+ none: false
147
+ requirements:
148
+ - - ! '>='
149
+ - !ruby/object:Gem::Version
150
+ version: '0'
151
+ requirements: []
152
+ rubyforge_project:
153
+ rubygems_version: 1.8.23
154
+ signing_key:
155
+ specification_version: 3
156
+ summary: An Integration server notifier
157
+ test_files: []