Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/release-gem.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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: |
Expand Down
15 changes: 15 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
34 changes: 18 additions & 16 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -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)
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion contentstack.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
33 changes: 32 additions & 1 deletion lib/contentstack/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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
14 changes: 14 additions & 0 deletions lib/contentstack/entry.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 12 additions & 0 deletions lib/contentstack/query.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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.
#
Expand Down
2 changes: 2 additions & 0 deletions lib/contentstack/region.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,7 @@ module Contentstack
class Region
EU='eu'
US='us'
AZURE_NA='azure-na'
AZURE_EU='azure-eu'
end
end
2 changes: 1 addition & 1 deletion lib/contentstack/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module Contentstack
VERSION = "0.6.3"
VERSION = "0.6.4"
end
5 changes: 5 additions & 0 deletions spec/entry_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions spec/query_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down