contentstack 0.6.1 → 0.6.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (53) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/codeql-analysis.yml +68 -68
  3. data/.github/workflows/jira.yml +28 -0
  4. data/.github/workflows/release-gem.yml +31 -0
  5. data/.github/workflows/sast-scan.yml +10 -10
  6. data/.github/workflows/sca-scan.yml +15 -13
  7. data/.github/workflows/secrets-scan.yml +10 -10
  8. data/.gitignore +11 -11
  9. data/.yardopts +6 -6
  10. data/CHANGELOG.md +108 -78
  11. data/CODEOWNERS +1 -1
  12. data/CODE_OF_CONDUCT.md +73 -73
  13. data/Gemfile +2 -2
  14. data/Gemfile.lock +29 -24
  15. data/LICENSE.txt +21 -21
  16. data/README.md +197 -197
  17. data/SECURITY.md +27 -27
  18. data/contentstack.gemspec +29 -29
  19. data/lib/contentstack/api.rb +191 -212
  20. data/lib/contentstack/asset.rb +68 -68
  21. data/lib/contentstack/asset_collection.rb +27 -27
  22. data/lib/contentstack/client.rb +91 -91
  23. data/lib/contentstack/content_type.rb +53 -53
  24. data/lib/contentstack/entry.rb +221 -221
  25. data/lib/contentstack/entry_collection.rb +44 -44
  26. data/lib/contentstack/error.rb +6 -6
  27. data/lib/contentstack/query.rb +653 -653
  28. data/lib/contentstack/region.rb +5 -5
  29. data/lib/contentstack/sync_result.rb +29 -29
  30. data/lib/contentstack/version.rb +2 -2
  31. data/lib/contentstack.rb +31 -31
  32. data/lib/util.rb +110 -110
  33. data/rakefile.rb +3 -3
  34. data/spec/asset_collection_spec.rb +15 -15
  35. data/spec/asset_spec.rb +47 -47
  36. data/spec/content_type_spec.rb +80 -80
  37. data/spec/contentstack_spec.rb +38 -38
  38. data/spec/entry_collection_spec.rb +41 -41
  39. data/spec/entry_spec.rb +101 -101
  40. data/spec/fixtures/asset.json +1 -1
  41. data/spec/fixtures/asset_collection.json +1 -1
  42. data/spec/fixtures/category_content_type.json +1 -1
  43. data/spec/fixtures/category_entry.json +1 -1
  44. data/spec/fixtures/category_entry_collection.json +1 -1
  45. data/spec/fixtures/category_entry_collection_without_count.json +1 -1
  46. data/spec/fixtures/content_types.json +1 -1
  47. data/spec/fixtures/product_entry.json +1 -1
  48. data/spec/fixtures/product_entry_collection.json +1 -1
  49. data/spec/fixtures/sync_init.json +2974 -2974
  50. data/spec/query_spec.rb +205 -205
  51. data/spec/spec_helper.rb +180 -180
  52. data/spec/sync_spec.rb +26 -26
  53. metadata +9 -7
@@ -1,6 +1,6 @@
1
- module Contentstack
2
- class Region
3
- EU='eu'
4
- US='us'
5
- end
1
+ module Contentstack
2
+ class Region
3
+ EU='eu'
4
+ US='us'
5
+ end
6
6
  end
@@ -1,30 +1,30 @@
1
- require 'active_support/core_ext'
2
-
3
- module Contentstack
4
- class SyncResult
5
- attr_reader :items
6
- attr_reader :sync_token
7
- attr_reader :pagination_token
8
- attr_reader :total_count
9
- attr_reader :skip
10
- attr_reader :limit
11
-
12
- def initialize(sync_result)
13
- if sync_result.nil?
14
- @items = []
15
- @sync_token = nil
16
- @pagination_token = nil
17
- @total_count = 0
18
- @skip = 0
19
- @limit = 100
20
- else
21
- @items = sync_result["items"] || []
22
- @sync_token = sync_result["sync_token"] || nil
23
- @pagination_token = sync_result["pagination_token"] || nil
24
- @total_count = sync_result["total_count"] || 0
25
- @skip = sync_result["skip"] || 0
26
- @limit = sync_result["limit"] || 100
27
- end
28
- end
29
- end
1
+ require 'active_support/core_ext'
2
+
3
+ module Contentstack
4
+ class SyncResult
5
+ attr_reader :items
6
+ attr_reader :sync_token
7
+ attr_reader :pagination_token
8
+ attr_reader :total_count
9
+ attr_reader :skip
10
+ attr_reader :limit
11
+
12
+ def initialize(sync_result)
13
+ if sync_result.nil?
14
+ @items = []
15
+ @sync_token = nil
16
+ @pagination_token = nil
17
+ @total_count = 0
18
+ @skip = 0
19
+ @limit = 100
20
+ else
21
+ @items = sync_result["items"] || []
22
+ @sync_token = sync_result["sync_token"] || nil
23
+ @pagination_token = sync_result["pagination_token"] || nil
24
+ @total_count = sync_result["total_count"] || 0
25
+ @skip = sync_result["skip"] || 0
26
+ @limit = sync_result["limit"] || 100
27
+ end
28
+ end
29
+ end
30
30
  end
@@ -1,3 +1,3 @@
1
- module Contentstack
2
- VERSION = "0.6.1"
1
+ module Contentstack
2
+ VERSION = "0.6.2"
3
3
  end
data/lib/contentstack.rb CHANGED
@@ -1,32 +1,32 @@
1
- $LOAD_PATH.unshift File.expand_path("../../lib", __FILE__)
2
-
3
- require "contentstack/version"
4
- require "contentstack/client"
5
- require "contentstack/region"
6
- require "contentstack_utils"
7
-
8
- # == Contentstack - Ruby SDK
9
- # Contentstack is a content management system that facilitates the process of publication by separating the content from site-related programming and design.
10
- # == Installation
11
- # gem install contentstack
12
- # == Initialize the Stack
13
- # @stack = Contentstack::Client.new("site_api_key", "delivery_token", "enviroment_name")
14
- # == Initialize the Stack for EU region
15
- # @stack = Contentstack::Client.new("site_api_key", "delivery_token", "enviroment_name", {"region": Contentstack::Region::EU })
16
- # == Initialize the Stack for custom host
17
- # @stack = Contentstack::Client.new("site_api_key", "delivery_token", "enviroment_name", {"host": "https://custom-cdn.contentstack.com" })
18
- # == Initialize the Stack for EU region
19
- # @stack = Contentstack::Client.new("site_api_key", "delivery_token", "enviroment_name", {"branch":"branch_name" })
20
- # == Usage
21
- # ==== Get single entry
22
- # @stack.content_type('blog').entry('<entry_uid_here>').fetch
23
- # ==== Query entries
24
- # @stack.content_type('blog').query.regex('title', '.*hello.*').fetch
25
- module Contentstack
26
- def self.render_content(content, options)
27
- ContentstackUtils.render_content(content, options)
28
- end
29
- def self.json_to_html(content, options)
30
- ContentstackUtils.json_to_html(content, options)
31
- end
1
+ $LOAD_PATH.unshift File.expand_path("../../lib", __FILE__)
2
+
3
+ require "contentstack/version"
4
+ require "contentstack/client"
5
+ require "contentstack/region"
6
+ require "contentstack_utils"
7
+
8
+ # == Contentstack - Ruby SDK
9
+ # Contentstack is a content management system that facilitates the process of publication by separating the content from site-related programming and design.
10
+ # == Installation
11
+ # gem install contentstack
12
+ # == Initialize the Stack
13
+ # @stack = Contentstack::Client.new("site_api_key", "delivery_token", "enviroment_name")
14
+ # == Initialize the Stack for EU region
15
+ # @stack = Contentstack::Client.new("site_api_key", "delivery_token", "enviroment_name", {"region": Contentstack::Region::EU })
16
+ # == Initialize the Stack for custom host
17
+ # @stack = Contentstack::Client.new("site_api_key", "delivery_token", "enviroment_name", {"host": "https://custom-cdn.contentstack.com" })
18
+ # == Initialize the Stack for EU region
19
+ # @stack = Contentstack::Client.new("site_api_key", "delivery_token", "enviroment_name", {"branch":"branch_name" })
20
+ # == Usage
21
+ # ==== Get single entry
22
+ # @stack.content_type('blog').entry('<entry_uid_here>').fetch
23
+ # ==== Query entries
24
+ # @stack.content_type('blog').query.regex('title', '.*hello.*').fetch
25
+ module Contentstack
26
+ def self.render_content(content, options)
27
+ ContentstackUtils.render_content(content, options)
28
+ end
29
+ def self.json_to_html(content, options)
30
+ ContentstackUtils.json_to_html(content, options)
31
+ end
32
32
  end
data/lib/util.rb CHANGED
@@ -1,111 +1,111 @@
1
- module Contentstack
2
- module Utility
3
- refine Hash do
4
- def to_query(namespace = nil)
5
- collect do |key, value|
6
- value.to_query(namespace ? "#{namespace}[#{key}]" : key)
7
- end.sort * '&'
8
- end
9
-
10
- def symbolize_keys
11
- new_hash = {}
12
- self.each do |key,value|
13
- if [Hash, Array].include?(value.class)
14
- new_hash[key.to_sym] = value.symbolize_keys
15
- else
16
- new_hash[key.to_sym] = value
17
- end
18
- end
19
- new_hash
20
- end
21
- end
22
-
23
- refine Array do
24
- def to_query(key)
25
- prefix = "#{key}[]"
26
- collect { |value| value.to_query(prefix) }.join '&'
27
- end
28
-
29
- def symbolize_keys
30
- collect do |entry|
31
- if entry.class == Hash
32
- entry.symbolize_keys
33
- else
34
- entry
35
- end
36
- end
37
- end
38
- end
39
-
40
- refine String do
41
- def to_query(key)
42
- require 'cgi' unless defined?(CGI) && defined?(CGI::escape)
43
- "#{CGI.escape(key.to_param)}=#{CGI.escape(to_param.to_s)}"
44
- end
45
-
46
- def to_param
47
- to_s
48
- end
49
- end
50
-
51
- refine Symbol do
52
- def to_query(key)
53
- to_s.to_query(key)
54
- end
55
-
56
- def to_param
57
- to_s
58
- end
59
- end
60
-
61
- refine NilClass do
62
- def to_query(key)
63
- to_s.to_query(key)
64
- end
65
-
66
- def to_param
67
- to_s
68
- end
69
- end
70
-
71
- refine TrueClass do
72
- def to_query(key)
73
- to_s.to_query(key)
74
- end
75
-
76
- def to_query(val)
77
- "#{CGI.escape(val.to_param)}=#{CGI.escape(to_s)}"
78
- end
79
- end
80
-
81
- refine FalseClass do
82
- def to_query(key)
83
- to_s.to_query(key)
84
- end
85
-
86
- def to_query(val)
87
- "#{CGI.escape(val.to_param)}=#{CGI.escape(to_s)}"
88
- end
89
- end
90
-
91
- refine Integer do
92
- def to_query(key)
93
- to_s.to_query(key)
94
- end
95
-
96
- def to_query(val)
97
- "#{CGI.escape(val.to_param)}=#{CGI.escape(to_s)}"
98
- end
99
- end
100
-
101
- refine Numeric do
102
- def to_query(key)
103
- to_s.to_query(key)
104
- end
105
-
106
- def to_query(val)
107
- "#{CGI.escape(val.to_param)}=#{CGI.escape(to_s)}"
108
- end
109
- end
110
- end
1
+ module Contentstack
2
+ module Utility
3
+ refine Hash do
4
+ def to_query(namespace = nil)
5
+ collect do |key, value|
6
+ value.to_query(namespace ? "#{namespace}[#{key}]" : key)
7
+ end.sort * '&'
8
+ end
9
+
10
+ def symbolize_keys
11
+ new_hash = {}
12
+ self.each do |key,value|
13
+ if [Hash, Array].include?(value.class)
14
+ new_hash[key.to_sym] = value.symbolize_keys
15
+ else
16
+ new_hash[key.to_sym] = value
17
+ end
18
+ end
19
+ new_hash
20
+ end
21
+ end
22
+
23
+ refine Array do
24
+ def to_query(key)
25
+ prefix = "#{key}[]"
26
+ collect { |value| value.to_query(prefix) }.join '&'
27
+ end
28
+
29
+ def symbolize_keys
30
+ collect do |entry|
31
+ if entry.class == Hash
32
+ entry.symbolize_keys
33
+ else
34
+ entry
35
+ end
36
+ end
37
+ end
38
+ end
39
+
40
+ refine String do
41
+ def to_query(key)
42
+ require 'cgi' unless defined?(CGI) && defined?(CGI::escape)
43
+ "#{CGI.escape(key.to_param)}=#{CGI.escape(to_param.to_s)}"
44
+ end
45
+
46
+ def to_param
47
+ to_s
48
+ end
49
+ end
50
+
51
+ refine Symbol do
52
+ def to_query(key)
53
+ to_s.to_query(key)
54
+ end
55
+
56
+ def to_param
57
+ to_s
58
+ end
59
+ end
60
+
61
+ refine NilClass do
62
+ def to_query(key)
63
+ to_s.to_query(key)
64
+ end
65
+
66
+ def to_param
67
+ to_s
68
+ end
69
+ end
70
+
71
+ refine TrueClass do
72
+ def to_query(key)
73
+ to_s.to_query(key)
74
+ end
75
+
76
+ def to_query(val)
77
+ "#{CGI.escape(val.to_param)}=#{CGI.escape(to_s)}"
78
+ end
79
+ end
80
+
81
+ refine FalseClass do
82
+ def to_query(key)
83
+ to_s.to_query(key)
84
+ end
85
+
86
+ def to_query(val)
87
+ "#{CGI.escape(val.to_param)}=#{CGI.escape(to_s)}"
88
+ end
89
+ end
90
+
91
+ refine Integer do
92
+ def to_query(key)
93
+ to_s.to_query(key)
94
+ end
95
+
96
+ def to_query(val)
97
+ "#{CGI.escape(val.to_param)}=#{CGI.escape(to_s)}"
98
+ end
99
+ end
100
+
101
+ refine Numeric do
102
+ def to_query(key)
103
+ to_s.to_query(key)
104
+ end
105
+
106
+ def to_query(val)
107
+ "#{CGI.escape(val.to_param)}=#{CGI.escape(to_s)}"
108
+ end
109
+ end
110
+ end
111
111
  end
data/rakefile.rb CHANGED
@@ -1,4 +1,4 @@
1
- require 'yard'
2
- YARD::Rake::YardocTask.new do |t|
3
- t.files = ["README.rdoc", 'lib/contentstack/*.rb', 'lib/contentstack.rb'] # optional
1
+ require 'yard'
2
+ YARD::Rake::YardocTask.new do |t|
3
+ t.files = ["README.rdoc", 'lib/contentstack/*.rb', 'lib/contentstack.rb'] # optional
4
4
  end
@@ -1,16 +1,16 @@
1
- require 'spec_helper'
2
- require_relative '../lib/contentstack.rb'
3
-
4
- describe Contentstack::AssetCollection do
5
- let(:client) { create_client }
6
-
7
- it "has attribute called `assets`" do
8
- data = client.assets.fetch
9
- expect(data.assets).not_to be nil
10
- end
11
-
12
- it "is instance of `Contentstack::AssetCollection`" do
13
- data = client.assets.fetch
14
- expect(data.class).to be Contentstack::AssetCollection
15
- end
1
+ require 'spec_helper'
2
+ require_relative '../lib/contentstack.rb'
3
+
4
+ describe Contentstack::AssetCollection do
5
+ let(:client) { create_client }
6
+
7
+ it "has attribute called `assets`" do
8
+ data = client.assets.fetch
9
+ expect(data.assets).not_to be nil
10
+ end
11
+
12
+ it "is instance of `Contentstack::AssetCollection`" do
13
+ data = client.assets.fetch
14
+ expect(data.class).to be Contentstack::AssetCollection
15
+ end
16
16
  end
data/spec/asset_spec.rb CHANGED
@@ -1,48 +1,48 @@
1
- require 'spec_helper'
2
- require_relative '../lib/contentstack.rb'
3
-
4
- describe Contentstack::Asset do
5
- let(:client) { create_client }
6
-
7
- it "has attribute called `uid`" do
8
- @uid = "image_1"
9
- @asset = client.asset(@uid).fetch
10
- expect(@asset.uid).not_to be nil
11
- end
12
-
13
- it "should match uid" do
14
- @uid = "image_1"
15
- @asset = client.asset(@uid).fetch
16
- expect(@asset.uid).to eq @uid
17
- end
18
-
19
- it "has attribute called `url`" do
20
- @uid = "image_1"
21
- @asset = client.asset(@uid).fetch
22
- expect(@asset.url).not_to be nil
23
- end
24
-
25
- it "has attribute called `tags`" do
26
- @uid = "image_1"
27
- @asset = client.asset(@uid).fetch
28
- expect(@asset.tags).not_to be nil
29
- end
30
-
31
- it "has attribute called `file_size`" do
32
- @uid = "image_1"
33
- @asset = client.asset(@uid).fetch
34
- expect(@asset.file_size).not_to be nil
35
- end
36
-
37
- it "has attribute called `filename`" do
38
- @uid = "image_1"
39
- @asset = client.asset(@uid).fetch
40
- expect(@asset.filename).not_to be nil
41
- end
42
-
43
- it "has attribute called `content_type`" do
44
- @uid = "image_1"
45
- @asset = client.asset(@uid).fetch
46
- expect(@asset.content_type).not_to be nil
47
- end
1
+ require 'spec_helper'
2
+ require_relative '../lib/contentstack.rb'
3
+
4
+ describe Contentstack::Asset do
5
+ let(:client) { create_client }
6
+
7
+ it "has attribute called `uid`" do
8
+ @uid = "image_1"
9
+ @asset = client.asset(@uid).fetch
10
+ expect(@asset.uid).not_to be nil
11
+ end
12
+
13
+ it "should match uid" do
14
+ @uid = "image_1"
15
+ @asset = client.asset(@uid).fetch
16
+ expect(@asset.uid).to eq @uid
17
+ end
18
+
19
+ it "has attribute called `url`" do
20
+ @uid = "image_1"
21
+ @asset = client.asset(@uid).fetch
22
+ expect(@asset.url).not_to be nil
23
+ end
24
+
25
+ it "has attribute called `tags`" do
26
+ @uid = "image_1"
27
+ @asset = client.asset(@uid).fetch
28
+ expect(@asset.tags).not_to be nil
29
+ end
30
+
31
+ it "has attribute called `file_size`" do
32
+ @uid = "image_1"
33
+ @asset = client.asset(@uid).fetch
34
+ expect(@asset.file_size).not_to be nil
35
+ end
36
+
37
+ it "has attribute called `filename`" do
38
+ @uid = "image_1"
39
+ @asset = client.asset(@uid).fetch
40
+ expect(@asset.filename).not_to be nil
41
+ end
42
+
43
+ it "has attribute called `content_type`" do
44
+ @uid = "image_1"
45
+ @asset = client.asset(@uid).fetch
46
+ expect(@asset.content_type).not_to be nil
47
+ end
48
48
  end
@@ -1,81 +1,81 @@
1
- require 'spec_helper'
2
- require_relative '../lib/contentstack.rb'
3
-
4
- describe Contentstack::ContentType do
5
- let(:client) { create_client }
6
- let(:eu_client) { create_client('DELIVERY_TOKEN', 'API_KEY', 'STACK_ENV', {region: Contentstack::Region::EU}) }
7
- let(:custom_host_client) { create_client('DELIVERY_TOKEN', 'API_KEY', 'STACK_ENV', {host: "https://custom-cdn.contentstack.com"}) }
8
-
9
- describe "Fetch data from API" do
10
- it "has class as Contentstack::ContentType" do
11
- @data = client.content_types.first
12
- expect(@data.class).to eq Contentstack::ContentType
13
- end
14
-
15
- it "has method called title with data" do
16
- @data = client.content_types.first
17
- expect(@data.title).not_to be nil
18
- end
19
-
20
- it "has method called title with data from eu" do
21
- @data = eu_client.content_types.first
22
- expect(@data.title).not_to be nil
23
- end
24
-
25
- it "has method called title with data from custom client" do
26
- @data = custom_host_client.content_types.first
27
- expect(@data.title).not_to be nil
28
- end
29
-
30
- it "has method called uid with data" do
31
- @data = client.content_types.first
32
- expect(@data.uid).not_to be nil
33
- end
34
-
35
- it "has method called created_at with data" do
36
- @data = client.content_types.first
37
- expect(@data.created_at).not_to be nil
38
- end
39
-
40
- it "has method called updated_at with data" do
41
- @data = client.content_types.first
42
- expect(@data.updated_at).not_to be nil
43
- end
44
-
45
- it "has method called attributes with data" do
46
- @data = client.content_types.first
47
- expect(@data.attributes).not_to be nil
48
- end
49
-
50
- it "Should get content type from uid" do
51
- @data = client.content_type("category").fetch
52
- expect(@data.attributes).not_to be nil
53
- end
54
- end
55
-
56
- describe "Initialized using class" do
57
- before(:each) do
58
- @data = Contentstack::ContentType.new({uid: "DummyUID"})
59
- end
60
-
61
- it "has method called title without data" do
62
- expect(@data.title).to be nil
63
- end
64
-
65
- it "has method called uid with data" do
66
- expect(@data.uid).not_to be nil
67
- end
68
-
69
- it "has method called created_at without data" do
70
- expect(@data.created_at).to be nil
71
- end
72
-
73
- it "has method called updated_at without data" do
74
- expect(@data.updated_at).to be nil
75
- end
76
-
77
- it "has method called attributes without data" do
78
- expect(@data.attributes).not_to be nil
79
- end
80
- end
1
+ require 'spec_helper'
2
+ require_relative '../lib/contentstack.rb'
3
+
4
+ describe Contentstack::ContentType do
5
+ let(:client) { create_client }
6
+ let(:eu_client) { create_client('DELIVERY_TOKEN', 'API_KEY', 'STACK_ENV', {region: Contentstack::Region::EU}) }
7
+ let(:custom_host_client) { create_client('DELIVERY_TOKEN', 'API_KEY', 'STACK_ENV', {host: "https://custom-cdn.contentstack.com"}) }
8
+
9
+ describe "Fetch data from API" do
10
+ it "has class as Contentstack::ContentType" do
11
+ @data = client.content_types.first
12
+ expect(@data.class).to eq Contentstack::ContentType
13
+ end
14
+
15
+ it "has method called title with data" do
16
+ @data = client.content_types.first
17
+ expect(@data.title).not_to be nil
18
+ end
19
+
20
+ it "has method called title with data from eu" do
21
+ @data = eu_client.content_types.first
22
+ expect(@data.title).not_to be nil
23
+ end
24
+
25
+ it "has method called title with data from custom client" do
26
+ @data = custom_host_client.content_types.first
27
+ expect(@data.title).not_to be nil
28
+ end
29
+
30
+ it "has method called uid with data" do
31
+ @data = client.content_types.first
32
+ expect(@data.uid).not_to be nil
33
+ end
34
+
35
+ it "has method called created_at with data" do
36
+ @data = client.content_types.first
37
+ expect(@data.created_at).not_to be nil
38
+ end
39
+
40
+ it "has method called updated_at with data" do
41
+ @data = client.content_types.first
42
+ expect(@data.updated_at).not_to be nil
43
+ end
44
+
45
+ it "has method called attributes with data" do
46
+ @data = client.content_types.first
47
+ expect(@data.attributes).not_to be nil
48
+ end
49
+
50
+ it "Should get content type from uid" do
51
+ @data = client.content_type("category").fetch
52
+ expect(@data.attributes).not_to be nil
53
+ end
54
+ end
55
+
56
+ describe "Initialized using class" do
57
+ before(:each) do
58
+ @data = Contentstack::ContentType.new({uid: "DummyUID"})
59
+ end
60
+
61
+ it "has method called title without data" do
62
+ expect(@data.title).to be nil
63
+ end
64
+
65
+ it "has method called uid with data" do
66
+ expect(@data.uid).not_to be nil
67
+ end
68
+
69
+ it "has method called created_at without data" do
70
+ expect(@data.created_at).to be nil
71
+ end
72
+
73
+ it "has method called updated_at without data" do
74
+ expect(@data.updated_at).to be nil
75
+ end
76
+
77
+ it "has method called attributes without data" do
78
+ expect(@data.attributes).not_to be nil
79
+ end
80
+ end
81
81
  end