contentstack 0.1.0 → 0.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: cc7aab29132806e94f049f49be18f7bbb285423f13a949dfc6ea8288d4d52a51
4
- data.tar.gz: d290838ee0df496dedf6cc1912fd180cc646b018041bac733afccce190a9dd24
3
+ metadata.gz: 3949c440892014edf589197aec6d7a2d963276733873dc5319b2653c6d844686
4
+ data.tar.gz: 9a97e2069261e8641c5d30c1bb10dcbc55f321942fa167fb9e99ff252fad07be
5
5
  SHA512:
6
- metadata.gz: ff4947a727bcb0f195c7e9712b6072192942c2de8be5edfc420ec16176924eaf24f61ddef3ee13dca2659d1c5c3abefe598dbf43efee9ae1e81d9571dcddad3f
7
- data.tar.gz: 9625bc07c44f7cc31d7f43212fc3f9cb9cfe108063b894e9cd17d1c49fa8b45d68f37d828796333448033c8d05db2cdd8ab4e02693e34db3e70cd51f56cf45bf
6
+ metadata.gz: ab0a704d2c95f80a2805cdfa9bea9f24725d7a664d8d973a88be57228d1a832dfff2e54fca0b26622e6e587665d882c1568c7cdad47fdc963f40124e481f1f25
7
+ data.tar.gz: ecfa5005a71b0304419ec4487c2c1da0aab1bd72e4e1af496fb62a41e9dcdcbb7048a61a1c67cb63d70590d7fdfe8b59ce76804212b12c8947d818a98bd1d847
data/.gitignore CHANGED
@@ -7,4 +7,5 @@ coverage
7
7
  \.yardoc
8
8
  .DS_Store
9
9
  .bundle/
10
- */rspec_results.html
10
+ **/rspec_results.html
11
+ vendor/
data/CHANGELOG.md ADDED
@@ -0,0 +1,65 @@
1
+ ## CHANGELOG
2
+ ------------------------------------------------
3
+ ## Version 0.4.1
4
+ ### Date: 2nd-Jun-2021
5
+ ### Dependency update
6
+ - Updated gemspec dependency
7
+
8
+ ## Version 0.4.0
9
+ ### Date: 16th-Apr-2021
10
+ ### New Features
11
+ - Embedded feature Support added
12
+
13
+ ------------------------------------------------
14
+
15
+ ## Version 0.3.0
16
+ ### Date: 17th-Mar-2021
17
+ ### New Features
18
+ - Sync API module support added
19
+
20
+ ------------------------------------------------
21
+ ## Version 0.2.0
22
+
23
+ ### New Features
24
+ - Entry
25
+ - locale - function for passing locale is added
26
+ - only - function for getting only specified field
27
+ - except - function for getting field except specified field
28
+ - include_reference - function for including reference in entry
29
+ - include_schema - function for including schema along with entry added
30
+ - include_content_type - function for including content type details along with entry added
31
+ - include_owner - function for getting owner of entry
32
+ - include_fallback - function for getting published fallback locale content, if specified locale content is not published
33
+
34
+ - Query
35
+ - include_fallback - function for getting published fallback locale content, if specified locale content is not published
36
+
37
+
38
+ ------------------------------------------------
39
+
40
+ ## Version 0.1.0
41
+
42
+ ### Bug
43
+ - Stack Tokens Moved to Headers
44
+
45
+ ------------------------------------------------
46
+
47
+ ## Version 0.0.4
48
+
49
+ ### Enhancement
50
+ - Region support added
51
+
52
+ ------------------------------------------------
53
+
54
+ ## Version 0.0.3
55
+
56
+ ### Enhancement
57
+ - Query - function for passing locale is added.
58
+
59
+ ------------------------------------------------
60
+
61
+ ## Version 0.0.1
62
+
63
+ - Initial release
64
+
65
+ ------------------------------------------------
data/CODE_OF_CONDUCT.md CHANGED
@@ -22,8 +22,7 @@ include:
22
22
 
23
23
  Examples of unacceptable behavior by participants include:
24
24
 
25
- * The use of sexualized language or imagery and unwelcome sexual attention or
26
- advances
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or advances
27
26
  * Trolling, insulting/derogatory comments, and personal or political attacks
28
27
  * Public or private harassment
29
28
  * Publishing others' private information, such as a physical or electronic
data/Gemfile CHANGED
@@ -1,7 +1,3 @@
1
1
  # Gemfile
2
2
  source "https://rubygems.org"
3
-
4
- gem "rspec"
5
- gem "webmock"
6
- gem "simplecov"
7
- gem "activesupport"
3
+ gemspec
data/Gemfile.lock CHANGED
@@ -1,59 +1,77 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ contentstack (0.4.1)
5
+ activesupport (>= 3.2, < 6.2)
6
+ contentstack_utils (~> 1.0, >= 1.0.1)
7
+
1
8
  GEM
2
9
  remote: https://rubygems.org/
3
10
  specs:
4
- activesupport (6.0.2.2)
11
+ activesupport (6.1.3.2)
5
12
  concurrent-ruby (~> 1.0, >= 1.0.2)
6
- i18n (>= 0.7, < 2)
7
- minitest (~> 5.1)
8
- tzinfo (~> 1.1)
9
- zeitwerk (~> 2.2)
13
+ i18n (>= 1.6, < 2)
14
+ minitest (>= 5.1)
15
+ tzinfo (~> 2.0)
16
+ zeitwerk (~> 2.3)
10
17
  addressable (2.7.0)
11
18
  public_suffix (>= 2.0.2, < 5.0)
12
- concurrent-ruby (1.1.6)
13
- crack (0.4.3)
14
- safe_yaml (~> 1.0.0)
15
- diff-lcs (1.3)
16
- docile (1.3.2)
19
+ concurrent-ruby (1.1.8)
20
+ contentstack_utils (1.0.1)
21
+ activesupport (>= 3.2, < 6.2)
22
+ nokogiri (~> 1.11, >= 1.11.0)
23
+ crack (0.4.5)
24
+ rexml
25
+ diff-lcs (1.4.4)
26
+ docile (1.4.0)
17
27
  hashdiff (1.0.1)
18
- i18n (1.8.2)
28
+ i18n (1.8.10)
19
29
  concurrent-ruby (~> 1.0)
20
- minitest (5.14.0)
21
- public_suffix (4.0.4)
22
- rspec (3.9.0)
23
- rspec-core (~> 3.9.0)
24
- rspec-expectations (~> 3.9.0)
25
- rspec-mocks (~> 3.9.0)
26
- rspec-core (3.9.1)
27
- rspec-support (~> 3.9.1)
28
- rspec-expectations (3.9.1)
30
+ mini_portile2 (2.5.3)
31
+ minitest (5.14.4)
32
+ nokogiri (1.11.6)
33
+ mini_portile2 (~> 2.5.0)
34
+ racc (~> 1.4)
35
+ public_suffix (4.0.6)
36
+ racc (1.5.2)
37
+ rexml (3.2.5)
38
+ rspec (3.10.0)
39
+ rspec-core (~> 3.10.0)
40
+ rspec-expectations (~> 3.10.0)
41
+ rspec-mocks (~> 3.10.0)
42
+ rspec-core (3.10.1)
43
+ rspec-support (~> 3.10.0)
44
+ rspec-expectations (3.10.1)
29
45
  diff-lcs (>= 1.2.0, < 2.0)
30
- rspec-support (~> 3.9.0)
31
- rspec-mocks (3.9.1)
46
+ rspec-support (~> 3.10.0)
47
+ rspec-mocks (3.10.2)
32
48
  diff-lcs (>= 1.2.0, < 2.0)
33
- rspec-support (~> 3.9.0)
34
- rspec-support (3.9.2)
35
- safe_yaml (1.0.5)
36
- simplecov (0.18.5)
49
+ rspec-support (~> 3.10.0)
50
+ rspec-support (3.10.2)
51
+ simplecov (0.21.2)
37
52
  docile (~> 1.1)
38
53
  simplecov-html (~> 0.11)
39
- simplecov-html (0.12.2)
40
- thread_safe (0.3.6)
41
- tzinfo (1.2.7)
42
- thread_safe (~> 0.1)
43
- webmock (3.8.3)
54
+ simplecov_json_formatter (~> 0.1)
55
+ simplecov-html (0.12.3)
56
+ simplecov_json_formatter (0.1.3)
57
+ tzinfo (2.0.4)
58
+ concurrent-ruby (~> 1.0)
59
+ webmock (3.11.3)
44
60
  addressable (>= 2.3.6)
45
61
  crack (>= 0.3.2)
46
62
  hashdiff (>= 0.4.0, < 2.0.0)
47
- zeitwerk (2.3.0)
63
+ yard (0.9.26)
64
+ zeitwerk (2.4.2)
48
65
 
49
66
  PLATFORMS
50
67
  ruby
51
68
 
52
69
  DEPENDENCIES
53
- activesupport
54
- rspec
55
- simplecov
56
- webmock
70
+ contentstack!
71
+ rspec (~> 3.10.0)
72
+ simplecov (~> 0.21.1)
73
+ webmock (~> 3.11.0)
74
+ yard (~> 0.9.26)
57
75
 
58
76
  BUNDLED WITH
59
- 2.1.4
77
+ 2.2.7
data/LICENSE.txt CHANGED
@@ -1,6 +1,6 @@
1
1
  The MIT License (MIT)
2
2
 
3
- Copyright (c) 2012-2019 Contentstack. All Rights Reserved
3
+ Copyright (c) 2012-2021 Contentstack. All Rights Reserved
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
data/README.md CHANGED
@@ -1,4 +1,3 @@
1
-
2
1
  # **Ruby SDK for Contentstack**
3
2
 
4
3
  Contentstack is a headless CMS with an API-first approach. It is a CMS that developers can use to build powerful cross-platform applications in their favorite languages. Build your application frontend, and Contentstack will take care of the rest. [Read More](https://www.contentstack.com/).
@@ -20,18 +19,16 @@ Or you can run this command in your terminal (you might need administrator privi
20
19
  gem install contentstack
21
20
 
22
21
  To start using the SDK in your application, you will need to initialize the stack by providing the values for the keys given in the code snippet below.
23
-
22
+ ```ruby
24
23
  # with default region
25
- client = Contentstack::Client.new("site_api_key", "delivery_token", "enviroment_name")
24
+ client = Contentstack::Client.new("api_key", "delivery_token", "enviroment_name")
26
25
 
27
26
  # with specific region
28
- client = Contentstack::Client.new("site_api_key", "delivery_token", "enviroment_name",{"region": Contentstack::Region::EU})
27
+ client = Contentstack::Client.new("api_key", "delivery_token", "enviroment_name",{"region": Contentstack::Region::EU})
29
28
 
30
29
  # with custom host
31
- client = Contentstack::Client.new("site_api_key", "delivery_token", "enviroment_name",{"host": "https://custom-cdn.contentstack.com"})
32
-
33
-
34
-
30
+ client = Contentstack::Client.new("api_key", "delivery_token", "enviroment_name",{"host": "https://custom-cdn.contentstack.com"})
31
+ ```
35
32
 
36
33
  ## **Key Concepts for using Contentstack**
37
34
 
@@ -57,23 +54,44 @@ A publishing environment corresponds to one or more deployment servers or a cont
57
54
 
58
55
  ## **Contentstack Ruby SDK: 5-minute Quickstart**
59
56
 
60
- ### **Initializing your SDK **
57
+ ### **Initializing your SDK**
61
58
 
62
59
  To initialize the SDK, you need to provide values for the keys given in the snippet below:
63
-
64
- stack = Contentstack::Client.new("site_api_key", "delivery_token", "enviroment_name")
60
+ ```ruby
61
+ @stack = Contentstack::Client.new("api_key", "delivery_token", "enviroment_name")
62
+ ```
65
63
 
66
64
  To get the API credentials mentioned above, log in to your Contentstack account and then in your top panel navigation, go to Settings > Stack to view the API Key and Access Token.
67
65
 
68
66
  ### **Querying content from your stack**
69
67
 
70
68
  To fetch all entries of of a content type, use the query given below:
71
-
72
- entry = stack.content_type(<<CONTENT_TYPE_UID>>).query();
69
+ ```ruby
70
+ @entry = stack.content_type(<<CONTENT_TYPE_UID>>).query();
71
+ ```
73
72
 
74
73
  To fetch a specific entry from a content type, use the following query:
75
-
76
- entry = stack.content_type(<<CONTENT_TYPE_UID>>).entry(<<ENTRY_UID>>);
74
+ ```ruby
75
+ @entry = stack.content_type(<<CONTENT_TYPE_UID>>).entry(<<ENTRY_UID>>);
76
+ ```
77
+
78
+ ### Get Multiple Entries
79
+ To retrieve multiple entries of a content type, specify the content type UID. You can also specify search parameters to filter results:
80
+ ```ruby
81
+ @query = @stack.content_type('blog').query
82
+ @entries = @query.where('title', 'welcome')
83
+ .include_schema
84
+ .include_count
85
+ .fetch
86
+ puts "Total Entries -- #{@entries.count}"
87
+ @entries.each{|entry| puts "#{entry.get('title')}" }
88
+ ```
89
+
90
+ To retrieve localized versions of entries, you can use the query attribute:
91
+ ```ruby
92
+ entry = @stack.content_type('content_type_uid').query.locale('locale_code').fetch()
93
+ ```
94
+ > Note: Currently, the above query works in case of retrieving localized versions of multiple entries only.
77
95
 
78
96
  ## **Advanced Queries**
79
97
 
@@ -81,6 +99,19 @@ You can query for content types, entries, assets and more using our Ruby API Ref
81
99
 
82
100
  [Ruby API Reference Doc](http://www.rubydoc.info/gems/contentstack)
83
101
 
102
+ ### Paginating Responses
103
+ In a single instance, the [Get Multiple Entries](https://www.contentstack.com/docs/developers/ruby/get-started-with-ruby-sdk/#get-multiple-entries) query will retrieve only the first 100 items of the specified content type. You can paginate and retrieve the rest of the items in batches using the [skip](https://www.rubydoc.info/gems/contentstack/Contentstack/Query#skip-instance_method) and [limit](https://www.rubydoc.info/gems/contentstack/Contentstack/Query#limit-instance_method) parameters in subsequent requests.
104
+
105
+ ```ruby
106
+ @stack = Contentstack::Client.new("api_key", "delivery_token", "environment")
107
+ @entries = @stack.content_type('category').query
108
+ .limit(20)
109
+ .skip(50)
110
+ .fetch
111
+ ```
112
+
113
+ > Note: Currently, the Ruby SDK does not support multiple content types referencing in a single query. For more information on how to query entries and assets, refer the Queries section of our Content Delivery API documentation.
114
+
84
115
  ## **Working with Images**
85
116
 
86
117
  We have introduced Image Delivery APIs that let you retrieve images and then manipulate and optimize them for your digital properties. It lets you perform a host of other actions such as crop, trim, resize, rotate, overlay, and so on.
@@ -89,8 +120,63 @@ For example, if you want to crop an image (with width as 300 and height as 400),
89
120
 
90
121
  [Read Image Delivery API documentation](https://www.contentstack.com/docs/apis/image-delivery-api/).
91
122
 
92
- SDK functions for Image Delivery API coming soon.
93
123
 
124
+ ## **Using the Sync API with Ruby SDK**
125
+
126
+ The Sync API takes care of syncing your Contentstack data with your app and ensures that the data is always up-to-date by providing delta updates. Contentstack’s Ruby SDK supports Sync API, which you can use to build powerful apps. Read through to understand how to use the Sync API with Contentstack Ruby SDK.
127
+ [Read Sync API documentation](https://www.contentstack.com/docs/platforms/ruby#using-the-sync-api-with-ruby-sdk).
128
+
129
+ ### Initial sync
130
+
131
+ The Initial Sync process performs a complete sync of your app data. It returns all the published entries and assets of the specified stack in response.
132
+
133
+ To start the Initial Sync process, use the syncStack method.
134
+
135
+ ```ruby
136
+ @sync_result = @stack.sync({init: true})
137
+ # @sync_result.items: contains sync data
138
+ # @sync_result.pagination_token: for fetching the next batch of entries using pagination token
139
+ # @sync_result.sync_token: for performing subsequent sync after initial sync
140
+ ```
141
+
142
+ The response also contains a sync token, which you need to store, since this token is used to get subsequent delta updates later, as shown in the Subsequent Sync section below.
143
+
144
+ You can also fetch custom results in initial sync by using advanced sync queries.
145
+
146
+ ### Sync pagination
147
+
148
+ If the result of the initial sync (or subsequent sync) contains more than 100 records, the response would be paginated. It provides pagination token in the response. You will need to use this token to get the next batch of data.
149
+
150
+ ```ruby
151
+ @sync_result = @stack.sync({pagination_token : "<pagination_token>"})
152
+ # @sync_result.items: contains sync data
153
+ # @sync_result.pagination_token: For fetching the next batch of entries using pagination token
154
+ # @sync_result.sync_token: For performing subsequent sync after initial sync
155
+ ```
156
+
157
+ ### Subsequent sync
158
+
159
+ You can use the sync token (that you receive after initial sync) to get the updated content next time. The sync token fetches only the content that was added after your last sync, and the details of the content that was deleted or updated.
160
+
161
+ ```ruby
162
+ @sync_result = @stack.sync({sync_token : "<sync_token>"})
163
+ # @sync_result.items: contains sync data
164
+ # @sync_result.pagination_token: For fetching the next batch of entries using pagination token
165
+ # @sync_result.sync_token: For performing subsequent sync after initial sync
166
+ ```
167
+
168
+ ### Advanced sync queries
169
+
170
+ You can use advanced sync queries to fetch custom results while performing initial sync.
171
+ [Read advanced sync queries documentation](https://www.contentstack.com/docs/guide/synchronization/using-the-sync-api-with-ruby-sdk#advanced-sync-queries)
172
+
173
+
174
+ ```ruby
175
+ @sync_result = @stack.sync({init : true, locale: "<locale>" content_type_uid: "<content_type_uid>"})
176
+ # @sync_result.items: contains sync data
177
+ # @sync_result.pagination_token: For fetching the next batch of entries using pagination token
178
+ # @sync_result.sync_token: For performing subsequent sync after initial sync
179
+ ```
94
180
  ## **Helpful Links**
95
181
 
96
182
  * [Contentstack Website](https://www.contentstack.com)
@@ -101,7 +187,7 @@ SDK functions for Image Delivery API coming soon.
101
187
 
102
188
  ## **The MIT License (MIT)**
103
189
 
104
- Copyright © 2012-2020 [Contentstack](https://www.contentstack.com). All Rights Reserved
190
+ Copyright © 2012-2021 [Contentstack](https://www.contentstack.com). All Rights Reserved
105
191
 
106
192
  Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
107
193
 
data/contentstack.gemspec CHANGED
@@ -20,9 +20,11 @@ Gem::Specification.new do |s|
20
20
  s.files = `git ls-files`.split("\n")
21
21
  s.require_paths = ["lib"]
22
22
 
23
- s.add_dependency 'activesupport', "> 3.2.5"
24
-
25
- s.add_development_dependency 'rspec'
26
- s.add_development_dependency 'webmock'
27
- s.add_development_dependency 'simplecov'
23
+ s.add_dependency 'activesupport', '>= 3.2', '< 6.2'
24
+ s.add_dependency "contentstack_utils", '~> 1.0', '>= 1.0.1'
25
+
26
+ s.add_development_dependency 'rspec', '~> 3.10.0'
27
+ s.add_development_dependency 'webmock', '~> 3.11.0'
28
+ s.add_development_dependency 'simplecov', '~> 0.21.1'
29
+ s.add_development_dependency 'yard', '~> 0.9.26'
28
30
  end
data/lib/contentstack.rb CHANGED
@@ -3,6 +3,7 @@ $LOAD_PATH.unshift File.expand_path("../../lib", __FILE__)
3
3
  require "contentstack/version"
4
4
  require "contentstack/client"
5
5
  require "contentstack/region"
6
+ require "contentstack_utils"
6
7
  require "util"
7
8
 
8
9
 
@@ -22,4 +23,7 @@ require "util"
22
23
  # ==== Query entries
23
24
  # @stack.content_type('blog').query.regex('title', '.*hello.*').fetch
24
25
  module Contentstack
26
+ def self.render_content(content, options)
27
+ ContentstackUtils.render_content(content, options)
28
+ end
25
29
  end
@@ -29,9 +29,9 @@ module Contentstack
29
29
  send_request(path, query)
30
30
  end
31
31
 
32
- def self.fetch_entry(content_type, entry_uid)
32
+ def self.fetch_entry(content_type, entry_uid, query)
33
33
  path = "/content_types/#{content_type}/entries/#{entry_uid}"
34
- send_request(path)
34
+ send_request(path, query)
35
35
  end
36
36
 
37
37
  def self.get_assets(asset_uid=nil)
@@ -40,6 +40,11 @@ module Contentstack
40
40
  send_request(path)
41
41
  end
42
42
 
43
+ def self.get_sync_items(query)
44
+ path = "/stacks/sync"
45
+ send_request(path, query)
46
+ end
47
+
43
48
  private
44
49
  def self.send_request(path, q=nil)
45
50
  q ||= {}