Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Next #34

Merged
merged 9 commits into from
Apr 25, 2023
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
35 changes: 19 additions & 16 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -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)
sunil-lakshman marked this conversation as resolved.
Show resolved Hide resolved

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 +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
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
37 changes: 34 additions & 3 deletions 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 = "#{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 = "#{Contentstack::Region::PROTOCOL}azure-na-cdn.#{Contentstack::Region::HOST}"
when "azure-eu"
host = "#{Contentstack::Region::PROTOCOL}azure-eu-cdn.#{Contentstack::Region::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::Region::PROTOCOL}cdn.#{custom_host}"
when "eu"
host = "#{Contentstack::Region::PROTOCOL}eu-cdn.#{custom_host}"
when "azure-na"
host = "#{Contentstack::Region::PROTOCOL}azure-na-cdn.#{custom_host}"
when "azure-eu"
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}"
else
host = "#{Contentstack::Region::PROTOCOL}#{Contentstack::Region::DEFAULT_HOST}" #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
5 changes: 5 additions & 0 deletions lib/contentstack/region.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,10 @@ module Contentstack
class Region
EU='eu'
US='us'
AZURE_NA='azure-na'
AZURE_EU='azure-eu'
PROTOCOL='https://'
sunil-lakshman marked this conversation as resolved.
Show resolved Hide resolved
DEFAULT_HOST='cdn.contentstack.io'
HOST='contentstack.com'
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.7.0"
end
31 changes: 28 additions & 3 deletions spec/contentstack_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
15 changes: 15 additions & 0 deletions spec/entry_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
ishaileshmishra marked this conversation as resolved.
Show resolved Hide resolved
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
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