Class: InstagramConnect::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/instagram_connect/configuration.rb

Overview

Host-facing configuration, set via InstagramConnect.configure { |c| ... }.

auth_path selects which Meta login flow + Graph host the gem talks to:

:instagram_login  -> graph.instagram.com, no Facebook Page required
:facebook_login   -> graph.facebook.com, requires a linked Facebook Page

Secrets fall back to ENV so a host can configure entirely through the environment (e.g. container secrets) without an initializer edit.

Constant Summary collapse

AUTH_PATHS =
%i[instagram_login facebook_login].freeze
DEFAULT_THEME =

The gem ships a complete, self-styled UI. A host tints it to its brand by overriding any of these via config.theme = { primary: "#0057a8", ... } — no CSS or view files needed in the host app.

{
  primary: "#2563eb",
  primary_contrast: "#ffffff",
  bg: "#f7f8fa",
  surface: "#ffffff",
  text: "#111827",
  muted: "#6b7280",
  border: "#e5e7eb",
  radius: "12px",
  font: "Inter, system-ui, -apple-system, Segoe UI, Roboto, sans-serif",
  customer_bubble: "#f1f3f5",
  staff_bubble: "#eef2ff",
  ok: "#16a34a",
  warn: "#d97706",
  err: "#dc2626"
}.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfiguration

Returns a new instance of Configuration.



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/instagram_connect/configuration.rb', line 44

def initialize
  @auth_path = (ENV["INSTAGRAM_CONNECT_AUTH_PATH"] || "instagram_login").to_sym
  @app_id = ENV["INSTAGRAM_CONNECT_APP_ID"] || ENV["INSTAGRAM_APP_ID"]
  @app_secret = ENV["INSTAGRAM_CONNECT_APP_SECRET"] || ENV["INSTAGRAM_APP_SECRET"]
  @verify_token = ENV["INSTAGRAM_CONNECT_VERIFY_TOKEN"] || ENV["INSTAGRAM_VERIFY_TOKEN"]
  @graph_version = ENV.fetch("INSTAGRAM_CONNECT_GRAPH_VERSION", "v21.0")
  @redirect_uri = ENV["INSTAGRAM_CONNECT_REDIRECT_URI"]
  @encrypt_tokens = true
  @parent_controller = "::ApplicationController"
  @authenticate_with = nil
  @current_user_id_resolver = -> { respond_to?(:current_user) && current_user ? current_user.id : nil }
  @on_message = nil
  @on_comment = nil
  @on_postback = nil
  @logger = Logger.new($stdout)
  @default_per_page = 25
  # Default false: the gem renders in its own self-contained layout (its own
  # chrome + styles), like an admin engine. Set true to render inside the
  # host's application layout instead (then include the gem styles in your
  # <head> via `instagram_connect_styles`).
  @inherit_host_layout = false
  @theme = {}
  # Where the OAuth callback redirects after connecting an account.
  @after_connect_redirect = "/"
  @media_max_bytes = 25 * 1024 * 1024
  @allowed_media_types = %w[
    image/jpeg image/png image/gif image/webp
    video/mp4 audio/mpeg audio/aac application/pdf
  ].freeze
end

Instance Attribute Details

#after_connect_redirectObject

Returns the value of attribute after_connect_redirect.



35
36
37
# File 'lib/instagram_connect/configuration.rb', line 35

def after_connect_redirect
  @after_connect_redirect
end

#allowed_media_typesObject

Returns the value of attribute allowed_media_types.



35
36
37
# File 'lib/instagram_connect/configuration.rb', line 35

def allowed_media_types
  @allowed_media_types
end

#app_idObject

Returns the value of attribute app_id.



35
36
37
# File 'lib/instagram_connect/configuration.rb', line 35

def app_id
  @app_id
end

#app_secretObject

Returns the value of attribute app_secret.



35
36
37
# File 'lib/instagram_connect/configuration.rb', line 35

def app_secret
  @app_secret
end

#auth_pathObject

Returns the value of attribute auth_path.



41
42
43
# File 'lib/instagram_connect/configuration.rb', line 41

def auth_path
  @auth_path
end

#authenticate_withObject

Returns the value of attribute authenticate_with.



35
36
37
# File 'lib/instagram_connect/configuration.rb', line 35

def authenticate_with
  @authenticate_with
end

#current_user_id_resolverObject

Returns the value of attribute current_user_id_resolver.



35
36
37
# File 'lib/instagram_connect/configuration.rb', line 35

def current_user_id_resolver
  @current_user_id_resolver
end

#default_per_pageObject

Returns the value of attribute default_per_page.



35
36
37
# File 'lib/instagram_connect/configuration.rb', line 35

def default_per_page
  @default_per_page
end

#encrypt_tokensObject

Returns the value of attribute encrypt_tokens.



35
36
37
# File 'lib/instagram_connect/configuration.rb', line 35

def encrypt_tokens
  @encrypt_tokens
end

#graph_versionObject

Returns the value of attribute graph_version.



35
36
37
# File 'lib/instagram_connect/configuration.rb', line 35

def graph_version
  @graph_version
end

#inherit_host_layoutObject

Returns the value of attribute inherit_host_layout.



35
36
37
# File 'lib/instagram_connect/configuration.rb', line 35

def inherit_host_layout
  @inherit_host_layout
end

#loggerObject

Returns the value of attribute logger.



35
36
37
# File 'lib/instagram_connect/configuration.rb', line 35

def logger
  @logger
end

#media_max_bytesObject

Returns the value of attribute media_max_bytes.



35
36
37
# File 'lib/instagram_connect/configuration.rb', line 35

def media_max_bytes
  @media_max_bytes
end

#on_commentObject

Returns the value of attribute on_comment.



35
36
37
# File 'lib/instagram_connect/configuration.rb', line 35

def on_comment
  @on_comment
end

#on_messageObject

Returns the value of attribute on_message.



35
36
37
# File 'lib/instagram_connect/configuration.rb', line 35

def on_message
  @on_message
end

#on_postbackObject

Returns the value of attribute on_postback.



35
36
37
# File 'lib/instagram_connect/configuration.rb', line 35

def on_postback
  @on_postback
end

#parent_controllerObject

Returns the value of attribute parent_controller.



35
36
37
# File 'lib/instagram_connect/configuration.rb', line 35

def parent_controller
  @parent_controller
end

#redirect_uriObject

Returns the value of attribute redirect_uri.



35
36
37
# File 'lib/instagram_connect/configuration.rb', line 35

def redirect_uri
  @redirect_uri
end

#theme=(value) ⇒ Object (writeonly)

Sets the attribute theme

Parameters:

  • value

    the value to set the attribute theme to.



42
43
44
# File 'lib/instagram_connect/configuration.rb', line 42

def theme=(value)
  @theme = value
end

#verify_tokenObject

Returns the value of attribute verify_token.



35
36
37
# File 'lib/instagram_connect/configuration.rb', line 35

def verify_token
  @verify_token
end

Instance Method Details

#resolved_themeObject

The host's theme overrides merged over the gem defaults.



82
83
84
# File 'lib/instagram_connect/configuration.rb', line 82

def resolved_theme
  DEFAULT_THEME.merge(@theme || {})
end

#validate!Object

Called by .configure at boot. Validates only structural config (a known auth_path) so an unconfigured host can still boot; secret presence is enforced lazily at the point of use (Client / OAuth).



89
90
91
92
93
94
95
# File 'lib/instagram_connect/configuration.rb', line 89

def validate!
  unless AUTH_PATHS.include?(auth_path)
    raise ConfigurationError,
      "auth_path must be one of #{AUTH_PATHS.join(', ')} (got #{auth_path.inspect})"
  end
  true
end