hcutil 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/hcutil/auth.rb +5 -7
- data/lib/hcutil/cli.rb +5 -1
- data/lib/hcutil/copier.rb +19 -8
- data/lib/hcutil/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 77f30f1edefb05532d52792c5cb1a4db31fb6564
|
4
|
+
data.tar.gz: ddbf759d7463550d63f6f5d2489310cdcb4b8539
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c36bc23ce9663b9fb30eb6ab49085aedf99286c11175e0495f99366ffe6e4bfc406afcacba2ecdd44c5dd6d5b2121f3f6e7cd1e71369b8bc94cf77d9fe9626e8
|
7
|
+
data.tar.gz: 319b336a8ca69bf84dfbfe0a57f6b58a794b86db1ecb558ee9ba2c491c879ae300f712dab51bd9557cf09fc5b2d4c73363504a69d1a2c9f5234f07dff1486370
|
data/lib/hcutil/auth.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
module HCUtil
|
2
2
|
class AuthError < StandardError
|
3
|
-
def initialize(
|
4
|
-
|
3
|
+
def initialize(msg = 'AuthError')
|
4
|
+
super
|
5
5
|
end
|
6
6
|
end
|
7
7
|
|
@@ -10,10 +10,8 @@ module HCUtil
|
|
10
10
|
attr_reader :auth_token
|
11
11
|
|
12
12
|
def initialize(options = {})
|
13
|
-
if ENV['HOME'].nil? or
|
14
|
-
|
15
|
-
(not Dir.exist?(ENV['HOME']))
|
16
|
-
raise AuthError.new('[error]: HOME env var not set or dir does not exist')
|
13
|
+
if ENV['HOME'].nil? or ENV['HOME'] == '' or not Dir.exist?(ENV['HOME'])
|
14
|
+
raise(AuthError, 'HOME env var not set or dir does not exist')
|
17
15
|
end
|
18
16
|
|
19
17
|
auth_file = File.join(ENV['HOME'], '.hcapi')
|
@@ -21,7 +19,7 @@ module HCUtil
|
|
21
19
|
@auth_token = File.read(auth_file).gsub("\n", ' ').squeeze(' ')
|
22
20
|
$stderr.puts("Auth token: #{auth_token}") if options[:verbose]
|
23
21
|
else
|
24
|
-
raise
|
22
|
+
raise(AuthError, 'missing auth token file ~/.hcapi')
|
25
23
|
end
|
26
24
|
end
|
27
25
|
end
|
data/lib/hcutil/cli.rb
CHANGED
@@ -33,15 +33,19 @@ module HCUtil
|
|
33
33
|
:desc => 'Date from which to copy messages',
|
34
34
|
:type => :string,
|
35
35
|
:aliases => '-d',
|
36
|
-
:default => Time.now
|
36
|
+
:default => Time.now)
|
37
37
|
option(:num_items,
|
38
38
|
:desc => 'Number of chat messages to copy',
|
39
39
|
:aliases => '-n',
|
40
40
|
:type => :numeric,
|
41
41
|
:default => 25)
|
42
42
|
def copy(room_name)
|
43
|
+
begin
|
43
44
|
copier = HCUtil::Copier.new(room_name, options)
|
44
45
|
copier.copy()
|
46
|
+
rescue AuthError, CopierError => e
|
47
|
+
$stderr.puts("[error] #{e.message}")
|
48
|
+
end
|
45
49
|
end
|
46
50
|
end
|
47
51
|
end
|
data/lib/hcutil/copier.rb
CHANGED
@@ -7,6 +7,9 @@ require 'hcutil/auth'
|
|
7
7
|
module HCUtil
|
8
8
|
|
9
9
|
class CopierError < StandardError
|
10
|
+
def initialize(msg = 'CopierError')
|
11
|
+
super
|
12
|
+
end
|
10
13
|
end
|
11
14
|
|
12
15
|
class Copier
|
@@ -32,14 +35,18 @@ module HCUtil
|
|
32
35
|
}
|
33
36
|
}
|
34
37
|
RestClient.get('https://api.hipchat.com/v2/room', param_arg) do |response, request, result|
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
38
|
+
if result.is_a? Net::HTTPSuccess
|
39
|
+
json = JSON.parse(response.body)
|
40
|
+
items = json['items']
|
41
|
+
items.each do |item|
|
42
|
+
if item['name'] == @room_name
|
43
|
+
room_id = item['id']
|
44
|
+
$stderr.puts("Room '#{@room_name}' has ID #{room_id}") if @verbose
|
45
|
+
break
|
46
|
+
end
|
42
47
|
end
|
48
|
+
else
|
49
|
+
raise(CopierError, "REST error: #{result}|#{response}")
|
43
50
|
end
|
44
51
|
end
|
45
52
|
|
@@ -57,7 +64,11 @@ module HCUtil
|
|
57
64
|
|
58
65
|
json = nil
|
59
66
|
RestClient.get("https://api.hipchat.com/v2/room/#{room_id}/history", param_arg) do |response, request, result|
|
60
|
-
|
67
|
+
if result.is_a? Net::HTTPSuccess
|
68
|
+
json = JSON.parse(response.body)
|
69
|
+
else
|
70
|
+
raise(CopierError, "REST error: #{result}|#{response}")
|
71
|
+
end
|
61
72
|
end
|
62
73
|
|
63
74
|
if @debug
|
data/lib/hcutil/version.rb
CHANGED
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.
|
4
|
+
version: 0.0.2
|
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-
|
11
|
+
date: 2014-03-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: json
|