hcutil 0.1.0 → 0.2.0
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.
- checksums.yaml +4 -4
- data/lib/hcutil/cli.rb +1 -1
- data/lib/hcutil/copier.rb +62 -21
- 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: 1b2d4db37dec70fc55763424aeb341cae0a595ee
|
4
|
+
data.tar.gz: f1b7ae56e3ebc44be84c593d73a2f2cd0162149f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3f5112d7905de4e6f90c8160b1320ad82cfee7605e4c4fbbbab667606614e3f35ebdabfbd9686a0b65ecfb9a26aee0ba7a57583be49beec709b1552ebe94e45c
|
7
|
+
data.tar.gz: a2968479fcc425d637b87df4d056c34c0c3502f5c9b21c9be588801e14dd5193f1905eb1cc0ce551905d65a6d8de2c70607b6071c45a27ed2c6b499f1ce74ef1
|
data/lib/hcutil/cli.rb
CHANGED
data/lib/hcutil/copier.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'hcutil/errors'
|
2
|
+
require 'hcutil/extensions'
|
2
3
|
require 'hcutil/op_base'
|
3
4
|
require 'uri'
|
4
5
|
require 'cgi'
|
@@ -9,7 +10,7 @@ module HCUtil
|
|
9
10
|
def initialize(room_name = 'Client Services', options = {})
|
10
11
|
super(options)
|
11
12
|
@room_name = room_name
|
12
|
-
@num_items = @options[:num_items] ||25
|
13
|
+
@num_items = @options[:num_items] || 25
|
13
14
|
end
|
14
15
|
|
15
16
|
def get_room_id(start_index=0)
|
@@ -81,21 +82,15 @@ module HCUtil
|
|
81
82
|
return room_id
|
82
83
|
end
|
83
84
|
|
84
|
-
def
|
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
|
85
|
+
def get_history(room_id, chat_date, msg_count, start_index, jsons)
|
92
86
|
|
93
87
|
param_arg = {
|
94
88
|
:accept => :json,
|
95
89
|
:params => {
|
96
90
|
:auth_token => @auth.auth_token,
|
97
91
|
:date => chat_date,
|
98
|
-
'
|
92
|
+
'start-index' => start_index,
|
93
|
+
'max-results' => 100
|
99
94
|
}
|
100
95
|
}
|
101
96
|
|
@@ -104,28 +99,74 @@ module HCUtil
|
|
104
99
|
RestClient.get(uri, param_arg) do |response, request, result|
|
105
100
|
if result.is_a? Net::HTTPSuccess
|
106
101
|
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
|
107
122
|
else
|
108
123
|
raise(Errors::RESTError.new(result, uri, response))
|
109
124
|
end
|
110
125
|
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)
|
111
146
|
|
112
147
|
if @debug
|
113
148
|
chat_json_file = "messages-#{room_id}-#{chat_date.strftime('%Y-%m-%d')}.json"
|
114
|
-
File.open(chat_json_file, 'w')
|
149
|
+
File.open(chat_json_file, 'w') do |f|
|
150
|
+
jsons.each do |json|
|
151
|
+
f.write(json.inspect)
|
152
|
+
end
|
153
|
+
end
|
115
154
|
$stderr.puts "Chat JSON saved to #{chat_json_file}"
|
116
155
|
end
|
117
156
|
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
157
|
+
jsons.each do |json|
|
158
|
+
items = json['items']
|
159
|
+
items.each do |item|
|
160
|
+
date = Time.parse(item['date']).strftime('%Y-%m-%d %H:%M:%S')
|
161
|
+
from = item['from']
|
162
|
+
if from.is_a?(Hash)
|
163
|
+
name = from['name']
|
164
|
+
else
|
165
|
+
name = from
|
166
|
+
end
|
167
|
+
message = item['message']
|
168
|
+
puts "#{date} #{name}: #{message}"
|
126
169
|
end
|
127
|
-
message = item['message']
|
128
|
-
puts "#{date} #{name}: #{message}"
|
129
170
|
end
|
130
171
|
end
|
131
172
|
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.2.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-05-
|
11
|
+
date: 2014-05-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: thor
|