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,92 +1,92 @@
1
- require 'contentstack/api'
2
- require 'contentstack/content_type'
3
- require 'contentstack/asset_collection'
4
- require 'contentstack/sync_result'
5
- require 'util'
6
- require 'contentstack/error'
7
- module Contentstack
8
- class Client
9
- using Utility
10
- attr_reader :region, :host
11
- # Initialize "Contentstack" Client instance
12
- def initialize(api_key, delivery_token, environment, options={})
13
- raise Contentstack::Error.new("Api Key is not valid") if api_key.class != String
14
- raise Contentstack::Error.new("Api Key Field Should not be Empty") if api_key.empty?
15
- raise Contentstack::Error.new("Delivery Token is not valid") if delivery_token.class != String
16
- raise Contentstack::Error.new("Delivery Token Field Should not be Empty") if delivery_token.empty?
17
- raise Contentstack::Error.new("Envirnoment Field is not valid") if environment.class != String
18
- raise Contentstack::Error.new("Envirnoment Field Should not be Empty") if environment.empty?
19
- @region = options[:region].nil? ? Contentstack::Region::US : options[:region]
20
- @host = options[:host].nil? ? get_default_region_hosts(@region) : options[:host]
21
- @live_preview = !options.key?(:live_preview) ? {} : options[:live_preview]
22
- @branch = options[:branch].nil? ? "" : options[:branch]
23
- @proxy_details = options[:proxy].nil? ? "" : options[:proxy]
24
- @timeout = options[:timeout].nil? ? 3000 : options[:timeout]
25
- @retryDelay = options[:retryDelay].nil? ? 3000 : options[:retryDelay]
26
- @retryLimit = options[:retryLimit].nil? ? 5 : options[:retryLimit]
27
- @errorRetry = options[:errorRetry].nil? ? [408, 429] : options[:errorRetry]
28
- retry_options = {
29
- "timeout" => @timeout.to_s,
30
- "retryDelay"=> @retryDelay,
31
- "retryLimit"=> @retryLimit,
32
- "errorRetry" => @errorRetry
33
- }
34
- raise Contentstack::Error.new("Proxy URL Should not be Empty") if @proxy_details.present? && @proxy_details[:url].empty?
35
- raise Contentstack::Error.new("Proxy Port Should not be Empty") if @proxy_details.present? && @proxy_details[:port].empty?
36
- API.init_api(api_key, delivery_token, environment, @host, @branch, @live_preview, @proxy_details, retry_options)
37
- end
38
-
39
- def content_types
40
- ContentType.all
41
- end
42
-
43
- def content_type(uid)
44
- ContentType.new({uid: uid})
45
- end
46
-
47
- def assets
48
- AssetCollection.new
49
- end
50
-
51
- def asset(uid)
52
- Asset.new(uid)
53
- end
54
-
55
- def live_preview_query(query={})
56
- API.live_preview_query(query)
57
- end
58
-
59
- # Syncs your Contentstack data with your app and ensures that the data is always up-to-date by providing delta updates
60
- #
61
- # Stack.sync({'init': true}) // For initializing sync
62
- #
63
- # Stack.sync({'init': true, 'locale': 'en-us'}) //For initializing sync with entries of a specific locale
64
- #
65
- # Stack.sync({'init': true, 'start_date': '2018-10-22'}) //For initializing sync with entries published after a specific date
66
- #
67
- # Stack.sync({'init': true, 'content_type_uid': 'session'}) //For initializing sync with entries of a specific content type
68
- #
69
- # Stack.sync({'init': true, 'type': 'entry_published'}) // Use the type parameter to get a specific type of content.Supports 'asset_published', 'entry_published', 'asset_unpublished', 'entry_unpublished', 'asset_deleted', 'entry_deleted', 'content_type_deleted'.
70
- #
71
- # Stack.sync({'pagination_token': '<pagination>'}) // For fetching the next batch of entries using pagination token
72
- #
73
- # Stack.sync({'sync_token': '<sync>'}) // For performing subsequent sync after initial sync
74
- #
75
- # @param params [Hash] params is an object that supports ‘locale’, ‘start_date’, ‘content_type_uid’, and ‘type’ queries.
76
- def sync(params)
77
- sync_result = API.get_sync_items(params)
78
- SyncResult.new(sync_result)
79
- end
80
-
81
- private
82
- def get_default_region_hosts(region='us')
83
- case region
84
- when "us"
85
- host = "https://cdn.contentstack.io"
86
- when "eu"
87
- host = "https://eu-cdn.contentstack.com"
88
- end
89
- host
90
- end
91
- end
1
+ require 'contentstack/api'
2
+ require 'contentstack/content_type'
3
+ require 'contentstack/asset_collection'
4
+ require 'contentstack/sync_result'
5
+ require 'util'
6
+ require 'contentstack/error'
7
+ module Contentstack
8
+ class Client
9
+ using Utility
10
+ attr_reader :region, :host
11
+ # Initialize "Contentstack" Client instance
12
+ def initialize(api_key, delivery_token, environment, options={})
13
+ raise Contentstack::Error.new("Api Key is not valid") if api_key.class != String
14
+ raise Contentstack::Error.new("Api Key Field Should not be Empty") if api_key.empty?
15
+ raise Contentstack::Error.new("Delivery Token is not valid") if delivery_token.class != String
16
+ raise Contentstack::Error.new("Delivery Token Field Should not be Empty") if delivery_token.empty?
17
+ raise Contentstack::Error.new("Envirnoment Field is not valid") if environment.class != String
18
+ raise Contentstack::Error.new("Envirnoment Field Should not be Empty") if environment.empty?
19
+ @region = options[:region].nil? ? Contentstack::Region::US : options[:region]
20
+ @host = options[:host].nil? ? get_default_region_hosts(@region) : options[:host]
21
+ @live_preview = !options.key?(:live_preview) ? {} : options[:live_preview]
22
+ @branch = options[:branch].nil? ? "" : options[:branch]
23
+ @proxy_details = options[:proxy].nil? ? "" : options[:proxy]
24
+ @timeout = options[:timeout].nil? ? 3000 : options[:timeout]
25
+ @retryDelay = options[:retryDelay].nil? ? 3000 : options[:retryDelay]
26
+ @retryLimit = options[:retryLimit].nil? ? 5 : options[:retryLimit]
27
+ @errorRetry = options[:errorRetry].nil? ? [408, 429] : options[:errorRetry]
28
+ retry_options = {
29
+ "timeout" => @timeout.to_s,
30
+ "retryDelay"=> @retryDelay,
31
+ "retryLimit"=> @retryLimit,
32
+ "errorRetry" => @errorRetry
33
+ }
34
+ raise Contentstack::Error.new("Proxy URL Should not be Empty") if @proxy_details.present? && @proxy_details[:url].empty?
35
+ raise Contentstack::Error.new("Proxy Port Should not be Empty") if @proxy_details.present? && @proxy_details[:port].empty?
36
+ API.init_api(api_key, delivery_token, environment, @host, @branch, @live_preview, @proxy_details, retry_options)
37
+ end
38
+
39
+ def content_types
40
+ ContentType.all
41
+ end
42
+
43
+ def content_type(uid)
44
+ ContentType.new({uid: uid})
45
+ end
46
+
47
+ def assets
48
+ AssetCollection.new
49
+ end
50
+
51
+ def asset(uid)
52
+ Asset.new(uid)
53
+ end
54
+
55
+ def live_preview_query(query={})
56
+ API.live_preview_query(query)
57
+ end
58
+
59
+ # Syncs your Contentstack data with your app and ensures that the data is always up-to-date by providing delta updates
60
+ #
61
+ # Stack.sync({'init': true}) // For initializing sync
62
+ #
63
+ # Stack.sync({'init': true, 'locale': 'en-us'}) //For initializing sync with entries of a specific locale
64
+ #
65
+ # Stack.sync({'init': true, 'start_date': '2018-10-22'}) //For initializing sync with entries published after a specific date
66
+ #
67
+ # Stack.sync({'init': true, 'content_type_uid': 'session'}) //For initializing sync with entries of a specific content type
68
+ #
69
+ # Stack.sync({'init': true, 'type': 'entry_published'}) // Use the type parameter to get a specific type of content.Supports 'asset_published', 'entry_published', 'asset_unpublished', 'entry_unpublished', 'asset_deleted', 'entry_deleted', 'content_type_deleted'.
70
+ #
71
+ # Stack.sync({'pagination_token': '<pagination>'}) // For fetching the next batch of entries using pagination token
72
+ #
73
+ # Stack.sync({'sync_token': '<sync>'}) // For performing subsequent sync after initial sync
74
+ #
75
+ # @param params [Hash] params is an object that supports ‘locale’, ‘start_date’, ‘content_type_uid’, and ‘type’ queries.
76
+ def sync(params)
77
+ sync_result = API.get_sync_items(params)
78
+ SyncResult.new(sync_result)
79
+ end
80
+
81
+ private
82
+ def get_default_region_hosts(region='us')
83
+ case region
84
+ when "us"
85
+ host = "https://cdn.contentstack.io"
86
+ when "eu"
87
+ host = "https://eu-cdn.contentstack.com"
88
+ end
89
+ host
90
+ end
91
+ end
92
92
  end
@@ -1,54 +1,54 @@
1
- require 'contentstack/query'
2
- require 'util'
3
-
4
- module Contentstack
5
- class ContentType
6
- using Utility
7
- [:title, :uid, :created_at, :updated_at, :attributes].each do |method_name|
8
- if [:created_at, :updated_at].include?(method_name)
9
- define_method method_name do
10
- return Time.parse(@attributes[method_name]) if @attributes[method_name] && !@attributes[method_name].nil?
11
- end
12
- elsif :attributes == method_name
13
- define_method :attributes do
14
- {
15
- title: self.title,
16
- uid: self.uid,
17
- created_at: self.created_at,
18
- updated_at: self.updated_at,
19
- schema: @attributes[:schema]
20
- }
21
- end
22
- else
23
- define_method method_name do
24
- return @attributes[method_name]
25
- end
26
- end
27
- end
28
-
29
- def initialize(object)
30
- @attributes = object.symbolize_keys
31
- end
32
-
33
- def query
34
- Query.new(self.uid)
35
- end
36
-
37
- def entry(entry_uid)
38
- Entry.new({uid: entry_uid}, self.uid)
39
- end
40
-
41
-
42
- def self.all
43
- content_types = API.fetch_content_types["content_types"]
44
- content_types.map do |content_type|
45
- ContentType.new(content_type.inject({}){|clone,(k,v)| clone[k.to_sym] = v; clone})
46
- end
47
- end
48
-
49
- def fetch
50
- content_type = API.fetch_content_types(uid)["content_type"]
51
- ContentType.new(content_type.inject({}){|clone,(k,v)| clone[k.to_sym] = v; clone})
52
- end
53
- end
1
+ require 'contentstack/query'
2
+ require 'util'
3
+
4
+ module Contentstack
5
+ class ContentType
6
+ using Utility
7
+ [:title, :uid, :created_at, :updated_at, :attributes].each do |method_name|
8
+ if [:created_at, :updated_at].include?(method_name)
9
+ define_method method_name do
10
+ return Time.parse(@attributes[method_name]) if @attributes[method_name] && !@attributes[method_name].nil?
11
+ end
12
+ elsif :attributes == method_name
13
+ define_method :attributes do
14
+ {
15
+ title: self.title,
16
+ uid: self.uid,
17
+ created_at: self.created_at,
18
+ updated_at: self.updated_at,
19
+ schema: @attributes[:schema]
20
+ }
21
+ end
22
+ else
23
+ define_method method_name do
24
+ return @attributes[method_name]
25
+ end
26
+ end
27
+ end
28
+
29
+ def initialize(object)
30
+ @attributes = object.symbolize_keys
31
+ end
32
+
33
+ def query
34
+ Query.new(self.uid)
35
+ end
36
+
37
+ def entry(entry_uid)
38
+ Entry.new({uid: entry_uid}, self.uid)
39
+ end
40
+
41
+
42
+ def self.all
43
+ content_types = API.fetch_content_types["content_types"]
44
+ content_types.map do |content_type|
45
+ ContentType.new(content_type.inject({}){|clone,(k,v)| clone[k.to_sym] = v; clone})
46
+ end
47
+ end
48
+
49
+ def fetch
50
+ content_type = API.fetch_content_types(uid)["content_type"]
51
+ ContentType.new(content_type.inject({}){|clone,(k,v)| clone[k.to_sym] = v; clone})
52
+ end
53
+ end
54
54
  end