class Redirect
Public Class Methods
Gets the value of the flag to determine if google analytics info should be sent with the url @returns [Boolean] value of the append_google_analytics
flag
# File lib/model/redirect.rb, line 21 def self.append_google_analytics @@append_google_analytics end
Sets the value of the flag to determine if google analytics info should be sent with the url appends utm_source=<@@host>&utm_campaign=<Redirect._id>__<RedirectLog._id> @param [Boolean] value to set append_google_analytics
flag to
# File lib/model/redirect.rb, line 15 def self.append_google_analytics= google_analytics_flag @@append_google_analytics = google_analytics_flag end
Gets the value of the flag to determine if tracking info should be sent with the url @returns [Boolean] value of append_tracking_info
flag
# File lib/model/redirect.rb, line 35 def self.append_tracking_info @@append_tracking_info end
Sets the value of the flag to determine if tracking info should be sent with the url adds the following to the url being redirected to redirect_mongo_id=<Redirect._id>&redirect_log_mongo_id=<RedirectLog._id> @param [Boolean] value to set append_tracking_info
flag to
# File lib/model/redirect.rb, line 29 def self.append_tracking_info= tracking_info_flag @@append_tracking_info = tracking_info_flag end
Creates a shortened url id of 8 characters, creates and saves a redirect object with the
new shortened url id.
@param [String] the url to redirect to @return [Redirect] a saved redirect object with the newly created shortened url.
# File lib/model/redirect.rb, line 68 def self.create_shortened_url(original_url) redir = self.new :original_url => original_url shortened_id = SecureRandom.urlsafe_base64(6) duplicate_find = Redirect.where(:shortened_id => shortened_id) if duplicate_find and duplicate_find.last and (shortened_id == duplicate_find.last.shortened_id) shortened_id = SecureRandom.urlsafe_base64(6) end redir.shortened_id = shortened_id redir.save! redir end
Gets the host for the shortened url @return [String] the host for the shortened url
# File lib/model/redirect.rb, line 60 def self.host @@host.end_with?('/') ? @@host : "#{@@host}/" end
Sets the host to use in the shortened url @param [String] the host to use in the shotened url
# File lib/model/redirect.rb, line 54 def self.host= host @@host = host end
Gets the path for the shortened url @return [String] the path
# File lib/model/redirect.rb, line 47 def self.path path = @@path.end_with?('/') ? @@path : "#{@@path}/" path.start_with?('/') ? path[1..path.length] : path end
Sets the path to use in the shortened url @param [String] the path you want to use for your shortened url instead of the default a/
# File lib/model/redirect.rb, line 41 def self.path= path @@path = path end
Public Instance Methods
Returns the shortened url path consisting of the path and shortened id @return [String] the shortened path
# File lib/model/redirect.rb, line 88 def shortened_path "#{self.class.path}#{shortened_id}" end
Returns the entire shortened url which consists of the host, path and shortened id @return [String] the shortened url
# File lib/model/redirect.rb, line 82 def shortened_url "#{self.class.host}#{self.class.path}#{shortened_id}" end