Class: LucidIntercom::RenderSnippet

Inherits:
Object
  • Object
show all
Defined in:
lib/lucid_intercom/render_snippet.rb

Constant Summary collapse

TEMPLATE =
File.read("#{__dir__}/snippet.html").freeze

Instance Method Summary collapse

Instance Method Details

#call(shopify_data_or_user = {}, app_data = {}) ⇒ String

Examples:

Unauthenticated visitor

render_snippet.()
render_snippet.(shopify_data, app_data)

Parameters:

  • shopify_data_or_user (Hash, UserAttributes) (defaults to: {})

    shop attributes as returned by the Shopify API

  • app_data (Hash) (defaults to: {})

    app attributes (unprefixed)

Returns:

  • (String)


21
22
23
24
25
26
27
28
# File 'lib/lucid_intercom/render_snippet.rb', line 21

def call(shopify_data_or_user = {}, app_data = {})
  user = shopify_data_or_user
  user = UserAttributes.new(user, app_data) if user.is_a?(Hash)

  settings = shopify_data_or_user.is_a?(Hash) && shopify_data_or_user.empty? ? unauthenticated_settings : authenticated_settings(user)

  TEMPLATE % {settings: settings.to_json, app_id: settings[:app_id]}
end