Class: Cinder::Campfire
- Inherits:
-
Object
- Object
- Cinder::Campfire
- Defined in:
- lib/cinder/campfire.rb
Overview
Usage
campfire = Cinder::Campfire.new 'mysubdomain', :ssl => true
campfire.login '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
-
#agent ⇒ Object
readonly
Returns the value of attribute agent.
-
#directory ⇒ Object
readonly
Returns the value of attribute directory.
-
#room ⇒ Object
readonly
Returns the value of attribute room.
-
#subdomain ⇒ Object
readonly
Returns the value of attribute subdomain.
-
#uri ⇒ Object
readonly
Returns the value of attribute uri.
Instance Method Summary collapse
-
#initialize(subdomain, options = {}) ⇒ Campfire
constructor
Create a new connection to a campfire account with the given
subdomain
. -
#logged_in? ⇒ Boolean
Returns true if currently logged in.
-
#login(email, password) ⇒ Object
Log in to campfire using your
email
andpassword
. -
#login_with_email_and_password(email_address, password) ⇒ Object
Post a login request to the Campfire servers with the provided
email_address
andpassword
. -
#logout ⇒ Object
Logs out of the campfire account.
-
#retrieve_all_transcripts ⇒ Object
Retrieve all of the transcripts for the current room.
-
#retrieve_all_transcripts_from_all_rooms ⇒ Object
Retrieve all of the transcripts created in all of the rooms in this Campfire account.
-
#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. -
#retrieve_transcripts_between(start_date, end_date) ⇒ Object
Retrieve the transcripts for the current room created between the
start_date
andend_date
passed in as a Time objects. -
#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. -
#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 theend_date
passed in as a Time objects. -
#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. -
#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. -
#set_directory(path) ⇒ Object
Set the directory where Cinder saves transcripts to
path
,. -
#set_room(room_name) ⇒ Object
Selects the room with name
room_name
to retrieve transcripts from.
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, = {}) = { :ssl => false }.merge() @subdomain = subdomain @uri = URI.parse("#{[: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
#agent ⇒ Object (readonly)
Returns the value of attribute agent.
20 21 22 |
# File 'lib/cinder/campfire.rb', line 20 def agent @agent end |
#directory ⇒ Object (readonly)
Returns the value of attribute directory.
20 21 22 |
# File 'lib/cinder/campfire.rb', line 20 def directory @directory end |
#room ⇒ Object (readonly)
Returns the value of attribute room.
20 21 22 |
# File 'lib/cinder/campfire.rb', line 20 def room @room end |
#subdomain ⇒ Object (readonly)
Returns the value of attribute subdomain.
20 21 22 |
# File 'lib/cinder/campfire.rb', line 20 def subdomain @subdomain end |
#uri ⇒ Object (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
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 login(email, password) unless login_with_email_and_password(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 login_with_email_and_password(email_address, password) agent.post("#{@uri.to_s}/login", "email_address" => email_address, "password" => password) end |
#logout ⇒ Object
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_transcripts ⇒ Object
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_rooms ⇒ Object
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 |