class Talkable::Offer

Public Class Methods

parse(result_hash) click to toggle source
# File lib/talkable/resources/offer.rb, line 3
def self.parse(result_hash)
  return nil unless result_hash && result_hash[:offer] && result_hash[:offer].size > 0
  offer = self.new(result_hash[:offer])
  offer.claim_links ||= Hashie::Mash.new(result_hash[:claim_links])
  offer
end

Public Instance Methods

advocate_share_iframe(options = {}) click to toggle source
# File lib/talkable/resources/offer.rb, line 10
def advocate_share_iframe(options = {})
  show_trigger = !options[:ignore_trigger]
  iframe_options = default_iframe_options.merge(options[:iframe] || {})
  url = show_trigger ? Furi.merge(show_url, query: {trigger_enabled: 1}) : show_url

  snippets = []
  if !options[:iframe] || !options[:iframe][:container]
    snippets << render_container_snipet(iframe_options[:container])
  end
  snippets << render_share_snipet({
    url: url,
    iframe: iframe_options,
  })

  snippets.join("\n")
end

Protected Instance Methods

default_iframe_options() click to toggle source
# File lib/talkable/resources/offer.rb, line 29
def default_iframe_options
  {
    container: "talkable-offer",
  }
end
render_container_snipet(name) click to toggle source
# File lib/talkable/resources/offer.rb, line 35
def render_container_snipet(name)
  "<div id='#{CGI.escape(name)}'></div>"
end
render_share_snipet(show_options) click to toggle source
# File lib/talkable/resources/offer.rb, line 39
    def render_share_snipet(show_options)
      %Q{
<script>
_talkableq.push(['show_offer', #{show_options.to_json}])
</script>
      }
    end