Class: FlowChat::Intercom::Configuration
- Inherits:
-
Object
- Object
- FlowChat::Intercom::Configuration
- Includes:
- NamedConfiguration
- Defined in:
- lib/flow_chat/intercom/configuration.rb
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
-
.from_credentials ⇒ Object
Load configuration from Rails credentials or environment variables.
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.
- #valid? ⇒ Boolean
Methods included from NamedConfiguration
Constructor Details
#initialize(name) ⇒ Configuration
Returns a new instance of Configuration.
8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/flow_chat/intercom/configuration.rb', line 8 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.
6 7 8 |
# File 'lib/flow_chat/intercom/configuration.rb', line 6 def access_token @access_token end |
#admin_id ⇒ Object
Returns the value of attribute admin_id.
6 7 8 |
# File 'lib/flow_chat/intercom/configuration.rb', line 6 def admin_id @admin_id end |
#client_secret ⇒ Object
Returns the value of attribute client_secret.
6 7 8 |
# File 'lib/flow_chat/intercom/configuration.rb', line 6 def client_secret @client_secret end |
#name ⇒ Object
Returns the value of attribute name.
6 7 8 |
# File 'lib/flow_chat/intercom/configuration.rb', line 6 def name @name end |
#skip_signature_validation ⇒ Object
Returns the value of attribute skip_signature_validation.
6 7 8 |
# File 'lib/flow_chat/intercom/configuration.rb', line 6 def skip_signature_validation @skip_signature_validation end |
Class Method Details
.from_credentials ⇒ Object
Load configuration from Rails credentials or environment variables
21 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 |
# File 'lib/flow_chat/intercom/configuration.rb', line 21 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 |
Instance Method Details
#admins_url ⇒ Object
87 88 89 |
# File 'lib/flow_chat/intercom/configuration.rb', line 87 def admins_url "#{api_base_url}/admins" end |
#api_base_url ⇒ Object
API endpoints
59 60 61 |
# File 'lib/flow_chat/intercom/configuration.rb', line 59 def api_base_url "https://api.intercom.io" end |
#api_headers ⇒ Object
Headers for API requests
92 93 94 95 96 97 98 99 |
# File 'lib/flow_chat/intercom/configuration.rb', line 92 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
75 76 77 |
# File 'lib/flow_chat/intercom/configuration.rb', line 75 def conversation_parts_url(conversation_id) "#{conversations_url(conversation_id)}/parts" end |
#conversation_reply_url(conversation_id) ⇒ Object
71 72 73 |
# File 'lib/flow_chat/intercom/configuration.rb', line 71 def conversation_reply_url(conversation_id) "#{conversations_url(conversation_id)}/reply" end |
#conversation_tags_url(conversation_id, tag_id = nil) ⇒ Object
79 80 81 82 83 84 85 |
# File 'lib/flow_chat/intercom/configuration.rb', line 79 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
63 64 65 66 67 68 69 |
# File 'lib/flow_chat/intercom/configuration.rb', line 63 def conversations_url(conversation_id = nil) if conversation_id "#{api_base_url}/conversations/#{conversation_id}" else "#{api_base_url}/conversations" end end |