blend 0.1.4

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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 120a7c05e22b4043bb3650ed02fb6860ed58ac51
4
+ data.tar.gz: f1f7afe02e7b7b702b2fb8eeb85562cca2459f8a
5
+ SHA512:
6
+ metadata.gz: ccf612f425adba2e546170d4430e42bdc360e63b3a64c8e0c456efbe5d05d2ed0d4e04f37082c4c4f068ea2738d1902f5bcc91e7c79564671244868be136136e
7
+ data.tar.gz: cac60c4e263c71a15ee9e00161e6e6d5eb7a5939ce8f3af512c77e9cf2c66707562456fb0cc5f121d745f29577c3ef55e105f4a71066757fc54698e946b62b80
@@ -0,0 +1,38 @@
1
+ #!/usr/bin/env rake
2
+ begin
3
+ require 'bundler/setup'
4
+ rescue LoadError
5
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
6
+ end
7
+ begin
8
+ require 'rdoc/task'
9
+ rescue LoadError
10
+ require 'rdoc/rdoc'
11
+ require 'rake/rdoctask'
12
+ RDoc::Task = Rake::RDocTask
13
+ end
14
+
15
+ RDoc::Task.new(:rdoc) do |rdoc|
16
+ rdoc.rdoc_dir = 'rdoc'
17
+ rdoc.title = 'blend'
18
+ rdoc.options << '--line-numbers'
19
+ rdoc.rdoc_files.include('README.rdoc')
20
+ rdoc.rdoc_files.include('lib/**/*.rb')
21
+ end
22
+
23
+
24
+
25
+
26
+ Bundler::GemHelper.install_tasks
27
+
28
+ require 'rake/testtask'
29
+
30
+ Rake::TestTask.new(:test) do |t|
31
+ t.libs << 'lib'
32
+ t.libs << 'test'
33
+ t.pattern = 'test/**/*_test.rb'
34
+ t.verbose = false
35
+ end
36
+
37
+
38
+ task :default => :test
@@ -0,0 +1,34 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'blend'
4
+ require 'colorize'
5
+
6
+ begin
7
+ Blend::CLI::CLI.start( ARGV )
8
+
9
+ rescue Blend::Exceptions::LoginAuthenticationFailure
10
+ puts "Login credentials invalid.".red
11
+
12
+ rescue Blend::Exceptions::AuthenticationFailure
13
+ puts "Login credentials invalid.".red
14
+ puts ""
15
+ puts "You probably need to log out and log back in again:"
16
+ puts " $ blend juice logout"
17
+ puts " $ blend juice login"
18
+
19
+ rescue Blend::Exceptions::AlreadyLoggedIn
20
+ puts "You're already logged in."
21
+
22
+ rescue Blend::Exceptions::AlreadyLoggedOut
23
+ puts "You're already logged out."
24
+
25
+ rescue Psych::SyntaxError
26
+ $stderr.puts "\n\tError during processing: #{$!.message}\n\n"
27
+
28
+ rescue Heroku::API::Errors::Forbidden
29
+ puts "\nError: You don't have permission to access this Heroku resource".red
30
+
31
+ rescue Heroku::API::Errors::NotFound
32
+ puts "\nError: Heroku resource not found".red
33
+
34
+ end
@@ -0,0 +1,28 @@
1
+ require 'thor'
2
+ require 'colorize'
3
+ require 'hipchat-api'
4
+ require 'github_api' # Note the underbar
5
+ require 'heroku-api'
6
+
7
+ require 'blend/core_ext/string'
8
+ require 'blend/core_ext/object'
9
+ require 'blend/core_ext/fixnum'
10
+
11
+ # require 'blend/domain_checker'
12
+ require 'blend/exceptions'
13
+ require 'blend/cli'
14
+ require 'blend/client'
15
+ require 'blend/status/project'
16
+ require 'blend/version'
17
+
18
+ require 'pp'
19
+
20
+ begin
21
+ Lita
22
+ require 'blend/chatbot/bot'
23
+ rescue NameError
24
+ end
25
+
26
+ module Blend
27
+
28
+ end
@@ -0,0 +1,352 @@
1
+ require 'active_support/time'
2
+ require 'json'
3
+ require 'httparty'
4
+
5
+ module Blend
6
+ class Bot < Lita::Handler
7
+ route /^echo\s+(.+)/, :echo, command: true, help: { "echo test" => "Replies back with test" }
8
+ route /^(wtf|what)\s*(happened )?([\w\s]*)\??$/i, :wtf, command: true, help: { "wtf [time interval]" => "Project activity. Time interval defaults to this week. Options are 'today', 'yesterday', 'this week', 'last week', 'this month', 'last month'. 'wtf happened' and 'what happened' are also valid." }
9
+ route /^project_id/i, :project_id, command: true, help: { 'project_id' => 'Print the juice project id' }
10
+ route /^projects/, :projects, command: true, help: {'projects' => 'A list of Juice projects'}
11
+ route /^who\s+is\s+(\w+)\??/i, :whois, command: true, help: {'who is [SEARCH TERM]' => 'Search the rosetta stone for employee info'}
12
+
13
+ route /^check$/, :check, command: true #totally incomplete and useless right now.
14
+ route /^tell (\w+)\s*(he|to)?\s+(.*)/i, :tell, command: true
15
+ route /^chuck$/, :chuck, command: true
16
+ route /^make me a sandwich/, :make_me_a_sandwich, command: true
17
+ route /^sudo make me a sandwich/, :sudo_make_me_a_sandwich, command: true
18
+ route /^emoticons/, :emoticons, command: true, :help: {'emoticons' => 'List all emoticons'}
19
+
20
+ def whois(response)
21
+ answer = StringIO.new
22
+ Client.juice_client.search_users( response.match_data[1] ).each_with_index do |user,i|
23
+ answer.puts if i>0
24
+ answer.puts "#{user['name'] || user['email']}:"
25
+ %w( name country phone email personal_email skype_handle github_handle heroku_handle hipchat_handle).each do |field|
26
+ answer.printf "%-15s: %s\n", field, (user[field].nil? || user[field].length==0 ? '?' : user[field])
27
+ end
28
+ end
29
+ response.reply( answer.string )
30
+ end
31
+
32
+
33
+ class << self
34
+ def project_id( response )
35
+ Blend::Client.juice_client.project_id_from_room( ENV['HIPBOT_ROOM'] || response.message.source.room )
36
+ end
37
+
38
+ def capture_stderr
39
+ previous_stderr, $stderr = $stderr, StringIO.new
40
+ yield
41
+ $stderr.string
42
+ ensure
43
+ $stderr = previous_stderr
44
+ end
45
+
46
+ end
47
+
48
+
49
+ def tell(response)
50
+ response.reply( "Hey #{response.match_data[1]}, #{response.match_data[3]}" )
51
+ end
52
+
53
+
54
+
55
+
56
+ def project_id(response)
57
+ project_id = self.class.project_id(response)
58
+ response.reply( 'No project found for this room!' ) and return if project_id.nil?
59
+
60
+ response.reply( project_id )
61
+ end
62
+
63
+
64
+ def check(response)
65
+ project_id = self.class.project_id(response)
66
+ response.reply( 'No project found for this room!' ) and return if project_id.nil?
67
+
68
+ response.reply( Client.juice_client.check( project_id ).to_s)
69
+ end
70
+
71
+
72
+
73
+ def wtf(response)
74
+
75
+ case response.match_data[-1].strip
76
+ when 'last month', 'lastmonth', 'last_month'
77
+ after = (Time.now-1.month).beginning_of_month
78
+ before = (Time.now-1.month).end_of_month
79
+ when 'this month', 'thismonth', 'this_month'
80
+ after = (Time.now).beginning_of_month
81
+ before = (Time.now).end_of_month
82
+
83
+ when 'last week', 'lastweek', 'last_week'
84
+ after = (Time.now-1.week).beginning_of_week
85
+ before = (Time.now-1.week).end_of_week
86
+ when 'this week', 'thisweek', 'this_week'
87
+ after = (Time.now).beginning_of_week
88
+ before = (Time.now).end_of_week
89
+
90
+ when 'today'
91
+ after = (Time.now).beginning_of_day
92
+ before = (Time.now).end_of_day
93
+ when 'yesterday'
94
+ after = (Time.now-1.day).beginning_of_day
95
+ before = (Time.now-1.day).end_of_day
96
+ else
97
+ if response.match_data[-1].nil? or response.match_data[-1].length==0
98
+ after = (Time.now).beginning_of_week
99
+ before = (Time.now).end_of_week
100
+ else
101
+ response.reply("Unrecognized time interval, '#{response.match_data[-1]}'. Valid options are today, yesterday, this week, last week, this month, last month.")
102
+ return
103
+ end
104
+ end
105
+
106
+
107
+ project_id = self.class.project_id(response)
108
+ response.reply( 'No project found for this room!' ) and return if project_id.nil?
109
+
110
+ summary = Client.juice_client.activities( project_id, after, before)
111
+
112
+ answer = StringIO.new
113
+
114
+ answer.printf "Project activity from #{after.strftime('%A, %F')} to #{before.strftime('%A, %F')}\n"
115
+
116
+ summary[:actors_activites].keys.sort.each do |x|
117
+ summary[:actors_activites][x].keys.reject(&:nil?).sort.each do |type|
118
+ answer.printf "%-6s %-25s %s\n", summary[:actors_activites][x][type].count, type.strip_email, x
119
+ end
120
+ end
121
+
122
+ answer.puts
123
+
124
+ #summary[:type].keys.sort.each do |x|
125
+ #answer.printf( "%-6s %s\n", summary[:type][x].count, x )
126
+ #end
127
+
128
+ response.reply(answer.string)
129
+ end
130
+
131
+
132
+ def projects(response)
133
+ answer = Blend::Client.juice_client.projects
134
+ response.reply( answer.collect{|x| x['name']}.join(', ') )
135
+ end
136
+
137
+
138
+ def chuck(response)
139
+ response.reply HTTParty.get('http://api.icndb.com/jokes/random').parsed_response['value']['joke']
140
+ end
141
+
142
+ def make_me_a_sandwich(response)
143
+ response.reply('What? No. Make it yourself.')
144
+ end
145
+
146
+ def emoticons(response)
147
+ response.reply(DATA)
148
+ end
149
+
150
+ def sudo_make_me_a_sandwich(response)
151
+ response.reply('Okay.')
152
+ end
153
+
154
+
155
+ def echo(response)
156
+ pp response.message.source
157
+ domain = response.match_data[1]
158
+ puts "Printing back #{domain}"
159
+ # line = ::Cocaine::CommandLine.new("whois", ':domain')
160
+ response.reply(domain)
161
+ end
162
+
163
+ end
164
+
165
+ Lita.register_handler(Bot)
166
+ end
167
+
168
+
169
+ __END__
170
+ (allthethings)
171
+ (android)
172
+ (areyoukiddingme)
173
+ (arrington)
174
+ (ashton)
175
+ (atlassian)
176
+ (awthanks)
177
+ (awyeah)
178
+ (badass)
179
+ (badjokeeel)
180
+ (badpokerface)
181
+ (basket)
182
+ (beer)
183
+ (bitbucket)
184
+ (boom)
185
+ (branch)
186
+ (bumble)
187
+ (bunny)
188
+ (cadbury)
189
+ (cake)
190
+ (candycorn)
191
+ (caruso)
192
+ (ceilingcat)
193
+ (cereal)
194
+ (cerealspit)
195
+ (challengeaccepted)
196
+ (chewie)
197
+ (chocobunny)
198
+ (chompy)
199
+ (chris)
200
+ (chucknorris)
201
+ (clarence)
202
+ (coffee)
203
+ (confluence)
204
+ (content)
205
+ (continue)
206
+ (cornelius)
207
+ (dance)
208
+ (dealwithit)
209
+ (derp)
210
+ (disapproval)
211
+ (dosequis)
212
+ (drevil)
213
+ (ducreux)
214
+ (dumb)
215
+ (embarrassed)
216
+ (facepalm)
217
+ (failed)
218
+ (fap)
219
+ (firstworldproblem)
220
+ (fonzie)
221
+ (foreveralone)
222
+ (freddie)
223
+ (fry)
224
+ (fuckyeah)
225
+ (fwp)
226
+ (gangnamstyle)
227
+ (garret)
228
+ (gates)
229
+ (ghost)
230
+ (goodnews)
231
+ (greenbeer)
232
+ (grumpycat)
233
+ (gtfo)
234
+ (haveaseat)
235
+ (heart)
236
+ (hipchat)
237
+ (hipster)
238
+ (huh)
239
+ (ilied)
240
+ (indeed)
241
+ (iseewhatyoudidthere)
242
+ (itsatrap)
243
+ (jackie)
244
+ (jira)
245
+ (jobs)
246
+ (kennypowers)
247
+ (krang)
248
+ (kwanzaa)
249
+ (lincoln)
250
+ (lol)
251
+ (lolwut)
252
+ (megusta)
253
+ (menorah)
254
+ (mindblown)
255
+ (ninja)
256
+ (notbad)
257
+ (nothingtodohere)
258
+ (notsureif)
259
+ (notsureifgusta)
260
+ (obama)
261
+ (ohcrap)
262
+ (ohgodwhy)
263
+ (okay)
264
+ (omg)
265
+ (oops)
266
+ (orly)
267
+ (pbr)
268
+ (pete)
269
+ (philosoraptor)
270
+ (pingpong)
271
+ (pirate)
272
+ (pokerface)
273
+ (poo)
274
+ (present)
275
+ (pumpkin)
276
+ (rageguy)
277
+ (rebeccablack)
278
+ (reddit)
279
+ (romney)
280
+ (rudolph)
281
+ (sadpanda)
282
+ (sadtroll)
283
+ (samuel)
284
+ (santa)
285
+ (scumbag)
286
+ (seomoz)
287
+ (shamrock)
288
+ (shrug)
289
+ (skyrim)
290
+ (stare)
291
+ (success)
292
+ (successful)
293
+ (sweetjesus)
294
+ (tableflip)
295
+ (taft)
296
+ (tea)
297
+ (thumbsdown)
298
+ (thumbsup)
299
+ (tree)
300
+ (troll)
301
+ (truestory)
302
+ (trump)
303
+ (turkey)
304
+ (twss)
305
+ (unknown)
306
+ (washington)
307
+ (wat)
308
+ (wtf)
309
+ (yey)
310
+ (yodawg)
311
+ (yougotitdude)
312
+ (yuno)
313
+ (zoidberg)
314
+ (zzz)
315
+ 8)
316
+ :#
317
+ :$
318
+ :'(
319
+ :')
320
+ :(
321
+ :)
322
+ :-*
323
+ :D
324
+ :Z
325
+ :\
326
+ :o
327
+ :p
328
+ :|
329
+ ;)
330
+ ;p
331
+ >:-(
332
+ O:)
333
+ (rock)
334
+ (will)
335
+ (whatdoesthatevenmean)
336
+ (fairenough)
337
+ (thatsawesome)
338
+ (doyouwanttochatnow)
339
+ (angryasian)
340
+ (racist)
341
+ (lacist)
342
+ (samsung)
343
+ (canweusejira)
344
+ (thatamazing)
345
+ (thatsamazeballs)
346
+ (chatnow)
347
+ (amazeballs)
348
+ (ricky)
349
+ (lumbergh)
350
+ (lumberg)
351
+ (sick)
352
+ (aaron)