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