campfire_export 0.2.1 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +3 -0
- data/campfire_export.gemspec +2 -2
- data/lib/campfire_export.rb +21 -20
- data/lib/campfire_export/version.rb +1 -1
- data/spec/campfire_export/message_spec.rb +63 -0
- data/spec/campfire_export/room_spec.rb +2 -1
- metadata +9 -7
data/README.md
CHANGED
@@ -95,6 +95,9 @@ Also, thanks much for all the help, comments and contributions:
|
|
95
95
|
* [Andre Arko](https://github.com/indirect)
|
96
96
|
* [Brian Donovan](https://github.com/eventualbuddha)
|
97
97
|
* [Andrew Wong](https://github.com/andrewwong1221)
|
98
|
+
* [Junya Ogura](https://github.com/juno)
|
99
|
+
* [Chase Lee](https://github.com/chaselee)
|
100
|
+
* [Alex Hofsteede](https://github.com/alex-hofsteede)
|
98
101
|
|
99
102
|
As mentioned above, some of the work on this was done by other people. The
|
100
103
|
Gist I forked had contributions from:
|
data/campfire_export.gemspec
CHANGED
@@ -16,12 +16,12 @@ Gem::Specification.new do |s|
|
|
16
16
|
s.rubyforge_project = "campfire_export"
|
17
17
|
s.required_ruby_version = '>= 1.8.7'
|
18
18
|
|
19
|
-
s.add_development_dependency "bundler", "
|
19
|
+
s.add_development_dependency "bundler", "> 1.0.15"
|
20
20
|
s.add_development_dependency "fuubar", "~> 0.0.5"
|
21
21
|
s.add_development_dependency "rspec", "~> 2.6.0"
|
22
22
|
s.add_dependency "tzinfo", "~> 0.3.29"
|
23
23
|
s.add_dependency "httparty", "~> 0.7.8"
|
24
|
-
s.add_dependency "nokogiri", "~> 1.
|
24
|
+
s.add_dependency "nokogiri", "~> 1.5.6"
|
25
25
|
|
26
26
|
s.files = `git ls-files`.split("\n")
|
27
27
|
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
data/lib/campfire_export.rb
CHANGED
@@ -144,13 +144,13 @@ module CampfireExport
|
|
144
144
|
|
145
145
|
def find_timezone
|
146
146
|
settings = Nokogiri::XML get('/account.xml').body
|
147
|
-
selected_zone = settings.
|
147
|
+
selected_zone = settings.xpath('/account/time-zone')
|
148
148
|
Account.timezone = find_tzinfo(selected_zone.text)
|
149
149
|
end
|
150
150
|
|
151
151
|
def rooms
|
152
152
|
doc = Nokogiri::XML get('/rooms.xml').body
|
153
|
-
doc.
|
153
|
+
doc.xpath('/rooms/room').map {|room_xml| Room.new(room_xml) }
|
154
154
|
end
|
155
155
|
end
|
156
156
|
|
@@ -159,9 +159,9 @@ module CampfireExport
|
|
159
159
|
attr_accessor :id, :name, :created_at, :last_update
|
160
160
|
|
161
161
|
def initialize(room_xml)
|
162
|
-
@id = room_xml.
|
163
|
-
@name = room_xml.
|
164
|
-
created_utc = DateTime.parse(room_xml.
|
162
|
+
@id = room_xml.xpath('id').text
|
163
|
+
@name = room_xml.xpath('name').text
|
164
|
+
created_utc = DateTime.parse(room_xml.xpath('created-at').text)
|
165
165
|
@created_at = Account.timezone.utc_to_local(created_utc)
|
166
166
|
end
|
167
167
|
|
@@ -186,7 +186,7 @@ module CampfireExport
|
|
186
186
|
def find_last_update
|
187
187
|
begin
|
188
188
|
last_message = Nokogiri::XML get("/room/#{id}/recent.xml?limit=1").body
|
189
|
-
update_utc = DateTime.parse(last_message.
|
189
|
+
update_utc = DateTime.parse(last_message.xpath('/messages/message[1]/created-at').text)
|
190
190
|
@last_update = Account.timezone.utc_to_local(update_utc)
|
191
191
|
rescue Exception => e
|
192
192
|
log(:error,
|
@@ -213,11 +213,11 @@ module CampfireExport
|
|
213
213
|
def export
|
214
214
|
begin
|
215
215
|
log(:info, "#{export_dir} ... ")
|
216
|
-
@xml = Nokogiri::XML get("#{transcript_path}.xml").body
|
216
|
+
@xml = Nokogiri::XML get("#{transcript_path}.xml").body
|
217
217
|
rescue Exception => e
|
218
218
|
log(:error, "transcript export for #{export_dir} failed", e)
|
219
219
|
else
|
220
|
-
@messages = xml.
|
220
|
+
@messages = xml.xpath('/messages/message').map do |message|
|
221
221
|
CampfireExport::Message.new(message, room, date)
|
222
222
|
end
|
223
223
|
|
@@ -301,19 +301,19 @@ module CampfireExport
|
|
301
301
|
attr_accessor :id, :room, :body, :type, :user, :date, :timestamp, :upload
|
302
302
|
|
303
303
|
def initialize(message, room, date)
|
304
|
-
@id = message.
|
304
|
+
@id = message.xpath('id').text
|
305
305
|
@room = room
|
306
306
|
@date = date
|
307
|
-
@body = message.
|
308
|
-
@type = message.
|
307
|
+
@body = message.xpath('body').text
|
308
|
+
@type = message.xpath('type').text
|
309
309
|
|
310
|
-
time = Time.parse message.
|
310
|
+
time = Time.parse message.xpath('created-at').text
|
311
311
|
localtime = CampfireExport::Account.timezone.utc_to_local(time)
|
312
312
|
@timestamp = localtime.strftime '%I:%M %p'
|
313
313
|
|
314
314
|
no_user = ['TimestampMessage', 'SystemMessage', 'AdvertisementMessage']
|
315
315
|
unless no_user.include?(@type)
|
316
|
-
@user = username(message.
|
316
|
+
@user = username(message.xpath('user-id').text)
|
317
317
|
end
|
318
318
|
|
319
319
|
@upload = CampfireExport::Upload.new(self) if is_upload?
|
@@ -327,7 +327,7 @@ module CampfireExport
|
|
327
327
|
"[unknown user]"
|
328
328
|
else
|
329
329
|
# Take the first name and last initial, if there is more than one name.
|
330
|
-
name_parts = doc.
|
330
|
+
name_parts = doc.xpath('/user/name').text.split
|
331
331
|
if name_parts.length > 1
|
332
332
|
name_parts[-1] = "#{name_parts.last[0,1]}."
|
333
333
|
name_parts.join(" ")
|
@@ -392,7 +392,7 @@ module CampfireExport
|
|
392
392
|
|
393
393
|
class Upload
|
394
394
|
include CampfireExport::IO
|
395
|
-
attr_accessor :message, :room, :date, :id, :filename, :content_type, :byte_size
|
395
|
+
attr_accessor :message, :room, :date, :id, :filename, :content_type, :byte_size, :full_url
|
396
396
|
|
397
397
|
def initialize(message)
|
398
398
|
@message = message
|
@@ -427,10 +427,11 @@ module CampfireExport
|
|
427
427
|
upload = Nokogiri::XML get(upload_path).body
|
428
428
|
|
429
429
|
# Get the upload itself and export it.
|
430
|
-
@id = upload.
|
431
|
-
@byte_size = upload.
|
432
|
-
@content_type = upload.
|
433
|
-
@filename = upload.
|
430
|
+
@id = upload.xpath('/upload/id').text
|
431
|
+
@byte_size = upload.xpath('/upload/byte-size').text.to_i
|
432
|
+
@content_type = upload.xpath('/upload/content-type').text
|
433
|
+
@filename = upload.xpath('/upload/name').text
|
434
|
+
@full_url = upload.xpath('/upload/full-url').text
|
434
435
|
|
435
436
|
export_content(upload_dir)
|
436
437
|
export_content(thumb_dir, path_component="thumb/#{id}", verify=false) if is_image?
|
@@ -458,7 +459,7 @@ module CampfireExport
|
|
458
459
|
# in a day, this will preserve both copies). This path pattern also
|
459
460
|
# matches the tail of the upload path in the HTML transcript, making
|
460
461
|
# it easier to make downloads functional from the HTML transcripts.
|
461
|
-
content_path = "/room/#{room.id}/#{path_component}/#{CGI.escape(filename)}"
|
462
|
+
content_path = "/room/#{room.id}/#{path_component}/#{CGI.escape(filename)}"
|
462
463
|
content = get(content_path).body
|
463
464
|
FileUtils.mkdir_p(File.join(export_dir, content_dir))
|
464
465
|
export_file(content, "#{content_dir}/#{filename}", 'wb')
|
@@ -0,0 +1,63 @@
|
|
1
|
+
require 'campfire_export'
|
2
|
+
require 'campfire_export/timezone'
|
3
|
+
|
4
|
+
require 'nokogiri'
|
5
|
+
|
6
|
+
module CampfireExport
|
7
|
+
describe Message do
|
8
|
+
include TimeZone
|
9
|
+
|
10
|
+
before :each do
|
11
|
+
@messages = Nokogiri::XML <<XML
|
12
|
+
<messages>
|
13
|
+
<message>
|
14
|
+
<created-at type="datetime">2012-05-11T17:45:00Z</created-at>
|
15
|
+
<id type="integer">111</id>
|
16
|
+
<room-id type="integer">222</room-id>
|
17
|
+
<user-id type="integer" nil="true"/>
|
18
|
+
<body nil="true"/>
|
19
|
+
<type>TimestampMessage</type>
|
20
|
+
</message>
|
21
|
+
<message>
|
22
|
+
<created-at type="datetime">2012-05-11T17:47:20Z</created-at>
|
23
|
+
<id type="integer">333</id>
|
24
|
+
<room-id type="integer">222</room-id>
|
25
|
+
<user-id type="integer">555</user-id>
|
26
|
+
<body>This is a tweet</body>
|
27
|
+
<type>TweetMessage</type>
|
28
|
+
<tweet>
|
29
|
+
<id>20100487385931234</id>
|
30
|
+
<message>This is a tweet</message>
|
31
|
+
<author_username>twitter_user</author_username>
|
32
|
+
<author_avatar_url>avatar.jpg</author_avatar_url>
|
33
|
+
</tweet>
|
34
|
+
</message>
|
35
|
+
<message>
|
36
|
+
<created-at type="datetime">2012-05-11T17:47:23Z</created-at>
|
37
|
+
<id type="integer">666</id>
|
38
|
+
<room-id type="integer">222</room-id>
|
39
|
+
<user-id type="integer">555</user-id>
|
40
|
+
<body>Regular message</body>
|
41
|
+
<type>TextMessage</type>
|
42
|
+
</message>
|
43
|
+
</messages>
|
44
|
+
XML
|
45
|
+
Account.timezone = find_tzinfo("America/Los_Angeles")
|
46
|
+
end
|
47
|
+
|
48
|
+
context "when it is created" do
|
49
|
+
it "sets up basic properties" do
|
50
|
+
message = Message.new(@messages.xpath('/messages/message[3]')[0], nil, nil)
|
51
|
+
message.body.should == "Regular message"
|
52
|
+
message.id.should == "666"
|
53
|
+
message.timestamp.should == "10:47 AM"
|
54
|
+
end
|
55
|
+
|
56
|
+
it "handles tweets correctly" do
|
57
|
+
message = Message.new(@messages.xpath('/messages/message[2]'), nil, nil)
|
58
|
+
message.body.should == "This is a tweet"
|
59
|
+
message.id.should == "333"
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
@@ -8,8 +8,9 @@ module CampfireExport
|
|
8
8
|
include TimeZone
|
9
9
|
|
10
10
|
before :each do
|
11
|
-
|
11
|
+
doc = Nokogiri::XML "<room><name>Test Room</name><id>666</id>" +
|
12
12
|
"<created-at>2009-11-17T19:41:38Z</created-at></room>"
|
13
|
+
@room_xml = doc.xpath('/room')
|
13
14
|
Account.timezone = find_tzinfo("America/Los_Angeles")
|
14
15
|
end
|
15
16
|
|
metadata
CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
|
|
4
4
|
prerelease: false
|
5
5
|
segments:
|
6
6
|
- 0
|
7
|
-
-
|
8
|
-
-
|
9
|
-
version: 0.
|
7
|
+
- 3
|
8
|
+
- 0
|
9
|
+
version: 0.3.0
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Marc Hedlund
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date:
|
17
|
+
date: 2013-03-09 00:00:00 -05:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
@@ -22,7 +22,7 @@ dependencies:
|
|
22
22
|
prerelease: false
|
23
23
|
requirement: &id001 !ruby/object:Gem::Requirement
|
24
24
|
requirements:
|
25
|
-
- -
|
25
|
+
- - ">"
|
26
26
|
- !ruby/object:Gem::Version
|
27
27
|
segments:
|
28
28
|
- 1
|
@@ -96,9 +96,9 @@ dependencies:
|
|
96
96
|
- !ruby/object:Gem::Version
|
97
97
|
segments:
|
98
98
|
- 1
|
99
|
-
- 4
|
100
99
|
- 5
|
101
|
-
|
100
|
+
- 6
|
101
|
+
version: 1.5.6
|
102
102
|
type: :runtime
|
103
103
|
version_requirements: *id006
|
104
104
|
description: Export transcripts and uploaded files from your 37signals' Campfire account.
|
@@ -122,6 +122,7 @@ files:
|
|
122
122
|
- lib/campfire_export/timezone.rb
|
123
123
|
- lib/campfire_export/version.rb
|
124
124
|
- spec/campfire_export/account_spec.rb
|
125
|
+
- spec/campfire_export/message_spec.rb
|
125
126
|
- spec/campfire_export/room_spec.rb
|
126
127
|
has_rdoc: true
|
127
128
|
homepage: https://github.com/precipice/campfire_export
|
@@ -157,4 +158,5 @@ specification_version: 3
|
|
157
158
|
summary: Export transcripts and uploaded files from your 37signals' Campfire account.
|
158
159
|
test_files:
|
159
160
|
- spec/campfire_export/account_spec.rb
|
161
|
+
- spec/campfire_export/message_spec.rb
|
160
162
|
- spec/campfire_export/room_spec.rb
|