Class: Cinder::Campfire

Inherits:
Object
  • Object
show all
Defined in:
lib/cinder/campfire.rb

Overview

Usage

campfire = Cinder::Campfire.new 'mysubdomain', :ssl => true
campfire. 'myemail@example.com', 'mypassword'
campfire.set_room 'Room Name'
campfire.set_directory 'dir/path'
campfire.retrieve_transcript date
campfire.retrieve_transcripts_since date
campfire.retrieve_transcripts_between start_date, end_date
campfire.retrieve_all_transcripts
campfire.retrieve_transcripts_from_all_rooms date
campfire.retrieve_transcripts_from_all_rooms_since date
campfire.retrieve_transcripts_from_all_rooms_between start_date, end_date
campfire.retrieve_all_transcripts_from_all_rooms
campfire.logout

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(subdomain, options = {}) ⇒ Campfire

Create a new connection to a campfire account with the given subdomain. There’s an :ssl option to use SSL for the connection.

campfire = Cinder::Campfire.new(“my_subdomain”, :ssl => true)


26
27
28
29
30
31
32
33
34
35
# File 'lib/cinder/campfire.rb', line 26

def initialize(subdomain, options = {})
  options = { :ssl => false }.merge(options)
  @subdomain = subdomain
  @uri = URI.parse("#{options[:ssl] ? "https" : "http"}://#{subdomain}.campfirenow.com")
  @room = nil
  @directory = "."
  @agent = WWW::Mechanize.new
  @agent.user_agent_alias = "Mac FireFox"
  @logged_in = false
end

Instance Attribute Details

#agentObject (readonly)

Returns the value of attribute agent.


20
21
22
# File 'lib/cinder/campfire.rb', line 20

def agent
  @agent
end

#directoryObject (readonly)

Returns the value of attribute directory.


20
21
22
# File 'lib/cinder/campfire.rb', line 20

def directory
  @directory
end

#roomObject (readonly)

Returns the value of attribute room.


20
21
22
# File 'lib/cinder/campfire.rb', line 20

def room
  @room
end

#subdomainObject (readonly)

Returns the value of attribute subdomain.


20
21
22
# File 'lib/cinder/campfire.rb', line 20

def subdomain
  @subdomain
end

#uriObject (readonly)

Returns the value of attribute uri.


20
21
22
# File 'lib/cinder/campfire.rb', line 20

def uri
  @uri
end

Instance Method Details

#logged_in?Boolean

Returns true if currently logged in

Returns:

  • (Boolean)

53
54
55
# File 'lib/cinder/campfire.rb', line 53

def logged_in?
  @logged_in == true
end

#login(email, password) ⇒ Object

Log in to campfire using your email and password


38
39
40
41
42
43
44
45
# File 'lib/cinder/campfire.rb', line 38

def (email, password)
   unless (email, password).uri == @uri
     raise Error, "Campfire login failed"
   end
   @lobby = agent.page
   @rooms = get_rooms(@lobby)
   @logged_in = true
end

#login_with_email_and_password(email_address, password) ⇒ Object

Post a login request to the Campfire servers with the provided email_address and password


48
49
50
# File 'lib/cinder/campfire.rb', line 48

def (email_address, password)
  agent.post("#{@uri.to_s}/login", "email_address" => email_address, "password" => password)
end

#logoutObject

Logs out of the campfire account


58
59
60
61
62
# File 'lib/cinder/campfire.rb', line 58

def logout 
  if @agent.get("#{@uri.to_s}/logout").uri == URI.parse("#{@uri.to_s}/login")
    @logged_in = false
  end
end

#retrieve_all_transcriptsObject

Retrieve all of the transcripts for the current room


89
90
91
92
# File 'lib/cinder/campfire.rb', line 89

def retrieve_all_transcripts
  puts "Retrieving all transcripts from '#{@room[:name]}'. This could take some time.".yellow
  retrieve_transcripts_since find_start_date(@room)
end

#retrieve_all_transcripts_from_all_roomsObject

Retrieve all of the transcripts created in all of the rooms in this Campfire account


137
138
139
140
141
142
143
144
145
# File 'lib/cinder/campfire.rb', line 137

def retrieve_all_transcripts_from_all_rooms
  puts "Retrieving all transcripts from #{@uri.to_s}. This could take some time.".yellow 
  preset_room = @room
  @rooms.each do |room|
    @room = room
    retrieve_all_transcripts
  end
  @room = preset_room
end

#retrieve_transcript(date = Time.now) ⇒ Object

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


79
80
81
82
83
84
85
86
# File 'lib/cinder/campfire.rb', line 79

def retrieve_transcript(date = Time.now)
  transcript_uri = URI.parse("#{@room[:uri].to_s}/transcript/#{date.strftime("%Y/%m/%d")}")
  transcript = get_transcript(transcript_uri)
  write_transcript(transcript, "#{@directory}/#{@room[:name].gsub(" ", "_")}_#{date.strftime("%m_%d_%Y")}", date)
  puts "Transcript retrieved from room '#{@room[:name]}' for #{date.strftime("%m/%d/%Y")}".green
rescue WWW::Mechanize::ResponseCodeError
  puts "No transcript found in room '#{@room[:name]}' for #{date.strftime("%m/%d/%Y")}".red
end

#retrieve_transcripts_between(start_date, end_date) ⇒ Object

Retrieve the transcripts for the current room created between the start_date and end_date passed in as a Time objects


101
102
103
104
105
106
107
# File 'lib/cinder/campfire.rb', line 101

def retrieve_transcripts_between(start_date, end_date)
  puts "Retrieving transcripts from '#{@room[:name]}' between #{start_date.strftime("%m/%d/%Y")} and #{end_date.strftime("%m/%d/%Y")}.".blue
  while start_date <= end_date
    retrieve_transcript(start_date)
    start_date = start_date + 24*60*60
  end
end

#retrieve_transcripts_from_all_rooms(date = Time.now) ⇒ Object

Retrieve the transcripts from all rooms in this Campfire account for the date passed in as a Time object


110
111
112
113
114
115
116
117
# File 'lib/cinder/campfire.rb', line 110

def retrieve_transcripts_from_all_rooms(date = Time.now)
  preset_room = @room
  @rooms.each do |room|
    @room = room
    retrieve_transcript date
  end
  @room = preset_room
end

#retrieve_transcripts_from_all_rooms_between(start_date, end_date) ⇒ Object

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


126
127
128
129
130
131
132
133
134
# File 'lib/cinder/campfire.rb', line 126

def retrieve_transcripts_from_all_rooms_between(start_date, end_date)
  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
  preset_room = @room
  @rooms.each do |room|
    @room = room
    retrieve_transcripts_between start_date, end_date
  end
  @room = preset_room
end

#retrieve_transcripts_from_all_rooms_since(date) ⇒ Object

Retrieve the transcripts from all rooms in this Campfire account created since the date passed in as a Time object


120
121
122
123
# File 'lib/cinder/campfire.rb', line 120

def retrieve_transcripts_from_all_rooms_since(date)
  puts "Retrieving transcripts from all rooms in #{@uri.to_s} since #{date.strftime("%m/%d/%Y")}.".yellow
  retrieve_transcripts_from_all_rooms_between date, Time.now
end

#retrieve_transcripts_since(date) ⇒ Object

Retrieve the transcripts for the current room from the date passed in as a Time object, up until and including the current date


95
96
97
98
# File 'lib/cinder/campfire.rb', line 95

def retrieve_transcripts_since(date)
  puts "Retrieving transcripts from '#{@room[:name]}' since #{date.strftime("%m/%d/%Y")}.".blue
  retrieve_transcripts_between(date, Time.now)
end

#set_directory(path) ⇒ Object

Set the directory where Cinder saves transcripts to path,


70
71
72
73
74
75
76
# File 'lib/cinder/campfire.rb', line 70

def set_directory(path)
  if File.exists? path and File.directory? path
    @directory = path.reverse.index("/") == 0 ? path.chop : path
  else
    raise Error, "Invalid path name"
  end 
end

#set_room(room_name) ⇒ Object

Selects the room with name room_name to retrieve transcripts from


65
66
67
# File 'lib/cinder/campfire.rb', line 65

def set_room(room_name)
  @room = find_room_by_name(room_name)
end