Skip to content

Commit a88f936

Browse files
Merge pull request #34 from contentstack/next
Added region support for Azure-EU Added support for include_metadata in Asset, Entry and Query classes.
2 parents 30705f9 + 935cfb3 commit a88f936

File tree

12 files changed

+154
-26
lines changed

12 files changed

+154
-26
lines changed

.github/workflows/release-gem.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@ jobs:
1414

1515
steps:
1616
- uses: actions/checkout@v3
17-
- name: Set up Ruby 2.6
17+
- name: Set up Ruby 2.7
1818
uses: actions/setup-ruby@v1
1919
with:
20-
ruby-version: 2.6.x
20+
ruby-version: 2.7.x
2121

2222
- name: Publish to RubyGems
2323
run: |

CHANGELOG.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,20 @@
11
## CHANGELOG
22

3+
## Version 0.6.4
4+
### Date: 17th-Apr-2023
5+
### Enhancement
6+
- Include metadata support for Asset, Entry and Query,
7+
- Region support for Azure-EU added
8+
9+
------------------------------------------------
10+
11+
## Version 0.6.3.1
12+
### Date: 17th-Mar-2023
13+
### Package Update
14+
- Activesupport gem version limit removed (for supporting ruby v3.0 and above) .
15+
16+
------------------------------------------------
17+
318
## Version 0.6.3
419
### Date: 16th-Mar-2023
520
### Package Update

Gemfile.lock

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,38 @@
11
PATH
22
remote: .
33
specs:
4-
contentstack (0.6.3)
5-
activesupport (~> 3.2)
4+
5+
contentstack (0.7.0)
6+
activesupport (>= 3.2)
67
contentstack_utils (~> 1.0)
78

89
GEM
910
remote: https://rubygems.org/
1011
specs:
11-
activesupport (3.2.22.5)
12-
i18n (~> 0.6, >= 0.6.4)
13-
multi_json (~> 1.0)
14-
addressable (2.8.1)
12+
activesupport (7.0.4.3)
13+
concurrent-ruby (~> 1.0, >= 1.0.2)
14+
i18n (>= 1.6, < 2)
15+
minitest (>= 5.1)
16+
tzinfo (~> 2.0)
17+
addressable (2.8.4)
1518
public_suffix (>= 2.0.2, < 6.0)
1619
concurrent-ruby (1.2.2)
17-
contentstack_utils (1.1.2)
18-
activesupport (>= 3.2, < 7.0.4)
19-
nokogiri (~> 1.11, >= 1.11.0)
20+
contentstack_utils (1.1.3.2)
21+
activesupport (>= 3.2)
22+
nokogiri (~> 1.11)
2023
crack (0.4.5)
2124
rexml
2225
diff-lcs (1.5.0)
2326
docile (1.4.0)
2427
hashdiff (1.0.1)
25-
i18n (0.9.5)
28+
i18n (1.12.0)
2629
concurrent-ruby (~> 1.0)
2730
mini_portile2 (2.8.1)
28-
multi_json (1.15.0)
29-
nokogiri (1.13.10)
31+
minitest (5.18.0)
32+
nokogiri (1.14.3)
3033
mini_portile2 (~> 2.8.0)
3134
racc (~> 1.4)
32-
nokogiri (1.13.10-x64-mingw32)
35+
nokogiri (1.14.3-x64-mingw32)
3336
racc (~> 1.4)
3437
public_suffix (5.0.1)
3538
racc (1.6.2)
@@ -53,13 +56,13 @@ GEM
5356
simplecov_json_formatter (~> 0.1)
5457
simplecov-html (0.12.3)
5558
simplecov_json_formatter (0.1.4)
59+
tzinfo (2.0.6)
60+
concurrent-ruby (~> 1.0)
5661
webmock (3.11.3)
5762
addressable (>= 2.3.6)
5863
crack (>= 0.3.2)
5964
hashdiff (>= 0.4.0, < 2.0.0)
60-
webrick (1.7.0)
61-
yard (0.9.28)
62-
webrick (~> 1.7.0)
65+
yard (0.9.34)
6366

6467
PLATFORMS
6568
ruby

contentstack.gemspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ Gem::Specification.new do |s|
2020
s.files = `git ls-files`.split("\n")
2121
s.require_paths = ["lib"]
2222

23-
s.add_dependency 'activesupport', '~> 3.2'
23+
s.add_dependency 'activesupport', '>= 3.2'
2424
s.add_dependency 'contentstack_utils' , '~> 1.0'
2525

2626
s.add_development_dependency 'rspec', '~> 3.10.0'

lib/contentstack/client.rb

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ def initialize(api_key, delivery_token, environment, options={})
1717
raise Contentstack::Error.new("Envirnoment Field is not valid") if environment.class != String
1818
raise Contentstack::Error.new("Envirnoment Field Should not be Empty") if environment.empty?
1919
@region = options[:region].nil? ? Contentstack::Region::US : options[:region]
20-
@host = options[:host].nil? ? get_default_region_hosts(@region) : options[:host]
20+
# @host = options[:host].nil? ? get_default_region_hosts(@region) : options[:host] #removed for not supporting custom host with regions
21+
@host = get_host_by_region(@region, options) # Added new method for custom host support with different regions
2122
@live_preview = !options.key?(:live_preview) ? {} : options[:live_preview]
2223
@branch = options[:branch].nil? ? "" : options[:branch]
2324
@proxy_details = options[:proxy].nil? ? "" : options[:proxy]
@@ -80,13 +81,43 @@ def sync(params)
8081

8182
private
8283
def get_default_region_hosts(region='us')
84+
host = "#{Contentstack::Host::PROTOCOL}#{Contentstack::Host::DEFAULT_HOST}" #set default host if region is nil
8385
case region
8486
when "us"
85-
host = "https://cdn.contentstack.io"
87+
host = "#{Contentstack::Host::PROTOCOL}#{Contentstack::Host::DEFAULT_HOST}"
8688
when "eu"
87-
host = "https://eu-cdn.contentstack.com"
89+
host = "#{Contentstack::Host::PROTOCOL}eu-cdn.#{Contentstack::Host::HOST}"
90+
when "azure-na"
91+
host = "#{Contentstack::Host::PROTOCOL}azure-na-cdn.#{Contentstack::Host::HOST}"
92+
when "azure-eu"
93+
host = "#{Contentstack::Host::PROTOCOL}azure-eu-cdn.#{Contentstack::Host::HOST}"
8894
end
8995
host
9096
end
97+
98+
def get_host_by_region(region, options)
99+
if options[:host].nil? && region.present?
100+
host = get_default_region_hosts(region)
101+
elsif options[:host].present? && region.present?
102+
custom_host = options[:host]
103+
case region
104+
when "us"
105+
host = "#{Contentstack::Host::PROTOCOL}cdn.#{custom_host}"
106+
when "eu"
107+
host = "#{Contentstack::Host::PROTOCOL}eu-cdn.#{custom_host}"
108+
when "azure-na"
109+
host = "#{Contentstack::Host::PROTOCOL}azure-na-cdn.#{custom_host}"
110+
when "azure-eu"
111+
host = "#{Contentstack::Host::PROTOCOL}azure-eu-cdn.#{custom_host}"
112+
end
113+
elsif options[:host].present? && region.empty?
114+
custom_host = options[:host]
115+
host = "#{Contentstack::Host::PROTOCOL}cdn.#{custom_host}"
116+
else
117+
host = "#{Contentstack::Host::PROTOCOL}#{Contentstack::Host::DEFAULT_HOST}" #set default host if region and host is empty
118+
end
119+
host
120+
end
121+
91122
end
92123
end

lib/contentstack/entry.rb

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,20 @@ def include_branch(flag=true)
167167
self
168168
end
169169

170+
# Include the metadata for publish content.
171+
#
172+
# Example
173+
#
174+
# @entry = @stack.content_type('product').entry(entry_uid)
175+
# @entry.include_metadata
176+
#
177+
# @return [Contentstack::Entry]
178+
def include_metadata(flag=true)
179+
@query[:include_metadata] = flag
180+
self
181+
end
182+
183+
170184
# Include Embedded Objects (Entries and Assets) along with entry/entries details.
171185
#
172186
# Example

lib/contentstack/query.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -348,6 +348,18 @@ def include_count(flag=true)
348348
self
349349
end
350350

351+
# Retrieve count and data of objects in result.
352+
#
353+
# Example
354+
# @query = @stack.content_type('category').query
355+
# @query.include_metadata
356+
#
357+
# @return [Contentstack::Query]
358+
def include_metadata(flag=true)
359+
@query[:include_metadata] = flag
360+
self
361+
end
362+
351363
# Sort the results in ascending order with the given key.
352364
# Sort the returned entries in ascending order of the provided key.
353365
#

lib/contentstack/region.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,13 @@ module Contentstack
22
class Region
33
EU='eu'
44
US='us'
5+
AZURE_NA='azure-na'
6+
AZURE_EU='azure-eu'
7+
end
8+
9+
class Host
10+
PROTOCOL='https://'
11+
DEFAULT_HOST='cdn.contentstack.io'
12+
HOST='contentstack.com'
513
end
614
end

lib/contentstack/version.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
module Contentstack
2-
VERSION = "0.6.3"
2+
VERSION = "0.7.0"
33
end

spec/contentstack_spec.rb

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,11 @@
44
describe Contentstack do
55
let(:client) { create_client }
66
let(:eu_client) { create_client('DELIVERY_TOKEN_TOKEN', 'API_KEY', 'STACK_ENV', {region: Contentstack::Region::EU}) }
7-
let(:custom_host_client) { create_client('DELIVERY_TOKEN_TOKEN', 'API_KEY', 'STACK_ENV', {host: "https://custom-cdn.contentstack.com"}) }
7+
let(:azure_na_client) { create_client('DELIVERY_TOKEN_TOKEN', 'API_KEY', 'STACK_ENV', {region: Contentstack::Region::AZURE_NA}) }
8+
let(:azure_eu_client) { create_client('DELIVERY_TOKEN_TOKEN', 'API_KEY', 'STACK_ENV', {region: Contentstack::Region::AZURE_EU}) }
9+
let(:custom_host_eu_client) { create_client('DELIVERY_TOKEN_TOKEN', 'API_KEY', 'STACK_ENV', {host: "contentstack.com", region: Contentstack::Region::EU}) }
10+
let(:custom_host_azure_eu_client) { create_client('DELIVERY_TOKEN_TOKEN', 'API_KEY', 'STACK_ENV', {host: "contentstack.com", region: Contentstack::Region::AZURE_EU}) }
11+
let(:custom_host_azure_na_client) { create_client('DELIVERY_TOKEN_TOKEN', 'API_KEY', 'STACK_ENV', {host: "contentstack.com", region: Contentstack::Region::AZURE_NA}) }
812

913
it "has a version number" do
1014
expect(Contentstack::VERSION).not_to be nil
@@ -13,6 +17,8 @@
1317
it "has region data" do
1418
expect(Contentstack::Region::EU).not_to be 'eu'
1519
expect(Contentstack::Region::US).not_to be 'us'
20+
expect(Contentstack::Region::AZURE_NA).not_to be 'azure-na'
21+
expect(Contentstack::Region::AZURE_EU).not_to be 'azure-eu'
1622
end
1723

1824
it "has default host and region" do
@@ -25,10 +31,29 @@
2531
expect(eu_client.host).to eq 'https://eu-cdn.contentstack.com'
2632
end
2733

28-
it "has custom host" do
29-
expect(custom_host_client.host).to eq 'https://custom-cdn.contentstack.com'
34+
it "has custom region with region host" do
35+
expect(azure_na_client.region).to eq Contentstack::Region::AZURE_NA
36+
expect(azure_na_client.host).to eq 'https://azure-na-cdn.contentstack.com'
37+
end
38+
39+
it "has custom region with region host" do
40+
expect(azure_eu_client.region).to eq Contentstack::Region::AZURE_EU
41+
expect(azure_eu_client.host).to eq 'https://azure-eu-cdn.contentstack.com'
42+
end
43+
44+
it "has custom host and eu region" do
45+
expect(custom_host_eu_client.host).to eq 'https://eu-cdn.contentstack.com'
3046
end
3147

48+
it "has custom host and azure-eu region" do
49+
expect(custom_host_azure_eu_client.host).to eq 'https://azure-eu-cdn.contentstack.com'
50+
end
51+
52+
it "has custom host and azure-na region" do
53+
expect(custom_host_azure_na_client.host).to eq 'https://azure-na-cdn.contentstack.com'
54+
end
55+
56+
3257
it "JSON to HTML" do
3358
expect(Contentstack::json_to_html({}, ContentstackUtils::Model::Options.new())).to eq ''
3459
end

0 commit comments

Comments
 (0)