class Redirect

Public Class Methods

append_google_analytics() click to toggle source

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
append_google_analytics=(google_analytics_flag) click to toggle source

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
append_tracking_info() click to toggle source

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
append_tracking_info=(tracking_info_flag) click to toggle source

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
create_shortened_url(original_url) click to toggle source

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
host() click to toggle source

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
host=(host) click to toggle source

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
path() click to toggle source

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
path=(path) click to toggle source

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

shortened_path() click to toggle source

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
shortened_url() click to toggle source

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