Class: NeetoCommonsBackend::AppUrlCarrier

Inherits:
Object
  • Object
show all
Defined in:
lib/neeto_commons_backend/carriers/app_url_carrier.rb

Class Method Summary collapse

Class Method Details

.app_portObject



55
56
57
# File 'lib/neeto_commons_backend/carriers/app_url_carrier.rb', line 55

def self.app_port
  app_secrets[:app_port_string] || ""
end

.app_protocolObject



59
60
61
# File 'lib/neeto_commons_backend/carriers/app_url_carrier.rb', line 59

def self.app_protocol
  app_secrets[:app_protocol]
end

.app_secretsObject



67
68
69
# File 'lib/neeto_commons_backend/carriers/app_url_carrier.rb', line 67

def self.app_secrets
  @_app_secrets ||= Rails.application.secrets
end

.app_url(request = nil) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
# File 'lib/neeto_commons_backend/carriers/app_url_carrier.rb', line 5

def self.app_url(request = nil)
  return URI(request.base_url) if request.present?

  # APP URL for review apps
  return review_app_url if Rails.env.heroku?

  host_url = app_secrets.host
  return URI(host_url) if host_url.present?

  URI "http://#{app_secrets.local_domain}"
end

.domain_url(organization) ⇒ Object



45
46
47
48
49
50
51
52
53
# File 'lib/neeto_commons_backend/carriers/app_url_carrier.rb', line 45

def self.domain_url(organization)
  custom_domain = organization.custom_domains&.where(status: "active").first

  if custom_domain.present?
    "#{app_protocol}#{custom_domain.hostname}"
  else
    root_url(organization.subdomain)
  end
end

.review_app_urlObject



38
39
40
41
42
43
# File 'lib/neeto_commons_backend/carriers/app_url_carrier.rb', line 38

def self.review_app_url
  heroku = app_secrets.heroku
  if heroku[:app_name].present?
    URI("https://#{heroku[:app_name]}.#{heroku[:domain_name]}")
  end
end

.root_url(subdomain) ⇒ Object



17
18
19
20
21
22
23
24
25
# File 'lib/neeto_commons_backend/carriers/app_url_carrier.rb', line 17

def self.root_url(subdomain)
  if Rails.env.heroku?
    review_app_url.to_s
  else
    app_protocol + subdomain + "." + app_url.host.sub(
      /(\A#{Organization::PLATFORM_SUBDOMAINS.join('|')})./,
      "") + app_port
  end
end

.websocket_url(subdomain) ⇒ Object



27
28
29
30
31
32
33
34
35
36
# File 'lib/neeto_commons_backend/carriers/app_url_carrier.rb', line 27

def self.websocket_url(subdomain)
  if Rails.env.heroku?
    uri = review_app_url
    uri.scheme = "wss"
    uri.path = "/cable"
    uri.to_s
  else
    ws_protocol + subdomain + "." + app_url.host.sub(/(\A#{Organization::PLATFORM_SUBDOMAINS.join('|')})./, "") + app_port + "/cable"
  end
end

.ws_protocolObject



63
64
65
# File 'lib/neeto_commons_backend/carriers/app_url_carrier.rb', line 63

def self.ws_protocol
  app_secrets[:ws_protocol]
end