pivotal-tracker-client 0.1.0 → 0.2.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.
data/.gitignore CHANGED
@@ -19,3 +19,7 @@ rdoc
19
19
  pkg
20
20
 
21
21
  ## PROJECT::SPECIFIC
22
+ *.gemspec
23
+ cache
24
+ gems
25
+ bin/pivotal-tracker-client.rb.pid
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.0
1
+ 0.2.0
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'rubygems'
4
+ require 'daemons'
5
+
6
+ Daemons.run File.join(File.dirname(__FILE__), 'pivotal-tracker-client.rb')
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env sh
2
+
3
+ echo token: $1 > ~/.pivotal_tracker
4
+
5
+ echo Successful installed, execute pivotal-tracker-client to start.
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'rubygems'
4
+ require 'yaml'
5
+ require 'pivotal-tracker-client'
6
+
7
+
8
+ token = YAML.load_file(File.expand_path("~/.pivotal_tracker"))['token']
9
+
10
+ PivotalTrackerClient.init token
11
+
12
+ loop do
13
+ sleep 5
14
+ end
@@ -1,37 +1,41 @@
1
- require 'httparty'
1
+ require 'rest_client'
2
2
  require 'crack/xml'
3
3
  require 'rufus/scheduler'
4
4
 
5
5
  class PivotalTrackerClient
6
- include HTTParty
7
6
  include Crack
8
7
 
9
- attr_reader :version
8
+ attr_reader :id
10
9
 
11
10
  def self.init(token)
12
11
  new token
13
12
  end
14
13
 
15
- def fetch
16
- data = update_by "newer_than_version=#{@version}"
17
- data['activities'].reverse.each do |activity|
18
- system "growlnotify -t 'Pivotal Tracker' -m '#{activity['description']}'"
14
+ def update
15
+ activities = fetch_activities
16
+ activities.reverse.each do |activity|
17
+ if activity['id'] > @id.to_i
18
+ system "growlnotify -t 'Pivotal Tracker' -m '#{activity['description']}'"
19
+ end
19
20
  end
21
+ update_id_from activities
20
22
  end
21
23
 
22
24
  protected
23
25
 
24
26
  def initialize(token)
25
27
  @token = token
26
- update_by 'limit=10'
27
- Rufus::Scheduler.start_new.every('30s') { fetch }
28
+ update_id_from fetch_activities
29
+ Rufus::Scheduler.start_new.every('30s') { update }
28
30
  end
29
31
 
30
32
  private
31
33
 
32
- def update_by(qs)
33
- xml = XML.parse(self.class.get("http://www.pivotaltracker.com/services/v3/activities?#{qs}", :headers => {'X-TrackerToken' => @token}))
34
- @version = xml['activities'].first['version']
35
- return xml
34
+ def update_id_from(activities)
35
+ @id = activities.first['id'].to_s
36
+ end
37
+
38
+ def fetch_activities
39
+ return XML.parse(RestClient.get("http://www.pivotaltracker.com/services/v3/activities?limit=10", 'X-TrackerToken' => @token).body)['activities']
36
40
  end
37
41
  end
@@ -7,7 +7,23 @@
7
7
  <occurred_at type="datetime">2010/03/17 21:48:15 ARST</occurred_at>
8
8
  <author>Superman</author>
9
9
  <project_id type="integer">32498</project_id>
10
- <description>Superman finished &quot;When creating an alert, I want to define a severity&quot;</description>
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>
11
27
  <stories>
12
28
  <story>
13
29
  <id type="integer">3934566</id>
@@ -23,7 +39,7 @@
23
39
  <occurred_at type="datetime">2010/03/17 21:44:42 ARST</occurred_at>
24
40
  <author>Spiderman</author>
25
41
  <project_id type="integer">43498</project_id>
26
- <description>Superman edited &quot;I want to delete alert notifications from the main alert notification page&quot;</description>
42
+ <description>Spiderman edited &quot;I want to delete alert notifications from the main alert notification page&quot;</description>
27
43
  <stories>
28
44
  <story>
29
45
  <id type="integer">3935407</id>
@@ -6,16 +6,16 @@ describe PivotalTrackerClient do
6
6
  Rufus::Scheduler.stub(:start_new).and_return(@scheduler = mock(Object, :every => nil))
7
7
  end
8
8
 
9
- it "should save the verstion of the latest activity" do
9
+ it "should save the id of the latest activity" do
10
10
  client = PivotalTrackerClient.init '123456789'
11
- client.version.should == 27585
11
+ client.id.should == '25906467'
12
12
  end
13
-
13
+
14
14
  it "should request the feed with the token" do
15
15
  token = '34g43g4334g43g43'
16
- PivotalTrackerClient.should_receive(:get) do |url, opts|
17
- opts[:headers]['X-TrackerToken'].should eql(token)
18
- latests_activities
16
+ RestClient.should_receive(:get) do |url, opts|
17
+ opts['X-TrackerToken'].should eql(token)
18
+ mock(Object, :body => latests_activities)
19
19
  end
20
20
  PivotalTrackerClient.init token
21
21
  end
@@ -29,37 +29,40 @@ describe PivotalTrackerClient do
29
29
  @scheduler.stub(:every) do |time, block|
30
30
  block.call
31
31
  end
32
- PivotalTrackerClient.should_receive(:get).exactly(2).times { latests_activities }
32
+ RestClient.should_receive(:get).exactly(2).times do
33
+ mock(Object, :body => latests_activities)
34
+ end
33
35
  PivotalTrackerClient.init 'fegegege'
34
36
  end
35
37
  end
36
38
 
37
- context "on fetch" do
39
+ context "on update" do
38
40
  before :each do
39
41
  @client = PivotalTrackerClient.init('fake')
40
42
  @client.stub! :system
43
+ @client.instance_variable_set "@id", '25906311'
41
44
  end
42
45
 
43
- it "should get the feed from the current version and update the version" do
44
- @client.fetch
45
- @client.version.should == 28585
46
+ it "should get the new activities and update the id" do
47
+ @client.update
48
+ @client.id.should == '25906467'
46
49
  end
47
50
 
48
- context "on os x" do
49
- it "should notifify growl about each activity" do
50
- @client.should_receive(:system).exactly(2).times
51
- @client.fetch
52
- end
51
+ it "should notifify about each new activity" do
52
+ @client.should_receive(:system).exactly(2).times
53
+ @client.update
54
+ end
53
55
 
56
+ context "on os x" do
54
57
  it "should notify growl calling growlnotify with 'Pivotal Tracker' as the name the application, the author and the action" do
55
58
  @client.should_receive(:system).with("growlnotify -t 'Pivotal Tracker' -m 'Superman finished lorem ipsum'")
56
- @client.fetch
59
+ @client.update
57
60
  end
58
61
 
59
62
  it "should notify newer activities at least" do
60
- @client.should_receive(:system).with("growlnotify -t 'Pivotal Tracker' -m 'Spiderman edited lorem ipsum'").ordered
63
+ @client.should_receive(:system).with("growlnotify -t 'Pivotal Tracker' -m 'SpongeBog finished lorem ipsum'").ordered
61
64
  @client.should_receive(:system).with("growlnotify -t 'Pivotal Tracker' -m 'Superman finished lorem ipsum'").ordered
62
- @client.fetch
65
+ @client.update
63
66
  end
64
67
  end
65
68
  end
data/spec/spec_helper.rb CHANGED
@@ -21,4 +21,3 @@ end
21
21
  require 'fakeweb'
22
22
 
23
23
  FakeWeb.register_uri(:get, "http://www.pivotaltracker.com/services/v3/activities?limit=10", :body => latests_activities)
24
- FakeWeb.register_uri(:get, "http://www.pivotaltracker.com/services/v3/activities?newer_than_version=27585", :body => read('newer_than_version'))
metadata CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
4
4
  prerelease: false
5
5
  segments:
6
6
  - 0
7
- - 1
7
+ - 2
8
8
  - 0
9
- version: 0.1.0
9
+ version: 0.2.0
10
10
  platform: ruby
11
11
  authors:
12
12
  - Diego Carrion
@@ -55,8 +55,11 @@ dependencies:
55
55
  version_requirements: *id003
56
56
  description: A client that listens to Pivotal Tracker activities and notifies them with Growl.
57
57
  email: dc.rec1@gmail.com
58
- executables: []
59
-
58
+ executables:
59
+ - pivotal-tracker-client
60
+ - pivotal-tracker-client-install
61
+ - pivotal-tracker-client.rb
62
+ - pivotal-tracker-client.rb.pid
60
63
  extensions: []
61
64
 
62
65
  extra_rdoc_files:
@@ -69,9 +72,11 @@ files:
69
72
  - README.textile
70
73
  - Rakefile
71
74
  - VERSION
75
+ - bin/pivotal-tracker-client
76
+ - bin/pivotal-tracker-client-install
77
+ - bin/pivotal-tracker-client.rb
72
78
  - lib/pivotal-tracker-client.rb
73
79
  - spec/data/latests_activities.xml
74
- - spec/data/newer_than_version.xml
75
80
  - spec/pivotal-tracker-client_spec.rb
76
81
  - spec/spec.opts
77
82
  - spec/spec_helper.rb
@@ -1,37 +0,0 @@
1
- <?xml version="1.0" encoding="UTF-8"?>
2
- <activities type="array">
3
- <activity>
4
- <id type="integer">25906467</id>
5
- <version type="integer">28585</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">25906311</id>
21
- <version type="integer">27584</version>
22
- <event_type>story_update</event_type>
23
- <occurred_at type="datetime">2010/03/17 21:44:42 ARST</occurred_at>
24
- <author>Spiderman</author>
25
- <project_id type="integer">43498</project_id>
26
- <description>Spiderman edited lorem ipsum</description>
27
- <stories>
28
- <story>
29
- <id type="integer">3935407</id>
30
- <url>http://www.pivotaltracker.com/services/v3/projects/43498/stories/3935407</url>
31
- <description>In the main page, in place of the &quot;Ignore&quot; column, we will have a &quot;Delete&quot; column.
32
-
33
- 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>
34
- </story>
35
- </stories>
36
- </activity>
37
- </activities>