Module: IntercomWrapper

Extended by:
Intercom
Defined in:
lib/intercom_wrapper.rb

Class Method Summary collapse

Class Method Details

.post(path, payload_hash, app_id, app_api_key) ⇒ Object



6
7
8
# File 'lib/intercom_wrapper.rb', line 6

def self.post(path, payload_hash, app_id, app_api_key)
  send_request_to_path(Intercom::Request.post(path, payload_hash), app_id, app_api_key)
end

.put(path, payload_hash, app_id, app_api_key) ⇒ Object



10
11
12
# File 'lib/intercom_wrapper.rb', line 10

def self.put(path, payload_hash, app_id, app_api_key)
  send_request_to_path(Intercom::Request.put(path, payload_hash), app_id, app_api_key)
end

.retry_on_alternative_endpoint(request, app_id, app_api_key) ⇒ Object



24
25
26
27
# File 'lib/intercom_wrapper.rb', line 24

def self.retry_on_alternative_endpoint(request, app_id, app_api_key)
  Intercom.current_endpoint = Intercom::alternative_random_endpoint
  request.execute(target_base_url, app_id, app_api_key)
end

.send_request_to_path(request, app_id, app_api_key) ⇒ Object



14
15
16
17
18
19
20
21
22
# File 'lib/intercom_wrapper.rb', line 14

def self.send_request_to_path(request, app_id, app_api_key)
  request.execute(target_base_url(app_id, app_api_key))
rescue Intercom::ServiceUnavailableError => e
  if Intercom::endpoints.length > 1
    retry_on_alternative_endpoint(request, app_id, app_api_key)
  else
    raise e
  end
end

.target_base_url(app_id, app_api_key) ⇒ Object

Raises:

  • (ArgumentError)


29
30
31
32
33
# File 'lib/intercom_wrapper.rb', line 29

def self.target_base_url(app_id, app_api_key)
  raise ArgumentError, "#{Intercom.configuration_required_text} #{Intercom.related_docs_text}" if [app_id, app_api_key].any?(&:nil?)
  basic_auth_part = "#{app_id}:#{app_api_key}@"
  Intercom.current_endpoint.gsub(/(https?:\/\/)(.*)/, "\\1#{basic_auth_part}\\2")
end