contentstack 0.0.4 → 0.4.0

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
- SHA1:
3
- metadata.gz: 2c05a60239a20793be053c9afa3684e579f1b744
4
- data.tar.gz: 002d29d76b307264a6353cb13b6a7d07a5372d35
2
+ SHA256:
3
+ metadata.gz: 671d9ee269ba5d1ab29949d9c76c55c74fa6b27567c5810ef72992cbcac698d5
4
+ data.tar.gz: 40e49c3028c79f1a9b54556a739d29aa745c9c280523b5bb166b3297f39db965
5
5
  SHA512:
6
- metadata.gz: 3fa5770932d3c6e4de5dbb6c90790f3ae889802863403c45a4aff7338d1ca591ec72e6920798fb81f85c3c745ef33e770898e852e3ad68bf9c490b356a957a17
7
- data.tar.gz: 63b98d912dcbf97dc4b1e34f326ef125a53fcccdb1748211126ff4a3f311ab5d65d762216703a8fdda46cb8c3a2871d16d210c323561373bdad6cdf76cd76f31
6
+ metadata.gz: 455dce0b18e04b9bb7e129466c01f083497c0f80a9dcb99a6ed80c8c3f22c16bd65a2a46f3bf2191f65f7020a549b5a80292cf5cc945860f75438c4ff1ed0229
7
+ data.tar.gz: 5ac68f4344f8aff3de2964f452cf34591caef69a3ed29af9c58d0a32d0acaff74a278927a7cc602cf24aec379c6df9e3edbbb3b836e9d35aee28a2d610d9ff16
data/.gitignore CHANGED
@@ -5,3 +5,7 @@ doc
5
5
  spec-integration
6
6
  coverage
7
7
  \.yardoc
8
+ .DS_Store
9
+ .bundle/
10
+ */rspec_results.html
11
+ vendor/
data/CHANGELOG.md ADDED
@@ -0,0 +1,54 @@
1
+ ## CHANGELOG
2
+ ------------------------------------------------
3
+
4
+ ## Version 0.3.0
5
+ ### Date: 17th-Mar-2021
6
+ ### New Features
7
+ - Sync API module support added
8
+
9
+ ------------------------------------------------
10
+ ## Version 0.2.0
11
+
12
+ ### New Features
13
+ - Entry
14
+ - locale - function for passing locale is added
15
+ - only - function for getting only specified field
16
+ - except - function for getting field except specified field
17
+ - include_reference - function for including reference in entry
18
+ - include_schema - function for including schema along with entry added
19
+ - include_content_type - function for including content type details along with entry added
20
+ - include_owner - function for getting owner of entry
21
+ - include_fallback - function for getting published fallback locale content, if specified locale content is not published
22
+
23
+ - Query
24
+ - include_fallback - function for getting published fallback locale content, if specified locale content is not published
25
+
26
+
27
+ ------------------------------------------------
28
+
29
+ ## Version 0.1.0
30
+
31
+ ### Bug
32
+ - Stack Tokens Moved to Headers
33
+
34
+ ------------------------------------------------
35
+
36
+ ## Version 0.0.4
37
+
38
+ ### Enhancement
39
+ - Region support added
40
+
41
+ ------------------------------------------------
42
+
43
+ ## Version 0.0.3
44
+
45
+ ### Enhancement
46
+ - Query - function for passing locale is added.
47
+
48
+ ------------------------------------------------
49
+
50
+ ## Version 0.0.1
51
+
52
+ - Initial release
53
+
54
+ ------------------------------------------------
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 ADDED
@@ -0,0 +1,3 @@
1
+ # Gemfile
2
+ source "https://rubygems.org"
3
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,75 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ contentstack (0.2.0)
5
+ activesupport (> 3.2.5)
6
+ contentstack_utils (~> 1.0.0)
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ activesupport (6.1.3.1)
12
+ concurrent-ruby (~> 1.0, >= 1.0.2)
13
+ i18n (>= 1.6, < 2)
14
+ minitest (>= 5.1)
15
+ tzinfo (~> 2.0)
16
+ zeitwerk (~> 2.3)
17
+ addressable (2.7.0)
18
+ public_suffix (>= 2.0.2, < 5.0)
19
+ concurrent-ruby (1.1.8)
20
+ contentstack_utils (1.0.0)
21
+ activesupport (~> 6.1.0)
22
+ nokogiri (~> 1.11.0)
23
+ crack (0.4.5)
24
+ rexml
25
+ diff-lcs (1.4.4)
26
+ docile (1.3.5)
27
+ hashdiff (1.0.1)
28
+ i18n (1.8.10)
29
+ concurrent-ruby (~> 1.0)
30
+ minitest (5.14.4)
31
+ nokogiri (1.11.2-arm64-darwin)
32
+ racc (~> 1.4)
33
+ public_suffix (4.0.6)
34
+ racc (1.5.2)
35
+ rexml (3.2.5)
36
+ rspec (3.10.0)
37
+ rspec-core (~> 3.10.0)
38
+ rspec-expectations (~> 3.10.0)
39
+ rspec-mocks (~> 3.10.0)
40
+ rspec-core (3.10.1)
41
+ rspec-support (~> 3.10.0)
42
+ rspec-expectations (3.10.1)
43
+ diff-lcs (>= 1.2.0, < 2.0)
44
+ rspec-support (~> 3.10.0)
45
+ rspec-mocks (3.10.2)
46
+ diff-lcs (>= 1.2.0, < 2.0)
47
+ rspec-support (~> 3.10.0)
48
+ rspec-support (3.10.2)
49
+ simplecov (0.21.2)
50
+ docile (~> 1.1)
51
+ simplecov-html (~> 0.11)
52
+ simplecov_json_formatter (~> 0.1)
53
+ simplecov-html (0.12.3)
54
+ simplecov_json_formatter (0.1.2)
55
+ tzinfo (2.0.4)
56
+ concurrent-ruby (~> 1.0)
57
+ webmock (3.11.3)
58
+ addressable (>= 2.3.6)
59
+ crack (>= 0.3.2)
60
+ hashdiff (>= 0.4.0, < 2.0.0)
61
+ yard (0.9.26)
62
+ zeitwerk (2.4.2)
63
+
64
+ PLATFORMS
65
+ universal-darwin-19
66
+
67
+ DEPENDENCIES
68
+ contentstack!
69
+ rspec (~> 3.10.0)
70
+ simplecov (~> 0.21.1)
71
+ webmock (~> 3.11.0)
72
+ yard (~> 0.9.26)
73
+
74
+ BUNDLED WITH
75
+ 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", "access_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", "access_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", "access_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", "access_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-2019 [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
@@ -12,7 +12,7 @@ Gem::Specification.new do |s|
12
12
  s.required_ruby_version = '>= 2.0'
13
13
 
14
14
  s.license = "MIT"
15
- s.homepage = "https://github.com/builtio-contentstack/contentstack-ruby"
15
+ s.homepage = "https://github.com/contentstack/contentstack-ruby"
16
16
 
17
17
  s.summary = %q{Contentstack Ruby client for the Content Delivery API}
18
18
  s.description = %q{Contentstack Ruby client for the Content Delivery API}
@@ -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"
24
+ s.add_dependency "contentstack_utils", "~> 1.0.0"
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,23 +3,27 @@ $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
 
9
- # == Built.io Contentstack - Ruby SDK
10
- # Built.io Contentstack is a content management system that facilitates the process of publication by separating the content from site-related programming and design.
10
+ # == Contentstack - Ruby SDK
11
+ # Contentstack is a content management system that facilitates the process of publication by separating the content from site-related programming and design.
11
12
  # == Installation
12
13
  # gem install contentstack
13
14
  # == Initialize the Stack
14
- # @stack = Contentstack::Client.new("site_api_key", "access_token", "enviroment_name")
15
+ # @stack = Contentstack::Client.new("site_api_key", "delivery_token", "enviroment_name")
15
16
  # == Initialize the Stack for EU region
16
- # @stack = Contentstack::Client.new("site_api_key", "access_token", "enviroment_name", {"region": Contentstack::Region::EU })
17
+ # @stack = Contentstack::Client.new("site_api_key", "delivery_token", "enviroment_name", {"region": Contentstack::Region::EU })
17
18
  # == Initialize the Stack for custom host
18
- # @stack = Contentstack::Client.new("site_api_key", "access_token", "enviroment_name", {"host": "https://custom-cdn.contentstack.com" })
19
+ # @stack = Contentstack::Client.new("site_api_key", "delivery_token", "enviroment_name", {"host": "https://custom-cdn.contentstack.com" })
19
20
  # == Usage
20
21
  # ==== Get single entry
21
22
  # @stack.content_type('blog').entry('<entry_uid_here>').fetch
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
@@ -6,11 +6,13 @@ require 'open-uri'
6
6
 
7
7
  module Contentstack
8
8
  class API
9
- def self.init_api(api_key, access_token, environment,host)
9
+ def self.init_api(api_key, delivery_token, environment,host)
10
10
  @host = host
11
11
  @api_version = '/v3'
12
12
  @environment = environment
13
- @headers = {api_key: api_key, access_token: access_token, user_agent: "ruby-sdk/#{Contentstack::VERSION}", environment: @environment}
13
+ @api_key = api_key
14
+ @access_token = delivery_token
15
+ @headers = {environment: @environment}
14
16
  end
15
17
 
16
18
  def self.fetch_content_types(uid="")
@@ -27,9 +29,9 @@ module Contentstack
27
29
  send_request(path, query)
28
30
  end
29
31
 
30
- def self.fetch_entry(content_type, entry_uid)
32
+ def self.fetch_entry(content_type, entry_uid, query)
31
33
  path = "/content_types/#{content_type}/entries/#{entry_uid}"
32
- send_request(path)
34
+ send_request(path, query)
33
35
  end
34
36
 
35
37
  def self.get_assets(asset_uid=nil)
@@ -38,6 +40,11 @@ module Contentstack
38
40
  send_request(path)
39
41
  end
40
42
 
43
+ def self.get_sync_items(query)
44
+ path = "/stacks/sync"
45
+ send_request(path, query)
46
+ end
47
+
41
48
  private
42
49
  def self.send_request(path, q=nil)
43
50
  q ||= {}
@@ -47,7 +54,11 @@ module Contentstack
47
54
  query = "?" + q.to_query
48
55
  # puts "Request URL:- #{@host}#{@api_version}#{path}#{query} \n\n"
49
56
 
50
- ActiveSupport::JSON.decode(open("#{@host}#{@api_version}#{path}#{query}").read)
57
+ ActiveSupport::JSON.decode(open("#{@host}#{@api_version}#{path}#{query}",
58
+ "api_key" => @api_key,
59
+ "access_token"=> @access_token,
60
+ "user_agent"=> "ruby-sdk/#{Contentstack::VERSION}",
61
+ "x-user-agent" => "ruby-sdk/#{Contentstack::VERSION}").read)
51
62
  end
52
63
  end
53
- end
64
+ end