Module: CalInvite::Providers::IcsDownload
- Defined in:
- lib/cal_invite/providers/ics_content.rb
Overview
Module for handling ICS file downloads with proper headers and file naming. Provides utility methods for preparing ICS content for HTTP download.
Class Method Summary collapse
-
.headers(filename, method: nil) ⇒ Hash
Generates appropriate HTTP headers for ICS file download.
-
.sanitize_filename(filename) ⇒ String
Sanitizes a filename by removing potentially problematic characters.
-
.wrap_for_download(content, title, method: nil) ⇒ Hash
Wraps ICS content with appropriate download information.
Class Method Details
.headers(filename, method: nil) ⇒ Hash
Generates appropriate HTTP headers for ICS file download.
157 158 159 160 161 162 163 164 165 |
# File 'lib/cal_invite/providers/ics_content.rb', line 157 def self.headers(filename, method: nil) content_type = 'text/calendar; charset=UTF-8' content_type += "; method=#{method == :decline_counter ? 'DECLINECOUNTER' : method.to_s.upcase}" if method { 'Content-Type' => content_type, 'Content-Disposition' => "attachment; filename=#{sanitize_filename(filename)}" } end |
.sanitize_filename(filename) ⇒ String
Sanitizes a filename by removing potentially problematic characters.
171 172 173 |
# File 'lib/cal_invite/providers/ics_content.rb', line 171 def self.sanitize_filename(filename) filename.gsub(/[^0-9A-Za-z.\-]/, '_') end |
.wrap_for_download(content, title, method: nil) ⇒ Hash
Wraps ICS content with appropriate download information.
186 187 188 189 190 191 192 |
# File 'lib/cal_invite/providers/ics_content.rb', line 186 def self.wrap_for_download(content, title, method: nil) filename = sanitize_filename("#{title.downcase}_#{Time.now.strftime('%Y%m%d')}.ics") { content: content, headers: headers(filename, method: method) } end |