Skip to content

Commit 2c0fac7

Browse files
Feat/cs 37229 azure eu and include metadata (#32)
* Feat/cs 37229 azure eu and include metadata * Added new method for custom host support with different regions
1 parent 30705f9 commit 2c0fac7

File tree

11 files changed

+107
-21
lines changed

11 files changed

+107
-21
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: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,37 @@
11
PATH
22
remote: .
33
specs:
4-
contentstack (0.6.3)
5-
activesupport (~> 3.2)
4+
contentstack (0.6.4)
5+
activesupport (>= 3.2)
66
contentstack_utils (~> 1.0)
77

88
GEM
99
remote: https://rubygems.org/
1010
specs:
11-
activesupport (3.2.22.5)
12-
i18n (~> 0.6, >= 0.6.4)
13-
multi_json (~> 1.0)
14-
addressable (2.8.1)
11+
activesupport (7.0.4.3)
12+
concurrent-ruby (~> 1.0, >= 1.0.2)
13+
i18n (>= 1.6, < 2)
14+
minitest (>= 5.1)
15+
tzinfo (~> 2.0)
16+
addressable (2.8.4)
1517
public_suffix (>= 2.0.2, < 6.0)
1618
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)
19+
contentstack_utils (1.1.3.2)
20+
activesupport (>= 3.2)
21+
nokogiri (~> 1.11)
2022
crack (0.4.5)
2123
rexml
2224
diff-lcs (1.5.0)
2325
docile (1.4.0)
2426
hashdiff (1.0.1)
25-
i18n (0.9.5)
27+
i18n (1.12.0)
2628
concurrent-ruby (~> 1.0)
2729
mini_portile2 (2.8.1)
28-
multi_json (1.15.0)
29-
nokogiri (1.13.10)
30+
minitest (5.18.0)
31+
nokogiri (1.14.3)
3032
mini_portile2 (~> 2.8.0)
3133
racc (~> 1.4)
32-
nokogiri (1.13.10-x64-mingw32)
34+
nokogiri (1.14.3-x64-mingw32)
3335
racc (~> 1.4)
3436
public_suffix (5.0.1)
3537
racc (1.6.2)
@@ -53,13 +55,13 @@ GEM
5355
simplecov_json_formatter (~> 0.1)
5456
simplecov-html (0.12.3)
5557
simplecov_json_formatter (0.1.4)
58+
tzinfo (2.0.6)
59+
concurrent-ruby (~> 1.0)
5660
webmock (3.11.3)
5761
addressable (>= 2.3.6)
5862
crack (>= 0.3.2)
5963
hashdiff (>= 0.4.0, < 2.0.0)
60-
webrick (1.7.0)
61-
yard (0.9.28)
62-
webrick (~> 1.7.0)
64+
yard (0.9.34)
6365

6466
PLATFORMS
6567
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: 32 additions & 1 deletion
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 = "https://cdn.contentstack.io" #set default host if region is nil
8385
case region
8486
when "us"
8587
host = "https://cdn.contentstack.io"
8688
when "eu"
8789
host = "https://eu-cdn.contentstack.com"
90+
when "azure-na"
91+
host = "https://azure-na-cdn.contentstack.com"
92+
when "azure-eu"
93+
host = "https://azure-eu-cdn.contentstack.com"
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 = "https://cdn.#{custom_host}"
106+
when "eu"
107+
host = "https://eu-cdn.#{custom_host}"
108+
when "azure-na"
109+
host = "https://azure-na-cdn.#{custom_host}"
110+
when "azure-eu"
111+
host = "https://azure-eu-cdn.#{custom_host}"
112+
end
113+
elsif options[:host].present? && region.empty?
114+
custom_host = options[:host]
115+
host = "https://cdn.#{custom_host}"
116+
else
117+
host = "https://cdn.contentstack.io" #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: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,7 @@ module Contentstack
22
class Region
33
EU='eu'
44
US='us'
5+
AZURE_NA='azure-na'
6+
AZURE_EU='azure-eu'
57
end
68
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.6.4"
33
end

spec/entry_spec.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,11 @@
8787
data = category.include_content_type.fetch
8888
expect(data.content_type).not_to be nil
8989
end
90+
91+
it "should get data using `include_metadata` method" do
92+
data = category.include_metadata.fetch
93+
expect(data.content_type).not_to be nil
94+
end
9095

9196
it "should get data using `include_reference` method" do
9297
data = product.include_reference('categories').fetch

spec/query_spec.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,11 @@
6565
expect(data.count).to eq 5
6666
end
6767

68+
it "should get data using `include_metadata` method" do
69+
data = category_query.include_metadata.fetch
70+
expect(data.length).to eq 5
71+
end
72+
6873
it "should get data using `only` method with string parameter" do
6974
data = category_query.only("title").fetch
7075
expect(data.first.fields[:title]).not_to be nil

0 commit comments

Comments
 (0)