From bcb294fa49bf1ce84b0e06b6a4359d37fec9e395 Mon Sep 17 00:00:00 2001 From: Daniel Carter Date: Wed, 7 Oct 2020 15:33:18 +0100 Subject: [PATCH 1/2] Adds access to api_base configuration option --- lib/intercom-rails/config.rb | 1 + lib/intercom-rails/script_tag.rb | 1 + lib/rails/generators/intercom/config/intercom.rb.erb | 4 ++++ spec/config_spec.rb | 5 +++++ spec/script_tag_spec.rb | 4 ++++ 5 files changed, 15 insertions(+) diff --git a/lib/intercom-rails/config.rb b/lib/intercom-rails/config.rb index bec8a08..1093b2d 100644 --- a/lib/intercom-rails/config.rb +++ b/lib/intercom-rails/config.rb @@ -108,6 +108,7 @@ def self.reset! config_accessor :enabled_environments, &ARRAY_VALIDATOR config_accessor :include_for_logged_out_users config_accessor :hide_default_launcher + config_accessor :api_base config_accessor :encrypted_mode def self.api_key=(*) diff --git a/lib/intercom-rails/script_tag.rb b/lib/intercom-rails/script_tag.rb index ea1a219..319f471 100644 --- a/lib/intercom-rails/script_tag.rb +++ b/lib/intercom-rails/script_tag.rb @@ -71,6 +71,7 @@ def intercom_settings hsh[:widget] = widget_options if widget_options.present? hsh[:company] = company_details if company_details.present? hsh[:hide_default_launcher] = Config.hide_default_launcher if Config.hide_default_launcher + hsh[:api_base] = Config.api_base if Config.api_base hsh end diff --git a/lib/rails/generators/intercom/config/intercom.rb.erb b/lib/rails/generators/intercom/config/intercom.rb.erb index 77a718b..6d7b6b2 100644 --- a/lib/rails/generators/intercom/config/intercom.rb.erb +++ b/lib/rails/generators/intercom/config/intercom.rb.erb @@ -127,4 +127,8 @@ IntercomRails.config do |config| # # If you'd like to hide default launcher button uncomment this line # config.hide_default_launcher = true + # + # If you need to route your Messenger requests through a different endpoint than the default, replace the below with your app id, and uncomment below line. Generally speaking, this is not needed. + # confid.api_base = https://{app_id}.intercom-messenger.com + # end diff --git a/spec/config_spec.rb b/spec/config_spec.rb index 9e6c005..c84fd26 100644 --- a/spec/config_spec.rb +++ b/spec/config_spec.rb @@ -56,6 +56,11 @@ expect(IntercomRails.config.hide_default_launcher).to eq(true) end + it 'gets/sets api_base' do + IntercomRails.config.api_base = "https://abcde1.intercom-messenger.com" + expect(IntercomRails.config.api_base).to eq("https://abcde1.intercom-messenger.com") + end + it 'gets/sets Encrypted Mode' do IntercomRails.config.encrypted_mode = true expect(IntercomRails.config.encrypted_mode).to eq(true) diff --git a/spec/script_tag_spec.rb b/spec/script_tag_spec.rb index 0746371..705fe24 100644 --- a/spec/script_tag_spec.rb +++ b/spec/script_tag_spec.rb @@ -150,6 +150,10 @@ def sha256_hmac(secret, input) IntercomRails.config.hide_default_launcher = true expect(ScriptTag.new.intercom_settings['hide_default_launcher']).to eq(true) end + it 'knows about :api_base' do + IntercomRails.config.api_base = "https://abcde1.intercom-messenger.com" + expect(ScriptTag.new.intercom_settings['api_base']).to eq("https://abcde1.intercom-messenger.com") + end end context 'company' do From 246cbd410790bf17b9401093d7d332b305913fb2 Mon Sep 17 00:00:00 2001 From: Daniel Carter Date: Wed, 7 Oct 2020 15:35:53 +0100 Subject: [PATCH 2/2] adds use for Encrypted mode and fixes typo in config erb --- lib/intercom-rails/encrypted_mode.rb | 2 +- lib/rails/generators/intercom/config/intercom.rb.erb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/intercom-rails/encrypted_mode.rb b/lib/intercom-rails/encrypted_mode.rb index 88d4ad8..94fd86d 100644 --- a/lib/intercom-rails/encrypted_mode.rb +++ b/lib/intercom-rails/encrypted_mode.rb @@ -2,7 +2,7 @@ module IntercomRails class EncryptedMode attr_reader :secret, :initialization_vector, :enabled - ENCRYPTED_MODE_SETTINGS_WHITELIST = [:app_id, :session_duration, :widget, :custom_launcher_selector, :hide_default_launcher, :alignment, :horizontal_padding, :vertical_padding] + ENCRYPTED_MODE_SETTINGS_WHITELIST = [:app_id, :session_duration, :widget, :custom_launcher_selector, :hide_default_launcher, :api_base, :alignment, :horizontal_padding, :vertical_padding] def initialize(secret, initialization_vector, options) @secret = secret diff --git a/lib/rails/generators/intercom/config/intercom.rb.erb b/lib/rails/generators/intercom/config/intercom.rb.erb index 6d7b6b2..b476920 100644 --- a/lib/rails/generators/intercom/config/intercom.rb.erb +++ b/lib/rails/generators/intercom/config/intercom.rb.erb @@ -129,6 +129,6 @@ IntercomRails.config do |config| # config.hide_default_launcher = true # # If you need to route your Messenger requests through a different endpoint than the default, replace the below with your app id, and uncomment below line. Generally speaking, this is not needed. - # confid.api_base = https://{app_id}.intercom-messenger.com + # config.api_base = https://{app_id}.intercom-messenger.com # end