marcosinger-kilt 0.5.2

Sign up to get free protection for your applications and to get access to all the features.
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ README.rdoc
2
+ lib/**/*.rb
3
+ bin/*
4
+ features/**/*.feature
5
+ LICENSE
data/LICENSE ADDED
File without changes
data/README.textile ADDED
@@ -0,0 +1,73 @@
1
+ h2. ABOUT
2
+
3
+ Kilt looks for new activities in all your projects and displays them with Growl/Libnotify/Snarl, so you are up-to-date with everything is happening.
4
+ If you want to help, please send me a pull request.
5
+
6
+ h2. SCREENSHOTS
7
+
8
+ OS X
9
+ !http://img13.imageshack.us/img13/2583/kiltonosx.png!
10
+
11
+ Ubuntu
12
+ !http://img691.imageshack.us/img691/9453/kiltonubuntu.png!
13
+
14
+ Windows
15
+ !http://img192.imageshack.us/img192/9405/kiltonwindows.png!
16
+
17
+ h2. DEPENDENCIES
18
+
19
+ On OS X:
20
+
21
+ * "Growl":http://growl.info
22
+ * "growlnotify":http://growl.info/extras.php#growlnotify
23
+
24
+ On Ubuntu:
25
+
26
+ * "libnotify-bin":http://packages.ubuntu.com/lucid/libnotify-bin
27
+
28
+ On Windows:
29
+ * "Snarl":http://www.fullphat.net
30
+ * "ruby-snarl":http://rubygems.org/gems/ruby-snarl
31
+ * "win32-process":http://rubygems.org/gems/win32-process
32
+
33
+ h2. INSTALLATION
34
+
35
+ <pre><code>gem install kilt
36
+ kilt-install TOKEN</code></pre>
37
+
38
+ If you don't know your token, you can execute this:
39
+
40
+ <pre><code>curl -u USERNAME:PASSWORD -X GET https://www.pivotaltracker.com/services/v3/tokens/active</code></pre>
41
+
42
+ More info and other alternative "here":http://www.pivotaltracker.com/help/api?version=v3#retrieve_token.
43
+
44
+ h2. USAGE
45
+
46
+ <pre><code>kilt-app</code></pre>
47
+
48
+ h2. TODO
49
+
50
+ * kilt-check (see issues)
51
+
52
+ h2. LICENSE
53
+
54
+ Copyright (c) 2010 Diego Carrion
55
+
56
+ Permission is hereby granted, free of charge, to any person obtaining
57
+ a copy of this software and associated documentation files (the
58
+ "Software"), to deal in the Software without restriction, including
59
+ without limitation the rights to use, copy, modify, merge, publish,
60
+ distribute, sublicense, and/or sell copies of the Software, and to
61
+ permit persons to whom the Software is furnished to do so, subject to
62
+ the following conditions:
63
+
64
+ The above copyright notice and this permission notice shall be
65
+ included in all copies or substantial portions of the Software.
66
+
67
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
68
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
69
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
70
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
71
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
72
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
73
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Rakefile ADDED
@@ -0,0 +1,48 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "marcosinger-kilt"
8
+ gem.summary = "A client that listens to Pivotal Tracker activities and notifies them with Growl."
9
+ gem.description = "A client that listens to Pivotal Tracker activities and notifies them with Growl."
10
+ gem.email = "markaum@gmail.com"
11
+ gem.homepage = "http://github.com/marcosinger/kilt"
12
+ gem.authors = ["Original - Diego Carrion", "Marco Singer"]
13
+ gem.add_dependency "rest-client"
14
+ gem.add_dependency "crack"
15
+ gem.add_dependency "rufus-scheduler"
16
+ gem.add_development_dependency "rspec"
17
+ gem.add_development_dependency "fakeweb"
18
+ end
19
+ Jeweler::GemcutterTasks.new
20
+ rescue LoadError
21
+ puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
22
+ end
23
+
24
+ require 'spec/rake/spectask'
25
+ Spec::Rake::SpecTask.new(:spec) do |spec|
26
+ spec.libs << 'lib' << 'spec'
27
+ spec.spec_files = FileList['spec/**/*_spec.rb']
28
+ end
29
+
30
+ Spec::Rake::SpecTask.new(:rcov) do |spec|
31
+ spec.libs << 'lib' << 'spec'
32
+ spec.pattern = 'spec/**/*_spec.rb'
33
+ spec.rcov = true
34
+ end
35
+
36
+ task :spec => :check_dependencies
37
+
38
+ task :default => :spec
39
+
40
+ require 'rake/rdoctask'
41
+ Rake::RDocTask.new do |rdoc|
42
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
43
+
44
+ rdoc.rdoc_dir = 'rdoc'
45
+ rdoc.title = "pivotal-tracker-client #{version}"
46
+ rdoc.rdoc_files.include('README*')
47
+ rdoc.rdoc_files.include('lib/**/*.rb')
48
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.5.2
data/bin/kilt-app ADDED
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'rubygems'
4
+ require 'yaml'
5
+ require 'kilt'
6
+ require 'win32/process' if RUBY_PLATFORM =~ /mswin|mingw|win32/
7
+
8
+ fork do
9
+ token = YAML.load_file(File.expand_path("~/.pivotal_tracker"))['token']
10
+
11
+ Kilt.init token
12
+
13
+ loop do
14
+ sleep 5
15
+ end
16
+ end
data/bin/kilt-install ADDED
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ filename = File.expand_path "~/.pivotal_tracker"
4
+ File.open(filename, 'w') { |file| file.write "token: #{ARGV.first}" }
5
+ puts "Successful installed, execute kilt-app to start."
data/img/pivotal.png ADDED
Binary file
data/lib/kilt.rb ADDED
@@ -0,0 +1,68 @@
1
+ require 'rest_client'
2
+ require 'crack/xml'
3
+ require 'rufus/scheduler'
4
+ #require 'snarl' if RUBY_PLATFORM =~ /mswin|mingw|win32/
5
+
6
+ class Kilt
7
+ include Crack
8
+
9
+ attr_reader :id, :date_last_activity
10
+
11
+ ICON = File.expand_path(File.join(File.dirname(__FILE__), '..', 'img', 'pivotal.png'))
12
+
13
+ def date_last_activity
14
+ # FIXME Diferença de 3hrs no UTC do Pivotal
15
+ (@date_last_activity ||= Time.now) - 60*60*3
16
+ end
17
+
18
+
19
+ def self.init(token)
20
+ new token
21
+ end
22
+
23
+ def pivotal_format_date
24
+ URI.escape(date_last_activity.strftime("%Y/%m/%d %H:%M:%S"))
25
+ end
26
+
27
+ def update
28
+ activities = fetch_activities
29
+ activities.reverse.each do |activity|
30
+ if activity['occurred_at'] > @date_last_activity
31
+ notify_about activity['description']
32
+ end
33
+ end
34
+ update_date_from activities
35
+ end
36
+
37
+ protected
38
+
39
+ def initialize(token)
40
+ @token = token
41
+ update_date_from fetch_activities
42
+ Rufus::Scheduler.start_new.every('30s') { update }
43
+ end
44
+
45
+ private
46
+
47
+ def update_date_from(activities)
48
+ #@id = activities.first['id'].to_s
49
+ @date_last_activity = activities.first['occurred_at']
50
+ end
51
+
52
+ def fetch_activities
53
+ return XML.parse(RestClient.get("http://www.pivotaltracker.com/services/v3/activities?occurred_since_date=#{pivotal_format_date}",
54
+ 'X-TrackerToken' => @token).body)['activities']
55
+ end
56
+
57
+ def notify_about(message)
58
+ title = 'Pivotal Tracker'
59
+ case RUBY_PLATFORM
60
+ when /linux/
61
+ system "notify-send '#{title}' '#{message}' --icon #{Kilt::ICON}"
62
+ when /darwin/
63
+ system "growlnotify -t '#{title}' -m '#{message}' --image #{Kilt::ICON}"
64
+ # when /mswin|mingw|win32/
65
+ # Snarl.show_message title, message, Kilt::ICON
66
+ end
67
+ end
68
+ end
@@ -0,0 +1,53 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <activities type="array">
3
+ <activity>
4
+ <id type="integer">25906467</id>
5
+ <version type="integer">27585</version>
6
+ <event_type>story_update</event_type>
7
+ <occurred_at type="datetime">2010/03/17 21:48:15 ARST</occurred_at>
8
+ <author>Superman</author>
9
+ <project_id type="integer">32498</project_id>
10
+ <description>Superman finished lorem ipsum</description>
11
+ <stories>
12
+ <story>
13
+ <id type="integer">3934566</id>
14
+ <url>http://www.pivotaltracker.com/services/v3/projects/43498/stories/3934566</url>
15
+ <current_state>finished</current_state>
16
+ </story>
17
+ </stories>
18
+ </activity>
19
+ <activity>
20
+ <id type="integer">225906466</id>
21
+ <version type="integer">27585</version>
22
+ <event_type>story_update</event_type>
23
+ <occurred_at type="datetime">2010/03/17 21:48:15 ARST</occurred_at>
24
+ <author>SpongeBob</author>
25
+ <project_id type="integer">32498</project_id>
26
+ <description>SpongeBog finished lorem ipsum</description>
27
+ <stories>
28
+ <story>
29
+ <id type="integer">3934566</id>
30
+ <url>http://www.pivotaltracker.com/services/v3/projects/43498/stories/3934566</url>
31
+ <current_state>finished</current_state>
32
+ </story>
33
+ </stories>
34
+ </activity>
35
+ <activity>
36
+ <id type="integer">25906311</id>
37
+ <version type="integer">27584</version>
38
+ <event_type>story_update</event_type>
39
+ <occurred_at type="datetime">2010/03/17 21:44:42 ARST</occurred_at>
40
+ <author>Spiderman</author>
41
+ <project_id type="integer">43498</project_id>
42
+ <description>Spiderman edited &quot;I want to delete alert notifications from the main alert notification page&quot;</description>
43
+ <stories>
44
+ <story>
45
+ <id type="integer">3935407</id>
46
+ <url>http://www.pivotaltracker.com/services/v3/projects/43498/stories/3935407</url>
47
+ <description>In the main page, in place of the &quot;Ignore&quot; column, we will have a &quot;Delete&quot; column.
48
+
49
+ At the bottom, there should be a Deletar button, just like the &quot;Aplicar&quot; button (without the dropdown) in the Solicitacao management page. So, the user will be able to select many notifications and delete multiples at the same time.</description>
50
+ </story>
51
+ </stories>
52
+ </activity>
53
+ </activities>
data/spec/kilt_spec.rb ADDED
@@ -0,0 +1,115 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe Kilt do
4
+ context "on init with a token" do
5
+ before :each do
6
+ Rufus::Scheduler.stub(:start_new).and_return(@scheduler = mock(Object, :every => nil))
7
+ end
8
+
9
+ it "should save the date of the latest activity" do
10
+ client = Kilt.init '123456789'
11
+ client.date_last_activity.should == Time.utc(2010,"mar",17,21,48,15)
12
+ end
13
+
14
+ it "should request the feed with the token" do
15
+ token = '34g43g4334g43g43'
16
+ RestClient.should_receive(:get) do |url, opts|
17
+ opts['X-TrackerToken'].should eql(token)
18
+ mock(Object, :body => latests_activities)
19
+ end
20
+ Kilt.init token
21
+ end
22
+
23
+ it "should fetch new activities every 30 seconds" do
24
+ @scheduler.should_receive(:every).with('30s')
25
+ Kilt.init 'fegegege'
26
+ end
27
+
28
+ it "should fetch new activities" do
29
+ @scheduler.stub(:every) do |time, block|
30
+ block.call
31
+ end
32
+ RestClient.should_receive(:get).exactly(2).times do
33
+ mock(Object, :body => latests_activities)
34
+ end
35
+ Kilt.init 'fegegege'
36
+ end
37
+ end
38
+
39
+ context "on update" do
40
+ before :each do
41
+ @client = Kilt.init('fake')
42
+ @client.stub! :system
43
+ @client.instance_variable_set "@date_last_activity", Time.utc(2010,"mar",17,21,44,42)
44
+ end
45
+
46
+ it "should get the new activities and update the date last activity" do
47
+ @client.update
48
+ @client.date_last_activity.should == Time.utc(2010,"mar",17,21,48,15)
49
+ end
50
+
51
+ it "should notifify about each new activity" do
52
+ @client.should_receive(:system).exactly(2).times
53
+ @client.update
54
+ end
55
+
56
+ context "on os x" do
57
+ before :all do
58
+ silence_warnings { RUBY_PLATFORM = "darwin" }
59
+ end
60
+
61
+ it "should notify growl calling growlnotify with 'Pivotal Tracker' as the name the application, the author and the action" do
62
+ regexp = /growlnotify -t \'Pivotal Tracker\' -m \'\S+. finished lorem ipsum\' --image \S+.pivotal\.png/
63
+ @client.should_receive(:system).with(regexp)
64
+ @client.update
65
+ end
66
+
67
+ it "should notify newer activities at least" do
68
+ regexp = /growlnotify -t \'Pivotal Tracker\' -m \'SpongeBog finished lorem ipsum\' --image \S+.pivotal\.png/
69
+ regexp2 = /growlnotify -t \'Pivotal Tracker\' -m \'Superman finished lorem ipsum\' --image \S+.pivotal\.png/
70
+ @client.should_receive(:system).with(regexp).ordered
71
+ @client.should_receive(:system).with(regexp2).ordered
72
+ @client.update
73
+ end
74
+ end
75
+
76
+ context "on linux" do
77
+ before :all do
78
+ silence_warnings { RUBY_PLATFORM = "linux" }
79
+ end
80
+
81
+ it "should notify libnotify calling notify-send with 'Pivotal Tracker' as the name the application, the author and the action" do
82
+ regexp = /notify-send \'Pivotal Tracker\' \'\S+. finished lorem ipsum\' --icon \S+.pivotal\.png/
83
+ @client.should_receive(:system).with(regexp)
84
+ @client.update
85
+ end
86
+
87
+ it "should notify newer activities at least" do
88
+ regexp = /notify-send \'Pivotal Tracker\' \'SpongeBog finished lorem ipsum\' --icon \S+.pivotal\.png/
89
+ regexp2 = /notify-send \'Pivotal Tracker\' \'Superman finished lorem ipsum\' --icon \S+.pivotal\.png/
90
+ @client.should_receive(:system).with(regexp).ordered
91
+ @client.should_receive(:system).with(regexp2).ordered
92
+ @client.update
93
+ end
94
+ end
95
+
96
+ #FIXME SNARL completamente pirado. Cada hora joga uma mensagem diferente
97
+ # context "on windows" do
98
+ # before :all do
99
+ # silence_warnings { RUBY_PLATFORM = "mswin" }
100
+ # Kilt.const_set(:Snarl, @snarl = mock)
101
+ # end
102
+ #
103
+ # it "should notify Snarl calling show_message with 'Pivotal Tracker' as the name the application, the author and the action" do
104
+ # @snarl.should_receive(:show_message).with('Pivotal Tracker', /\S+ finished lorem ipsum/, /\S+.pivotal\.png/).twice
105
+ # @client.update
106
+ # end
107
+ #
108
+ # it "should notify newer activities at least" do
109
+ # @snarl.should_receive(:show_message).with('Pivotal Tracker', 'SpongeBog finished lorem ipsum', /\S+.pivotal\.png/).ordered
110
+ # @snarl.should_receive(:show_message).with('Pivotal Tracker', 'Superman finished lorem ipsum', /\S+.pivotal\.png/).ordered
111
+ # @client.update
112
+ # end
113
+ # end
114
+ end
115
+ end
data/spec/spec.opts ADDED
@@ -0,0 +1,4 @@
1
+ --colour
2
+ --format specdoc
3
+ --loadby mtime
4
+ --reverse
@@ -0,0 +1,32 @@
1
+ require 'rubygems'
2
+
3
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
4
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
5
+ require 'kilt'
6
+ require 'spec'
7
+ require 'spec/autorun'
8
+ require 'ruby-debug'
9
+
10
+ Spec::Runner.configure do |config|
11
+
12
+ end
13
+
14
+ def read(name)
15
+ File.open(File.join(File.dirname(__FILE__), 'data', "#{name}.xml")).read
16
+ end
17
+
18
+ def latests_activities
19
+ read "latests_activities"
20
+ end
21
+
22
+ def silence_warnings(&block)
23
+ old_verbose, $VERBOSE = $VERBOSE, nil
24
+ yield
25
+ ensure
26
+ $VERBOSE = old_verbose
27
+ end
28
+
29
+ require 'fakeweb'
30
+
31
+ #FakeWeb.register_uri(:get, "http://www.pivotaltracker.com/services/v3/activities?limit=10", :body => latests_activities)
32
+ FakeWeb.register_uri(:get, %r|http://www.pivotaltracker\.com/|, :body => latests_activities)
data/tags ADDED
@@ -0,0 +1,16 @@
1
+ !_TAG_FILE_FORMAT 2 /extended format; --format=1 will not append ;" to lines/
2
+ !_TAG_FILE_SORTED 1 /0=unsorted, 1=sorted, 2=foldcase/
3
+ !_TAG_PROGRAM_AUTHOR Darren Hiebert /dhiebert@users.sourceforge.net/
4
+ !_TAG_PROGRAM_NAME Exuberant Ctags //
5
+ !_TAG_PROGRAM_URL http://ctags.sourceforge.net /official site/
6
+ !_TAG_PROGRAM_VERSION 5.8 //
7
+ Kilt lib/kilt.rb /^class Kilt$/;" c
8
+ fetch_activities lib/kilt.rb /^ def fetch_activities$/;" f class:Kilt
9
+ init lib/kilt.rb /^ def self.init(token) $/;" F class:Kilt
10
+ initialize lib/kilt.rb /^ def initialize(token)$/;" f class:Kilt
11
+ latests_activities spec/spec_helper.rb /^def latests_activities$/;" f
12
+ notify_about lib/kilt.rb /^ def notify_about(message)$/;" f class:Kilt
13
+ read spec/spec_helper.rb /^def read(name)$/;" f
14
+ silence_warnings spec/spec_helper.rb /^def silence_warnings(&block)$/;" f
15
+ update lib/kilt.rb /^ def update$/;" f class:Kilt
16
+ update_id_from lib/kilt.rb /^ def update_id_from(activities)$/;" f class:Kilt
metadata ADDED
@@ -0,0 +1,138 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: marcosinger-kilt
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 5
8
+ - 2
9
+ version: 0.5.2
10
+ platform: ruby
11
+ authors:
12
+ - Original - Diego Carrion
13
+ - Marco Singer
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2010-12-01 00:00:00 -02:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: rest-client
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ requirements:
26
+ - - ">="
27
+ - !ruby/object:Gem::Version
28
+ segments:
29
+ - 0
30
+ version: "0"
31
+ type: :runtime
32
+ version_requirements: *id001
33
+ - !ruby/object:Gem::Dependency
34
+ name: crack
35
+ prerelease: false
36
+ requirement: &id002 !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ segments:
41
+ - 0
42
+ version: "0"
43
+ type: :runtime
44
+ version_requirements: *id002
45
+ - !ruby/object:Gem::Dependency
46
+ name: rufus-scheduler
47
+ prerelease: false
48
+ requirement: &id003 !ruby/object:Gem::Requirement
49
+ requirements:
50
+ - - ">="
51
+ - !ruby/object:Gem::Version
52
+ segments:
53
+ - 0
54
+ version: "0"
55
+ type: :runtime
56
+ version_requirements: *id003
57
+ - !ruby/object:Gem::Dependency
58
+ name: rspec
59
+ prerelease: false
60
+ requirement: &id004 !ruby/object:Gem::Requirement
61
+ requirements:
62
+ - - ">="
63
+ - !ruby/object:Gem::Version
64
+ segments:
65
+ - 0
66
+ version: "0"
67
+ type: :development
68
+ version_requirements: *id004
69
+ - !ruby/object:Gem::Dependency
70
+ name: fakeweb
71
+ prerelease: false
72
+ requirement: &id005 !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - ">="
75
+ - !ruby/object:Gem::Version
76
+ segments:
77
+ - 0
78
+ version: "0"
79
+ type: :development
80
+ version_requirements: *id005
81
+ description: A client that listens to Pivotal Tracker activities and notifies them with Growl.
82
+ email: markaum@gmail.com
83
+ executables:
84
+ - kilt-app
85
+ - kilt-install
86
+ extensions: []
87
+
88
+ extra_rdoc_files:
89
+ - LICENSE
90
+ - README.textile
91
+ files:
92
+ - .document
93
+ - LICENSE
94
+ - README.textile
95
+ - Rakefile
96
+ - VERSION
97
+ - bin/kilt-app
98
+ - bin/kilt-install
99
+ - img/pivotal.png
100
+ - lib/kilt.rb
101
+ - spec/data/latests_activities.xml
102
+ - spec/kilt_spec.rb
103
+ - spec/spec.opts
104
+ - spec/spec_helper.rb
105
+ - tags
106
+ has_rdoc: true
107
+ homepage: http://github.com/marcosinger/kilt
108
+ licenses: []
109
+
110
+ post_install_message:
111
+ rdoc_options: []
112
+
113
+ require_paths:
114
+ - lib
115
+ required_ruby_version: !ruby/object:Gem::Requirement
116
+ requirements:
117
+ - - ">="
118
+ - !ruby/object:Gem::Version
119
+ segments:
120
+ - 0
121
+ version: "0"
122
+ required_rubygems_version: !ruby/object:Gem::Requirement
123
+ requirements:
124
+ - - ">="
125
+ - !ruby/object:Gem::Version
126
+ segments:
127
+ - 0
128
+ version: "0"
129
+ requirements: []
130
+
131
+ rubyforge_project:
132
+ rubygems_version: 1.3.6
133
+ signing_key:
134
+ specification_version: 3
135
+ summary: A client that listens to Pivotal Tracker activities and notifies them with Growl.
136
+ test_files:
137
+ - spec/kilt_spec.rb
138
+ - spec/spec_helper.rb