hcutil 0.0.5 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/hcutil/copier.rb +57 -10
- 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: cda8f8722f1082df41310321a8247b8d774faa9a
|
4
|
+
data.tar.gz: 5735490131e3f9a06e4e2530fcbccbad902edb66
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 237efc41d13f825978b7b2be90dbb4b94ecf53233c0cc642b664aae9e8bb6c3f923013f1d6063aa0262bc16d4509aa3b3bcca02cb6f756c453425e9aa6083a4a
|
7
|
+
data.tar.gz: c3f95714e3a609b3b9ddf790db4e57c2dc35e16a23e1c6c0e0224702b779859440789dea14c5ef862407cbf791ba767b25a02efee1531dd9cc75cb03ece8ce2f
|
data/lib/hcutil/copier.rb
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
require 'hcutil/errors'
|
2
2
|
require 'hcutil/op_base'
|
3
|
+
require 'uri'
|
4
|
+
require 'cgi'
|
3
5
|
|
4
6
|
module HCUtil
|
5
7
|
|
@@ -10,32 +12,77 @@ module HCUtil
|
|
10
12
|
@num_items = @options[:num_items] ||25
|
11
13
|
end
|
12
14
|
|
13
|
-
def
|
14
|
-
|
15
|
+
def get_room_id(start_index=0)
|
16
|
+
|
17
|
+
uri = 'https://api.hipchat.com/v2/room'
|
18
|
+
|
19
|
+
# First, try to get the room directly by name
|
20
|
+
if start_index == 0
|
21
|
+
param_arg = {
|
22
|
+
:accept => :json,
|
23
|
+
:params => {
|
24
|
+
'auth_token' => @auth.auth_token
|
25
|
+
}
|
26
|
+
}
|
27
|
+
uri_direct = uri + URI.escape("/#{@room_name}")
|
28
|
+
RestClient.get(uri_direct, param_arg) do |response, request, result|
|
29
|
+
if result.is_a? Net::HTTPSuccess
|
30
|
+
json = JSON.parse(response.body)
|
31
|
+
if json['id']
|
32
|
+
room_id = json['id']
|
33
|
+
$stderr.puts("Room '#{@room_name}' has ID #{room_id}") if @verbose
|
34
|
+
return room_id
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
15
39
|
|
16
40
|
param_arg = {
|
17
41
|
:accept => :json,
|
18
42
|
:params => {
|
19
|
-
|
43
|
+
'auth_token' => @auth.auth_token,
|
44
|
+
'start-index' => start_index,
|
45
|
+
'max-results' => 100
|
20
46
|
}
|
21
47
|
}
|
22
|
-
|
48
|
+
|
49
|
+
room_id = 0
|
50
|
+
|
23
51
|
RestClient.get(uri, param_arg) do |response, request, result|
|
24
52
|
if result.is_a? Net::HTTPSuccess
|
25
53
|
json = JSON.parse(response.body)
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
54
|
+
if json['items']
|
55
|
+
items = json['items']
|
56
|
+
items.each do |item|
|
57
|
+
if item['name'] == @room_name
|
58
|
+
room_id = item['id']
|
59
|
+
$stderr.puts("Room '#{@room_name}' has ID #{room_id}") if @verbose
|
60
|
+
break
|
61
|
+
end
|
62
|
+
end
|
63
|
+
links = json['links']
|
64
|
+
if room_id == 0 and not links.nil?
|
65
|
+
next_uri = links['next']
|
66
|
+
unless next_uri.nil_or_empty?
|
67
|
+
query = URI.parse(next_uri).query
|
68
|
+
query_params = CGI.parse(query)
|
69
|
+
start_index = query_params['start-index'].first
|
70
|
+
$stderr.puts("finding '#{@room_name}' with start_index #{start_index}") if @verbose
|
71
|
+
return get_room_id(start_index)
|
72
|
+
end
|
32
73
|
end
|
74
|
+
else
|
75
|
+
raise(Errors::CopierError, "Room with name '#{@room_name}' could not be found - could not parse JSON")
|
33
76
|
end
|
34
77
|
else
|
35
78
|
raise(Errors::RESTError.new(result, uri, response))
|
36
79
|
end
|
37
80
|
end
|
81
|
+
return room_id
|
82
|
+
end
|
38
83
|
|
84
|
+
def copy
|
85
|
+
room_id = get_room_id
|
39
86
|
if room_id == 0
|
40
87
|
raise(Errors::CopierError, "Room with name '#{@room_name}' could not be found")
|
41
88
|
end
|
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.1.0
|
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-
|
11
|
+
date: 2014-05-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: thor
|