Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Export list of rooms

  • Loading branch information...
commit c8b3d8c63e2165df817e291882c6ef87a8670377 1 parent 1946a36
@powdahound authored
Showing with 25 additions and 6 deletions.
  1. +2 −1  bin/campfire_export
  2. +23 −5 lib/campfire_export.rb
View
3  bin/campfire_export
@@ -57,8 +57,9 @@ begin
account = CampfireExport::Account.new(config['subdomain'],
config['api_token'])
account.find_timezone
+ account.export_rooms_list
account.rooms.each do |room|
- room.export(config_date(config, 'start_date'),
+ room.export(config_date(config, 'start_date'),
config_date(config, 'end_date'))
end
rescue => e
View
28 lib/campfire_export.rb
@@ -52,17 +52,23 @@ def zero_pad(number)
"%02d" % number
end
- # Requires that room and date be defined in the calling object.
+ # If room or date are defined in the calling object they will be used to
+ # build a more accurate directory.
def export_dir
- "campfire/#{Account.subdomain}/#{room.name}/" +
- "#{date.year}/#{zero_pad(date.mon)}/#{zero_pad(date.day)}"
+ dir = "campfire/#{Account.subdomain}"
+ if defined? room:
+ dir += "/#{room.name}"
+ end
+ if defined? date:
+ dir += "/#{date.year}/#{zero_pad(date.mon)}/#{zero_pad(date.day)}"
+ end
+ dir
end
- # Requires that room_name and date be defined in the calling object.
def export_file(content, filename, mode='w')
# Check to make sure we're writing into the target directory tree.
true_path = File.expand_path(File.join(export_dir, filename))
-
+
unless true_path.start_with?(File.expand_path(export_dir))
raise CampfireExport::Exception.new("#{export_dir}/#{filename}",
"can't export file to a directory higher than target directory; " +
@@ -152,6 +158,18 @@ def rooms
doc = Nokogiri::XML get('/rooms.xml').body
doc.css('room').map {|room_xml| Room.new(room_xml) }
end
+
+ def export_rooms_list
+ begin
+ log(:info, "Exporting rooms list ... ")
+ FileUtils.mkdir_p export_dir
+ xml = Nokogiri::XML get('/rooms.xml').body
+ export_file(xml, 'rooms.xml')
+ log(:info, "ok\n")
+ rescue Exception => e
+ log(:error, "Exporting rooms list failed", e)
+ end
+ end
end
class Room
Please sign in to comment.
Something went wrong with that request. Please try again.