Class: FlowChat::Intercom::Configuration
- Inherits:
-
Object
- Object
- FlowChat::Intercom::Configuration
- Defined in:
- lib/flow_chat/intercom/configuration.rb
Constant Summary collapse
- @@configurations =
Class-level storage for named configurations
{}
Instance Attribute Summary collapse
-
#access_token ⇒ Object
Returns the value of attribute access_token.
-
#admin_id ⇒ Object
Returns the value of attribute admin_id.
-
#client_secret ⇒ Object
Returns the value of attribute client_secret.
-
#name ⇒ Object
Returns the value of attribute name.
-
#skip_signature_validation ⇒ Object
Returns the value of attribute skip_signature_validation.
Class Method Summary collapse
-
.clear_all! ⇒ Object
Clear all registered configurations (useful for testing).
-
.configuration_names ⇒ Object
Get all configuration names.
-
.exists?(name) ⇒ Boolean
Check if a named configuration exists.
-
.from_credentials ⇒ Object
Load configuration from Rails credentials or environment variables.
-
.get(name) ⇒ Object
Get a named configuration.
-
.register(name, config) ⇒ Object
Register a named configuration.
Instance Method Summary collapse
- #admins_url ⇒ Object
-
#api_base_url ⇒ Object
API endpoints.
-
#api_headers ⇒ Object
Headers for API requests.
- #conversation_parts_url(conversation_id) ⇒ Object
- #conversation_reply_url(conversation_id) ⇒ Object
- #conversation_tags_url(conversation_id, tag_id = nil) ⇒ Object
- #conversations_url(conversation_id = nil) ⇒ Object
-
#initialize(name) ⇒ Configuration
constructor
A new instance of Configuration.
-
#register_as(name) ⇒ Object
Register this configuration with a name.
- #valid? ⇒ Boolean
Constructor Details
#initialize(name) ⇒ Configuration
Returns a new instance of Configuration.
9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/flow_chat/intercom/configuration.rb', line 9 def initialize(name) @name = name @access_token = nil @client_secret = nil @admin_id = nil @skip_signature_validation = false FlowChat.logger.debug { "Intercom::Configuration: Initialized configuration with name: #{name || "anonymous"}" } register_as(name) if name.present? end |
Instance Attribute Details
#access_token ⇒ Object
Returns the value of attribute access_token.
4 5 6 |
# File 'lib/flow_chat/intercom/configuration.rb', line 4 def access_token @access_token end |
#admin_id ⇒ Object
Returns the value of attribute admin_id.
4 5 6 |
# File 'lib/flow_chat/intercom/configuration.rb', line 4 def admin_id @admin_id end |
#client_secret ⇒ Object
Returns the value of attribute client_secret.
4 5 6 |
# File 'lib/flow_chat/intercom/configuration.rb', line 4 def client_secret @client_secret end |
#name ⇒ Object
Returns the value of attribute name.
4 5 6 |
# File 'lib/flow_chat/intercom/configuration.rb', line 4 def name @name end |
#skip_signature_validation ⇒ Object
Returns the value of attribute skip_signature_validation.
4 5 6 |
# File 'lib/flow_chat/intercom/configuration.rb', line 4 def skip_signature_validation @skip_signature_validation end |
Class Method Details
.clear_all! ⇒ Object
Clear all registered configurations (useful for testing)
85 86 87 88 |
# File 'lib/flow_chat/intercom/configuration.rb', line 85 def self.clear_all! FlowChat.logger.debug { "Intercom::Configuration: Clearing all registered configurations" } @@configurations.clear end |
.configuration_names ⇒ Object
Get all configuration names
78 79 80 81 82 |
# File 'lib/flow_chat/intercom/configuration.rb', line 78 def self.configuration_names names = @@configurations.keys FlowChat.logger.debug { "Intercom::Configuration: Available configurations: #{names}" } names end |
.exists?(name) ⇒ Boolean
Check if a named configuration exists
71 72 73 74 75 |
# File 'lib/flow_chat/intercom/configuration.rb', line 71 def self.exists?(name) exists = @@configurations.key?(name.to_sym) FlowChat.logger.debug { "Intercom::Configuration: Configuration '#{name}' exists: #{exists}" } exists end |
.from_credentials ⇒ Object
Load configuration from Rails credentials or environment variables
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/flow_chat/intercom/configuration.rb', line 22 def self.from_credentials FlowChat.logger.info { "Intercom::Configuration: Loading configuration from credentials/environment" } config = new(nil) if defined?(Rails) && Rails.application.credentials.intercom FlowChat.logger.debug { "Intercom::Configuration: Loading from Rails credentials" } credentials = Rails.application.credentials.intercom config.access_token = credentials[:access_token] config.client_secret = credentials[:client_secret] config.admin_id = credentials[:admin_id] config.skip_signature_validation = credentials[:skip_signature_validation] || false else FlowChat.logger.debug { "Intercom::Configuration: Loading from environment variables" } # Fallback to environment variables config.access_token = ENV["INTERCOM_ACCESS_TOKEN"] config.client_secret = ENV["INTERCOM_CLIENT_SECRET"] config.admin_id = ENV["INTERCOM_ADMIN_ID"] config.skip_signature_validation = ENV["INTERCOM_SKIP_SIGNATURE_VALIDATION"] == "true" end if config.valid? FlowChat.logger.info { "Intercom::Configuration: Configuration loaded successfully" } else FlowChat.logger.warn { "Intercom::Configuration: Incomplete configuration loaded - missing required fields" } end config end |
.get(name) ⇒ Object
Get a named configuration
59 60 61 62 63 64 65 66 67 68 |
# File 'lib/flow_chat/intercom/configuration.rb', line 59 def self.get(name) config = @@configurations[name.to_sym] if config FlowChat.logger.debug { "Intercom::Configuration: Retrieved configuration '#{name}'" } config else FlowChat.logger.error { "Intercom::Configuration: Configuration '#{name}' not found" } raise ArgumentError, "Intercom configuration '#{name}' not found" end end |
Instance Method Details
#admins_url ⇒ Object
134 135 136 |
# File 'lib/flow_chat/intercom/configuration.rb', line 134 def admins_url "#{api_base_url}/admins" end |
#api_base_url ⇒ Object
API endpoints
106 107 108 |
# File 'lib/flow_chat/intercom/configuration.rb', line 106 def api_base_url "https://api.intercom.io" end |
#api_headers ⇒ Object
Headers for API requests
139 140 141 142 143 144 145 146 |
# File 'lib/flow_chat/intercom/configuration.rb', line 139 def api_headers { "Authorization" => "Bearer #{access_token}", "Content-Type" => "application/json", "Accept" => "application/json", "Intercom-Version" => "2.11" } end |
#conversation_parts_url(conversation_id) ⇒ Object
122 123 124 |
# File 'lib/flow_chat/intercom/configuration.rb', line 122 def conversation_parts_url(conversation_id) "#{conversations_url(conversation_id)}/parts" end |
#conversation_reply_url(conversation_id) ⇒ Object
118 119 120 |
# File 'lib/flow_chat/intercom/configuration.rb', line 118 def conversation_reply_url(conversation_id) "#{conversations_url(conversation_id)}/reply" end |
#conversation_tags_url(conversation_id, tag_id = nil) ⇒ Object
126 127 128 129 130 131 132 |
# File 'lib/flow_chat/intercom/configuration.rb', line 126 def (conversation_id, tag_id = nil) if tag_id "#{conversations_url(conversation_id)}/tags/#{tag_id}" else "#{conversations_url(conversation_id)}/tags" end end |
#conversations_url(conversation_id = nil) ⇒ Object
110 111 112 113 114 115 116 |
# File 'lib/flow_chat/intercom/configuration.rb', line 110 def conversations_url(conversation_id = nil) if conversation_id "#{api_base_url}/conversations/#{conversation_id}" else "#{api_base_url}/conversations" end end |
#register_as(name) ⇒ Object
Register this configuration with a name
91 92 93 94 95 96 |
# File 'lib/flow_chat/intercom/configuration.rb', line 91 def register_as(name) FlowChat.logger.debug { "Intercom::Configuration: Registering configuration as '#{name}'" } @name = name.to_sym self.class.register(@name, self) self end |
#valid? ⇒ Boolean
98 99 100 101 102 103 |
# File 'lib/flow_chat/intercom/configuration.rb', line 98 def valid? is_valid = !!(access_token && !access_token.to_s.empty? && admin_id && !admin_id.to_s.empty?) FlowChat.logger.debug { "Intercom::Configuration: Configuration valid: #{is_valid}" } is_valid end |