interstate 0.0.2.1 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
data/.todo/list.yml ADDED
@@ -0,0 +1,3 @@
1
+ --- !map:Todo::List
2
+ Ask Simon to have a look at why log is returning really old entries first:
3
+ - log
data/interstate.gemspec CHANGED
@@ -19,6 +19,7 @@ Gem::Specification.new do |s|
19
19
  s.add_dependency "terminal-table"
20
20
  s.add_dependency "rainbow"
21
21
  s.add_dependency "time-ago-in-words"
22
+ s.add_dependency "typhoeus"
22
23
 
23
24
  s.rubyforge_project = "interstate"
24
25
 
data/lib/.DS_Store CHANGED
Binary file
data/lib/api.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  require "nestful"
2
- require "lib/store"
2
+ require "typhoeus"
3
3
 
4
4
  class API
5
5
 
@@ -39,4 +39,51 @@ class API
39
39
  return JSON.parse(Nestful.post url, :params => params)["response"]
40
40
  end
41
41
 
42
+ def self.delete_road(_id)
43
+ url = "https://api.interstateapp.com/v1/road/delete/id/#{_id}.json?oauth_token=#{@@token}"
44
+ return JSON.parse(Nestful.get url)["response"]
45
+ end
46
+
47
+ def self.log(_id, appId)
48
+ url = "https://api.interstateapp.com/v1/activity/list/id/#{appId}/limit/10.json?oauth_token=#{@@token}"
49
+ return JSON.parse(Nestful.post url, :params => { "filter" => "roadmap-#{_id}" } )["response"]
50
+ end
51
+
52
+ def self.updates(log) # we'll handle updates by parallel processing them with typhoeus
53
+ hydra = Typhoeus::Hydra.new(:max_concurrency => 50)
54
+ updates = []
55
+ log.each do |entry|
56
+
57
+ if entry["type"] == "github"
58
+ begin
59
+ info = entry["comments"][0]
60
+ updates << { "update" => info["comment"], "time" => info["time"], "staffId" => info["staffId"], "type" => "GitHub Commit" }
61
+ rescue
62
+ end
63
+ elsif entry["type"] == "road_update"
64
+ r = Typhoeus::Request.new("https://api.interstateapp.com/v1/update/get/id/#{entry["updateId"]}.json?oauth_token=#{@@token}")
65
+ r.on_complete do |response|
66
+ update = JSON.parse(response.body)["response"]
67
+ if update.class != NilClass
68
+ update["type"] = "Road Update"
69
+ updates << update
70
+ end
71
+ end
72
+ hydra.queue r
73
+
74
+ elsif entry["type"] == "road"
75
+ r = Typhoeus::Request.new("https://api.interstateapp.com/v1/road/#{entry["roadId"]}.json?oauth_token=#{@@token}")
76
+ r.on_complete do |response|
77
+ road = JSON.parse(response.body)["response"]
78
+ if road.class != NilClass
79
+ updates << { "update" => "New Road: #{road["title"]}", "time" => entry["time"], "staffId" => entry["staffId"], "type" => "New Road" }
80
+ end
81
+ end
82
+ hydra.queue r
83
+ end
84
+ hydra.run
85
+ end
86
+ return updates
87
+ end
88
+
42
89
  end
@@ -1,3 +1,3 @@
1
1
  module Interstate
2
- VERSION = "0.0.2.1"
2
+ VERSION = "0.0.3"
3
3
  end
data/lib/interstate.rb CHANGED
@@ -5,14 +5,14 @@ require "rainbow"
5
5
  require "nestful"
6
6
  require "pp"
7
7
  require "time-ago-in-words"
8
- require "lib/store"
9
- require "lib/api"
10
- require "lib/table"
8
+ require "store"
9
+ require "api"
10
+ require "table"
11
11
 
12
12
  # Interstate-CLI by BakedCode
13
13
 
14
14
  class Interstate < Thor
15
-
15
+
16
16
  # Load the config files etc.
17
17
  config = Store.load_config
18
18
  @@maps = Store.load_maps
@@ -21,25 +21,25 @@ class Interstate < Thor
21
21
  @@current_map = config["current_map"]
22
22
 
23
23
  # maps
24
- desc "maps", "List roadmaps"
24
+ desc "maps", "Show a list of roadmaps"
25
25
  method_option :reload, :type => :boolean, :force => true, :aliases => "-r"
26
26
  def maps
27
27
  Table.maps(@@maps, @@current_map)
28
28
  end
29
29
 
30
- # switch
31
- desc "switch", "Switch to a different roadmap"
32
- def switch(roadmapID)
30
+ # map
31
+ desc "map", "Switch to a different roadmap"
32
+ def map(roadmapID)
33
33
  if (@@maps[roadmapID])
34
34
  Store.set_current_map(roadmapID)
35
- puts "\nSwitch >> " + "#{@@maps[roadmapID]["title"]}\n".bright
35
+ puts "\nMap >> " + "#{@@maps[roadmapID]["title"]}\n".bright
36
36
  else
37
37
  puts "No roadmap with that shortcode".bright.color(:red)
38
38
  end
39
39
  end
40
40
 
41
41
  # roads
42
- desc "roads", "List roads in roadmap"
42
+ desc "roads", "Show a list of roads in roadmap"
43
43
  method_option :status, :type => :boolean, :aliases => "-r", :default => false, :desc => "Displays a guide and prompts you for a new status code."
44
44
  def roads
45
45
  currentRoads = @@roads[@@current_map]
@@ -54,11 +54,11 @@ class Interstate < Thor
54
54
  Table.roads(currentRoads, currentMap["title"])
55
55
  end
56
56
 
57
- # show
58
- desc "show", "Show details for particular road"
59
- def show(roadID)
57
+ # road
58
+ desc "road", "Show details for particular road"
59
+ def road(roadID)
60
60
  if @@roads[@@current_map][roadID] == nil
61
- puts "\nA roadmap with that shortcode does not exist.\n".bright.color(:red)
61
+ puts "\nA road with that shortcode does not exist.\n".bright.color(:red)
62
62
  else
63
63
  id = @@roads[@@current_map][roadID]["_id"]
64
64
  staff = @@staff["#{@@current_map}"]
@@ -67,15 +67,33 @@ class Interstate < Thor
67
67
  end
68
68
  end
69
69
 
70
+ # delete
71
+ desc "delete", "Delete an existing road"
72
+ def delete(roadID)
73
+ if @@roads[@@current_map][roadID] == nil
74
+ puts "\nA road with that shortcode does not exist.\n".bright.color(:red)
75
+ else
76
+ id = @@roads[@@current_map][roadID]["_id"]
77
+ success = API.delete_road(id)["deleted"]
78
+ if success == true
79
+ roads = API.roads(@@maps[@@current_map]["_id"])
80
+ Store.overwrite_roads(roads, @@current_map)
81
+ puts "\nRoad was successfully deleted.\n".bright.color(:green)
82
+ else
83
+ puts "\nThere was a problem deleting the road.\n".bright.color(:yellow)
84
+ end
85
+ end
86
+ end
87
+
70
88
  # add
71
89
  desc "add", "Add a new road to current roadmap"
72
90
  def add
73
91
  # Get user input
74
92
  id = @@maps[@@current_map]["_id"]
75
93
  puts "\nAdding a road to #{@@maps[@@current_map]["title"]}".bright
76
- puts "Title".bright
94
+ puts "Title:"
77
95
  title = STDIN.gets
78
- puts "Description".bright
96
+ puts "Description:"
79
97
  desc = STDIN.gets
80
98
  params = { :roadmapId => "#{id}", :title => "#{title}", :description => "#{desc}" }
81
99
 
@@ -93,27 +111,57 @@ class Interstate < Thor
93
111
 
94
112
  # update
95
113
  desc "update", "Update a road"
96
- method_option :message, :type => :string, :aliases => "-m", :required => true, :desc => "A required update message."
97
- method_option :status, :type => :boolean, :aliases => "-s", :default => false, :desc => "Displays a guide and prompts you for a new status code."
114
+ method_option :message, :type => :string, :aliases => "-m", :desc => "A required update message."
115
+ method_option :status, :type => :string, :aliases => "-s", :default => nil, :desc => "Displays a guide and prompts you for a new status code."
98
116
  def update(roadID)
99
117
  if @@roads[@@current_map][roadID] == nil
100
118
  puts "\nA road with that shortcode does not exist.\n".bright.color(:red)
101
119
  else
102
120
  status = nil
103
- if options.status == true
104
- puts "\n" + "Message".bright + " #{options.message}"
121
+ stati = Store.statuses
122
+ if options.status == "status"
105
123
  Table.status
106
124
  puts "Enter a new status code and press return".bright
107
125
  status = STDIN.gets
126
+ elsif stati.has_value?(options.status)
127
+ status = stati.index(options.status)
128
+ elsif stati.has_key?("#{options.status}")
129
+ status = "#{options.status}"
130
+ else
131
+ puts "Invalid status code.".color(:red)
132
+ end
133
+ message = nil
134
+ if options.message != nil
135
+ message = options.message
108
136
  end
109
137
  id = @@roads[@@current_map][roadID]["_id"]
110
- road = API.update_road(id, options.message, status)
138
+ road = API.update_road(id, message, status)
111
139
  staff = @@staff["#{@@current_map}"]
112
140
  puts "\n#{road["title"]} was updated successfully.".bright.color(:green)
113
141
  Table.road(road, roadID, staff)
114
142
  end
115
143
  end
116
144
 
145
+ # log
146
+ desc "log", "Show activity log"
147
+ def log
148
+ id = @@maps[@@current_map]["_id"]
149
+ appID = @@maps[@@current_map]["appId"]
150
+ log = API.log(id, appID) # get the log for current map
151
+ updates = API.updates(log)
152
+ staff = @@staff["#{@@current_map}"]
153
+ updates.each do |update|
154
+ if update != nil
155
+ type = update["type"]
156
+ staffID = update["staffId"]
157
+ name = staff[staffID]
158
+ time = Time.at(update["time"])
159
+ puts "\n #{update["update"]}\n\nType: #{type}\nAuthor: #{name}\nDate: #{time}"
160
+ end
161
+ end
162
+ puts "\n"
163
+ end
164
+
117
165
  # reset
118
166
  desc "reset", "Reset all config files"
119
167
  def reset
data/lib/store.rb CHANGED
@@ -21,7 +21,7 @@ class Store
21
21
  apps.each_pair do |key, app|
22
22
  app.each do |roadmap|
23
23
  shortcode = "#{Array.new(1) { (rand(122-97) + 97).chr }}#{10 + rand(89)}"
24
- newData["#{shortcode}"] = {"title" => roadmap["title"], "_id" => roadmap["_id"]}
24
+ newData["#{shortcode}"] = { "title" => roadmap["title"], "_id" => roadmap["_id"] , "appId" => roadmap["appId"] }
25
25
  end
26
26
  end
27
27
  open('.maps', 'wb') { |f| f.puts Marshal.dump(newData) }
@@ -60,21 +60,41 @@ class Store
60
60
  end
61
61
 
62
62
  def self.overwrite_roads(roads, current_map)
63
- allRoads = self.load_roads
64
- roadHash = {}
63
+ cachedRoads = self.load_roads
64
+ currentRoads = cachedRoads[current_map]
65
+ cachedIDs = []
66
+ toRemove = {}
67
+ currentRoads.each_pair do |k, v|
68
+ cachedIDs << v["_id"]
69
+ toRemove[v["_id"]] = k
70
+ end
71
+
65
72
  roads.each do |road|
66
73
  if road["isRoute"]
67
74
  road["roads"].each do |subRoad|
68
- shortcode = "#{Array.new(1) { (rand(122-97) + 97).chr }}#{10 + rand(89)}"
69
- roadHash["#{shortcode}"] = {"title" => subRoad["title"], "_id" => subRoad["_id"], "description" => subRoad["description"], "route" => road["title"]}
75
+ if cachedIDs.include?(subRoad["_id"])
76
+ cachedIDs.delete(subRoad["_id"])
77
+ else
78
+ shortcode = "#{Array.new(1) { (rand(122-97) + 97).chr }}#{10 + rand(89)}"
79
+ currentRoads["#{shortcode}"] = {"title" => subRoad["title"], "_id" => subRoad["_id"], "description" => subRoad["description"], "route" => road["title"]}
80
+ end
70
81
  end
71
82
  else
72
- shortcode = "#{Array.new(1) { (rand(122-97) + 97).chr }}#{10 + rand(89)}"
73
- roadHash["#{shortcode}"] = {"title" => road["title"], "_id" => road["_id"], "description" => road["description"], "route" => ""}
83
+ if cachedIDs.include?(road["_id"])
84
+ cachedIDs.delete(road["_id"])
85
+ else
86
+ shortcode = "#{Array.new(1) { (rand(122-97) + 97).chr }}#{10 + rand(89)}"
87
+ currentRoads["#{shortcode}"] = {"title" => road["title"], "_id" => road["_id"], "description" => road["description"], "route" => ""}
88
+ end
74
89
  end
75
90
  end
76
- allRoads[current_map] = roadHash
77
- open('.roads', 'wb') { |f| f.puts Marshal.dump(allRoads) }
91
+
92
+ cachedIDs.each do |_id|
93
+ currentRoads.delete(toRemove[_id])
94
+ end
95
+
96
+ cachedRoads[current_map] = currentRoads
97
+ open('.roads', 'wb') { |f| f.puts Marshal.dump(cachedRoads) }
78
98
  return self.load_roads
79
99
  end
80
100
 
@@ -115,4 +135,25 @@ class Store
115
135
  self.load_staff
116
136
  end
117
137
 
138
+ def self.statuses()
139
+ statuses = { "0" => "Stopped",
140
+ "1" => "Started",
141
+ "2" => "10%",
142
+ "3" => "20%",
143
+ "4" => "30%",
144
+ "5" => "40%",
145
+ "6" => "50%",
146
+ "7" => "60%",
147
+ "8" => "70%",
148
+ "9" => "80%",
149
+ "10" => "90%",
150
+ "11" => "Ready",
151
+ "12" => "Launched",
152
+ "13" => "Proposed",
153
+ "14" => "Postponed" }
154
+ end
155
+
156
+
157
+
158
+
118
159
  end
metadata CHANGED
@@ -1,14 +1,12 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: interstate
3
3
  version: !ruby/object:Gem::Version
4
- hash: 69
5
- prerelease:
4
+ prerelease: false
6
5
  segments:
7
6
  - 0
8
7
  - 0
9
- - 2
10
- - 1
11
- version: 0.0.2.1
8
+ - 3
9
+ version: 0.0.3
12
10
  platform: ruby
13
11
  authors:
14
12
  - Alec Sloman
@@ -16,17 +14,16 @@ autorequire:
16
14
  bindir: bin
17
15
  cert_chain: []
18
16
 
19
- date: 2011-06-04 00:00:00 Z
17
+ date: 2011-06-08 00:00:00 +09:00
18
+ default_executable:
20
19
  dependencies:
21
20
  - !ruby/object:Gem::Dependency
22
21
  name: thor
23
22
  prerelease: false
24
23
  requirement: &id001 !ruby/object:Gem::Requirement
25
- none: false
26
24
  requirements:
27
25
  - - ">="
28
26
  - !ruby/object:Gem::Version
29
- hash: 3
30
27
  segments:
31
28
  - 0
32
29
  version: "0"
@@ -36,11 +33,9 @@ dependencies:
36
33
  name: json
37
34
  prerelease: false
38
35
  requirement: &id002 !ruby/object:Gem::Requirement
39
- none: false
40
36
  requirements:
41
37
  - - ">="
42
38
  - !ruby/object:Gem::Version
43
- hash: 3
44
39
  segments:
45
40
  - 0
46
41
  version: "0"
@@ -50,11 +45,9 @@ dependencies:
50
45
  name: oauth2
51
46
  prerelease: false
52
47
  requirement: &id003 !ruby/object:Gem::Requirement
53
- none: false
54
48
  requirements:
55
49
  - - ">="
56
50
  - !ruby/object:Gem::Version
57
- hash: 3
58
51
  segments:
59
52
  - 0
60
53
  version: "0"
@@ -64,11 +57,9 @@ dependencies:
64
57
  name: nestful
65
58
  prerelease: false
66
59
  requirement: &id004 !ruby/object:Gem::Requirement
67
- none: false
68
60
  requirements:
69
61
  - - ">="
70
62
  - !ruby/object:Gem::Version
71
- hash: 3
72
63
  segments:
73
64
  - 0
74
65
  version: "0"
@@ -78,11 +69,9 @@ dependencies:
78
69
  name: terminal-table
79
70
  prerelease: false
80
71
  requirement: &id005 !ruby/object:Gem::Requirement
81
- none: false
82
72
  requirements:
83
73
  - - ">="
84
74
  - !ruby/object:Gem::Version
85
- hash: 3
86
75
  segments:
87
76
  - 0
88
77
  version: "0"
@@ -92,11 +81,9 @@ dependencies:
92
81
  name: rainbow
93
82
  prerelease: false
94
83
  requirement: &id006 !ruby/object:Gem::Requirement
95
- none: false
96
84
  requirements:
97
85
  - - ">="
98
86
  - !ruby/object:Gem::Version
99
- hash: 3
100
87
  segments:
101
88
  - 0
102
89
  version: "0"
@@ -106,16 +93,26 @@ dependencies:
106
93
  name: time-ago-in-words
107
94
  prerelease: false
108
95
  requirement: &id007 !ruby/object:Gem::Requirement
109
- none: false
110
96
  requirements:
111
97
  - - ">="
112
98
  - !ruby/object:Gem::Version
113
- hash: 3
114
99
  segments:
115
100
  - 0
116
101
  version: "0"
117
102
  type: :runtime
118
103
  version_requirements: *id007
104
+ - !ruby/object:Gem::Dependency
105
+ name: typhoeus
106
+ prerelease: false
107
+ requirement: &id008 !ruby/object:Gem::Requirement
108
+ requirements:
109
+ - - ">="
110
+ - !ruby/object:Gem::Version
111
+ segments:
112
+ - 0
113
+ version: "0"
114
+ type: :runtime
115
+ version_requirements: *id008
119
116
  description: A command line utility for Interstate, in Ruby using Thor
120
117
  email:
121
118
  - alec@suprfrends.com
@@ -127,6 +124,7 @@ extra_rdoc_files: []
127
124
 
128
125
  files:
129
126
  - .gitignore
127
+ - .todo/list.yml
130
128
  - Gemfile
131
129
  - Rakefile
132
130
  - bin/interstate
@@ -138,6 +136,7 @@ files:
138
136
  - lib/memfetcher.rb
139
137
  - lib/store.rb
140
138
  - lib/table.rb
139
+ has_rdoc: true
141
140
  homepage: http://www.bakedcode.com
142
141
  licenses: []
143
142
 
@@ -147,27 +146,23 @@ rdoc_options: []
147
146
  require_paths:
148
147
  - lib
149
148
  required_ruby_version: !ruby/object:Gem::Requirement
150
- none: false
151
149
  requirements:
152
150
  - - ">="
153
151
  - !ruby/object:Gem::Version
154
- hash: 3
155
152
  segments:
156
153
  - 0
157
154
  version: "0"
158
155
  required_rubygems_version: !ruby/object:Gem::Requirement
159
- none: false
160
156
  requirements:
161
157
  - - ">="
162
158
  - !ruby/object:Gem::Version
163
- hash: 3
164
159
  segments:
165
160
  - 0
166
161
  version: "0"
167
162
  requirements: []
168
163
 
169
164
  rubyforge_project: interstate
170
- rubygems_version: 1.8.5
165
+ rubygems_version: 1.3.6
171
166
  signing_key:
172
167
  specification_version: 3
173
168
  summary: Interstate-CLI