sunil 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.github/workflows/gem-push.yml +33 -0
- data/.gitignore +12 -0
- data/.talismanrc +1 -0
- data/.yardopts +6 -0
- data/CHANGELOG.md +79 -0
- data/CODEOWNERS +1 -0
- data/CODE_OF_CONDUCT.md +73 -0
- data/Gemfile +3 -0
- data/Gemfile.lock +77 -0
- data/LICENSE.txt +21 -0
- data/README.md +197 -0
- data/SECURITY.md +27 -0
- data/lib/contentstack/api.rb +191 -0
- data/lib/contentstack/asset.rb +69 -0
- data/lib/contentstack/asset_collection.rb +28 -0
- data/lib/contentstack/client.rb +92 -0
- data/lib/contentstack/content_type.rb +54 -0
- data/lib/contentstack/entry.rb +222 -0
- data/lib/contentstack/entry_collection.rb +45 -0
- data/lib/contentstack/error.rb +7 -0
- data/lib/contentstack/query.rb +654 -0
- data/lib/contentstack/region.rb +6 -0
- data/lib/contentstack/sync_result.rb +30 -0
- data/lib/contentstack/version.rb +3 -0
- data/lib/contentstack.rb +32 -0
- data/lib/util.rb +111 -0
- data/rakefile.rb +4 -0
- data/spec/asset_collection_spec.rb +16 -0
- data/spec/asset_spec.rb +48 -0
- data/spec/content_type_spec.rb +81 -0
- data/spec/contentstack_spec.rb +39 -0
- data/spec/entry_collection_spec.rb +42 -0
- data/spec/entry_spec.rb +102 -0
- data/spec/fixtures/asset.json +1 -0
- data/spec/fixtures/asset_collection.json +1 -0
- data/spec/fixtures/category_content_type.json +1 -0
- data/spec/fixtures/category_entry.json +1 -0
- data/spec/fixtures/category_entry_collection.json +1 -0
- data/spec/fixtures/category_entry_collection_without_count.json +1 -0
- data/spec/fixtures/content_types.json +1 -0
- data/spec/fixtures/product_entry.json +1 -0
- data/spec/fixtures/product_entry_collection.json +1 -0
- data/spec/fixtures/sync_init.json +2975 -0
- data/spec/query_spec.rb +206 -0
- data/spec/spec_helper.rb +181 -0
- data/spec/sync_spec.rb +27 -0
- data/sunil.gemspec +30 -0
- metadata +186 -0
data/spec/query_spec.rb
ADDED
@@ -0,0 +1,206 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require_relative '../lib/contentstack.rb'
|
3
|
+
|
4
|
+
describe Contentstack::Query do
|
5
|
+
let(:client) { create_client }
|
6
|
+
let(:preview_client) { create_preview_client }
|
7
|
+
let(:category_query) {client.content_type("category").query}
|
8
|
+
let(:preview_category) {preview_client.content_type("category").query}
|
9
|
+
let(:product_query) {client.content_type("product").query}
|
10
|
+
|
11
|
+
it "should get data using `where` method" do
|
12
|
+
data = category_query.where({title: "Electronics"}).fetch
|
13
|
+
expect(data.length).to eq 5
|
14
|
+
end
|
15
|
+
|
16
|
+
it "should get data using `regex` method" do
|
17
|
+
data = category_query.regex("title", "App.*").fetch
|
18
|
+
expect(data.length).to eq 5
|
19
|
+
end
|
20
|
+
|
21
|
+
it "is preview entry featch" do
|
22
|
+
preview_client.live_preview_query({hash: 'hash', content_type_uid: 'category'})
|
23
|
+
data = preview_category.fetch
|
24
|
+
expect(data.length).to eq 5
|
25
|
+
end
|
26
|
+
|
27
|
+
it "should get data using `less_than` method" do
|
28
|
+
data = product_query.less_than("price", 150).fetch
|
29
|
+
expect(data.length).to eq 3
|
30
|
+
end
|
31
|
+
|
32
|
+
it "should get data using `less_than_or_equal` method" do
|
33
|
+
data = product_query.less_than_or_equal("price", 166).fetch
|
34
|
+
expect(data.length).to eq 3
|
35
|
+
end
|
36
|
+
|
37
|
+
it "should get data using `greater_than` method" do
|
38
|
+
data = product_query.greater_than("price", 120).fetch
|
39
|
+
expect(data.length).to eq 3
|
40
|
+
end
|
41
|
+
|
42
|
+
it "should get data using `greater_than_or_equal` method" do
|
43
|
+
data = product_query.greater_than_or_equal("price", 166).fetch
|
44
|
+
expect(data.length).to eq 3
|
45
|
+
end
|
46
|
+
|
47
|
+
it "should get data using `not_equal_to` method" do
|
48
|
+
data = product_query.not_equal_to("price", 166).fetch
|
49
|
+
expect(data.length).to eq 3
|
50
|
+
end
|
51
|
+
|
52
|
+
it "should get data using `limit` method" do
|
53
|
+
data = category_query.limit(2).fetch
|
54
|
+
expect(data.length).to eq 5
|
55
|
+
end
|
56
|
+
|
57
|
+
it "should get data using `skip` method" do
|
58
|
+
data = category_query.skip(5).fetch
|
59
|
+
expect(data.length).to eq 5
|
60
|
+
end
|
61
|
+
|
62
|
+
it "should get data using `include_count` method" do
|
63
|
+
data = category_query.include_count.fetch
|
64
|
+
expect(data.count).not_to be nil
|
65
|
+
expect(data.count).to eq 5
|
66
|
+
end
|
67
|
+
|
68
|
+
it "should get data using `only` method with string parameter" do
|
69
|
+
data = category_query.only("title").fetch
|
70
|
+
expect(data.first.fields[:title]).not_to be nil
|
71
|
+
expect(data.first.fields[:uid]).not_to be nil
|
72
|
+
end
|
73
|
+
|
74
|
+
it "should get data using `only` method with array parameter" do
|
75
|
+
data = category_query.only(["title"]).fetch
|
76
|
+
expect(data.first.fields[:title]).not_to be nil
|
77
|
+
expect(data.first.fields[:uid]).not_to be nil
|
78
|
+
end
|
79
|
+
|
80
|
+
it "should get data using `except` method with string parameter" do
|
81
|
+
data = category_query.except("category_tags").fetch
|
82
|
+
expect(data.first.fields[:category_tags]).to be nil
|
83
|
+
end
|
84
|
+
|
85
|
+
it "should get data using `except` method with array parameter" do
|
86
|
+
data = category_query.except(["description"]).fetch
|
87
|
+
expect(data.first.fields[:description]).to be nil
|
88
|
+
end
|
89
|
+
|
90
|
+
it "should get data using `tags` method" do
|
91
|
+
data = category_query.tags(["tag1"]).fetch
|
92
|
+
expect(data.length).to eq 5
|
93
|
+
end
|
94
|
+
|
95
|
+
it "should get data using `contained_in` method" do
|
96
|
+
data = category_query.contained_in("title", ["Electronics", "Apparel"]).fetch
|
97
|
+
expect(data.length).to eq 5
|
98
|
+
expect(data.first.fields[:title]).to eq "Home & Appliances"
|
99
|
+
expect(data.last.fields[:title]).to eq "Headphones"
|
100
|
+
end
|
101
|
+
|
102
|
+
it "should get data using `not_contained_in` method" do
|
103
|
+
data = category_query.not_contained_in("title", ["Electronics", "Apparel"]).fetch
|
104
|
+
expect(data.length).to eq 5
|
105
|
+
end
|
106
|
+
|
107
|
+
it "should get data using `in` method" do
|
108
|
+
data = category_query.contained_in("title", ["Electronics", "Apparel"]).fetch
|
109
|
+
expect(data.length).to eq 5
|
110
|
+
end
|
111
|
+
|
112
|
+
it "should get data using `not_in` method" do
|
113
|
+
data = category_query.not_contained_in("title", ["Electronics", "Apparel"]).fetch
|
114
|
+
expect(data.length).to eq 5
|
115
|
+
end
|
116
|
+
|
117
|
+
it "should get data using `ascending` method" do
|
118
|
+
data = product_query.ascending("price").fetch
|
119
|
+
expect(data.first.fields[:title]).to eq "Motorola Moto X4"
|
120
|
+
end
|
121
|
+
|
122
|
+
it "should get data using `descending` method" do
|
123
|
+
data = product_query.descending("price").fetch
|
124
|
+
expect(data.first.fields[:title]).to eq "Motorola Moto X4"
|
125
|
+
end
|
126
|
+
|
127
|
+
it "should get data using `only` method for reference fields" do
|
128
|
+
data = product_query.include_reference('categories').only("categories", ["title", "description"]).fetch
|
129
|
+
expect(data.first.fields[:categories][0][:title]).to eq "Smartphones"
|
130
|
+
end
|
131
|
+
|
132
|
+
it "should get data using `except` method for reference fields" do
|
133
|
+
data = product_query.include_reference('categories').except("categories", "title").fetch
|
134
|
+
expect(data.first.fields[:categories][0][:title]).to eq 'Smartphones'
|
135
|
+
end
|
136
|
+
|
137
|
+
it "should get data using `include_schema` method" do
|
138
|
+
data = category_query.include_schema.fetch
|
139
|
+
expect(data.schema).not_to be nil
|
140
|
+
end
|
141
|
+
|
142
|
+
it "should get data using `include_content_type` method" do
|
143
|
+
data = category_query.include_content_type.fetch
|
144
|
+
expect(data.content_type).not_to be nil
|
145
|
+
end
|
146
|
+
|
147
|
+
it "should get data using `include_reference` method" do
|
148
|
+
data = product_query.include_reference('categories').fetch
|
149
|
+
puts data.first.get("categories.title")
|
150
|
+
expect(data.first.fields[:categories][0][:title]).not_to be nil
|
151
|
+
end
|
152
|
+
|
153
|
+
it "should get data using `include_owner` method" do
|
154
|
+
data = product_query.include_owner.fetch
|
155
|
+
expect(data.first.fields[:_owner]).not_to be nil
|
156
|
+
end
|
157
|
+
|
158
|
+
it "should get data using `include_owner` method" do
|
159
|
+
data = product_query.include_fallback.fetch
|
160
|
+
expect(data.first.fields[:locale]).not_to be nil
|
161
|
+
end
|
162
|
+
|
163
|
+
it "should get data using `include_draft` method" do
|
164
|
+
data = category_query.include_draft.fetch
|
165
|
+
expect(data.length).to eq 5
|
166
|
+
end
|
167
|
+
|
168
|
+
it "should get data using `search` method" do
|
169
|
+
data = category_query.search("App").fetch
|
170
|
+
expect(data.length).to eq 5
|
171
|
+
end
|
172
|
+
|
173
|
+
it "should get data using `count` method" do
|
174
|
+
data = category_query.count
|
175
|
+
expect(data).to eq 5
|
176
|
+
end
|
177
|
+
|
178
|
+
it "should get data using `exists` method" do
|
179
|
+
data = category_query.exists?('description').fetch
|
180
|
+
expect(data.length).to eq 5
|
181
|
+
end
|
182
|
+
|
183
|
+
it "should get data using `not_exists` method" do
|
184
|
+
data = product_query.not_exists?('banner_image').fetch
|
185
|
+
expect(data.length).to eq 3
|
186
|
+
end
|
187
|
+
|
188
|
+
it "should get data using `and` method" do
|
189
|
+
q1 = client.content_type("category").query.regex("title", "App.*")
|
190
|
+
q2 = client.content_type("category").query.where({"description"=>"Appliances Category"})
|
191
|
+
data = category_query.and([q1,q2]).fetch
|
192
|
+
expect(data.length).to eq 5
|
193
|
+
end
|
194
|
+
|
195
|
+
it "should get data using `or` method" do
|
196
|
+
q1 = client.content_type("category").query.regex("title", "App.*")
|
197
|
+
q2 = client.content_type("category").query.regex("description", "App*")
|
198
|
+
data = category_query.or([q1,q2]).fetch
|
199
|
+
expect(data.length).to eq 5
|
200
|
+
end
|
201
|
+
|
202
|
+
it "should set locale the in the request query" do
|
203
|
+
data = product_query.locale('en-us')
|
204
|
+
expect(data.query[:locale]).to eq 'en-us'
|
205
|
+
end
|
206
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,181 @@
|
|
1
|
+
# This file was generated by the `rspec --init` command. Conventionally, all
|
2
|
+
# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
|
3
|
+
# The generated `.rspec` file contains `--require spec_helper` which will cause
|
4
|
+
# this file to always be loaded, without a need to explicitly require it in any
|
5
|
+
# files.
|
6
|
+
#
|
7
|
+
# Given that it is always loaded, you are encouraged to keep this file as
|
8
|
+
# light-weight as possible. Requiring heavyweight dependencies from this file
|
9
|
+
# will add to the boot time of your test suite on EVERY test run, even for an
|
10
|
+
# individual file that may not need all of that loaded. Instead, consider making
|
11
|
+
# a separate helper file that requires the additional dependencies and performs
|
12
|
+
# the additional setup, and require it from the spec files that actually need
|
13
|
+
# it.
|
14
|
+
#
|
15
|
+
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
|
16
|
+
require 'webmock/rspec'
|
17
|
+
WebMock.disable_net_connect!(allow_localhost: true)
|
18
|
+
|
19
|
+
require 'simplecov'
|
20
|
+
SimpleCov.start
|
21
|
+
|
22
|
+
require 'contentstack'
|
23
|
+
|
24
|
+
RSpec.configure do |config|
|
25
|
+
# rspec-expectations config goes here. You can use an alternate
|
26
|
+
# assertion/expectation library such as wrong or the stdlib/minitest
|
27
|
+
# assertions if you prefer.
|
28
|
+
config.expect_with :rspec do |expectations|
|
29
|
+
# This option will default to `true` in RSpec 4. It makes the `description`
|
30
|
+
# and `failure_message` of custom matchers include text for helper methods
|
31
|
+
# defined using `chain`, e.g.:
|
32
|
+
# be_bigger_than(2).and_smaller_than(4).description
|
33
|
+
# # => "be bigger than 2 and smaller than 4"
|
34
|
+
# ...rather than:
|
35
|
+
# # => "be bigger than 2"
|
36
|
+
expectations.include_chain_clauses_in_custom_matcher_descriptions = true
|
37
|
+
end
|
38
|
+
|
39
|
+
# rspec-mocks config goes here. You can use an alternate test double
|
40
|
+
# library (such as bogus or mocha) by changing the `mock_with` option here.
|
41
|
+
config.mock_with :rspec do |mocks|
|
42
|
+
# Prevents you from mocking or stubbing a method that does not exist on
|
43
|
+
# a real object. This is generally recommended, and will default to
|
44
|
+
# `true` in RSpec 4.
|
45
|
+
mocks.verify_partial_doubles = true
|
46
|
+
end
|
47
|
+
|
48
|
+
# This option will default to `:apply_to_host_groups` in RSpec 4 (and will
|
49
|
+
# have no way to turn it off -- the option exists only for backwards
|
50
|
+
# compatibility in RSpec 3). It causes shared context metadata to be
|
51
|
+
# inherited by the metadata hash of host groups and examples, rather than
|
52
|
+
# triggering implicit auto-inclusion in groups with matching metadata.
|
53
|
+
config.shared_context_metadata_behavior = :apply_to_host_groups
|
54
|
+
|
55
|
+
# The settings below are suggested to provide a good initial experience
|
56
|
+
# with RSpec, but feel free to customize to your heart's content.
|
57
|
+
=begin
|
58
|
+
# This allows you to limit a spec run to individual examples or groups
|
59
|
+
# you care about by tagging them with `:focus` metadata. When nothing
|
60
|
+
# is tagged with `:focus`, all examples get run. RSpec also provides
|
61
|
+
# aliases for `it`, `describe`, and `context` that include `:focus`
|
62
|
+
# metadata: `fit`, `fdescribe` and `fcontext`, respectively.
|
63
|
+
config.filter_run_when_matching :focus
|
64
|
+
|
65
|
+
# Allows RSpec to persist some state between runs in order to support
|
66
|
+
# the `--only-failures` and `--next-failure` CLI options. We recommend
|
67
|
+
# you configure your source control system to ignore this file.
|
68
|
+
config.example_status_persistence_file_path = "spec/examples.txt"
|
69
|
+
|
70
|
+
# Limits the available syntax to the non-monkey patched syntax that is
|
71
|
+
# recommended. For more details, see:
|
72
|
+
# - http://rspec.info/blog/2012/06/rspecs-new-expectation-syntax/
|
73
|
+
# - http://www.teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
|
74
|
+
# - http://rspec.info/blog/2014/05/notable-changes-in-rspec-3/#zero-monkey-patching-mode
|
75
|
+
config.disable_monkey_patching!
|
76
|
+
|
77
|
+
# This setting enables warnings. It's recommended, but in some cases may
|
78
|
+
# be too noisy due to issues in dependencies.
|
79
|
+
config.warnings = true
|
80
|
+
|
81
|
+
# Many RSpec users commonly either run the entire suite or an individual
|
82
|
+
# file, and it's useful to allow more verbose output when running an
|
83
|
+
# individual spec file.
|
84
|
+
if config.files_to_run.one?
|
85
|
+
# Use the documentation formatter for detailed output,
|
86
|
+
# unless a formatter has already been configured
|
87
|
+
# (e.g. via a command-line flag).
|
88
|
+
config.default_formatter = "doc"
|
89
|
+
end
|
90
|
+
|
91
|
+
# Print the 10 slowest examples and example groups at the
|
92
|
+
# end of the spec run, to help surface which specs are running
|
93
|
+
# particularly slow.
|
94
|
+
config.profile_examples = 10
|
95
|
+
|
96
|
+
# Run specs in random order to surface order dependencies. If you find an
|
97
|
+
# order dependency and want to debug it, you can fix the order by providing
|
98
|
+
# the seed, which is printed after each run.
|
99
|
+
# --seed 1234
|
100
|
+
config.order = :random
|
101
|
+
|
102
|
+
# Seed global randomization in this process using the `--seed` CLI option.
|
103
|
+
# Setting this allows you to use `--seed` to deterministically reproduce
|
104
|
+
# test failures related to randomization by passing the same `--seed` value
|
105
|
+
# as the one that triggered the failure.
|
106
|
+
Kernel.srand config.seed
|
107
|
+
=end
|
108
|
+
|
109
|
+
config.before(:each) do
|
110
|
+
stub_request(:get, /custom-cdn.contentstack.com\/v3\/content_types/).
|
111
|
+
with(headers: {'Accept'=>'*/*', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'User-Agent'=>'Ruby'}).
|
112
|
+
to_return(:status => 200, :body => File.read(File.dirname(__FILE__) + '/fixtures/content_types.json'), :headers => {})
|
113
|
+
|
114
|
+
stub_request(:get, /eu-cdn.contentstack.com\/v3\/content_types/).
|
115
|
+
with(headers: {'Accept'=>'*/*', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'User-Agent'=>'Ruby'}).
|
116
|
+
to_return(:status => 200, :body => File.read(File.dirname(__FILE__) + '/fixtures/content_types.json'), :headers => {})
|
117
|
+
|
118
|
+
stub_request(:get, /cdn.contentstack.io\/v3\/content_types/).
|
119
|
+
with(headers: {'Accept'=>'*/*', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'User-Agent'=>'Ruby'}).
|
120
|
+
to_return(:status => 200, :body => File.read(File.dirname(__FILE__) + '/fixtures/content_types.json'), :headers => {})
|
121
|
+
|
122
|
+
stub_request(:get, /cdn.contentstack.io\/v3\/content_types\/category/).
|
123
|
+
with(headers: {'Accept'=>'*/*', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'User-Agent'=>'Ruby'}).
|
124
|
+
to_return(:status => 200, :body => File.read(File.dirname(__FILE__) + '/fixtures/category_content_type.json'), :headers => {})
|
125
|
+
|
126
|
+
stub_request(:get, /cdn.contentstack.io\/v3\/assets/).
|
127
|
+
with(headers: {'Accept'=>'*/*', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'User-Agent'=>'Ruby'}).
|
128
|
+
to_return(:status => 200, :body => File.read(File.dirname(__FILE__) + '/fixtures/asset_collection.json'), :headers => {})
|
129
|
+
|
130
|
+
stub_request(:get, /cdn.contentstack.io\/v3\/assets\/image_1/).
|
131
|
+
with(headers: {'Accept'=>'*/*', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'User-Agent'=>'Ruby'}).
|
132
|
+
to_return(:status => 200, :body => File.read(File.dirname(__FILE__) + '/fixtures/asset.json'), :headers => {})
|
133
|
+
|
134
|
+
stub_request(:get, /cdn.contentstack.io\/v3\/content_types\/product\/entries/).
|
135
|
+
with(headers: {'Accept'=>'*/*', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'User-Agent'=>'Ruby'}).
|
136
|
+
to_return(:status => 200, :body => File.read(File.dirname(__FILE__) + '/fixtures/product_entry_collection.json'), :headers => {})
|
137
|
+
|
138
|
+
stub_request(:get, /cdn.contentstack.io\/v3\/content_types\/product\/entries\/uid/).
|
139
|
+
with(headers: {'Accept'=>'*/*', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'User-Agent'=>'Ruby'}).
|
140
|
+
to_return(:status => 200, :body => File.read(File.dirname(__FILE__) + '/fixtures/product_entry.json'), :headers => {})
|
141
|
+
|
142
|
+
stub_request(:get, /cdn.contentstack.io\/v3\/content_types\/category\/entries/).
|
143
|
+
with(headers: {'Accept'=>'*/*', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'User-Agent'=>'Ruby'}).
|
144
|
+
to_return(:status => 200, :body => File.read(File.dirname(__FILE__) + '/fixtures/category_entry_collection_without_count.json'), :headers => {})
|
145
|
+
|
146
|
+
stub_request(:get, /cdn.contentstack.io\/v3\/content_types\/category\/entries.*include_count=true/).
|
147
|
+
with(headers: {'Accept'=>'*/*', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'User-Agent'=>'Ruby'}).
|
148
|
+
to_return(:status => 200, :body => File.read(File.dirname(__FILE__) + '/fixtures/category_entry_collection.json'), :headers => {})
|
149
|
+
|
150
|
+
stub_request(:get, /cdn.contentstack.io\/v3\/content_types\/category\/entries\/uid/).
|
151
|
+
with(headers: {'Accept'=>'*/*', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'User-Agent'=>'Ruby'}).
|
152
|
+
to_return(:status => 200, :body => File.read(File.dirname(__FILE__) + '/fixtures/category_entry.json'), :headers => {})
|
153
|
+
|
154
|
+
stub_request(:get, /cdn.contentstack.io\/v3\/stacks\/sync/).
|
155
|
+
with(headers: {'Accept'=>'*/*', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'User-Agent'=>'Ruby'}).
|
156
|
+
to_return(:status => 200, :body => File.read(File.dirname(__FILE__) + '/fixtures/sync_init.json'), :headers => {})
|
157
|
+
|
158
|
+
stub_request(:get, /preview.contentstack.io\/v3\/content_types\/category\/entries/).
|
159
|
+
with(headers: {'Accept'=>'*/*', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'User-Agent'=>'Ruby'}).
|
160
|
+
to_return(:status => 200, :body => File.read(File.dirname(__FILE__) + '/fixtures/category_entry_collection_without_count.json'), :headers => {})
|
161
|
+
|
162
|
+
stub_request(:get, /preview.contentstack.io\/v3\/content_types\/category\/entries\/uid/).
|
163
|
+
with(headers: {'Accept'=>'*/*', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'User-Agent'=>'Ruby'}).
|
164
|
+
to_return(:status => 200, :body => File.read(File.dirname(__FILE__) + '/fixtures/category_entry.json'), :headers => {})
|
165
|
+
end
|
166
|
+
|
167
|
+
def create_client(delivery_token = ENV['DELIVERY_TOKEN'], api_key = ENV['API_KEY'], environment = ENV['ENVIRONMENT'], options = {})
|
168
|
+
Contentstack::Client.new(api_key, delivery_token, environment, options)
|
169
|
+
end
|
170
|
+
|
171
|
+
def create_preview_client(delivery_token = ENV['DELIVERY_TOKEN'], api_key = ENV['API_KEY'], environment = ENV['ENVIRONMENT'], options = {live_preview: {host: 'https://preview.contentstack.io', enable: true, management_token: 'auth'}})
|
172
|
+
Contentstack::Client.new(api_key, delivery_token, environment, options)
|
173
|
+
end
|
174
|
+
|
175
|
+
def render(content, entry)
|
176
|
+
Contentstack::render_content(content, ContentstackUtils::Model::Options.new(entry))
|
177
|
+
end
|
178
|
+
def json_to_html(content, entry)
|
179
|
+
Contentstack::json_to_html(content, ContentstackUtils::Model::Options.new(entry))
|
180
|
+
end
|
181
|
+
end
|
data/spec/sync_spec.rb
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require_relative '../lib/contentstack.rb'
|
3
|
+
pagination_token = "token"
|
4
|
+
describe Contentstack::SyncResult do
|
5
|
+
let(:client) { create_client }
|
6
|
+
|
7
|
+
it "initial sync for Stack" do
|
8
|
+
@result = client.sync({init: true})
|
9
|
+
expect(@result.items.length).to be 100
|
10
|
+
expect(@result.skip).to be 0
|
11
|
+
expect(@result.limit).to be 100
|
12
|
+
expect(@result.total_count).to be 123
|
13
|
+
expect(@result.pagination_token).not_to be nil
|
14
|
+
expect(@result.sync_token).to be nil
|
15
|
+
pagination_token = @result.pagination_token
|
16
|
+
end
|
17
|
+
|
18
|
+
it "next paginated sync for Stack" do
|
19
|
+
@result = client.sync({pagination_token: pagination_token})
|
20
|
+
expect(@result.items.length).to be 100
|
21
|
+
expect(@result.skip).to be 0
|
22
|
+
expect(@result.limit).to be 100
|
23
|
+
expect(@result.total_count).to be 123
|
24
|
+
expect(@result.pagination_token).not_to be nil
|
25
|
+
expect(@result.sync_token).to be nil
|
26
|
+
end
|
27
|
+
end
|
data/sunil.gemspec
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
lib = File.expand_path('../lib', __FILE__)
|
2
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
|
+
|
4
|
+
require 'contentstack/version'
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "sunil"
|
7
|
+
s.version = Contentstack::VERSION.dup
|
8
|
+
s.date = Time.now
|
9
|
+
s.authors = [%q{Contentstack}]
|
10
|
+
s.email = ["support@contentstack.com"]
|
11
|
+
|
12
|
+
s.required_ruby_version = '>= 2.0'
|
13
|
+
|
14
|
+
s.license = "MIT"
|
15
|
+
s.homepage = "https://github.com/contentstack/contentstack-ruby"
|
16
|
+
|
17
|
+
s.summary = %q{Contentstack Ruby client for the Content Delivery API}
|
18
|
+
s.description = %q{Contentstack Ruby client for the Content Delivery API}
|
19
|
+
|
20
|
+
s.files = `git ls-files`.split("\n")
|
21
|
+
s.require_paths = ["lib"]
|
22
|
+
|
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'
|
30
|
+
end
|
metadata
ADDED
@@ -0,0 +1,186 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: sunil
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Contentstack
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2022-11-28 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: activesupport
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '3.2'
|
20
|
+
- - "<"
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: '6.2'
|
23
|
+
type: :runtime
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
requirements:
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '3.2'
|
30
|
+
- - "<"
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '6.2'
|
33
|
+
- !ruby/object:Gem::Dependency
|
34
|
+
name: contentstack_utils
|
35
|
+
requirement: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - "~>"
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '1.0'
|
40
|
+
- - ">="
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
version: 1.0.1
|
43
|
+
type: :runtime
|
44
|
+
prerelease: false
|
45
|
+
version_requirements: !ruby/object:Gem::Requirement
|
46
|
+
requirements:
|
47
|
+
- - "~>"
|
48
|
+
- !ruby/object:Gem::Version
|
49
|
+
version: '1.0'
|
50
|
+
- - ">="
|
51
|
+
- !ruby/object:Gem::Version
|
52
|
+
version: 1.0.1
|
53
|
+
- !ruby/object:Gem::Dependency
|
54
|
+
name: rspec
|
55
|
+
requirement: !ruby/object:Gem::Requirement
|
56
|
+
requirements:
|
57
|
+
- - "~>"
|
58
|
+
- !ruby/object:Gem::Version
|
59
|
+
version: 3.10.0
|
60
|
+
type: :development
|
61
|
+
prerelease: false
|
62
|
+
version_requirements: !ruby/object:Gem::Requirement
|
63
|
+
requirements:
|
64
|
+
- - "~>"
|
65
|
+
- !ruby/object:Gem::Version
|
66
|
+
version: 3.10.0
|
67
|
+
- !ruby/object:Gem::Dependency
|
68
|
+
name: webmock
|
69
|
+
requirement: !ruby/object:Gem::Requirement
|
70
|
+
requirements:
|
71
|
+
- - "~>"
|
72
|
+
- !ruby/object:Gem::Version
|
73
|
+
version: 3.11.0
|
74
|
+
type: :development
|
75
|
+
prerelease: false
|
76
|
+
version_requirements: !ruby/object:Gem::Requirement
|
77
|
+
requirements:
|
78
|
+
- - "~>"
|
79
|
+
- !ruby/object:Gem::Version
|
80
|
+
version: 3.11.0
|
81
|
+
- !ruby/object:Gem::Dependency
|
82
|
+
name: simplecov
|
83
|
+
requirement: !ruby/object:Gem::Requirement
|
84
|
+
requirements:
|
85
|
+
- - "~>"
|
86
|
+
- !ruby/object:Gem::Version
|
87
|
+
version: 0.21.1
|
88
|
+
type: :development
|
89
|
+
prerelease: false
|
90
|
+
version_requirements: !ruby/object:Gem::Requirement
|
91
|
+
requirements:
|
92
|
+
- - "~>"
|
93
|
+
- !ruby/object:Gem::Version
|
94
|
+
version: 0.21.1
|
95
|
+
- !ruby/object:Gem::Dependency
|
96
|
+
name: yard
|
97
|
+
requirement: !ruby/object:Gem::Requirement
|
98
|
+
requirements:
|
99
|
+
- - "~>"
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
version: 0.9.26
|
102
|
+
type: :development
|
103
|
+
prerelease: false
|
104
|
+
version_requirements: !ruby/object:Gem::Requirement
|
105
|
+
requirements:
|
106
|
+
- - "~>"
|
107
|
+
- !ruby/object:Gem::Version
|
108
|
+
version: 0.9.26
|
109
|
+
description: Contentstack Ruby client for the Content Delivery API
|
110
|
+
email:
|
111
|
+
- support@contentstack.com
|
112
|
+
executables: []
|
113
|
+
extensions: []
|
114
|
+
extra_rdoc_files: []
|
115
|
+
files:
|
116
|
+
- ".github/workflows/gem-push.yml"
|
117
|
+
- ".gitignore"
|
118
|
+
- ".talismanrc"
|
119
|
+
- ".yardopts"
|
120
|
+
- CHANGELOG.md
|
121
|
+
- CODEOWNERS
|
122
|
+
- CODE_OF_CONDUCT.md
|
123
|
+
- Gemfile
|
124
|
+
- Gemfile.lock
|
125
|
+
- LICENSE.txt
|
126
|
+
- README.md
|
127
|
+
- SECURITY.md
|
128
|
+
- lib/contentstack.rb
|
129
|
+
- lib/contentstack/api.rb
|
130
|
+
- lib/contentstack/asset.rb
|
131
|
+
- lib/contentstack/asset_collection.rb
|
132
|
+
- lib/contentstack/client.rb
|
133
|
+
- lib/contentstack/content_type.rb
|
134
|
+
- lib/contentstack/entry.rb
|
135
|
+
- lib/contentstack/entry_collection.rb
|
136
|
+
- lib/contentstack/error.rb
|
137
|
+
- lib/contentstack/query.rb
|
138
|
+
- lib/contentstack/region.rb
|
139
|
+
- lib/contentstack/sync_result.rb
|
140
|
+
- lib/contentstack/version.rb
|
141
|
+
- lib/util.rb
|
142
|
+
- rakefile.rb
|
143
|
+
- spec/asset_collection_spec.rb
|
144
|
+
- spec/asset_spec.rb
|
145
|
+
- spec/content_type_spec.rb
|
146
|
+
- spec/contentstack_spec.rb
|
147
|
+
- spec/entry_collection_spec.rb
|
148
|
+
- spec/entry_spec.rb
|
149
|
+
- spec/fixtures/asset.json
|
150
|
+
- spec/fixtures/asset_collection.json
|
151
|
+
- spec/fixtures/category_content_type.json
|
152
|
+
- spec/fixtures/category_entry.json
|
153
|
+
- spec/fixtures/category_entry_collection.json
|
154
|
+
- spec/fixtures/category_entry_collection_without_count.json
|
155
|
+
- spec/fixtures/content_types.json
|
156
|
+
- spec/fixtures/product_entry.json
|
157
|
+
- spec/fixtures/product_entry_collection.json
|
158
|
+
- spec/fixtures/sync_init.json
|
159
|
+
- spec/query_spec.rb
|
160
|
+
- spec/spec_helper.rb
|
161
|
+
- spec/sync_spec.rb
|
162
|
+
- sunil.gemspec
|
163
|
+
homepage: https://github.com/contentstack/contentstack-ruby
|
164
|
+
licenses:
|
165
|
+
- MIT
|
166
|
+
metadata: {}
|
167
|
+
post_install_message:
|
168
|
+
rdoc_options: []
|
169
|
+
require_paths:
|
170
|
+
- lib
|
171
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
172
|
+
requirements:
|
173
|
+
- - ">="
|
174
|
+
- !ruby/object:Gem::Version
|
175
|
+
version: '2.0'
|
176
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
177
|
+
requirements:
|
178
|
+
- - ">="
|
179
|
+
- !ruby/object:Gem::Version
|
180
|
+
version: '0'
|
181
|
+
requirements: []
|
182
|
+
rubygems_version: 3.0.3.1
|
183
|
+
signing_key:
|
184
|
+
specification_version: 4
|
185
|
+
summary: Contentstack Ruby client for the Content Delivery API
|
186
|
+
test_files: []
|