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..3e40999 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,35 +1,38 @@ PATH remote: . specs: - contentstack (0.6.3) - activesupport (~> 3.2) + + contentstack (0.7.0) + 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 +56,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..9137f95 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 = "#{Contentstack::Host::PROTOCOL}#{Contentstack::Host::DEFAULT_HOST}" #set default host if region is nil case region when "us" - host = "https://cdn.contentstack.io" + host = "#{Contentstack::Host::PROTOCOL}#{Contentstack::Host::DEFAULT_HOST}" when "eu" - host = "https://eu-cdn.contentstack.com" + host = "#{Contentstack::Host::PROTOCOL}eu-cdn.#{Contentstack::Host::HOST}" + when "azure-na" + host = "#{Contentstack::Host::PROTOCOL}azure-na-cdn.#{Contentstack::Host::HOST}" + when "azure-eu" + host = "#{Contentstack::Host::PROTOCOL}azure-eu-cdn.#{Contentstack::Host::HOST}" 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 = "#{Contentstack::Host::PROTOCOL}cdn.#{custom_host}" + when "eu" + host = "#{Contentstack::Host::PROTOCOL}eu-cdn.#{custom_host}" + when "azure-na" + host = "#{Contentstack::Host::PROTOCOL}azure-na-cdn.#{custom_host}" + when "azure-eu" + host = "#{Contentstack::Host::PROTOCOL}azure-eu-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 + 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..1260fe1 100644 --- a/lib/contentstack/region.rb +++ b/lib/contentstack/region.rb @@ -2,5 +2,13 @@ module Contentstack class Region EU='eu' US='us' + AZURE_NA='azure-na' + AZURE_EU='azure-eu' + end + + class Host + 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 c02b75b..3da3e6b 100644 --- a/lib/contentstack/version.rb +++ b/lib/contentstack/version.rb @@ -1,3 +1,3 @@ module Contentstack - VERSION = "0.6.3" + 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 41dc1bb..da6a196 100644 --- a/spec/entry_spec.rb +++ b/spec/entry_spec.rb @@ -87,6 +87,21 @@ 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_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 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