From 9924d61f10c632058341282470dcabe01ed08d49 Mon Sep 17 00:00:00 2001 From: sunil-lakshman <104969541+sunil-lakshman@users.noreply.github.com> Date: Tue, 7 May 2024 12:44:14 +0530 Subject: [PATCH] Added GCP NA support with testcases --- CHANGELOG.md | 8 +++++- Gemfile.lock | 49 ++++++++++++++++++++----------------- lib/contentstack/client.rb | 26 +++++++++++--------- lib/contentstack/region.rb | 3 ++- lib/contentstack/version.rb | 4 +-- spec/contentstack_spec.rb | 25 +++++++++++-------- 6 files changed, 68 insertions(+), 47 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ebb6385..a56dc16 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,12 @@ ## CHANGELOG -## Version 0.6.4 +## Version 0.8.0 +### Date: 14th-May-2024 + ### Enhancement + - Region support for GCP-NA added + +------------------------------------------------ +## Version 0.7.0 ### Date: 17th-Apr-2023 ### Enhancement - Include metadata support for Asset, Entry and Query, diff --git a/Gemfile.lock b/Gemfile.lock index 3e40999..505e9c9 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,42 +1,48 @@ PATH remote: . specs: - - contentstack (0.7.0) + contentstack (0.8.0) activesupport (>= 3.2) contentstack_utils (~> 1.0) GEM remote: https://rubygems.org/ specs: - activesupport (7.0.4.3) + activesupport (7.1.3.2) + base64 + bigdecimal concurrent-ruby (~> 1.0, >= 1.0.2) + connection_pool (>= 2.2.5) + drb i18n (>= 1.6, < 2) minitest (>= 5.1) + mutex_m tzinfo (~> 2.0) - addressable (2.8.4) + addressable (2.8.6) public_suffix (>= 2.0.2, < 6.0) - concurrent-ruby (1.2.2) - contentstack_utils (1.1.3.2) + base64 (0.2.0) + bigdecimal (3.1.8) + concurrent-ruby (1.2.3) + connection_pool (2.4.1) + contentstack_utils (1.2.0) activesupport (>= 3.2) nokogiri (~> 1.11) - crack (0.4.5) + crack (1.0.0) + bigdecimal rexml - diff-lcs (1.5.0) + diff-lcs (1.5.1) docile (1.4.0) - hashdiff (1.0.1) - i18n (1.12.0) + drb (2.2.1) + hashdiff (1.1.0) + i18n (1.14.5) concurrent-ruby (~> 1.0) - mini_portile2 (2.8.1) - minitest (5.18.0) - nokogiri (1.14.3) - mini_portile2 (~> 2.8.0) - racc (~> 1.4) - nokogiri (1.14.3-x64-mingw32) + minitest (5.22.3) + mutex_m (0.2.0) + nokogiri (1.15.6-arm64-darwin) racc (~> 1.4) - public_suffix (5.0.1) - racc (1.6.2) - rexml (3.2.5) + public_suffix (5.0.5) + racc (1.7.3) + rexml (3.2.6) rspec (3.10.0) rspec-core (~> 3.10.0) rspec-expectations (~> 3.10.0) @@ -62,11 +68,10 @@ GEM addressable (>= 2.3.6) crack (>= 0.3.2) hashdiff (>= 0.4.0, < 2.0.0) - yard (0.9.34) + yard (0.9.36) PLATFORMS - ruby - x64-mingw32 + arm64-darwin-22 DEPENDENCIES contentstack! diff --git a/lib/contentstack/client.rb b/lib/contentstack/client.rb index 9137f95..e66d5de 100644 --- a/lib/contentstack/client.rb +++ b/lib/contentstack/client.rb @@ -36,7 +36,7 @@ def initialize(api_key, delivery_token, environment, options={}) raise Contentstack::Error.new("Proxy Port Should not be Empty") if @proxy_details.present? && @proxy_details[:port].empty? API.init_api(api_key, delivery_token, environment, @host, @branch, @live_preview, @proxy_details, retry_options) end - + def content_types ContentType.all end @@ -56,21 +56,21 @@ def asset(uid) def live_preview_query(query={}) API.live_preview_query(query) end - + # Syncs your Contentstack data with your app and ensures that the data is always up-to-date by providing delta updates - # + # # Stack.sync({'init': true}) // For initializing sync - # + # # Stack.sync({'init': true, 'locale': 'en-us'}) //For initializing sync with entries of a specific locale - # + # # Stack.sync({'init': true, 'start_date': '2018-10-22'}) //For initializing sync with entries published after a specific date - # + # # Stack.sync({'init': true, 'content_type_uid': 'session'}) //For initializing sync with entries of a specific content type - # + # # Stack.sync({'init': true, 'type': 'entry_published'}) // Use the type parameter to get a specific type of content.Supports 'asset_published', 'entry_published', 'asset_unpublished', 'entry_unpublished', 'asset_deleted', 'entry_deleted', 'content_type_deleted'. - # + # # Stack.sync({'pagination_token': ''}) // For fetching the next batch of entries using pagination token - # + # # Stack.sync({'sync_token': ''}) // For performing subsequent sync after initial sync # # @param params [Hash] params is an object that supports ‘locale’, ‘start_date’, ‘content_type_uid’, and ‘type’ queries. @@ -91,6 +91,8 @@ def get_default_region_hosts(region='us') host = "#{Contentstack::Host::PROTOCOL}azure-na-cdn.#{Contentstack::Host::HOST}" when "azure-eu" host = "#{Contentstack::Host::PROTOCOL}azure-eu-cdn.#{Contentstack::Host::HOST}" + when "gcp-na" + host = "#{Contentstack::Host::PROTOCOL}gcp-na-cdn.#{Contentstack::Host::HOST}" end host end @@ -109,15 +111,17 @@ def get_host_by_region(region, options) host = "#{Contentstack::Host::PROTOCOL}azure-na-cdn.#{custom_host}" when "azure-eu" host = "#{Contentstack::Host::PROTOCOL}azure-eu-cdn.#{custom_host}" + when "gcp-na" + host = "#{Contentstack::Host::PROTOCOL}gcp-na-cdn.#{custom_host}" end elsif options[:host].present? && region.empty? custom_host = options[:host] host = "#{Contentstack::Host::PROTOCOL}cdn.#{custom_host}" else - host = "#{Contentstack::Host::PROTOCOL}#{Contentstack::Host::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 end -end \ No newline at end of file +end diff --git a/lib/contentstack/region.rb b/lib/contentstack/region.rb index 1260fe1..88673eb 100644 --- a/lib/contentstack/region.rb +++ b/lib/contentstack/region.rb @@ -4,6 +4,7 @@ class Region US='us' AZURE_NA='azure-na' AZURE_EU='azure-eu' + GCP_NA='gcp-na' end class Host @@ -11,4 +12,4 @@ class Host DEFAULT_HOST='cdn.contentstack.io' HOST='contentstack.com' end -end \ No newline at end of file +end diff --git a/lib/contentstack/version.rb b/lib/contentstack/version.rb index 3da3e6b..880f3b3 100644 --- a/lib/contentstack/version.rb +++ b/lib/contentstack/version.rb @@ -1,3 +1,3 @@ module Contentstack - VERSION = "0.7.0" -end \ No newline at end of file + VERSION = "0.8.0" +end diff --git a/spec/contentstack_spec.rb b/spec/contentstack_spec.rb index e1672be..8f5eebd 100644 --- a/spec/contentstack_spec.rb +++ b/spec/contentstack_spec.rb @@ -9,6 +9,7 @@ let(:custom_host_eu_client) { create_client('DELIVERY_TOKEN_TOKEN', 'API_KEY', 'STACK_ENV', {host: "contentstack.com", region: Contentstack::Region::EU}) } let(:custom_host_azure_eu_client) { create_client('DELIVERY_TOKEN_TOKEN', 'API_KEY', 'STACK_ENV', {host: "contentstack.com", region: Contentstack::Region::AZURE_EU}) } let(:custom_host_azure_na_client) { create_client('DELIVERY_TOKEN_TOKEN', 'API_KEY', 'STACK_ENV', {host: "contentstack.com", region: Contentstack::Region::AZURE_NA}) } + let(:custom_host_gcp_na_client) { create_client('DELIVERY_TOKEN_TOKEN', 'API_KEY', 'STACK_ENV', {host: "contentstack.com", region: Contentstack::Region::GCP_NA}) } it "has a version number" do expect(Contentstack::VERSION).not_to be nil @@ -23,42 +24,46 @@ it "has default host and region" do expect(client.region).to eq Contentstack::Region::US - expect(client.host).to eq 'https://cdn.contentstack.io' + expect(client.host).to eq 'https://cdn.contentstack.io' end it "has custom region with region host" do expect(eu_client.region).to eq Contentstack::Region::EU - expect(eu_client.host).to eq 'https://eu-cdn.contentstack.com' + expect(eu_client.host).to eq 'https://eu-cdn.contentstack.com' end it "has custom region with region host" do expect(azure_na_client.region).to eq Contentstack::Region::AZURE_NA - expect(azure_na_client.host).to eq 'https://azure-na-cdn.contentstack.com' + expect(azure_na_client.host).to eq 'https://azure-na-cdn.contentstack.com' end it "has custom region with region host" do expect(azure_eu_client.region).to eq Contentstack::Region::AZURE_EU - expect(azure_eu_client.host).to eq 'https://azure-eu-cdn.contentstack.com' + expect(azure_eu_client.host).to eq 'https://azure-eu-cdn.contentstack.com' end it "has custom host and eu region" do - expect(custom_host_eu_client.host).to eq 'https://eu-cdn.contentstack.com' + expect(custom_host_eu_client.host).to eq 'https://eu-cdn.contentstack.com' end it "has custom host and azure-eu region" do - expect(custom_host_azure_eu_client.host).to eq 'https://azure-eu-cdn.contentstack.com' + expect(custom_host_azure_eu_client.host).to eq 'https://azure-eu-cdn.contentstack.com' end it "has custom host and azure-na region" do - expect(custom_host_azure_na_client.host).to eq 'https://azure-na-cdn.contentstack.com' + expect(custom_host_azure_na_client.host).to eq 'https://azure-na-cdn.contentstack.com' + end + + it "has custom host and gcp-na region" do + expect(custom_host_gcp_na_client.host).to eq 'https://gcp-na-cdn.contentstack.com' end it "JSON to HTML" do - expect(Contentstack::json_to_html({}, ContentstackUtils::Model::Options.new())).to eq '' + expect(Contentstack::json_to_html({}, ContentstackUtils::Model::Options.new())).to eq '' end it "JSON to HTML" do - expect(Contentstack::render_content('', ContentstackUtils::Model::Options.new())).to eq '' + expect(Contentstack::render_content('', ContentstackUtils::Model::Options.new())).to eq '' end -end \ No newline at end of file +end