hcutil 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 77f30f1edefb05532d52792c5cb1a4db31fb6564
4
- data.tar.gz: ddbf759d7463550d63f6f5d2489310cdcb4b8539
3
+ metadata.gz: b3618c39717485726f3dd3e5ef4a72b96f99acf4
4
+ data.tar.gz: db70565f9a28b15923f7142e29b846621927ee7f
5
5
  SHA512:
6
- metadata.gz: c36bc23ce9663b9fb30eb6ab49085aedf99286c11175e0495f99366ffe6e4bfc406afcacba2ecdd44c5dd6d5b2121f3f6e7cd1e71369b8bc94cf77d9fe9626e8
7
- data.tar.gz: 319b336a8ca69bf84dfbfe0a57f6b58a794b86db1ecb558ee9ba2c491c879ae300f712dab51bd9557cf09fc5b2d4c73363504a69d1a2c9f5234f07dff1486370
6
+ metadata.gz: e7ff2825adbb74364a3ddc8c1323ac7916c4ee8638dfd8c6abf178302232c2cd339959be6c54e61b06a887b799212d5969d270a2b74f0c895445477a80360bab
7
+ data.tar.gz: 8424f71db151157a418918739e40f101b03487d4f6319c758b8b13d6439c9aa642a0db560131a0846938fe0fd6476b4ab28576e88fe416b16e7cab731044066d
data/lib/hcutil/auth.rb CHANGED
@@ -10,7 +10,8 @@ module HCUtil
10
10
  attr_reader :auth_token
11
11
 
12
12
  def initialize(options = {})
13
- if ENV['HOME'].nil? or ENV['HOME'] == '' or not Dir.exist?(ENV['HOME'])
13
+ home_env = ENV['HOME']
14
+ if home_env.nil_or_empty? or not Dir.exist?(ENV['HOME'])
14
15
  raise(AuthError, 'HOME env var not set or dir does not exist')
15
16
  end
16
17
 
data/lib/hcutil/cli.rb CHANGED
@@ -4,16 +4,11 @@
4
4
  require 'thor'
5
5
  require 'hcutil/version'
6
6
  require 'hcutil/copier'
7
+ require 'hcutil/pinger'
7
8
 
8
9
  module HCUtil
9
10
  class CLI < Thor
10
11
 
11
- class_option(:room,
12
- :desc => 'HipChat room with which to work',
13
- :aliases => '-r',
14
- :type => :string,
15
- :default => 'Client Services')
16
-
17
12
  class_option(:verbose,
18
13
  :desc => 'Verbose output',
19
14
  :type => :boolean,
@@ -29,6 +24,11 @@ module HCUtil
29
24
  end
30
25
 
31
26
  desc('copy ROOM_NAME', 'copy chat messages from ROOM_NAME')
27
+ option(:room,
28
+ :desc => 'HipChat room with which to work',
29
+ :aliases => '-r',
30
+ :type => :string,
31
+ :default => 'Client Services')
32
32
  option(:date,
33
33
  :desc => 'Date from which to copy messages',
34
34
  :type => :string,
@@ -41,12 +41,22 @@ module HCUtil
41
41
  :default => 25)
42
42
  def copy(room_name)
43
43
  begin
44
- copier = HCUtil::Copier.new(room_name, options)
45
- copier.copy()
44
+ copier = HCUtil::Copier.new(room_name, options)
45
+ copier.copy()
46
46
  rescue AuthError, CopierError => e
47
47
  $stderr.puts("[error] #{e.message}")
48
48
  end
49
49
  end
50
+
51
+ desc('ping TICKET_NUM RESPONSE_FILE SUMMARY', 'Ping Client Services HipChat room for ticket TICKET_NUM with text from RESPONSE_FILE. SUMMARY is optional.')
52
+ def ping(ticket_num, response_file, summary=nil)
53
+ begin
54
+ pinger = HCUtil::Pinger.new(ticket_num, response_file, summary, options)
55
+ pinger.ping()
56
+ rescue AuthError, PingerError => e
57
+ $stderr.puts("[error] #{e.message}")
58
+ end
59
+ end
50
60
  end
51
61
  end
52
62
 
data/lib/hcutil/copier.rb CHANGED
@@ -1,8 +1,4 @@
1
- require 'json'
2
- require 'rest_client'
3
- require 'time'
4
-
5
- require 'hcutil/auth'
1
+ require 'hcutil/op_base'
6
2
 
7
3
  module HCUtil
8
4
 
@@ -12,17 +8,11 @@ module HCUtil
12
8
  end
13
9
  end
14
10
 
15
- class Copier
11
+ class Copier < OpBase
16
12
  def initialize(room_name = 'Client Services', options = {})
13
+ super(options)
17
14
  @room_name = room_name
18
- @options = options
19
-
20
- @debug = @options[:debug]
21
- @verbose = @options[:verbose] || @options[:debug]
22
15
  @num_items = @options[:num_items] ||25
23
-
24
- RestClient.log = 'stdout' if @debug
25
- @auth = Auth.new(@options)
26
16
  end
27
17
 
28
18
  def copy
@@ -0,0 +1,12 @@
1
+ class NilClass
2
+ def nil_or_empty?
3
+ true
4
+ end
5
+ end
6
+
7
+ class String
8
+ def nil_or_empty?
9
+ empty?
10
+ end
11
+ end
12
+
@@ -0,0 +1,17 @@
1
+ require 'json'
2
+ require 'rest_client'
3
+ require 'time'
4
+ require 'hcutil/auth'
5
+
6
+ module HCUtil
7
+ class OpBase
8
+ def initialize(options = {})
9
+ @options = options
10
+ @debug = @options[:debug]
11
+ @verbose = @options[:verbose] || @options[:debug]
12
+ RestClient.log = 'stdout' if @debug
13
+ @auth = Auth.new(@options)
14
+ end
15
+ end
16
+ end
17
+
@@ -0,0 +1,53 @@
1
+ require 'hcutil/op_base'
2
+
3
+ module HCUtil
4
+
5
+ class PingerError < StandardError
6
+ def initialize(msg = 'PingerError')
7
+ super
8
+ end
9
+ end
10
+
11
+ class Pinger < OpBase
12
+ def initialize(ticket_num = nil, response_file = nil, summary = nil, options = {})
13
+ super(options)
14
+ if ticket_num =~ /^[0-9]{4,}$/
15
+ @ticket_num = ticket_num
16
+ else
17
+ raise(PingerError, 'Ticket number must be 4 or more digits')
18
+ end
19
+ if File.exists?(response_file)
20
+ @response_file = response_file
21
+ else
22
+ raise(PingerError, "Response file '#{response_file}' does not exist")
23
+ end
24
+ @summary = summary
25
+ end
26
+
27
+ def ping
28
+ message = <<"EOT"
29
+ ticket ##{@ticket_num} - #{@summary}
30
+ #{File.read(@response_file)}
31
+ EOT
32
+ post_data = {
33
+ :message_format => 'text',
34
+ :color => 'purple',
35
+ :message => message
36
+ }
37
+
38
+ header_args = {
39
+ :content_type => :json,
40
+ :accept => :json,
41
+ :authorization => "Bearer #{@auth.auth_token}"
42
+ }
43
+
44
+ RestClient.post('https://api.hipchat.com/v2/room/61640/notification',
45
+ post_data.to_json, header_args) do |response, request, result|
46
+ unless result.is_a? Net::HTTPSuccess
47
+ raise(PingerError, "REST error: #{result}|#{response}")
48
+ end
49
+ end
50
+ end
51
+ end
52
+ end
53
+
@@ -1,3 +1,3 @@
1
1
  module HCUtil
2
- VERSION = '0.0.2'.freeze
2
+ VERSION = '0.0.3'.freeze
3
3
  end
data/lib/hcutil.rb CHANGED
@@ -1,2 +1,4 @@
1
1
  require 'hcutil/version'
2
2
  require 'hcutil/cli'
3
+ require 'hcutil/extensions'
4
+
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hcutil
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Luke Bakken
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-03-31 00:00:00.000000000 Z
11
+ date: 2014-04-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: json
@@ -66,6 +66,9 @@ files:
66
66
  - lib/hcutil/auth.rb
67
67
  - lib/hcutil/cli.rb
68
68
  - lib/hcutil/copier.rb
69
+ - lib/hcutil/extensions.rb
70
+ - lib/hcutil/op_base.rb
71
+ - lib/hcutil/pinger.rb
69
72
  - lib/hcutil/version.rb
70
73
  homepage: http://github.com/lukebakken/hipchat-util
71
74
  licenses: []