hcutil 0.2.0 → 0.3.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.rb +0 -1
- data/lib/hcutil/cli.rb +1 -1
- data/lib/hcutil/copier.rb +24 -65
- data/lib/hcutil/op_base.rb +28 -0
- data/lib/hcutil/paster.rb +1 -5
- data/lib/hcutil/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 719f8fb9e87a73f65d314c91fd8308c45c1a52a6
|
4
|
+
data.tar.gz: 75591063b81f07c1fd0772c1a7d981749768b34f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 264f41c29b7d4f8b61b83d3d83a17ed3ee6b992be5b43218fa16620d80a2709428b7558edfcf99d1b9d9d38a80efec20724151300d07c28094d16c1114780c4d
|
7
|
+
data.tar.gz: f79033e32d7a4c5ca2c945128bf7c76c4ce9638e4fd4d8c3e906badaf6006dbdaacce92d3b35ef3d78f790e1c9fc775bc5d3aa65031fbdcf400a4edad6b93fd3
|
data/lib/hcutil.rb
CHANGED
data/lib/hcutil/cli.rb
CHANGED
data/lib/hcutil/copier.rb
CHANGED
@@ -1,5 +1,4 @@
|
|
1
1
|
require 'hcutil/errors'
|
2
|
-
require 'hcutil/extensions'
|
3
2
|
require 'hcutil/op_base'
|
4
3
|
require 'uri'
|
5
4
|
require 'cgi'
|
@@ -10,7 +9,7 @@ module HCUtil
|
|
10
9
|
def initialize(room_name = 'Client Services', options = {})
|
11
10
|
super(options)
|
12
11
|
@room_name = room_name
|
13
|
-
@num_items = @options[:num_items] ||
|
12
|
+
@num_items = @options[:num_items] ||25
|
14
13
|
end
|
15
14
|
|
16
15
|
def get_room_id(start_index=0)
|
@@ -26,7 +25,7 @@ module HCUtil
|
|
26
25
|
}
|
27
26
|
}
|
28
27
|
uri_direct = uri + URI.escape("/#{@room_name}")
|
29
|
-
|
28
|
+
get_request(uri_direct, param_arg) do |response, request, result|
|
30
29
|
if result.is_a? Net::HTTPSuccess
|
31
30
|
json = JSON.parse(response.body)
|
32
31
|
if json['id']
|
@@ -49,7 +48,7 @@ module HCUtil
|
|
49
48
|
|
50
49
|
room_id = 0
|
51
50
|
|
52
|
-
|
51
|
+
get_request(uri, param_arg) do |response, request, result|
|
53
52
|
if result.is_a? Net::HTTPSuccess
|
54
53
|
json = JSON.parse(response.body)
|
55
54
|
if json['items']
|
@@ -82,91 +81,51 @@ module HCUtil
|
|
82
81
|
return room_id
|
83
82
|
end
|
84
83
|
|
85
|
-
def
|
84
|
+
def copy
|
85
|
+
room_id = get_room_id
|
86
|
+
if room_id == 0
|
87
|
+
raise(Errors::CopierError, "Room with name '#{@room_name}' could not be found")
|
88
|
+
end
|
89
|
+
|
90
|
+
chat_date = @options[:date]
|
91
|
+
$stderr.puts("Getting history for #{chat_date.to_s}") if @verbose
|
86
92
|
|
87
93
|
param_arg = {
|
88
94
|
:accept => :json,
|
89
95
|
:params => {
|
90
96
|
:auth_token => @auth.auth_token,
|
91
97
|
:date => chat_date,
|
92
|
-
'
|
93
|
-
'max-results' => 100
|
98
|
+
'max-results' => @num_items
|
94
99
|
}
|
95
100
|
}
|
96
101
|
|
97
102
|
uri = "https://api.hipchat.com/v2/room/#{room_id}/history"
|
98
103
|
json = nil
|
99
|
-
|
104
|
+
get_request(uri, param_arg) do |response, request, result|
|
100
105
|
if result.is_a? Net::HTTPSuccess
|
101
106
|
json = JSON.parse(response.body)
|
102
|
-
jsons.unshift(json)
|
103
|
-
items = json['items']
|
104
|
-
unless items.nil?
|
105
|
-
msg_count += items.count
|
106
|
-
links = json['links']
|
107
|
-
if msg_count >= @num_items or links.nil?
|
108
|
-
return jsons
|
109
|
-
else
|
110
|
-
next_uri = links['next']
|
111
|
-
unless next_uri.nil_or_empty?
|
112
|
-
query = URI.parse(next_uri).query
|
113
|
-
query_params = CGI.parse(query)
|
114
|
-
start_index = query_params['start-index'].first
|
115
|
-
$stderr.puts("retrieving history for room '#{room_id}' with start_index #{start_index} next_uri #{next_uri}") if @verbose
|
116
|
-
return get_history(room_id, chat_date, msg_count, start_index, jsons)
|
117
|
-
end
|
118
|
-
end
|
119
|
-
else
|
120
|
-
raise(Errors::CopierError, "Room with id '#{room_id}' - could not parse history JSON - missing 'items'")
|
121
|
-
end
|
122
107
|
else
|
123
108
|
raise(Errors::RESTError.new(result, uri, response))
|
124
109
|
end
|
125
110
|
end
|
126
|
-
return jsons
|
127
|
-
end
|
128
|
-
|
129
|
-
def copy
|
130
|
-
room_id = get_room_id
|
131
|
-
if room_id == 0
|
132
|
-
raise(Errors::CopierError, "Room with name '#{@room_name}' could not be found")
|
133
|
-
end
|
134
|
-
|
135
|
-
opt_date = @options[:date]
|
136
|
-
if opt_date.is_a?(Time)
|
137
|
-
chat_date = opt_date
|
138
|
-
else
|
139
|
-
chat_date = Time.parse(opt_date)
|
140
|
-
end
|
141
|
-
chat_date_utc_iso8601_s = chat_date.dup.utc.iso8601.to_s
|
142
|
-
$stderr.puts("Getting history for date #{chat_date.to_s} utc/iso8601 #{chat_date_utc_iso8601_s}") if @verbose
|
143
|
-
|
144
|
-
jsons = []
|
145
|
-
get_history(room_id, chat_date_utc_iso8601_s, 0, 0, jsons)
|
146
111
|
|
147
112
|
if @debug
|
148
113
|
chat_json_file = "messages-#{room_id}-#{chat_date.strftime('%Y-%m-%d')}.json"
|
149
|
-
File.open(chat_json_file, 'w')
|
150
|
-
jsons.each do |json|
|
151
|
-
f.write(json.inspect)
|
152
|
-
end
|
153
|
-
end
|
114
|
+
File.open(chat_json_file, 'w') { |f| f.write(json.inspect) }
|
154
115
|
$stderr.puts "Chat JSON saved to #{chat_json_file}"
|
155
116
|
end
|
156
117
|
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
name = from
|
166
|
-
end
|
167
|
-
message = item['message']
|
168
|
-
puts "#{date} #{name}: #{message}"
|
118
|
+
items = json['items']
|
119
|
+
items.each do |item|
|
120
|
+
date = Time.parse(item['date']).strftime('%Y-%m-%d %H:%M:%S')
|
121
|
+
from = item['from']
|
122
|
+
if from.is_a?(Hash)
|
123
|
+
name = from['name']
|
124
|
+
else
|
125
|
+
name = from
|
169
126
|
end
|
127
|
+
message = item['message']
|
128
|
+
puts "#{date} #{name}: #{message}"
|
170
129
|
end
|
171
130
|
end
|
172
131
|
end
|
data/lib/hcutil/op_base.rb
CHANGED
@@ -12,6 +12,34 @@ module HCUtil
|
|
12
12
|
RestClient.log = 'stdout' if @debug
|
13
13
|
@auth = Auth.new(@options)
|
14
14
|
end
|
15
|
+
|
16
|
+
def post_request(url, payload, headers)
|
17
|
+
RestClient::Request.execute(:url => url, :method => :post,
|
18
|
+
:payload => payload, :headers => headers,
|
19
|
+
:ssl_version => :TLSv1_2) do |response, request, result|
|
20
|
+
if block_given?
|
21
|
+
yield(response, request, result)
|
22
|
+
else
|
23
|
+
unless result.is_a? Net::HTTPSuccess
|
24
|
+
raise(Errors::RESTError.new(result, url, response))
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def get_request(url, headers)
|
31
|
+
RestClient::Request.execute(:url => url, :method => :get,
|
32
|
+
:headers => headers,
|
33
|
+
:ssl_version => :TLSv1_2) do |response, request, result|
|
34
|
+
if block_given?
|
35
|
+
yield(response, request, result)
|
36
|
+
else
|
37
|
+
unless result.is_a? Net::HTTPSuccess
|
38
|
+
raise(Errors::RESTError.new(result, url, response))
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
15
43
|
end
|
16
44
|
end
|
17
45
|
|
data/lib/hcutil/paster.rb
CHANGED
@@ -46,11 +46,7 @@ EOT
|
|
46
46
|
|
47
47
|
room_esc = URI.escape(@room.to_s)
|
48
48
|
uri = "https://api.hipchat.com/v2/room/#{room_esc}/notification"
|
49
|
-
|
50
|
-
unless result.is_a? Net::HTTPSuccess
|
51
|
-
raise(Errors::RESTError.new(result, uri, response))
|
52
|
-
end
|
53
|
-
end
|
49
|
+
post_request(uri, post_data.to_json, header_args)
|
54
50
|
end
|
55
51
|
end
|
56
52
|
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.
|
4
|
+
version: 0.3.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-10-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: thor
|
@@ -78,7 +78,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
78
78
|
version: '0'
|
79
79
|
requirements: []
|
80
80
|
rubyforge_project: hipchat-util
|
81
|
-
rubygems_version: 2.
|
81
|
+
rubygems_version: 2.4.1
|
82
82
|
signing_key:
|
83
83
|
specification_version: 4
|
84
84
|
summary: Utility for working with HipChat from the command line
|