From 7e82ff63031bbf9b2c2b8ea257dd49c4b815cdf1 Mon Sep 17 00:00:00 2001 From: sunil-lakshman <104969541+sunil-lakshman@users.noreply.github.com> Date: Fri, 14 Apr 2023 18:30:54 +0530 Subject: [PATCH 1/6] Feat/cs 37229 azure eu and include metadata --- .github/workflows/release-gem.yml | 4 ++-- CHANGELOG.md | 15 ++++++++++++++ Gemfile.lock | 34 ++++++++++++++++--------------- contentstack.gemspec | 2 +- lib/contentstack/client.rb | 5 +++++ lib/contentstack/entry.rb | 14 +++++++++++++ lib/contentstack/query.rb | 12 +++++++++++ lib/contentstack/region.rb | 2 ++ lib/contentstack/version.rb | 2 +- spec/entry_spec.rb | 5 +++++ spec/query_spec.rb | 5 +++++ 11 files changed, 80 insertions(+), 20 deletions(-) diff --git a/.github/workflows/release-gem.yml b/.github/workflows/release-gem.yml index dfa609b..813be51 100644 --- a/.github/workflows/release-gem.yml +++ b/.github/workflows/release-gem.yml @@ -14,10 +14,10 @@ jobs: steps: - uses: actions/checkout@v3 - - name: Set up Ruby 2.6 + - name: Set up Ruby 2.7 uses: actions/setup-ruby@v1 with: - ruby-version: 2.6.x + ruby-version: 2.7.x - name: Publish to RubyGems run: | diff --git a/CHANGELOG.md b/CHANGELOG.md index ccc01fa..ebb6385 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,20 @@ ## CHANGELOG +## Version 0.6.4 +### Date: 17th-Apr-2023 + ### Enhancement + - Include metadata support for Asset, Entry and Query, + - Region support for Azure-EU added + +------------------------------------------------ + +## Version 0.6.3.1 +### Date: 17th-Mar-2023 + ### Package Update + - Activesupport gem version limit removed (for supporting ruby v3.0 and above) . + +------------------------------------------------ + ## Version 0.6.3 ### Date: 16th-Mar-2023 ### Package Update diff --git a/Gemfile.lock b/Gemfile.lock index fddcf62..276aeda 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,35 +1,37 @@ PATH remote: . specs: - contentstack (0.6.3) - activesupport (~> 3.2) + contentstack (0.6.4) + activesupport (>= 3.2) contentstack_utils (~> 1.0) GEM remote: https://rubygems.org/ specs: - activesupport (3.2.22.5) - i18n (~> 0.6, >= 0.6.4) - multi_json (~> 1.0) - addressable (2.8.1) + activesupport (7.0.4.3) + concurrent-ruby (~> 1.0, >= 1.0.2) + i18n (>= 1.6, < 2) + minitest (>= 5.1) + tzinfo (~> 2.0) + addressable (2.8.4) public_suffix (>= 2.0.2, < 6.0) concurrent-ruby (1.2.2) - contentstack_utils (1.1.2) - activesupport (>= 3.2, < 7.0.4) - nokogiri (~> 1.11, >= 1.11.0) + contentstack_utils (1.1.3.2) + activesupport (>= 3.2) + nokogiri (~> 1.11) crack (0.4.5) rexml diff-lcs (1.5.0) docile (1.4.0) hashdiff (1.0.1) - i18n (0.9.5) + i18n (1.12.0) concurrent-ruby (~> 1.0) mini_portile2 (2.8.1) - multi_json (1.15.0) - nokogiri (1.13.10) + minitest (5.18.0) + nokogiri (1.14.3) mini_portile2 (~> 2.8.0) racc (~> 1.4) - nokogiri (1.13.10-x64-mingw32) + nokogiri (1.14.3-x64-mingw32) racc (~> 1.4) public_suffix (5.0.1) racc (1.6.2) @@ -53,13 +55,13 @@ GEM simplecov_json_formatter (~> 0.1) simplecov-html (0.12.3) simplecov_json_formatter (0.1.4) + tzinfo (2.0.6) + concurrent-ruby (~> 1.0) webmock (3.11.3) addressable (>= 2.3.6) crack (>= 0.3.2) hashdiff (>= 0.4.0, < 2.0.0) - webrick (1.7.0) - yard (0.9.28) - webrick (~> 1.7.0) + yard (0.9.34) PLATFORMS ruby diff --git a/contentstack.gemspec b/contentstack.gemspec index 02e6c5d..1fef00c 100644 --- a/contentstack.gemspec +++ b/contentstack.gemspec @@ -20,7 +20,7 @@ Gem::Specification.new do |s| s.files = `git ls-files`.split("\n") s.require_paths = ["lib"] - s.add_dependency 'activesupport', '~> 3.2' + s.add_dependency 'activesupport', '>= 3.2' s.add_dependency 'contentstack_utils' , '~> 1.0' s.add_development_dependency 'rspec', '~> 3.10.0' diff --git a/lib/contentstack/client.rb b/lib/contentstack/client.rb index 11d9af3..4a8db03 100644 --- a/lib/contentstack/client.rb +++ b/lib/contentstack/client.rb @@ -80,11 +80,16 @@ def sync(params) private def get_default_region_hosts(region='us') + host = "https://cdn.contentstack.io" case region when "us" host = "https://cdn.contentstack.io" when "eu" host = "https://eu-cdn.contentstack.com" + when "azure-na" + host = "https://azure-na-cdn.contentstack.com" + when "azure-eu" + host = "https://azure-eu-cdn.contentstack.com" end host end diff --git a/lib/contentstack/entry.rb b/lib/contentstack/entry.rb index e42d550..571f495 100644 --- a/lib/contentstack/entry.rb +++ b/lib/contentstack/entry.rb @@ -167,6 +167,20 @@ def include_branch(flag=true) self end + # Include the metadata for publish content. + # + # Example + # + # @entry = @stack.content_type('product').entry(entry_uid) + # @entry.include_metadata + # + # @return [Contentstack::Entry] + def include_metadata(flag=true) + @query[:include_metadata] = flag + self + end + + # Include Embedded Objects (Entries and Assets) along with entry/entries details. # # Example diff --git a/lib/contentstack/query.rb b/lib/contentstack/query.rb index 85d9389..87bf22b 100644 --- a/lib/contentstack/query.rb +++ b/lib/contentstack/query.rb @@ -348,6 +348,18 @@ def include_count(flag=true) self end + # Retrieve count and data of objects in result. + # + # Example + # @query = @stack.content_type('category').query + # @query.include_metadata + # + # @return [Contentstack::Query] + def include_metadata(flag=true) + @query[:include_metadata] = flag + self + end + # Sort the results in ascending order with the given key. # Sort the returned entries in ascending order of the provided key. # diff --git a/lib/contentstack/region.rb b/lib/contentstack/region.rb index 20abbed..b191066 100644 --- a/lib/contentstack/region.rb +++ b/lib/contentstack/region.rb @@ -2,5 +2,7 @@ module Contentstack class Region EU='eu' US='us' + AZURE_NA='azure-na' + AZURE_EU='azure-eu' end end \ No newline at end of file diff --git a/lib/contentstack/version.rb b/lib/contentstack/version.rb index c02b75b..eddc6a0 100644 --- a/lib/contentstack/version.rb +++ b/lib/contentstack/version.rb @@ -1,3 +1,3 @@ module Contentstack - VERSION = "0.6.3" + VERSION = "0.6.4" end \ No newline at end of file diff --git a/spec/entry_spec.rb b/spec/entry_spec.rb index 41dc1bb..8e9441a 100644 --- a/spec/entry_spec.rb +++ b/spec/entry_spec.rb @@ -87,6 +87,11 @@ data = category.include_content_type.fetch expect(data.content_type).not_to be nil end + + it "should get data using `include_metadata` method" do + data = category.include_metadata.fetch + expect(data.content_type).not_to be nil + end it "should get data using `include_reference` method" do data = product.include_reference('categories').fetch diff --git a/spec/query_spec.rb b/spec/query_spec.rb index c580209..c845c4f 100644 --- a/spec/query_spec.rb +++ b/spec/query_spec.rb @@ -65,6 +65,11 @@ expect(data.count).to eq 5 end + it "should get data using `include_metadata` method" do + data = category_query.include_metadata.fetch + expect(data.length).to eq 5 + end + it "should get data using `only` method with string parameter" do data = category_query.only("title").fetch expect(data.first.fields[:title]).not_to be nil From 4475b7ad46401f507a1b7e8e6a43a26b9f293ab2 Mon Sep 17 00:00:00 2001 From: sunil-lakshman <104969541+sunil-lakshman@users.noreply.github.com> Date: Tue, 18 Apr 2023 12:58:40 +0530 Subject: [PATCH 2/6] Added new method for custom host support with different regions --- lib/contentstack/client.rb | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/lib/contentstack/client.rb b/lib/contentstack/client.rb index 4a8db03..991dac8 100644 --- a/lib/contentstack/client.rb +++ b/lib/contentstack/client.rb @@ -17,7 +17,8 @@ def initialize(api_key, delivery_token, environment, options={}) raise Contentstack::Error.new("Envirnoment Field is not valid") if environment.class != String raise Contentstack::Error.new("Envirnoment Field Should not be Empty") if environment.empty? @region = options[:region].nil? ? Contentstack::Region::US : options[:region] - @host = options[:host].nil? ? get_default_region_hosts(@region) : options[:host] + # @host = options[:host].nil? ? get_default_region_hosts(@region) : options[:host] #removed for not supporting custom host with regions + @host = get_host_by_region(@region, options) # Added new method for custom host support with different regions @live_preview = !options.key?(:live_preview) ? {} : options[:live_preview] @branch = options[:branch].nil? ? "" : options[:branch] @proxy_details = options[:proxy].nil? ? "" : options[:proxy] @@ -80,7 +81,7 @@ def sync(params) private def get_default_region_hosts(region='us') - host = "https://cdn.contentstack.io" + host = "https://cdn.contentstack.io" #set default host if region is nil case region when "us" host = "https://cdn.contentstack.io" @@ -93,5 +94,30 @@ def get_default_region_hosts(region='us') end host end + + def get_host_by_region(region, options) + if options[:host].nil? && region.present? + host = get_default_region_hosts(region) + elsif options[:host].present? && region.present? + custom_host = options[:host] + case region + when "us" + host = "https://cdn.#{custom_host}" + when "eu" + host = "https://eu-cdn.#{custom_host}" + when "azure-na" + host = "https://azure-na-cdn.#{custom_host}" + when "azure-eu" + host = "https://azure-eu-cdn.#{custom_host}" + end + elsif options[:host].present? && region.empty? + custom_host = options[:host] + host = "https://cdn.#{custom_host}" + else + host = "https://cdn.contentstack.io" #set default host if region and host is empty + end + host + end + end end \ No newline at end of file From 2c0fac7e0eadc9996fb88eb652e794ed952967b1 Mon Sep 17 00:00:00 2001 From: sunil-lakshman <104969541+sunil-lakshman@users.noreply.github.com> Date: Wed, 19 Apr 2023 17:09:06 +0530 Subject: [PATCH 3/6] Feat/cs 37229 azure eu and include metadata (#32) * Feat/cs 37229 azure eu and include metadata * Added new method for custom host support with different regions --- .github/workflows/release-gem.yml | 4 ++-- CHANGELOG.md | 15 ++++++++++++++ Gemfile.lock | 34 ++++++++++++++++--------------- contentstack.gemspec | 2 +- lib/contentstack/client.rb | 33 +++++++++++++++++++++++++++++- lib/contentstack/entry.rb | 14 +++++++++++++ lib/contentstack/query.rb | 12 +++++++++++ lib/contentstack/region.rb | 2 ++ lib/contentstack/version.rb | 2 +- spec/entry_spec.rb | 5 +++++ spec/query_spec.rb | 5 +++++ 11 files changed, 107 insertions(+), 21 deletions(-) diff --git a/.github/workflows/release-gem.yml b/.github/workflows/release-gem.yml index dfa609b..813be51 100644 --- a/.github/workflows/release-gem.yml +++ b/.github/workflows/release-gem.yml @@ -14,10 +14,10 @@ jobs: steps: - uses: actions/checkout@v3 - - name: Set up Ruby 2.6 + - name: Set up Ruby 2.7 uses: actions/setup-ruby@v1 with: - ruby-version: 2.6.x + ruby-version: 2.7.x - name: Publish to RubyGems run: | diff --git a/CHANGELOG.md b/CHANGELOG.md index ccc01fa..ebb6385 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,20 @@ ## CHANGELOG +## Version 0.6.4 +### Date: 17th-Apr-2023 + ### Enhancement + - Include metadata support for Asset, Entry and Query, + - Region support for Azure-EU added + +------------------------------------------------ + +## Version 0.6.3.1 +### Date: 17th-Mar-2023 + ### Package Update + - Activesupport gem version limit removed (for supporting ruby v3.0 and above) . + +------------------------------------------------ + ## Version 0.6.3 ### Date: 16th-Mar-2023 ### Package Update diff --git a/Gemfile.lock b/Gemfile.lock index fddcf62..276aeda 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,35 +1,37 @@ PATH remote: . specs: - contentstack (0.6.3) - activesupport (~> 3.2) + contentstack (0.6.4) + activesupport (>= 3.2) contentstack_utils (~> 1.0) GEM remote: https://rubygems.org/ specs: - activesupport (3.2.22.5) - i18n (~> 0.6, >= 0.6.4) - multi_json (~> 1.0) - addressable (2.8.1) + activesupport (7.0.4.3) + concurrent-ruby (~> 1.0, >= 1.0.2) + i18n (>= 1.6, < 2) + minitest (>= 5.1) + tzinfo (~> 2.0) + addressable (2.8.4) public_suffix (>= 2.0.2, < 6.0) concurrent-ruby (1.2.2) - contentstack_utils (1.1.2) - activesupport (>= 3.2, < 7.0.4) - nokogiri (~> 1.11, >= 1.11.0) + contentstack_utils (1.1.3.2) + activesupport (>= 3.2) + nokogiri (~> 1.11) crack (0.4.5) rexml diff-lcs (1.5.0) docile (1.4.0) hashdiff (1.0.1) - i18n (0.9.5) + i18n (1.12.0) concurrent-ruby (~> 1.0) mini_portile2 (2.8.1) - multi_json (1.15.0) - nokogiri (1.13.10) + minitest (5.18.0) + nokogiri (1.14.3) mini_portile2 (~> 2.8.0) racc (~> 1.4) - nokogiri (1.13.10-x64-mingw32) + nokogiri (1.14.3-x64-mingw32) racc (~> 1.4) public_suffix (5.0.1) racc (1.6.2) @@ -53,13 +55,13 @@ GEM simplecov_json_formatter (~> 0.1) simplecov-html (0.12.3) simplecov_json_formatter (0.1.4) + tzinfo (2.0.6) + concurrent-ruby (~> 1.0) webmock (3.11.3) addressable (>= 2.3.6) crack (>= 0.3.2) hashdiff (>= 0.4.0, < 2.0.0) - webrick (1.7.0) - yard (0.9.28) - webrick (~> 1.7.0) + yard (0.9.34) PLATFORMS ruby diff --git a/contentstack.gemspec b/contentstack.gemspec index 02e6c5d..1fef00c 100644 --- a/contentstack.gemspec +++ b/contentstack.gemspec @@ -20,7 +20,7 @@ Gem::Specification.new do |s| s.files = `git ls-files`.split("\n") s.require_paths = ["lib"] - s.add_dependency 'activesupport', '~> 3.2' + s.add_dependency 'activesupport', '>= 3.2' s.add_dependency 'contentstack_utils' , '~> 1.0' s.add_development_dependency 'rspec', '~> 3.10.0' diff --git a/lib/contentstack/client.rb b/lib/contentstack/client.rb index 11d9af3..991dac8 100644 --- a/lib/contentstack/client.rb +++ b/lib/contentstack/client.rb @@ -17,7 +17,8 @@ def initialize(api_key, delivery_token, environment, options={}) raise Contentstack::Error.new("Envirnoment Field is not valid") if environment.class != String raise Contentstack::Error.new("Envirnoment Field Should not be Empty") if environment.empty? @region = options[:region].nil? ? Contentstack::Region::US : options[:region] - @host = options[:host].nil? ? get_default_region_hosts(@region) : options[:host] + # @host = options[:host].nil? ? get_default_region_hosts(@region) : options[:host] #removed for not supporting custom host with regions + @host = get_host_by_region(@region, options) # Added new method for custom host support with different regions @live_preview = !options.key?(:live_preview) ? {} : options[:live_preview] @branch = options[:branch].nil? ? "" : options[:branch] @proxy_details = options[:proxy].nil? ? "" : options[:proxy] @@ -80,13 +81,43 @@ def sync(params) private def get_default_region_hosts(region='us') + host = "https://cdn.contentstack.io" #set default host if region is nil case region when "us" host = "https://cdn.contentstack.io" when "eu" host = "https://eu-cdn.contentstack.com" + when "azure-na" + host = "https://azure-na-cdn.contentstack.com" + when "azure-eu" + host = "https://azure-eu-cdn.contentstack.com" end host end + + def get_host_by_region(region, options) + if options[:host].nil? && region.present? + host = get_default_region_hosts(region) + elsif options[:host].present? && region.present? + custom_host = options[:host] + case region + when "us" + host = "https://cdn.#{custom_host}" + when "eu" + host = "https://eu-cdn.#{custom_host}" + when "azure-na" + host = "https://azure-na-cdn.#{custom_host}" + when "azure-eu" + host = "https://azure-eu-cdn.#{custom_host}" + end + elsif options[:host].present? && region.empty? + custom_host = options[:host] + host = "https://cdn.#{custom_host}" + else + host = "https://cdn.contentstack.io" #set default host if region and host is empty + end + host + end + end end \ No newline at end of file diff --git a/lib/contentstack/entry.rb b/lib/contentstack/entry.rb index e42d550..571f495 100644 --- a/lib/contentstack/entry.rb +++ b/lib/contentstack/entry.rb @@ -167,6 +167,20 @@ def include_branch(flag=true) self end + # Include the metadata for publish content. + # + # Example + # + # @entry = @stack.content_type('product').entry(entry_uid) + # @entry.include_metadata + # + # @return [Contentstack::Entry] + def include_metadata(flag=true) + @query[:include_metadata] = flag + self + end + + # Include Embedded Objects (Entries and Assets) along with entry/entries details. # # Example diff --git a/lib/contentstack/query.rb b/lib/contentstack/query.rb index 85d9389..87bf22b 100644 --- a/lib/contentstack/query.rb +++ b/lib/contentstack/query.rb @@ -348,6 +348,18 @@ def include_count(flag=true) self end + # Retrieve count and data of objects in result. + # + # Example + # @query = @stack.content_type('category').query + # @query.include_metadata + # + # @return [Contentstack::Query] + def include_metadata(flag=true) + @query[:include_metadata] = flag + self + end + # Sort the results in ascending order with the given key. # Sort the returned entries in ascending order of the provided key. # diff --git a/lib/contentstack/region.rb b/lib/contentstack/region.rb index 20abbed..b191066 100644 --- a/lib/contentstack/region.rb +++ b/lib/contentstack/region.rb @@ -2,5 +2,7 @@ module Contentstack class Region EU='eu' US='us' + AZURE_NA='azure-na' + AZURE_EU='azure-eu' end end \ No newline at end of file diff --git a/lib/contentstack/version.rb b/lib/contentstack/version.rb index c02b75b..eddc6a0 100644 --- a/lib/contentstack/version.rb +++ b/lib/contentstack/version.rb @@ -1,3 +1,3 @@ module Contentstack - VERSION = "0.6.3" + VERSION = "0.6.4" end \ No newline at end of file diff --git a/spec/entry_spec.rb b/spec/entry_spec.rb index 41dc1bb..8e9441a 100644 --- a/spec/entry_spec.rb +++ b/spec/entry_spec.rb @@ -87,6 +87,11 @@ data = category.include_content_type.fetch expect(data.content_type).not_to be nil end + + it "should get data using `include_metadata` method" do + data = category.include_metadata.fetch + expect(data.content_type).not_to be nil + end it "should get data using `include_reference` method" do data = product.include_reference('categories').fetch diff --git a/spec/query_spec.rb b/spec/query_spec.rb index c580209..c845c4f 100644 --- a/spec/query_spec.rb +++ b/spec/query_spec.rb @@ -65,6 +65,11 @@ expect(data.count).to eq 5 end + it "should get data using `include_metadata` method" do + data = category_query.include_metadata.fetch + expect(data.length).to eq 5 + end + it "should get data using `only` method with string parameter" do data = category_query.only("title").fetch expect(data.first.fields[:title]).not_to be nil From b6117d6fafa5257121b3870dd1157c0fcdda77c2 Mon Sep 17 00:00:00 2001 From: sunil-lakshman <104969541+sunil-lakshman@users.noreply.github.com> Date: Fri, 21 Apr 2023 17:57:10 +0530 Subject: [PATCH 4/6] Added test cases for region support and include_metadata --- Gemfile.lock | 2 +- lib/contentstack/client.rb | 22 +++++++++++----------- lib/contentstack/region.rb | 3 +++ lib/contentstack/version.rb | 2 +- spec/contentstack_spec.rb | 31 ++++++++++++++++++++++++++++--- spec/entry_spec.rb | 10 ++++++++++ 6 files changed, 54 insertions(+), 16 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index 276aeda..3b86b42 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,7 +1,7 @@ PATH remote: . specs: - contentstack (0.6.4) + contentstack (0.7.0) activesupport (>= 3.2) contentstack_utils (~> 1.0) diff --git a/lib/contentstack/client.rb b/lib/contentstack/client.rb index 991dac8..1d442aa 100644 --- a/lib/contentstack/client.rb +++ b/lib/contentstack/client.rb @@ -81,16 +81,16 @@ def sync(params) private def get_default_region_hosts(region='us') - host = "https://cdn.contentstack.io" #set default host if region is nil + host = "#{Contentstack::Region::PROTOCOL}://#{Contentstack::Region::DEFAULT_HOST}" #set default host if region is nil case region when "us" - host = "https://cdn.contentstack.io" + host = "#{Contentstack::Region::PROTOCOL}://#{Contentstack::Region::DEFAULT_HOST}" when "eu" - host = "https://eu-cdn.contentstack.com" + host = "#{Contentstack::Region::PROTOCOL}://eu-cdn.#{Contentstack::Region::HOST}" when "azure-na" - host = "https://azure-na-cdn.contentstack.com" + host = "#{Contentstack::Region::PROTOCOL}://azure-na-cdn.#{Contentstack::Region::HOST}" when "azure-eu" - host = "https://azure-eu-cdn.contentstack.com" + host = "#{Contentstack::Region::PROTOCOL}://azure-eu-cdn.#{Contentstack::Region::HOST}" end host end @@ -102,19 +102,19 @@ def get_host_by_region(region, options) custom_host = options[:host] case region when "us" - host = "https://cdn.#{custom_host}" + host = "#{Contentstack::Region::PROTOCOL}://cdn.#{custom_host}" when "eu" - host = "https://eu-cdn.#{custom_host}" + host = "#{Contentstack::Region::PROTOCOL}://eu-cdn.#{custom_host}" when "azure-na" - host = "https://azure-na-cdn.#{custom_host}" + host = "#{Contentstack::Region::PROTOCOL}://azure-na-cdn.#{custom_host}" when "azure-eu" - host = "https://azure-eu-cdn.#{custom_host}" + host = "#{Contentstack::Region::PROTOCOL}://azure-eu-cdn.#{custom_host}" end elsif options[:host].present? && region.empty? custom_host = options[:host] - host = "https://cdn.#{custom_host}" + host = "#{Contentstack::Region::PROTOCOL}://cdn.#{custom_host}" else - host = "https://cdn.contentstack.io" #set default host if region and host is empty + host = "#{Contentstack::Region::PROTOCOL}://#{Contentstack::Region::DEFAULT_HOST}" #set default host if region and host is empty end host end diff --git a/lib/contentstack/region.rb b/lib/contentstack/region.rb index b191066..d1931ab 100644 --- a/lib/contentstack/region.rb +++ b/lib/contentstack/region.rb @@ -4,5 +4,8 @@ class Region US='us' AZURE_NA='azure-na' AZURE_EU='azure-eu' + PROTOCOL='https' + DEFAULT_HOST='cdn.contentstack.io' + HOST='contentstack.com' end end \ No newline at end of file diff --git a/lib/contentstack/version.rb b/lib/contentstack/version.rb index eddc6a0..3da3e6b 100644 --- a/lib/contentstack/version.rb +++ b/lib/contentstack/version.rb @@ -1,3 +1,3 @@ module Contentstack - VERSION = "0.6.4" + VERSION = "0.7.0" end \ No newline at end of file diff --git a/spec/contentstack_spec.rb b/spec/contentstack_spec.rb index 62d3890..e1672be 100644 --- a/spec/contentstack_spec.rb +++ b/spec/contentstack_spec.rb @@ -4,7 +4,11 @@ describe Contentstack do let(:client) { create_client } let(:eu_client) { create_client('DELIVERY_TOKEN_TOKEN', 'API_KEY', 'STACK_ENV', {region: Contentstack::Region::EU}) } - let(:custom_host_client) { create_client('DELIVERY_TOKEN_TOKEN', 'API_KEY', 'STACK_ENV', {host: "https://custom-cdn.contentstack.com"}) } + let(:azure_na_client) { create_client('DELIVERY_TOKEN_TOKEN', 'API_KEY', 'STACK_ENV', {region: Contentstack::Region::AZURE_NA}) } + let(:azure_eu_client) { create_client('DELIVERY_TOKEN_TOKEN', 'API_KEY', 'STACK_ENV', {region: Contentstack::Region::AZURE_EU}) } + 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}) } it "has a version number" do expect(Contentstack::VERSION).not_to be nil @@ -13,6 +17,8 @@ it "has region data" do expect(Contentstack::Region::EU).not_to be 'eu' expect(Contentstack::Region::US).not_to be 'us' + expect(Contentstack::Region::AZURE_NA).not_to be 'azure-na' + expect(Contentstack::Region::AZURE_EU).not_to be 'azure-eu' end it "has default host and region" do @@ -25,10 +31,29 @@ expect(eu_client.host).to eq 'https://eu-cdn.contentstack.com' end - it "has custom host" do - expect(custom_host_client.host).to eq 'https://custom-cdn.contentstack.com' + 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' + 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' + end + + it "has custom host and eu region" do + 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' + 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' + end + + it "JSON to HTML" do expect(Contentstack::json_to_html({}, ContentstackUtils::Model::Options.new())).to eq '' end diff --git a/spec/entry_spec.rb b/spec/entry_spec.rb index 8e9441a..da6a196 100644 --- a/spec/entry_spec.rb +++ b/spec/entry_spec.rb @@ -92,6 +92,16 @@ data = category.include_metadata.fetch expect(data.content_type).not_to be nil end + + it "should get data using `include_metadata` method with param false" do + data = category.include_metadata(false).fetch + expect(data.content_type).not_to be nil + end + + it "should get data using `include_metadata` method with param true" do + data = category.include_metadata(true).fetch + expect(data.content_type).not_to be nil + end it "should get data using `include_reference` method" do data = product.include_reference('categories').fetch From a7777bd44908f970ad0f73bf78d9d00393fceff8 Mon Sep 17 00:00:00 2001 From: sunil-lakshman <104969541+sunil-lakshman@users.noreply.github.com> Date: Fri, 21 Apr 2023 19:09:12 +0530 Subject: [PATCH 5/6] Changed value of PROTOCOL constant variable --- lib/contentstack/client.rb | 23 +++++++++++------------ lib/contentstack/region.rb | 2 +- 2 files changed, 12 insertions(+), 13 deletions(-) diff --git a/lib/contentstack/client.rb b/lib/contentstack/client.rb index 73d60b3..a9aaf3d 100644 --- a/lib/contentstack/client.rb +++ b/lib/contentstack/client.rb @@ -81,17 +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::Region::PROTOCOL}#{Contentstack::Region::DEFAULT_HOST}" #set default host if region is nil case region when "us" - host = "#{Contentstack::Region::PROTOCOL}://#{Contentstack::Region::DEFAULT_HOST}" + host = "#{Contentstack::Region::PROTOCOL}#{Contentstack::Region::DEFAULT_HOST}" when "eu" - host = "#{Contentstack::Region::PROTOCOL}://eu-cdn.#{Contentstack::Region::HOST}" + host = "#{Contentstack::Region::PROTOCOL}eu-cdn.#{Contentstack::Region::HOST}" when "azure-na" - host = "#{Contentstack::Region::PROTOCOL}://azure-na-cdn.#{Contentstack::Region::HOST}" + host = "#{Contentstack::Region::PROTOCOL}azure-na-cdn.#{Contentstack::Region::HOST}" when "azure-eu" - host = "#{Contentstack::Region::PROTOCOL}://azure-eu-cdn.#{Contentstack::Region::HOST}" + host = "#{Contentstack::Region::PROTOCOL}azure-eu-cdn.#{Contentstack::Region::HOST}" end host end @@ -103,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::Region::PROTOCOL}cdn.#{custom_host}" when "eu" - host = "#{Contentstack::Region::PROTOCOL}://eu-cdn.#{custom_host}" + host = "#{Contentstack::Region::PROTOCOL}eu-cdn.#{custom_host}" when "azure-na" - host = "#{Contentstack::Region::PROTOCOL}://azure-na-cdn.#{custom_host}" + host = "#{Contentstack::Region::PROTOCOL}azure-na-cdn.#{custom_host}" when "azure-eu" - host = "#{Contentstack::Region::PROTOCOL}://azure-eu-cdn.#{custom_host}" + host = "#{Contentstack::Region::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::Region::PROTOCOL}cdn.#{custom_host}" else - host = "#{Contentstack::Region::PROTOCOL}://#{Contentstack::Region::DEFAULT_HOST}" #set default host if region and host is empty + host = "#{Contentstack::Region::PROTOCOL}#{Contentstack::Region::DEFAULT_HOST}" #set default host if region and host is empty end host end diff --git a/lib/contentstack/region.rb b/lib/contentstack/region.rb index d1931ab..15c86ab 100644 --- a/lib/contentstack/region.rb +++ b/lib/contentstack/region.rb @@ -4,7 +4,7 @@ class Region US='us' AZURE_NA='azure-na' AZURE_EU='azure-eu' - PROTOCOL='https' + PROTOCOL='https://' DEFAULT_HOST='cdn.contentstack.io' HOST='contentstack.com' end From 935cfb3c2d179cda55bd448de3351b570a7bd877 Mon Sep 17 00:00:00 2001 From: sunil-lakshman <104969541+sunil-lakshman@users.noreply.github.com> Date: Fri, 21 Apr 2023 19:57:16 +0530 Subject: [PATCH 6/6] Created new class for host and protocol --- lib/contentstack/client.rb | 22 +++++++++++----------- lib/contentstack/region.rb | 3 +++ 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/lib/contentstack/client.rb b/lib/contentstack/client.rb index a9aaf3d..9137f95 100644 --- a/lib/contentstack/client.rb +++ b/lib/contentstack/client.rb @@ -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 @@ -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 diff --git a/lib/contentstack/region.rb b/lib/contentstack/region.rb index 15c86ab..1260fe1 100644 --- a/lib/contentstack/region.rb +++ b/lib/contentstack/region.rb @@ -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'