class DistributionWrappers::Base
Attributes
params[RW]
name: A descriptive name for the service (based upon the parameters passed) icon: An (optional) image to identify the service by (might be based upon the parameters passed) banner: An (optional) descriptive image provided by the service
Public Class Methods
new(params={}, auth=nil)
click to toggle source
# File lib/distribution_wrappers/_base.rb, line 13 def initialize(params={}, auth=nil) @auth = auth @params = params end
Protected Instance Methods
append_parameters(doc, add_email=false)
click to toggle source
# File lib/distribution_wrappers/_base.rb, line 50 def append_parameters(doc, add_email=false) if ENV['ENVIRONMENT'] == 'production' regex = /.*backstit\.ch/ else regex = /.*localhost:3000/ end backstitch_links = doc.search('a[href]').select{ |n| n['href'][regex]} email_placeholder = "&email=<<email_placeholder>>" if add_email backstitch_links.each do |link| link.attributes['href'].value = "#{link.attributes['href'].value}&contact_id=#{@version_contact.id}&version_id=#{@version_contact.studio_post_version_id}&organization_id=#{@params[:organization].id}#{email_placeholder}" end doc end
redirect_links(doc, add_email=false)
click to toggle source
# File lib/distribution_wrappers/_base.rb, line 29 def redirect_links(doc, add_email=false) if ENV['ENVIRONMENT'] == "development" base_url = "http://localhost:3000" regex = /.*localhost:3000/ else base_url = "http://studio.backstit.ch" regex = /.*backstit\.ch/ end links = doc.search('a[href]').reject{ |n| n['href'][regex]} email_placeholder = "&email=<<email_placeholder>>" if add_email links.each do |link| old_link = link.attributes['href'].value link.attributes['href'].value = "#{base_url}/posts/#{@params[:post].id}/engagement/redirect_link?url=#{old_link}&contact_id=#{@version_contact.id}&version_id=#{@version_contact.studio_post_version_id}&organization_id=#{@params[:organization].id}#{email_placeholder}" end doc end
send_message(recipient)
click to toggle source
# File lib/distribution_wrappers/_base.rb, line 20 def send_message(recipient) @version_contact = PostVersionContactDistro.new @version_contact.studio_post_version_id = @params[:version_id] @version_contact.distribution_contact_id = recipient['id'] @version_contact.save @params[:version_contact_id] = @version_contact.id @message = prepare(recipient['identifier']) end