eastmedia-cinder 0.2.1 → 0.4.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.
@@ -2,24 +2,32 @@
2
2
 
3
3
  * Initial release. Provides support for single-day exporting.
4
4
 
5
- === 0.2.0 / 2008-06-16
5
+ === 0.2.0 / 2008-06-17
6
6
 
7
7
  * Minor release. Provides support for multi-day exporting to a specified directory.
8
8
 
9
- === 0.2.1 / 2008-06-16
9
+ === 0.2.1 / 2008-06-17
10
10
 
11
11
  * Bug fix. Removed explicit require of hpricot by cinder. Default retrieve_transcript to today.
12
12
 
13
- === 0.2.2 / 2008-06-16
13
+ === 0.2.2 / 2008-06-17
14
14
 
15
15
  * Tiny release. Provides support for retrieving all transcripts in a single room.
16
16
  * Bug fix. Fixed logic problem that was excluding the current date when calling retrieve_transcripts_since.
17
17
 
18
- === 0.3.0 / 2008-06-16
18
+ === 0.3.0 / 2008-06-17
19
19
 
20
20
  * Minor release. Provides support form single, multi, and all-day exporting to a specific directory across all rooms in a Campfire account
21
21
  * Bug fix. Replaces spaces in room names with underscores during file save.
22
22
 
23
- === 0.3.1 / 2008-06-16
23
+ === 0.3.1 / 2008-06-17
24
24
 
25
25
  * Tiny release. Provides the date column in the CSV file in universal date format mm/dd/yyyy.
26
+
27
+ === 0.4.0 / 2008-06-17
28
+
29
+ * Minor release. Provides colored output to the screen as transcripts are retrieved.
30
+
31
+ === 0.4.1 / 2008-06-18
32
+
33
+ * Tiny release. Provides a user agent alias of "Mac FireFox" to Campfire when scraping.
@@ -6,3 +6,5 @@ Rakefile
6
6
  cinder.gemspec
7
7
  lib/cinder.rb
8
8
  lib/cinder/campfire.rb
9
+ spec/cinder/campfire_spec.rb
10
+ spec/spec_helper.rb
data/README.txt CHANGED
@@ -12,7 +12,8 @@ Cinder is a Ruby library for exporting transcripts from Campfire into CSV files.
12
12
 
13
13
  * Ruby >= 1.8.6
14
14
  * Mechanize gem
15
-
15
+ * Colored gem
16
+
16
17
  == INSTALL:
17
18
 
18
19
  $ gem sources -a http://gems.github.com/ (you only need to do this once)
@@ -8,6 +8,6 @@ Dir[File.join(File.dirname(__FILE__), 'cinder/**/*.rb')].sort.each { |lib| requi
8
8
 
9
9
 
10
10
  module Cinder
11
- VERSION = '0.3.1'
11
+ VERSION = '0.4.1'
12
12
  class Error < StandardError; end
13
13
  end
@@ -6,9 +6,18 @@ module Cinder
6
6
  # campfire = Cinder::Campfire.new 'mysubdomain', :ssl => true
7
7
  # campfire.login 'myemail@example.com', 'mypassword'
8
8
  # campfire.set_room 'Room Name'
9
+ # campfire.set_directory 'dir/path'
9
10
  # campfire.retrieve_transcript date
11
+ # campfire.retrieve_transcripts_since date
12
+ # campfire.retrieve_transcripts_between start_date, end_date
13
+ # campfire.retrieve_all_transcripts
14
+ # campfire.retrieve_transcripts_from_all_rooms date
15
+ # campfire.retrieve_transcripts_from_all_rooms_since date
16
+ # campfire.retrieve_transcripts_from_all_rooms_between start_date, end_date
17
+ # campfire.retrieve_all_transcripts_from_all_rooms
18
+ # campfire.logout
10
19
  class Campfire
11
- attr_reader :subdomain, :uri, :room, :directory
20
+ attr_reader :subdomain, :uri, :room, :directory, :agent
12
21
 
13
22
  # Create a new connection to a campfire account with the given +subdomain+.
14
23
  # There's an +:ssl+ option to use SSL for the connection.
@@ -21,17 +30,23 @@ module Cinder
21
30
  @room = nil
22
31
  @directory = "."
23
32
  @agent = WWW::Mechanize.new
33
+ @agent.user_agent_alias = "Mac FireFox"
24
34
  @logged_in = false
25
35
  end
26
36
 
27
37
  # Log in to campfire using your +email+ and +password+
28
38
  def login(email, password)
29
- unless @agent.post("#{@uri.to_s}/login", "email_address" => email, "password" => password).uri == @uri
30
- raise Error, "Campfire login failed"
31
- end
32
- @lobby = @agent.page
33
- @rooms = get_rooms(@lobby)
34
- @logged_in = true
39
+ unless login_with_email_and_password(email, password).uri == @uri
40
+ raise Error, "Campfire login failed"
41
+ end
42
+ @lobby = agent.page
43
+ @rooms = get_rooms(@lobby)
44
+ @logged_in = true
45
+ end
46
+
47
+ # Post a login request to the Campfire servers with the provided +email_address+ and +password+
48
+ def login_with_email_and_password(email_address, password)
49
+ agent.post("#{@uri.to_s}/login", "email_address" => email_address, "password" => password)
35
50
  end
36
51
 
37
52
  # Returns true if currently logged in
@@ -41,7 +56,7 @@ module Cinder
41
56
 
42
57
  # Logs out of the campfire account
43
58
  def logout
44
- if @agent.get("#{@uri}/logout").uri == URI.parse("#{@uri.to_s}/login")
59
+ if @agent.get("#{@uri.to_s}/logout").uri == URI.parse("#{@uri.to_s}/login")
45
60
  @logged_in = false
46
61
  end
47
62
  end
@@ -63,35 +78,28 @@ module Cinder
63
78
  # Retrieve the transcript for the current room and +date+, passed in as a Time object, and store it locally as a csv file in the preselected directory, or the current location if no directory was set
64
79
  def retrieve_transcript(date = Time.now)
65
80
  transcript_uri = URI.parse("#{@room[:uri].to_s}/transcript/#{date.strftime("%Y/%m/%d")}")
66
- transcript_page = @agent.get(transcript_uri.to_s)
67
- transcript = transcript_page.parser
81
+ transcript = get_transcript(transcript_uri)
68
82
  write_transcript(transcript, "#{@directory}/#{@room[:name].gsub(" ", "_")}_#{date.strftime("%m_%d_%Y")}", date)
83
+ puts "Transcript retrieved from room '#{@room[:name]}' for #{date.strftime("%m/%d/%Y")}".green
69
84
  rescue WWW::Mechanize::ResponseCodeError
85
+ puts "No transcript found in room '#{@room[:name]}' for #{date.strftime("%m/%d/%Y")}".red
70
86
  end
71
87
 
72
88
  # Retrieve all of the transcripts for the current room
73
89
  def retrieve_all_transcripts
74
- list_page = @agent.get("#{@uri}/files+transcripts?room_id=#{@room[:uri].to_s.split("/").last}")
75
- while list_page.links.detect { |link| link.text == "Older" }
76
- list_page.links.detect { |link| link.text == "Older" }.click
77
- list_page = @agent.page
78
- end
79
- links = list_page.links
80
- links.pop
81
- earliest = links.pop.uri.to_s.split("/")
82
- day = earliest.pop
83
- month = earliest.pop
84
- year = earliest.pop
85
- retrieve_transcripts_since Time.mktime(year.to_i, month.to_i, day.to_i)
90
+ puts "Retrieving all transcripts from '#{@room[:name]}'. This could take some time.".yellow
91
+ retrieve_transcripts_since find_start_date(@room)
86
92
  end
87
93
 
88
94
  # Retrieve the transcripts for the current room from the +date+ passed in as a Time object, up until and including the current date
89
95
  def retrieve_transcripts_since(date)
96
+ puts "Retrieving transcripts from '#{@room[:name]}' since #{date.strftime("%m/%d/%Y")}.".blue
90
97
  retrieve_transcripts_between(date, Time.now)
91
98
  end
92
99
 
93
100
  # Retrieve the transcripts for the current room created between the +start_date+ and +end_date+ passed in as a Time objects
94
101
  def retrieve_transcripts_between(start_date, end_date)
102
+ puts "Retrieving transcripts from '#{@room[:name]}' between #{start_date.strftime("%m/%d/%Y")} and #{end_date.strftime("%m/%d/%Y")}.".blue
95
103
  while start_date <= end_date
96
104
  retrieve_transcript(start_date)
97
105
  start_date = start_date + 24*60*60
@@ -110,11 +118,13 @@ module Cinder
110
118
 
111
119
  # Retrieve the transcripts from all rooms in this Campfire account created since the +date+ passed in as a Time object
112
120
  def retrieve_transcripts_from_all_rooms_since(date)
121
+ puts "Retrieving transcripts from all rooms in #{@uri.to_s} since #{date.strftime("%m/%d/%Y")}.".yellow
113
122
  retrieve_transcripts_from_all_rooms_between date, Time.now
114
123
  end
115
124
 
116
125
  # Retrieve the transcripts from all rooms in this Campfire account created between the +start_date+ and the +end_date+ passed in as a Time objects
117
126
  def retrieve_transcripts_from_all_rooms_between(start_date, end_date)
127
+ puts "Retrieving transcripts from all rooms in #{@uri.to_s} between #{start_date.strftime("%m/%d/%Y")} and #{end_date.strftime("%m/%d/%Y")}.".yellow
118
128
  preset_room = @room
119
129
  @rooms.each do |room|
120
130
  @room = room
@@ -125,6 +135,7 @@ module Cinder
125
135
 
126
136
  # Retrieve all of the transcripts created in all of the rooms in this Campfire account
127
137
  def retrieve_all_transcripts_from_all_rooms
138
+ puts "Retrieving all transcripts from #{@uri.to_s}. This could take some time.".yellow
128
139
  preset_room = @room
129
140
  @rooms.each do |room|
130
141
  @room = room
@@ -144,6 +155,27 @@ module Cinder
144
155
  def find_room_by_name(room_name)
145
156
  @rooms.collect { |room| room if room[:name] == room_name }.reject { |room| room.nil? }.first
146
157
  end
158
+
159
+ # Retrieve the hpricot document representing the Campfire transcript at the provided +uri+
160
+ def get_transcript(uri)
161
+ @agent.get(uri.to_s).parser
162
+ end
163
+
164
+ # Find the first date that transcripts exist for the provided +room+
165
+ def find_start_date(room)
166
+ list_page = @agent.get("#{@uri}/files+transcripts?room_id=#{room[:uri].to_s.split("/").last}")
167
+ while list_page.links.detect { |link| link.text == "Older" }
168
+ list_page.links.detect { |link| link.text == "Older" }.click
169
+ list_page = @agent.page
170
+ end
171
+ links = list_page.links
172
+ links.pop
173
+ earliest = links.pop.uri.to_s.split("/")
174
+ day = earliest.pop
175
+ month = earliest.pop
176
+ year = earliest.pop
177
+ Time.mktime(year.to_i, month.to_i, day.to_i)
178
+ end
147
179
 
148
180
  # Parse the provided +transcript+ hpricot document and write the contents to the .csv file +file_name+
149
181
  def write_transcript(transcript, file_name, date)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: eastmedia-cinder
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mike Bueti