Skip to content

Commit

Permalink
Created new class for host and protocol
Browse files Browse the repository at this point in the history
  • Loading branch information
sunil-lakshman committed Apr 21, 2023
1 parent a7777bd commit 935cfb3
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 11 deletions.
22 changes: 11 additions & 11 deletions lib/contentstack/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -81,16 +81,16 @@ def sync(params)

private
def get_default_region_hosts(region='us')
host = "#{Contentstack::Region::PROTOCOL}#{Contentstack::Region::DEFAULT_HOST}" #set default host if region is nil
host = "#{Contentstack::Host::PROTOCOL}#{Contentstack::Host::DEFAULT_HOST}" #set default host if region is nil
case region
when "us"
host = "#{Contentstack::Region::PROTOCOL}#{Contentstack::Region::DEFAULT_HOST}"
host = "#{Contentstack::Host::PROTOCOL}#{Contentstack::Host::DEFAULT_HOST}"
when "eu"
host = "#{Contentstack::Region::PROTOCOL}eu-cdn.#{Contentstack::Region::HOST}"
host = "#{Contentstack::Host::PROTOCOL}eu-cdn.#{Contentstack::Host::HOST}"
when "azure-na"
host = "#{Contentstack::Region::PROTOCOL}azure-na-cdn.#{Contentstack::Region::HOST}"
host = "#{Contentstack::Host::PROTOCOL}azure-na-cdn.#{Contentstack::Host::HOST}"
when "azure-eu"
host = "#{Contentstack::Region::PROTOCOL}azure-eu-cdn.#{Contentstack::Region::HOST}"
host = "#{Contentstack::Host::PROTOCOL}azure-eu-cdn.#{Contentstack::Host::HOST}"
end
host
end
Expand All @@ -102,19 +102,19 @@ def get_host_by_region(region, options)
custom_host = options[:host]
case region
when "us"
host = "#{Contentstack::Region::PROTOCOL}cdn.#{custom_host}"
host = "#{Contentstack::Host::PROTOCOL}cdn.#{custom_host}"
when "eu"
host = "#{Contentstack::Region::PROTOCOL}eu-cdn.#{custom_host}"
host = "#{Contentstack::Host::PROTOCOL}eu-cdn.#{custom_host}"
when "azure-na"
host = "#{Contentstack::Region::PROTOCOL}azure-na-cdn.#{custom_host}"
host = "#{Contentstack::Host::PROTOCOL}azure-na-cdn.#{custom_host}"
when "azure-eu"
host = "#{Contentstack::Region::PROTOCOL}azure-eu-cdn.#{custom_host}"
host = "#{Contentstack::Host::PROTOCOL}azure-eu-cdn.#{custom_host}"
end
elsif options[:host].present? && region.empty?
custom_host = options[:host]
host = "#{Contentstack::Region::PROTOCOL}cdn.#{custom_host}"
host = "#{Contentstack::Host::PROTOCOL}cdn.#{custom_host}"
else
host = "#{Contentstack::Region::PROTOCOL}#{Contentstack::Region::DEFAULT_HOST}" #set default host if region and host is empty
host = "#{Contentstack::Host::PROTOCOL}#{Contentstack::Host::DEFAULT_HOST}" #set default host if region and host is empty
end
host
end
Expand Down
3 changes: 3 additions & 0 deletions lib/contentstack/region.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ class Region
US='us'
AZURE_NA='azure-na'
AZURE_EU='azure-eu'
end

class Host
PROTOCOL='https://'
DEFAULT_HOST='cdn.contentstack.io'
HOST='contentstack.com'
Expand Down

0 comments on commit 935cfb3

Please sign in to comment.