diff --git a/.gitignore b/.gitignore
index 1b2e5ae..1cbd975 100644
--- a/.gitignore
+++ b/.gitignore
@@ -5,3 +5,6 @@ doc
spec-integration
coverage
\.yardoc
+.DS_Store
+.bundle/
+*/rspec_results.html
\ No newline at end of file
diff --git a/Gemfile b/Gemfile
new file mode 100644
index 0000000..f69a735
--- /dev/null
+++ b/Gemfile
@@ -0,0 +1,7 @@
+# Gemfile
+source "https://rubygems.org"
+
+gem "rspec"
+gem "webmock"
+gem "simplecov"
+gem "activesupport"
\ No newline at end of file
diff --git a/Gemfile.lock b/Gemfile.lock
new file mode 100644
index 0000000..498cd43
--- /dev/null
+++ b/Gemfile.lock
@@ -0,0 +1,59 @@
+GEM
+ remote: https://rubygems.org/
+ specs:
+ activesupport (6.0.2.2)
+ concurrent-ruby (~> 1.0, >= 1.0.2)
+ i18n (>= 0.7, < 2)
+ minitest (~> 5.1)
+ tzinfo (~> 1.1)
+ zeitwerk (~> 2.2)
+ addressable (2.7.0)
+ public_suffix (>= 2.0.2, < 5.0)
+ concurrent-ruby (1.1.6)
+ crack (0.4.3)
+ safe_yaml (~> 1.0.0)
+ diff-lcs (1.3)
+ docile (1.3.2)
+ hashdiff (1.0.1)
+ i18n (1.8.2)
+ concurrent-ruby (~> 1.0)
+ minitest (5.14.0)
+ public_suffix (4.0.4)
+ rspec (3.9.0)
+ rspec-core (~> 3.9.0)
+ rspec-expectations (~> 3.9.0)
+ rspec-mocks (~> 3.9.0)
+ rspec-core (3.9.1)
+ rspec-support (~> 3.9.1)
+ rspec-expectations (3.9.1)
+ diff-lcs (>= 1.2.0, < 2.0)
+ rspec-support (~> 3.9.0)
+ rspec-mocks (3.9.1)
+ diff-lcs (>= 1.2.0, < 2.0)
+ rspec-support (~> 3.9.0)
+ rspec-support (3.9.2)
+ safe_yaml (1.0.5)
+ simplecov (0.18.5)
+ docile (~> 1.1)
+ simplecov-html (~> 0.11)
+ simplecov-html (0.12.2)
+ thread_safe (0.3.6)
+ tzinfo (1.2.7)
+ thread_safe (~> 0.1)
+ webmock (3.8.3)
+ addressable (>= 2.3.6)
+ crack (>= 0.3.2)
+ hashdiff (>= 0.4.0, < 2.0.0)
+ zeitwerk (2.3.0)
+
+PLATFORMS
+ ruby
+
+DEPENDENCIES
+ activesupport
+ rspec
+ simplecov
+ webmock
+
+BUNDLED WITH
+ 2.1.4
diff --git a/README.md b/README.md
index 3180bff..0d4c6c1 100644
--- a/README.md
+++ b/README.md
@@ -22,13 +22,13 @@ Or you can run this command in your terminal (you might need administrator privi
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.
# with default region
- client = Contentstack::Client.new("site_api_key", "access_token", "enviroment_name")
+ client = Contentstack::Client.new("site_api_key", "delivery_token", "enviroment_name")
# with specific region
- client = Contentstack::Client.new("site_api_key", "access_token", "enviroment_name",{"region": Contentstack::Region::EU})
+ client = Contentstack::Client.new("site_api_key", "delivery_token", "enviroment_name",{"region": Contentstack::Region::EU})
# with custom host
- client = Contentstack::Client.new("site_api_key", "access_token", "enviroment_name",{"host": "https://custom-cdn.contentstack.com"})
+ client = Contentstack::Client.new("site_api_key", "delivery_token", "enviroment_name",{"host": "https://custom-cdn.contentstack.com"})
@@ -61,7 +61,7 @@ A publishing environment corresponds to one or more deployment servers or a cont
To initialize the SDK, you need to provide values for the keys given in the snippet below:
- stack = Contentstack::Client.new("site_api_key", "access_token", "enviroment_name")
+ stack = Contentstack::Client.new("site_api_key", "delivery_token", "enviroment_name")
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.
diff --git a/contentstack.gemspec b/contentstack.gemspec
index 2849ba3..6b3cc8a 100644
--- a/contentstack.gemspec
+++ b/contentstack.gemspec
@@ -12,7 +12,7 @@ Gem::Specification.new do |s|
s.required_ruby_version = '>= 2.0'
s.license = "MIT"
- s.homepage = "https://github.com/builtio-contentstack/contentstack-ruby"
+ s.homepage = "https://github.com/contentstack/contentstack-ruby"
s.summary = %q{Contentstack Ruby client for the Content Delivery API}
s.description = %q{Contentstack Ruby client for the Content Delivery API}
diff --git a/coverage/.last_run.json b/coverage/.last_run.json
index ff908d7..4842a25 100644
--- a/coverage/.last_run.json
+++ b/coverage/.last_run.json
@@ -1,5 +1,5 @@
{
"result": {
- "covered_percent": 96.63
+ "covered_percent": 96.65
}
}
diff --git a/coverage/.resultset.json b/coverage/.resultset.json
index 1d639a9..6378267 100644
--- a/coverage/.resultset.json
+++ b/coverage/.resultset.json
@@ -1,1512 +1,1556 @@
{
"RSpec": {
"coverage": {
- "/Users/kevalgohil/contentstack-ruby/lib/contentstack.rb": [
- 1,
- null,
- 1,
- 1,
- 1,
- 1,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- 1,
- null
- ],
- "/Users/kevalgohil/contentstack-ruby/lib/contentstack/version.rb": [
- 1,
- 1,
- null
- ],
- "/Users/kevalgohil/contentstack-ruby/lib/contentstack/client.rb": [
- 1,
- 1,
- 1,
- null,
- 1,
- 1,
- 1,
- null,
- 1,
- 64,
- 64,
- 64,
- null,
- null,
- null,
- 1,
- 8,
- null,
- null,
- 1,
- 54,
- null,
- null,
- 1,
- 2,
- null,
- null,
- 1,
- 7,
- null,
- null,
- 1,
- 1,
- 62,
- null,
- 60,
- null,
- 2,
- null,
- 62,
- null,
- null,
- null
- ],
- "/Users/kevalgohil/contentstack-ruby/lib/contentstack/api.rb": [
- 1,
- 1,
- 1,
- 1,
- 1,
- null,
- 1,
- 1,
- 1,
- 64,
- 64,
- 64,
- 64,
- null,
- null,
- 1,
- 8,
- 0,
- null,
- 8,
- null,
- 8,
- null,
- null,
- 1,
- 47,
- 47,
- null,
- null,
- 1,
- 2,
- 2,
- null,
- null,
- 1,
- 9,
- 9,
- 9,
- null,
- null,
- 1,
- 1,
- 66,
- null,
- 66,
- null,
- 66,
- null,
- null,
- 66,
- null,
- null,
- null
- ],
- "/Users/kevalgohil/contentstack-ruby/lib/contentstack/content_type.rb": [
- 1,
- null,
- 1,
- 1,
- 1,
- 5,
- 2,
- 8,
- null,
- 3,
- 1,
- null,
- null,
- null,
- null,
- null,
- null,
- 2,
- null,
- null,
- 2,
- 64,
- null,
- null,
- null,
- null,
- 1,
- 75,
- null,
- null,
- 1,
- 52,
- null,
- null,
- 1,
- 2,
- null,
- null,
- null,
- 1,
- 8,
- 8,
- 224,
- null,
- null,
- null,
- 1,
- 0,
- 0,
- null,
- null,
- null
- ],
- "/Users/kevalgohil/contentstack-ruby/lib/contentstack/query.rb": [
- 1,
- null,
- 1,
- null,
- 1,
- null,
- null,
- null,
- null,
- null,
- null,
- 1,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- 1,
- 52,
- 52,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- 1,
- 0,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- 1,
- 0,
- 0,
- 0,
- 0,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- 1,
- 2,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- 1,
- 4,
- null,
- null,
- null,
- null,
- null,
- 4,
- null,
- 4,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- 1,
- 1,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- 1,
- 1,
- 1,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- 1,
- 1,
- 1,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- 1,
- 1,
- 1,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- 1,
- 1,
- 1,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- 1,
- 1,
- 1,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- 1,
- 1,
- 1,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- 1,
- 1,
- 1,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- 1,
- 1,
- 1,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- 1,
- 2,
- 2,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- 1,
- 2,
- 2,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- 1,
- 1,
- 1,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- 1,
- 1,
- 1,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- 1,
- 1,
- 1,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- 1,
- 1,
- 1,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- 1,
- 8,
- 8,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- 1,
- 1,
- 1,
- 1,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- 1,
- 1,
- 1,
- 1,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- 1,
- 1,
- 1,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- 1,
- 3,
- 3,
- 1,
- 1,
- null,
- 2,
- 2,
- null,
- null,
- 3,
- 3,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- 1,
- 3,
- 3,
- 1,
- 1,
- null,
- 2,
- 2,
- null,
- null,
- 3,
- 3,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- 1,
- 3,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- 1,
- 1,
- 1,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- 1,
- 1,
- 1,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- 1,
- 1,
- 1,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- 1,
- 1,
- 1,
- null,
- null,
- null,
- null,
- null,
- 1,
- 3,
- 3,
- 3,
- 3,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- 1,
- 1,
- 1,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- 1,
- 47,
- 47,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- 1,
- 0,
- 0,
- null,
- null,
- 1,
- 1,
- 1,
- null,
- 1,
- 1,
- 19,
- 19,
- 19,
- 19,
- null,
- null,
- 1,
- 2,
- 2,
- 2,
- 0,
- null,
- null,
- 2,
- 2,
- 4,
- 4,
- 4,
- null,
- null,
- null,
- null,
- 2,
- null,
- null,
- null
- ],
- "/Users/kevalgohil/contentstack-ruby/lib/contentstack/entry_collection.rb": [
- 1,
- null,
- 1,
- 1,
- 1,
- null,
- 1,
- 47,
- 258,
- 47,
- 47,
- 47,
- null,
- null,
- 1,
- 0,
- null,
- null,
- 1,
- 0,
- null,
- null,
- 1,
- 0,
- null,
- null,
- 1,
- 20,
- null,
- null,
- 1,
- 16,
- null,
- null,
- 1,
- 2,
- null,
- null,
- 1,
- 1,
- null,
- null,
- null
- ],
- "/Users/kevalgohil/contentstack-ruby/lib/contentstack/entry.rb": [
- 1,
- 1,
- 1,
- 1,
- 213,
- null,
- null,
- 1,
- 2,
- 2,
- 2,
- null,
- null,
- 1,
- 2,
- 2,
- null,
- null,
- 1,
- 1,
- 215,
- 215,
- 215,
- 215,
- null,
- null,
- null
- ],
- "/Users/kevalgohil/contentstack-ruby/lib/contentstack/asset_collection.rb": [
- 1,
- null,
- 1,
- null,
- 1,
- 1,
- null,
- 1,
- 4,
- 2,
- 2,
- null,
- 6,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- 1,
- 2,
- 2,
- null,
- null,
- null
- ],
- "/Users/kevalgohil/contentstack-ruby/lib/contentstack/asset.rb": [
- 1,
- null,
- null,
- 1,
- 1,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- 1,
- 18,
- 7,
- null,
- 11,
- 11,
- 11,
- 11,
- 11,
- 11,
- 11,
- null,
- null,
- 18,
- null,
- null,
- null,
- null,
- null,
- null,
- 1,
- 7,
- null,
- 7,
- null,
- null,
- null
- ],
- "/Users/kevalgohil/contentstack-ruby/lib/contentstack/region.rb": [
- 1,
- 1,
- 1,
- 1,
- null,
- null
- ],
- "/Users/kevalgohil/contentstack-ruby/lib/util.rb": [
- 1,
- 1,
- null,
- 521,
- 72,
- null,
- null,
- 1,
- 3056,
- 3056,
- 15692,
- 3118,
- null,
- 12574,
- null,
- null,
- 3056,
- null,
- null,
- null,
- 1,
- 1,
- 10,
- 21,
- null,
- null,
- 1,
- 1250,
- 1007,
- 801,
- null,
- 206,
- null,
- null,
- null,
- null,
- null,
- 1,
- 1,
- 370,
- 370,
- null,
- null,
- 1,
- 381,
- null,
- null,
- null,
- 1,
- 1,
- 0,
- null,
- null,
- 1,
- 505,
- null,
- null,
- null,
- 1,
- 1,
- 192,
- null,
- null,
- 1,
- 0,
- null,
- null,
- null,
- 1,
- 1,
- 0,
- null,
- null,
- 1,
- 12,
- null,
- null,
- null,
- 1,
- 1,
- 0,
- null,
- null,
- 1,
- 39,
- null,
- null,
- null,
- 1,
- 1,
- 0,
- null,
- null,
- 1,
- 95,
- null,
- null,
- null,
- 1,
- 1,
- 0,
- null,
- null,
- 1,
- 0,
- null,
- null
- ],
- "/Users/kevalgohil/contentstack-ruby/spec/asset_spec.rb": [
- 1,
- 1,
- null,
- 1,
- 8,
- null,
- 1,
- 1,
- 1,
- 1,
- null,
- null,
- 1,
- 1,
- 1,
- 1,
- null,
- null,
- 1,
- 1,
- 1,
- 1,
- null,
- null,
- 1,
- 1,
- 1,
- 1,
- null,
- null,
- 1,
- 1,
- 1,
- 1,
- null,
- null,
- 1,
- 1,
- 1,
- 1,
- null,
- null,
- 1,
- 1,
- 1,
- 1,
- null,
- null
- ],
- "/Users/kevalgohil/contentstack-ruby/spec/content_type_spec.rb": [
- 1,
- 1,
- null,
- 1,
- 7,
- 2,
- 2,
- null,
- 1,
- 1,
- 1,
- 1,
- null,
- null,
- 1,
- 1,
- 1,
- null,
- null,
- 1,
- 1,
- 1,
- null,
- null,
- 1,
- 1,
- 1,
- null,
- null,
- 1,
- 1,
- 1,
- null,
- null,
- 1,
- 1,
- 1,
- null,
- null,
- 1,
- 1,
- 1,
- null,
- null,
- 1,
- 1,
- 1,
- null,
- null,
- null,
- 1,
- 1,
- 5,
- null,
- null,
- 1,
- 1,
- null,
- null,
- 1,
- 1,
- null,
- null,
- 1,
- 1,
- null,
- null,
- 1,
- 1,
- null,
- null,
- 1,
- 1,
- null,
- null,
- null
- ],
- "/Users/kevalgohil/contentstack-ruby/spec/contentstack_spec.rb": [
- 1,
- 1,
- null,
- 1,
- 2,
- 2,
- 2,
- null,
- 1,
- 1,
- null,
- null,
- 1,
- 1,
- 1,
- null,
- null,
- 1,
- 1,
- 1,
- null,
- null,
- 1,
- 1,
- 1,
- null,
- null,
- 1,
- 1,
- null,
- null,
- null
- ],
- "/Users/kevalgohil/contentstack-ruby/spec/entry_collection_spec.rb": [
- 1,
- 1,
- null,
- 1,
- 7,
- null,
- 1,
- 1,
- 1,
- 1,
- null,
- null,
- 1,
- 1,
- 1,
- 1,
- null,
- null,
- 1,
- 1,
- 1,
- 1,
- null,
- null,
- 1,
- 1,
- 1,
- 1,
- null,
- null,
- 1,
- 1,
- 1,
- 1,
- null,
- null,
- 1,
- 1,
- 1,
- 1,
- null,
- null
- ],
- "/Users/kevalgohil/contentstack-ruby/spec/entry_spec.rb": [
- 1,
- 1,
- null,
- 1,
- 4,
- null,
- 1,
- 1,
- 1,
- 1,
- null,
- null,
- 1,
- 1,
- 1,
- null,
- null,
- 1,
- 1,
- 1,
- 1,
- null,
- null
- ],
- "/Users/kevalgohil/contentstack-ruby/spec/query_spec.rb": [
- 1,
- 1,
- null,
- 1,
- 36,
- 23,
- 14,
- null,
- 1,
- 1,
- 1,
- null,
- null,
- 1,
- 1,
- 1,
- null,
- null,
- 1,
- 1,
- 1,
- null,
- null,
- 1,
- 1,
- 1,
- null,
- null,
- 1,
- 1,
- 1,
- null,
- null,
- 1,
- 1,
- 1,
- null,
- null,
- 1,
- 1,
- 1,
- null,
- null,
- 1,
- 1,
- 1,
- null,
- null,
- 1,
- 1,
- 1,
- null,
- null,
- 1,
- 1,
- 1,
- 1,
- null,
- null,
- 1,
- 1,
- 1,
- 1,
- null,
- null,
- 1,
- 1,
- 1,
- 1,
- null,
- null,
- 1,
- 1,
- 1,
- null,
- null,
- 1,
- 1,
- 1,
- null,
- null,
- 1,
- 1,
- 1,
- null,
- null,
- 1,
- 1,
- 1,
- 1,
- 1,
- null,
- null,
- 1,
- 1,
- 1,
- null,
- null,
- 1,
- 1,
- 1,
- null,
- null,
- 1,
- 1,
- 1,
- null,
- null,
- 1,
- 1,
- 1,
- null,
- null,
- 1,
- 1,
- 1,
- null,
- null,
- 1,
- 1,
- 1,
- null,
- null,
- 1,
- 1,
- 1,
- null,
- null,
- 1,
- 1,
- 1,
- null,
- null,
- 1,
- 1,
- 1,
- null,
- null,
- 1,
- 1,
- 1,
- 1,
- null,
- null,
- 1,
- 1,
- 1,
- null,
- null,
- 1,
- 1,
- 1,
- null,
- null,
- 1,
- 1,
- 1,
- null,
- null,
- 1,
- 1,
- 1,
- null,
- null,
- 1,
- 1,
- 1,
- null,
- null,
- 1,
- 1,
- 1,
- null,
- null,
- 1,
- 1,
- 1,
- 1,
- 1,
- null,
- null,
- 1,
- 1,
- 1,
- 1,
- 1,
- null,
- null,
- 1,
- 1,
- 1,
- null,
- null
- ]
+ "/Users/uttamukkoji/Documents/Ruby/contentstack-ruby/lib/contentstack.rb": {
+ "lines": [
+ 1,
+ null,
+ 1,
+ 1,
+ 1,
+ 1,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ 1,
+ null
+ ]
+ },
+ "/Users/uttamukkoji/Documents/Ruby/contentstack-ruby/lib/contentstack/version.rb": {
+ "lines": [
+ 1,
+ 1,
+ null
+ ]
+ },
+ "/Users/uttamukkoji/Documents/Ruby/contentstack-ruby/lib/contentstack/client.rb": {
+ "lines": [
+ 1,
+ 1,
+ 1,
+ null,
+ 1,
+ 1,
+ 1,
+ null,
+ 1,
+ 64,
+ 64,
+ 64,
+ null,
+ null,
+ null,
+ 1,
+ 8,
+ null,
+ null,
+ 1,
+ 54,
+ null,
+ null,
+ 1,
+ 2,
+ null,
+ null,
+ 1,
+ 7,
+ null,
+ null,
+ 1,
+ 1,
+ 62,
+ null,
+ 60,
+ null,
+ 2,
+ null,
+ 62,
+ null,
+ null,
+ null
+ ]
+ },
+ "/Users/uttamukkoji/Documents/Ruby/contentstack-ruby/lib/contentstack/api.rb": {
+ "lines": [
+ 1,
+ 1,
+ 1,
+ 1,
+ 1,
+ null,
+ 1,
+ 1,
+ 1,
+ 64,
+ 64,
+ 64,
+ 64,
+ 64,
+ 64,
+ null,
+ null,
+ 1,
+ 8,
+ 0,
+ null,
+ 8,
+ null,
+ 8,
+ null,
+ null,
+ 1,
+ 47,
+ 47,
+ null,
+ null,
+ 1,
+ 2,
+ 2,
+ null,
+ null,
+ 1,
+ 9,
+ 9,
+ 9,
+ null,
+ null,
+ 1,
+ 1,
+ 66,
+ null,
+ 66,
+ null,
+ 66,
+ null,
+ null,
+ 66,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null
+ ]
+ },
+ "/Users/uttamukkoji/Documents/Ruby/contentstack-ruby/lib/contentstack/content_type.rb": {
+ "lines": [
+ 1,
+ null,
+ 1,
+ 1,
+ 1,
+ 5,
+ 2,
+ 8,
+ null,
+ 3,
+ 1,
+ null,
+ 2,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ 2,
+ 64,
+ null,
+ null,
+ null,
+ null,
+ 1,
+ 75,
+ null,
+ null,
+ 1,
+ 52,
+ null,
+ null,
+ 1,
+ 2,
+ null,
+ null,
+ null,
+ 1,
+ 8,
+ 8,
+ 224,
+ null,
+ null,
+ null,
+ 1,
+ 0,
+ 0,
+ null,
+ null,
+ null
+ ]
+ },
+ "/Users/uttamukkoji/Documents/Ruby/contentstack-ruby/lib/contentstack/query.rb": {
+ "lines": [
+ 1,
+ null,
+ 1,
+ null,
+ 1,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ 1,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ 1,
+ 52,
+ null,
+ 52,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ 1,
+ 0,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ 1,
+ 0,
+ 0,
+ 0,
+ 0,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ 1,
+ 2,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ 1,
+ null,
+ 4,
+ null,
+ null,
+ null,
+ null,
+ 4,
+ null,
+ 4,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ 1,
+ 1,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ 1,
+ 1,
+ 1,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ 1,
+ 1,
+ 1,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ 1,
+ 1,
+ 1,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ 1,
+ 1,
+ 1,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ 1,
+ 1,
+ 1,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ 1,
+ 1,
+ 1,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ 1,
+ 1,
+ 1,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ 1,
+ 1,
+ 1,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ 1,
+ 2,
+ 2,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ 1,
+ 2,
+ 2,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ 1,
+ 1,
+ 1,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ 1,
+ 1,
+ 1,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ 1,
+ 1,
+ 1,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ 1,
+ 1,
+ 1,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ 1,
+ 8,
+ 8,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ 1,
+ 1,
+ 1,
+ 1,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ 1,
+ 1,
+ 1,
+ 1,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ 1,
+ 1,
+ 1,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ 1,
+ 3,
+ 3,
+ 1,
+ 1,
+ null,
+ 2,
+ 2,
+ null,
+ null,
+ 3,
+ 3,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ 1,
+ 3,
+ 3,
+ 1,
+ 1,
+ null,
+ 2,
+ 2,
+ null,
+ null,
+ 3,
+ 3,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ 1,
+ 3,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ 1,
+ 1,
+ 1,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ 1,
+ 1,
+ 1,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ 1,
+ 1,
+ 1,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ 1,
+ 1,
+ 1,
+ null,
+ null,
+ null,
+ null,
+ null,
+ 1,
+ 3,
+ 3,
+ 3,
+ 3,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ 1,
+ 1,
+ 1,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ 1,
+ 47,
+ 47,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ 1,
+ 0,
+ 0,
+ null,
+ null,
+ 1,
+ 1,
+ 1,
+ null,
+ 1,
+ 1,
+ 19,
+ 19,
+ 19,
+ 19,
+ null,
+ null,
+ 1,
+ 2,
+ 2,
+ 2,
+ 0,
+ null,
+ null,
+ 2,
+ 2,
+ 4,
+ 4,
+ 4,
+ null,
+ null,
+ null,
+ null,
+ 2,
+ null,
+ null,
+ null
+ ]
+ },
+ "/Users/uttamukkoji/Documents/Ruby/contentstack-ruby/lib/contentstack/entry_collection.rb": {
+ "lines": [
+ 1,
+ null,
+ 1,
+ 1,
+ 1,
+ null,
+ 1,
+ 47,
+ 258,
+ 47,
+ 47,
+ 47,
+ null,
+ null,
+ 1,
+ 0,
+ null,
+ null,
+ 1,
+ 0,
+ null,
+ null,
+ 1,
+ 0,
+ null,
+ null,
+ 1,
+ 20,
+ null,
+ null,
+ 1,
+ 16,
+ null,
+ null,
+ 1,
+ 2,
+ null,
+ null,
+ 1,
+ 1,
+ null,
+ null,
+ null
+ ]
+ },
+ "/Users/uttamukkoji/Documents/Ruby/contentstack-ruby/lib/contentstack/entry.rb": {
+ "lines": [
+ 1,
+ null,
+ 1,
+ 1,
+ 1,
+ 1,
+ 213,
+ null,
+ null,
+ 1,
+ 2,
+ 2,
+ 2,
+ null,
+ null,
+ 1,
+ 2,
+ 2,
+ null,
+ null,
+ 1,
+ 1,
+ 215,
+ 215,
+ 215,
+ 215,
+ null,
+ null,
+ null
+ ]
+ },
+ "/Users/uttamukkoji/Documents/Ruby/contentstack-ruby/lib/contentstack/asset_collection.rb": {
+ "lines": [
+ 1,
+ null,
+ 1,
+ null,
+ 1,
+ 1,
+ null,
+ 1,
+ 4,
+ 2,
+ 2,
+ null,
+ 6,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ 1,
+ 2,
+ 2,
+ null,
+ null,
+ null
+ ]
+ },
+ "/Users/uttamukkoji/Documents/Ruby/contentstack-ruby/lib/contentstack/asset.rb": {
+ "lines": [
+ 1,
+ null,
+ null,
+ 1,
+ 1,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ 1,
+ 18,
+ 7,
+ null,
+ 11,
+ 11,
+ 11,
+ 11,
+ 11,
+ 11,
+ 11,
+ null,
+ null,
+ 18,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ 1,
+ 7,
+ null,
+ 7,
+ null,
+ null,
+ null
+ ]
+ },
+ "/Users/uttamukkoji/Documents/Ruby/contentstack-ruby/lib/contentstack/region.rb": {
+ "lines": [
+ 1,
+ 1,
+ 1,
+ 1,
+ null,
+ null
+ ]
+ },
+ "/Users/uttamukkoji/Documents/Ruby/contentstack-ruby/lib/util.rb": {
+ "lines": [
+ 1,
+ 1,
+ 72,
+ 323,
+ null,
+ null,
+ null,
+ 1,
+ 3056,
+ 3056,
+ 15692,
+ 3118,
+ null,
+ 12574,
+ null,
+ null,
+ 3056,
+ null,
+ null,
+ null,
+ 1,
+ 1,
+ 10,
+ 21,
+ null,
+ null,
+ 1,
+ 1250,
+ 1007,
+ 801,
+ null,
+ 206,
+ null,
+ null,
+ null,
+ null,
+ null,
+ 1,
+ 1,
+ 172,
+ 172,
+ null,
+ null,
+ 1,
+ 183,
+ null,
+ null,
+ null,
+ 1,
+ 1,
+ 0,
+ null,
+ null,
+ 1,
+ 307,
+ null,
+ null,
+ null,
+ 1,
+ 1,
+ 64,
+ null,
+ null,
+ 1,
+ 0,
+ null,
+ null,
+ null,
+ 1,
+ 1,
+ 0,
+ null,
+ null,
+ 1,
+ 12,
+ null,
+ null,
+ null,
+ 1,
+ 1,
+ 0,
+ null,
+ null,
+ 1,
+ 39,
+ null,
+ null,
+ null,
+ 1,
+ 1,
+ 0,
+ null,
+ null,
+ 1,
+ 95,
+ null,
+ null,
+ null,
+ 1,
+ 1,
+ 0,
+ null,
+ null,
+ 1,
+ 0,
+ null,
+ null
+ ]
+ },
+ "/Users/uttamukkoji/Documents/Ruby/contentstack-ruby/spec/asset_spec.rb": {
+ "lines": [
+ 1,
+ 1,
+ null,
+ 1,
+ 8,
+ null,
+ 1,
+ 1,
+ 1,
+ 1,
+ null,
+ null,
+ 1,
+ 1,
+ 1,
+ 1,
+ null,
+ null,
+ 1,
+ 1,
+ 1,
+ 1,
+ null,
+ null,
+ 1,
+ 1,
+ 1,
+ 1,
+ null,
+ null,
+ 1,
+ 1,
+ 1,
+ 1,
+ null,
+ null,
+ 1,
+ 1,
+ 1,
+ 1,
+ null,
+ null,
+ 1,
+ 1,
+ 1,
+ 1,
+ null,
+ null
+ ]
+ },
+ "/Users/uttamukkoji/Documents/Ruby/contentstack-ruby/spec/content_type_spec.rb": {
+ "lines": [
+ 1,
+ 1,
+ null,
+ 1,
+ 7,
+ 2,
+ 2,
+ null,
+ 1,
+ 1,
+ 1,
+ 1,
+ null,
+ null,
+ 1,
+ 1,
+ 1,
+ null,
+ null,
+ 1,
+ 1,
+ 1,
+ null,
+ null,
+ 1,
+ 1,
+ 1,
+ null,
+ null,
+ 1,
+ 1,
+ 1,
+ null,
+ null,
+ 1,
+ 1,
+ 1,
+ null,
+ null,
+ 1,
+ 1,
+ 1,
+ null,
+ null,
+ 1,
+ 1,
+ 1,
+ null,
+ null,
+ null,
+ 1,
+ 1,
+ 5,
+ null,
+ null,
+ 1,
+ 1,
+ null,
+ null,
+ 1,
+ 1,
+ null,
+ null,
+ 1,
+ 1,
+ null,
+ null,
+ 1,
+ 1,
+ null,
+ null,
+ 1,
+ 1,
+ null,
+ null,
+ null
+ ]
+ },
+ "/Users/uttamukkoji/Documents/Ruby/contentstack-ruby/spec/contentstack_spec.rb": {
+ "lines": [
+ 1,
+ 1,
+ null,
+ 1,
+ 2,
+ 2,
+ 2,
+ null,
+ 1,
+ 1,
+ null,
+ null,
+ 1,
+ 1,
+ 1,
+ null,
+ null,
+ 1,
+ 1,
+ 1,
+ null,
+ null,
+ 1,
+ 1,
+ 1,
+ null,
+ null,
+ 1,
+ 1,
+ null,
+ null,
+ null
+ ]
+ },
+ "/Users/uttamukkoji/Documents/Ruby/contentstack-ruby/spec/entry_collection_spec.rb": {
+ "lines": [
+ 1,
+ 1,
+ null,
+ 1,
+ 7,
+ null,
+ 1,
+ 1,
+ 1,
+ 1,
+ null,
+ null,
+ 1,
+ 1,
+ 1,
+ 1,
+ null,
+ null,
+ 1,
+ 1,
+ 1,
+ 1,
+ null,
+ null,
+ 1,
+ 1,
+ 1,
+ 1,
+ null,
+ null,
+ 1,
+ 1,
+ 1,
+ 1,
+ null,
+ null,
+ 1,
+ 1,
+ 1,
+ 1,
+ null,
+ null
+ ]
+ },
+ "/Users/uttamukkoji/Documents/Ruby/contentstack-ruby/spec/entry_spec.rb": {
+ "lines": [
+ 1,
+ 1,
+ null,
+ 1,
+ 4,
+ null,
+ 1,
+ 1,
+ 1,
+ 1,
+ null,
+ null,
+ 1,
+ 1,
+ 1,
+ null,
+ null,
+ 1,
+ 1,
+ 1,
+ 1,
+ null,
+ null
+ ]
+ },
+ "/Users/uttamukkoji/Documents/Ruby/contentstack-ruby/spec/query_spec.rb": {
+ "lines": [
+ 1,
+ 1,
+ null,
+ 1,
+ 36,
+ 23,
+ 14,
+ null,
+ 1,
+ 1,
+ 1,
+ null,
+ null,
+ 1,
+ 1,
+ 1,
+ null,
+ null,
+ 1,
+ 1,
+ 1,
+ null,
+ null,
+ 1,
+ 1,
+ 1,
+ null,
+ null,
+ 1,
+ 1,
+ 1,
+ null,
+ null,
+ 1,
+ 1,
+ 1,
+ null,
+ null,
+ 1,
+ 1,
+ 1,
+ null,
+ null,
+ 1,
+ 1,
+ 1,
+ null,
+ null,
+ 1,
+ 1,
+ 1,
+ null,
+ null,
+ 1,
+ 1,
+ 1,
+ 1,
+ null,
+ null,
+ 1,
+ 1,
+ 1,
+ 1,
+ null,
+ null,
+ 1,
+ 1,
+ 1,
+ 1,
+ null,
+ null,
+ 1,
+ 1,
+ 1,
+ null,
+ null,
+ 1,
+ 1,
+ 1,
+ null,
+ null,
+ 1,
+ 1,
+ 1,
+ null,
+ null,
+ 1,
+ 1,
+ 1,
+ 1,
+ 1,
+ null,
+ null,
+ 1,
+ 1,
+ 1,
+ null,
+ null,
+ 1,
+ 1,
+ 1,
+ null,
+ null,
+ 1,
+ 1,
+ 1,
+ null,
+ null,
+ 1,
+ 1,
+ 1,
+ null,
+ null,
+ 1,
+ 1,
+ 1,
+ null,
+ null,
+ 1,
+ 1,
+ 1,
+ null,
+ null,
+ 1,
+ 1,
+ 1,
+ null,
+ null,
+ 1,
+ 1,
+ 1,
+ null,
+ null,
+ 1,
+ 1,
+ 1,
+ null,
+ null,
+ 1,
+ 1,
+ 1,
+ 1,
+ null,
+ null,
+ 1,
+ 1,
+ 1,
+ null,
+ null,
+ 1,
+ 1,
+ 1,
+ null,
+ null,
+ 1,
+ 1,
+ 1,
+ null,
+ null,
+ 1,
+ 1,
+ 1,
+ null,
+ null,
+ 1,
+ 1,
+ 1,
+ null,
+ null,
+ 1,
+ 1,
+ 1,
+ null,
+ null,
+ 1,
+ 1,
+ 1,
+ 1,
+ 1,
+ null,
+ null,
+ 1,
+ 1,
+ 1,
+ 1,
+ 1,
+ null,
+ null,
+ 1,
+ 1,
+ 1,
+ null,
+ null
+ ]
+ }
},
- "timestamp": 1566976586
+ "timestamp": 1588167070
}
}
diff --git a/coverage/index.html b/coverage/index.html
index 4255392..89a4dc1 100644
--- a/coverage/index.html
+++ b/coverage/index.html
@@ -3,9399 +3,17087 @@
Code coverage for Contentstack-ruby
-
-
-
-
+
+
+
+
-
+
-
+
-
-
Generated
2019-08-28T12:46:26+05:30
+
+
Generated
2020-04-29T19:01:10+05:30
All Files
- (96.63%
+ (
+
+ 96.65%
+
+
+
covered at
- 81.16
+ 79.19
- hits/line)
+ hits/line
+ )
+
+
18 files in total.
- 624 relevant lines.
- 603 lines covered and
- 21 lines missed
-
+
+
+ 627 relevant lines,
+ 606 lines covered and
+ 21 lines missed.
+ (
+ 96.65%
+
+)
+
+
+
+
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
+
-
-
-
-
-
+
+
+
+
+
-
- 1
-
- def content_type(uid)
-
-
-
- 54
-
- ContentType.new({uid: uid})
-
-
-
-
-
- end
-
-
-
-
-
-
-
-
-
- 1
-
- def assets
-
-
-
- 2
-
- AssetCollection.new
-
-
-
-
-
- end
-
-
-
-
-
-
-
-
-
- 1
-
- def asset(uid)
-
-
-
- 7
-
- Asset.new(uid)
-
-
-
-
-
- end
-
-
-
-
-
-
-
-
-
- 1
-
- private
-
-
-
- 1
-
- def get_default_region_hosts(region='us')
-
-
-
- 62
-
- case region
-
-
-
-
-
- when "us"
-
-
-
- 60
-
- host = "https://cdn.contentstack.io"
-
-
-
-
-
- when "eu"
-
-
-
- 2
-
- host = "https://eu-cdn.contentstack.com"
-
-
-
-
-
- end
-
-
-
- 62
-
- host
-
+
+
+ 1
+
+
+
+
+ require 'contentstack/query'
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 1
+
+
+
+
+ module Contentstack
+
+
+
+
+
+ 1
+
+
+
+
+ class ContentType
+
+
+
+
+
+ 1
+
+
+
+
+ [:title, :uid, :created_at, :updated_at, :attributes].each do |method_name|
+
+
+
+
+
+ 5
+
+
+
+
+ if [:created_at, :updated_at].include?(method_name)
+
+
+
+
+
+ 2
+
+
+
+
+ define_method method_name do
+
+
+
+
+
+ 8
+
+
+
+
+ return Time.parse(@attributes[method_name]) if @attributes[method_name] && !@attributes[method_name].nil?
+
+
+
+
+
+
+
+
+
+
+ end
+
+
+
+
+
+ 3
+
+
+
+
+ elsif :attributes == method_name
+
+
+
+
+
+ 1
+
+
+
+
+ define_method :attributes do
+
+
+
+
+
+
+
+
+
+
+ {
+
+
+
+
+
+ 2
+
+
+
+
+ title: self.title,
+
+
+
+
+
+
+
+
+
+
+ uid: self.uid,
+
+
+
+
+
+
+
+
+
+
+ created_at: self.created_at,
+
+
+
+
+
+
+
+
+
+
+ updated_at: self.updated_at,
+
+
+
+
+
+
+
+
+
+
+ schema: @attributes[:schema]
+
+
+
+
+
+
+
+
+
+
+ }
+
+
+
+
+
+
+
+
+
+
+ end
+
+
+
+
+
+
+
+
+
+
+ else
+
+
+
+
+
+ 2
+
+
+
+
+ define_method method_name do
+
+
+
+
+
+ 64
+
+
+
+
+ return @attributes[method_name]
+
+
+
+
+
+
+
+
+
+
+ end
+
+
+
+
+
+
+
+
+
+
+ end
+
+
+
+
+
+
+
+
+
+
+ end
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 1
+
+
+
+
+ def initialize(object)
+
+
+
+
+
+ 75
+
+
+
+
+ @attributes = object.symbolize_keys
+
+
+
+
+
+
+
+
+
+
+ end
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 1
+
+
+
+
+ def query
+
+
+
+
+
+ 52
+
+
+
+
+ Query.new(self.uid)
+
+
+
+
+
+
+
+
+
+
+ end
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 1
+
+
+
+
+ def entry(entry_uid)
+
+
+
+
+
+ 2
+
+
+
+
+ Entry.new({uid: entry_uid}, self.uid)
+
+
+
+
+
+
+
+
+
+
+ end
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 1
+
+
+
+
+ def self.all
+
+
+
+
+
+ 8
+
+
+
+
+ content_types = API.fetch_content_types["content_types"]
+
+
+
+
+
+ 8
+
+
+
+
+ content_types.map do |content_type|
+
+
+
+
+
+ 224
+
+
+
+
+ ContentType.new(content_type.inject({}){|clone,(k,v)| clone[k.to_sym] = v; clone})
+
+
+
+
+
+
+
+
+
+
+ end
+
+
+
+
+
+
+
+
+
+
+ end
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 1
+
+
+
+
+ def self.find_by_uid(uid)
+
+
+
+
+
+
+
+
+
+
+ content_type = API.fetch_content_types(uid)["content_type"]
+
+
+
+
+
+
+
+
+
+
+ ContentType.new(content_type.inject({}){|clone,(k,v)| clone[k.to_sym] = v; clone})
+
+
+
+
+
+
+
+
+
+
+ end
+
+
+
+
+
+
+
+
+
+
+ end
+
+
+
+
+
+
+
+
+
+
+ end
+
+
-
-
-
- end
-
+
+
+
+
-
-
-
- end
-
+
+
+
+
+
-
-
-
- end
-
+
+
+ 1
+
+
+
+
+ require 'active_support/core_ext'
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 1
+
+
+
+
+ module Contentstack
+
+
+
+
+
+ 1
+
+
+
+
+ class Entry
+
+
+
+
+
+ 1
+
+
+
+
+ attr_reader :fields, :content_type, :uid, :owner
+
+
+
+
+
+ 1
+
+
+
+
+ def initialize(attrs, content_type_uid=nil)
+
+
+
+
+
+ 213
+
+
+
+
+ setup(attrs, content_type_uid)
+
+
+
+
+
+
+
+
+
+
+ end
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 1
+
+
+
+
+ def fetch
+
+
+
+
+
+ 2
+
+
+
+
+ entry = API.fetch_entry(@content_type, self.fields[:uid])
+
+
+
+
+
+ 2
+
+
+
+
+ setup(entry["entry"])
+
+
+
+
+
+ 2
+
+
+
+
+ self
+
+
+
+
+
+
+
+
+
+
+ end
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 1
+
+
+
+
+ def get(field_uid)
+
+
+
+
+
+ 2
+
+
+
+
+ raise Contentstack::Error("Please send a valid Field UID") if field_uid.class != String
+
+
+
+
+
+ 2
+
+
+
+
+ @fields[field_uid.to_sym]
+
+
+
+
+
+
+
+
+
+
+ end
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 1
+
+
+
+
+ private
+
+
+
+
+
+ 1
+
+
+
+
+ def setup(attrs, content_type_uid=nil)
+
+
+
+
+
+ 215
+
+
+
+
+ @fields = attrs.symbolize_keys
+
+
+
+
+
+ 215
+
+
+
+
+ @content_type = content_type_uid if !content_type_uid.blank?
+
+
+
+
+
+ 215
+
+
+
+
+ @owner = attrs[:_owner] if attrs[:_owner]
+
+
+
+
+
+ 215
+
+
+
+
+ @uid = attrs[:uid]
+
+
+
+
+
+
+
+
+
+
+ end
+
+
+
+
+
+
+
+
+
+
+ end
+
+
+
+
+
+
+
+
+
+
+ end
+
+
-
+
-
+
+
+
+ 1
+
-
-
-
-
-
-
-
-
- 1
-
- require 'contentstack/entry'
-
-
-
-
-
-
-
-
-
- 1
-
- module Contentstack
-
-
-
- 1
-
- class EntryCollection
-
-
-
- 1
-
- attr_reader :entries, :count, :content_type, :schema
-
-
-
-
-
-
-
-
-
- 1
-
- def initialize(json, content_type_uid=nil)
-
-
-
- 47
-
- @count = json["count"] if json["count"]
-
-
-
- 258
-
- @entries = json["entries"].collect{|entry| Entry.new(entry, content_type_uid) }
-
-
-
- 47
-
- @schema = json["schema"].symbolize_keys if json["schema"]
-
-
-
- 47
-
- @content_type = json["content_type"].symbolize_keys if json["content_type"]
-
-
-
- 47
-
- self
-
-
-
-
-
- end
-
-
-
-
-
-
-
-
-
- 1
-
- def each &block
-
-
-
-
-
- @entries.map{|e| block.call(e)}
-
-
-
-
-
- end
-
-
-
-
-
-
-
-
-
- 1
-
- def map &block
-
-
-
-
-
- self.each(&block)
-
-
-
-
-
- end
-
-
-
-
-
-
-
-
-
- 1
-
- def collect &block
-
-
-
-
-
- self.each(&block)
-
-
-
-
-
- end
-
-
-
-
-
-
-
-
-
- 1
-
- def length
-
-
-
- 20
-
- @entries.length
-
-
-
-
-
- end
-
-
-
-
-
-
-
-
-
- 1
-
- def first
-
-
-
- 16
-
- @entries.first
-
-
-
-
-
- end
-
-
-
-
-
-
-
-
-
- 1
-
- def last
-
-
-
- 2
-
- @entries.last
-
-
-
-
-
- end
-
-
-
-
-
-
-
-
-
- 1
-
- def get(index)
-
-
-
- 1
-
- @entries[index]
-
-
-
-
-
- end
-
-
-
-
-
- end
-
-
-
-
-
- end
-
-
-
-
-
+
+ require 'contentstack/entry_collection'
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 1
+
+
+
+
+ module Contentstack
+
+
+
+
+
+
+
+
+
+
+ # A class that defines a query that is used to query for Entry instance.
+
+
+
+
+
+ 1
+
+
+
+
+ class Query
+
+
+
+
+
+
+
+
+
+
+ # @!attribute [r] query
+
+
+
+
+
+
+
+
+
+
+ # Attribute which has all the information about the query which will be executed against Contentstack API
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ # @!attribute [r] content_type
+
+
+
+
+
+
+
+
+
+
+ # Denotes which `content_type` should the query be executed for
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 1
+
+
+
+
+ attr_reader :query, :content_type
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ # Initialize the Query instance
+
+
+
+
+
+
+
+
+
+
+ # @param [String] content_type
+
+
+
+
+
+
+
+
+
+
+ #
+
+
+
+
+
+
+
+
+
+
+ # Example:
+
+
+
+
+
+
+
+
+
+
+ # @query = @stack.content_type('blog').query
+
+
+
+
+
+
+
+
+
+
+ # @entries = @query.where('author', 'John Doe').fetch
+
+
+
+
+
+
+
+
+
+
+ #
+
+
+
+
+
+
+
+
+
+
+ # @return [Contentstack::Query]
+
+
+
+
+
+ 1
+
+
+
+
+ def initialize(content_type)
+
+
+
+
+
+ 52
+
+
+
+
+ @content_type = content_type
+
+
+
+
+
+
+
+
+
+
+ @query = {
+
+
+
+
+
+ 52
+
+
+
+
+ query: "{}",
+
+
+
+
+
+
+
+
+
+
+ include_count: false,
+
+
+
+
+
+
+
+
+
+
+ skip: 0,
+
+
+
+
+
+
+
+
+
+
+ count: 10,
+
+
+
+
+
+
+
+
+
+
+ desc: 'created_at'
+
+
+
+
+
+
+
+
+
+
+ }
+
+
+
+
+
+
+
+
+
+
+ end
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ # Add a custom query against specified key.
+
+
+
+
+
+
+
+
+
+
+ # @param [String] field_uid
+
+
+
+
+
+
+
+
+
+
+ # @param [String/Number/Boolean/Hash] value
+
+
+
+
+
+
+
+
+
+
+ #
+
+
+
+
+
+
+
+
+
+
+ # Example:
+
+
+
+
+
+
+
+
+
+
+ # @query = @stack.content_type('blog').query
+
+
+
+
+
+
+
+
+
+
+ # @query.add_query('author', "Jane Doe")
+
+
+
+
+
+
+
+
+
+
+ #
+
+
+
+
+
+
+
+
+
+
+ # @return [Contentstack::Query]
+
+
+
+
+
+ 1
+
+
+
+
+ def add_query(field_uid, value)
+
+
+
+
+
+
+
+
+
+
+ add_query_hash({:"#{field_uid}" => value})
+
+
+
+
+
+
+
+
+
+
+ end
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ # Remove provided query key from custom query if exist.
+
+
+
+
+
+
+
+
+
+
+ # @param [String] field_uid
+
+
+
+
+
+
+
+
+
+
+ #
+
+
+
+
+
+
+
+
+
+
+ # Example:
+
+
+
+
+
+
+
+
+
+
+ # @query = @stack.content_type('blog').query
+
+
+
+
+
+
+
+
+
+
+ # @query.remove_query('author')
+
+
+
+
+
+
+
+
+
+
+ #
+
+
+
+
+
+
+
+
+
+
+ # @return [Contentstack::Query]
+
+
+
+
+
+ 1
+
+
+
+
+ def remove_query(field_uid)
+
+
+
+
+
+
+
+
+
+
+ q = ActiveSupport::JSON.decode(@query[:query])
+
+
+
+
+
+
+
+
+
+
+ q.delete(field_uid)
+
+
+
+
+
+
+
+
+
+
+ @query[:query] = ActiveSupport::JSON.encode(q)
+
+
+
+
+
+
+
+
+
+
+ self
+
+
+
+
+
+
+
+
+
+
+ end
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ # Add a constraint to fetch all entries that contains given value against specified key.
+
+
+
+
+
+
+
+
+
+
+ # @param [Hash] query_hash
+
+
+
+
+
+
+
+
+
+
+ #
+
+
+
+
+
+
+
+
+
+
+ # Example:
+
+
+
+
+
+
+
+
+
+
+ # @query = @stack.content_type('blog').query
+
+
+
+
+
+
+
+
+
+
+ # @query.where({:author => "Jane Doe"})
+
+
+
+
+
+
+
+
+
+
+ #
+
+
+
+
+
+
+
+
+
+
+ # @return [Contentstack::Query]
+
+
+
+
+
+ 1
+
+
+
+
+ def where(query_hash)
+
+
+
+
+
+ 2
+
+
+
+
+ add_query_hash(query_hash)
+
+
+
+
+
+
+
+
+
+
+ end
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ # Add a regular expression constraint for finding string values that match the provided regular expression. This may be slow for large data sets.
+
+
+
+
+
+
+
+
+
+
+ # @param [String] field_uid The key to be constrained.
+
+
+
+
+
+
+
+
+
+
+ # @param [String] pattern The regular expression pattern to match.
+
+
+
+
+
+
+
+
+
+
+ # @param [String] options Regex options
+
+
+
+
+
+
+
+
+
+
+ #
+
+
+
+
+
+
+
+
+
+
+ # Example:
+
+
+
+
+
+
+
+
+
+
+ # @query = @stack.content_type('product').query
+
+
+
+
+
+
+
+
+
+
+ # @query.regex('title', '.*Mobile.*', 'i') # Search without case sensitivity
+
+
+
+
+
+
+
+
+
+
+ #
+
+
+
+
+
+
+
+
+
+
+ # @return [Contentstack::Query]
+
+
+
+
+
+ 1
+
+
+
+
+ def regex(field_uid, pattern, options="")
+
+
+
+
+
+
+
+
+
+
+ hash = {
+
+
+
+
+
+ 4
+
+
+
+
+ "#{field_uid}" => {
+
+
+
+
+
+
+
+
+
+
+ "$regex": pattern
+
+
+
+
+
+
+
+
+
+
+ }
+
+
+
+
+
+
+
+
+
+
+ }
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 4
+
+
+
+
+ hash["#{field_uid}"]["$options"] = options if !options.empty? || !options.nil?
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 4
+
+
+
+
+ add_query_hash(hash)
+
+
+
+
+
+
+
+
+
+
+ end
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ # Add a constraint that requires, a specified key exists in response.
+
+
+
+
+
+
+
+
+
+
+ # @param [String] field_uid The key to be constrained.
+
+
+
+
+
+
+
+
+
+
+ #
+
+
+
+
+
+
+
+
+
+
+ # Example:
+
+
+
+
+
+
+
+
+
+
+ # @query = @stack.content_type('product').query
+
+
+
+
+
+
+
+
+
+
+ # @query.exists?('product_image') # only fetch products which have a `product_image`
+
+
+
+
+
+
+
+
+
+
+ #
+
+
+
+
+
+
+
+
+
+
+ # @return [Contentstack::Query]
+
+
+
+
+
+ 1
+
+
+
+
+ def exists?(field_uid)
+
+
+
+
+
+ 1
+
+
+
+
+ add_query_hash({:"#{field_uid}" => {"$exists" => true}})
+
+
+
+
+
+
+
+
+
+
+ end
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ # Add a constraint that requires, a specified key does not exists in response.
+
+
+
+
+
+
+
+
+
+
+ # @param [String] field_uid The key to be constrained.
+
+
+
+
+
+
+
+
+
+
+ #
+
+
+
+
+
+
+
+
+
+
+ # Example:
+
+
+
+
+
+
+
+
+
+
+ # @query = @stack.content_type('product').query
+
+
+
+
+
+
+
+
+
+
+ # @query.not_exists?('product_image') # only fetch products which do not have a `product_image`
+
+
+
+
+
+
+
+
+
+
+ #
+
+
+
+
+
+
+
+
+
+
+ # @return [Contentstack::Query]
+
+
+
+
+
+ 1
+
+
+
+
+ def not_exists?(field_uid)
+
+
+
+
+
+ 1
+
+
+
+
+ add_query_hash({:"#{field_uid}" => {"$exists" => false}})
+
+
+
+
+
+ 1
+
+
+
+
+ self
+
+
+
+
+
+
+
+
+
+
+ end
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ # Combines all the queries together using AND operator.
+
+
+
+
+
+
+
+
+
+
+ #
+
+
+
+
+
+
+
+
+
+
+ # @param [Array] queries Array of instances of the Query class
+
+
+
+
+
+
+
+
+
+
+ #
+
+
+
+
+
+
+
+
+
+
+ # Each query should be an instance of the Contentstack::Query class, and belong to the same `content_type`
+
+
+
+
+
+
+
+
+
+
+ # Example:
+
+
+
+
+
+
+
+
+
+
+ # @query1 = @stack.content_type('category').query
+
+
+
+
+
+
+
+
+
+
+ # @query1.where('title', 'Electronics')
+
+
+
+
+
+
+
+
+
+
+ #
+
+
+
+
+
+
+
+
+
+
+ # @query2 = @stack.content_type('category').query
+
+
+
+
+
+
+
+
+
+
+ # @query2.regex('description', '.*Electronics.*')
+
+
+
+
+
+
+
+
+
+
+ #
+
+
+
+
+
+
+
+
+
+
+ # query_array = [@query1, @query2]
+
+
+
+
+
+
+
+
+
+
+ #
+
+
+
+
+
+
+
+
+
+
+ # @query = @stack.content_type('category').query
+
+
+
+
+
+
+
+
+
+
+ # @query.and(query_array)
+
+
+
+
+
+
+
+
+
+
+ #
+
+
+
+
+
+
+
+
+
+
+ # @return [Contentstack::Query]
+
+
+
+
+
+ 1
+
+
+
+
+ def and(queries)
+
+
+
+
+
+ 1
+
+
+
+
+ add_query_hash({"$and" => concat_queries(queries)})
+
+
+
+
+
+ 1
+
+
+
+
+ self
+
+
+
+
+
+
+
+
+
+
+ end
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ # Combines all the queries together using OR operator.
+
+
+
+
+
+
+
+
+
+
+ #
+
+
+
+
+
+
+
+
+
+
+ # @param [Array] queries Array of instances of the Query class
+
+
+
+
+
+
+
+
+
+
+ #
+
+
+
+
+
+
+
+
+
+
+ # Each query should be an instance of the Contentstack::Query class, and belong to the same `content_type`
+
+
+
+
+
+
+
+
+
+
+ # Example:
+
+
+
+
+
+
+
+
+
+
+ # @query1 = @stack.content_type('category').query
+
+
+
+
+
+
+
+
+
+
+ # @query1.where('title', 'Electronics')
+
+
+
+
+
+
+
+
+
+
+ #
+
+
+
+
+
+
+
+
+
+
+ # @query2 = @stack.content_type('category').query
+
+
+
+
+
+
+
+
+
+
+ # @query2.where('title', 'Apparel')
+
+
+
+
+
+
+
+
+
+
+ #
+
+
+
+
+
+
+
+
+
+
+ # query_array = [@query1, @query2]
+
+
+
+
+
+
+
+
+
+
+ #
+
+
+
+
+
+
+
+
+
+
+ # @query = @stack.content_type('category').query
+
+
+
+
+
+
+
+
+
+
+ # @query.or(query_array)
+
+
+
+
+
+
+
+
+
+
+ #
+
+
+
+
+
+
+
+
+
+
+ # @return [Contentstack::Query]
+
+
+
+
+
+ 1
+
+
+
+
+ def or(queries)
+
+
+
+
+
+ 1
+
+
+
+
+ add_query_hash({"$or" => concat_queries(queries)})
+
+
+
+
+
+ 1
+
+
+
+
+ self
+
+
+
+
+
+
+
+
+
+
+ end
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ # Add a constraint to the query that requires a particular key entry to be less than the provided value.
+
+
+
+
+
+
+
+
+
+
+ #
+
+
+
+
+
+
+
+
+
+
+ # @param [String] field_uid UID of the field for which query should be executed
+
+
+
+
+
+
+
+
+
+
+ #
+
+
+
+
+
+
+
+
+
+
+ # @param [String/Number] value Value that provides an upper bound
+
+
+
+
+
+
+
+
+
+
+ #
+
+
+
+
+
+
+
+
+
+
+ # Example
+
+
+
+
+
+
+
+
+
+
+ # @query = @stack.content_type('product').query
+
+
+
+
+
+
+
+
+
+
+ # @query.less_than('price', '100')
+
+
+
+
+
+
+
+
+
+
+ #
+
+
+
+
+
+
+
+
+
+
+ # @return [Contentstack::Query]
+
+
+
+
+
+ 1
+
+
+
+
+ def less_than(field_uid, value)
+
+
+
+
+
+ 1
+
+
+
+
+ add_query_hash({:"#{field_uid}" => {"$lt" => value}})
+
+
+
+
+
+ 1
+
+
+
+
+ self
+
+
+
+
+
+
+
+
+
+
+ end
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ # Add a constraint to the query that requires a particular key entry to be less than or equal to the provided value.
+
+
+
+
+
+
+
+
+
+
+ #
+
+
+
+
+
+
+
+
+
+
+ # @param [String] field_uid UID of the field for which query should be executed
+
+
+
+
+
+
+
+
+
+
+ #
+
+
+
+
+
+
+
+
+
+
+ # @param [String/Number] value Value that provides an upper bound
+
+
+
+
+
+
+
+
+
+
+ #
+
+
+
+
+
+
+
+
+
+
+ # Example
+
+
+
+
+
+
+
+
+
+
+ # @query = @stack.content_type('product').query
+
+
+
+
+
+
+
+
+
+
+ # @query.less_than_or_equal('price', '100')
+
+
+
+
+
+
+
+
+
+
+ #
+
+
+
+
+
+
+
+
+
+
+ # @return [Contentstack::Query]
+
+
+
+
+
+ 1
+
+
+
+
+ def less_than_or_equal(field_uid, value)
+
+
+
+
+
+ 1
+
+
+
+
+ add_query_hash({:"#{field_uid}" => {"$lte" => value}})
+
+
+
+
+
+ 1
+
+
+
+
+ self
+
+
+
+
+
+
+
+
+
+
+ end
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ # Add a constraint to the query that requires a particular key entry to be greater than the provided value.
+
+
+
+
+
+
+
+
+
+
+ #
+
+
+
+
+
+
+
+
+
+
+ # @param [String] field_uid UID of the field for which query should be executed
+
+
+
+
+
+
+
+
+
+
+ #
+
+
+
+
+
+
+
+
+
+
+ # @param [String/Number] value Value that provides a lower bound
+
+
+
+
+
+
+
+
+
+
+ #
+
+
+
+
+
+
+
+
+
+
+ # Example
+
+
+
+
+
+
+
+
+
+
+ # @query = @stack.content_type('product').query
+
+
+
+
+
+
+
+
+
+
+ # @query.greater_than('price', '100')
+
+
+
+
+
+
+
+
+
+
+ #
+
+
+
+
+
+
+
+
+
+
+ # @return [Contentstack::Query]
+
+
+
+
+
+ 1
+
+
+
+
+ def greater_than(field_uid, value)
+
+
+
+
+
+ 1
+
+
+
+
+ add_query_hash({:"#{field_uid}" => {"$gt" => value}})
+
+
+
+
+
+ 1
+
+
+
+
+ self
+
+
+
+
+
+
+
+
+
+
+ end
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ # Add a constraint to the query that requires a particular key entry to be greater than or equal to the provided value.
+
+
+
+
+
+
+
+
+
+
+ #
+
+
+
+
+
+
+
+
+
+
+ # @param [String] field_uid UID of the field for which query should be executed
+
+
+
+
+
+
+
+
+
+
+ #
+
+
+
+
+
+
+
+
+
+
+ # @param [String/Number] value Value that provides a lower bound
+
+
+
+
+
+
+
+
+
+
+ #
+
+
+
+
+
+
+
+
+
+
+ # Example
+
+
+
+
+
+
+
+
+
+
+ # @query = @stack.content_type('product').query
+
+
+
+
+
+
+
+
+
+
+ # @query.greater_than_or_equal('price', '100')
+
+
+
+
+
+
+
+
+
+
+ #
+
+
+
+
+
+
+
+
+
+
+ # @return [Contentstack::Query]
+
+
+
+
+
+ 1
+
+
+
+
+ def greater_than_or_equal(field_uid, value)
+
+
+
+
+
+ 1
+
+
+
+
+ add_query_hash({:"#{field_uid}" => {"$gte" => value}})
+
+
+
+
+
+ 1
+
+
+
+
+ self
+
+
+
+
+
+
+
+
+
+
+ end
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ # Add a constraint to the query that requires a particular key's entry to be not equal to the provided value.
+
+
+
+
+
+
+
+
+
+
+ #
+
+
+
+
+
+
+
+
+
+
+ # @param [String] field_uid UID of the field for which query should be executed
+
+
+
+
+
+
+
+
+
+
+ # @param [String] value The object that must not be equaled.
+
+
+
+
+
+
+
+
+
+
+ #
+
+
+
+
+
+
+
+
+
+
+ # Example
+
+
+
+
+
+
+
+
+
+
+ # @query = @stack.content_type('product').query
+
+
+
+
+
+
+
+
+
+
+ # @query.not_equal_to('price', '100')
+
+
+
+
+
+
+
+
+
+
+ #
+
+
+
+
+
+
+
+
+
+
+ # @return [Contentstack::Query]
+
+
+
+
+
+ 1
+
+
+
+
+ def not_equal_to(field_uid, value)
+
+
+
+
+
+ 1
+
+
+
+
+ add_query_hash({:"#{field_uid}" => {"$ne" => value}})
+
+
+
+
+
+ 1
+
+
+
+
+ self
+
+
+
+
+
+
+
+
+
+
+ end
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ # Add a constraint to the query that requires a particular key's entry to be contained in the provided array.
+
+
+
+
+
+
+
+
+
+
+ #
+
+
+
+
+
+
+
+
+
+
+ # @param [String] field_uid UID of the field for which query should be executed
+
+
+
+
+
+
+
+
+
+
+ # @param [String] values The possible values for the key's object
+
+
+
+
+
+
+
+
+
+
+ #
+
+
+
+
+
+
+
+
+
+
+ # Example
+
+
+
+
+
+
+
+
+
+
+ # @query = @stack.content_type('category').query
+
+
+
+
+
+
+
+
+
+
+ # @query.contained_in("title", ["Electronics", "Apparel"])
+
+
+
+
+
+
+
+
+
+
+ #
+
+
+
+
+
+
+
+
+
+
+ # @return [Contentstack::Query]
+
+
+
+
+
+ 1
+
+
+
+
+ def contained_in(field_uid, values)
+
+
+
+
+
+ 2
+
+
+
+
+ add_query_hash({:"#{field_uid}" => {"$in" => values}})
+
+
+
+
+
+ 2
+
+
+
+
+ self
+
+
+
+
+
+
+
+
+
+
+ end
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ # Add a constraint to the query that requires a particular key entry's value not be contained in the provided array.
+
+
+
+
+
+
+
+
+
+
+ #
+
+
+
+
+
+
+
+
+
+
+ # @param [String] field_uid UID of the field for which query should be executed
+
+
+
+
+
+
+
+
+
+
+ # @param [String] values The possible values for the key's object
+
+
+
+
+
+
+
+
+
+
+ #
+
+
+
+
+
+
+
+
+
+
+ # Example
+
+
+
+
+
+
+
+
+
+
+ # @query = @stack.content_type('category').query
+
+
+
+
+
+
+
+
+
+
+ # @query.not_contained_in("title", ["Electronics", "Apparel"])
+
+
+
+
+
+
+
+
+
+
+ #
+
+
+
+
+
+
+
+
+
+
+ # @return [Contentstack::Query]
+
+
+
+
+
+ 1
+
+
+
+
+ def not_contained_in(field_uid, values)
+
+
+
+
+
+ 2
+
+
+
+
+ add_query_hash({:"#{field_uid}" => {"$nin" => values}})
+
+
+
+
+
+ 2
+
+
+
+
+ self
+
+
+
+
+
+
+
+
+
+
+ end
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ # The number of objects to skip before returning any.
+
+
+
+
+
+
+
+
+
+
+ #
+
+
+
+
+
+
+
+
+
+
+ # @param [Number] count of objects to skip from resulset.
+
+
+
+
+
+
+
+
+
+
+ #
+
+
+
+
+
+
+
+
+
+
+ # Example
+
+
+
+
+
+
+
+
+
+
+ # @query = @stack.content_type('category').query
+
+
+
+
+
+
+
+
+
+
+ # @query.skip(50)
+
+
+
+
+
+
+
+
+
+
+ #
+
+
+
+
+
+
+
+
+
+
+ # @return [Contentstack::Query]
+
+
+
+
+
+ 1
+
+
+
+
+ def skip(count)
+
+
+
+
+
+ 1
+
+
+
+
+ @query[:skip] = count
+
+
+
+
+
+ 1
+
+
+
+
+ self
+
+
+
+
+
+
+
+
+
+
+ end
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ # This method provides only the entries matching the specified value.
+
+
+
+
+
+
+
+
+
+
+ #
+
+
+
+
+
+
+
+
+
+
+ # @param [String] text value used to match or compare
+
+
+
+
+
+
+
+
+
+
+ #
+
+
+
+
+
+
+
+
+
+
+ # Example
+
+
+
+
+
+
+
+
+
+
+ # @query = @stack.content_type('product').query
+
+
+
+
+
+
+
+
+
+
+ # @query.search("This is an awesome product")
+
+
+
+
+
+
+
+
+
+
+ #
+
+
+
+
+
+
+
+
+
+
+ # @return [Contentstack::Query]
+
+
+
+
+
+ 1
+
+
+
+
+ def search(text)
+
+
+
+
+
+ 1
+
+
+
+
+ @query[:typeahead] = text
+
+
+
+
+
+ 1
+
+
+
+
+ self
+
+
+
+
+
+
+
+
+
+
+ end
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ # A limit on the number of objects to return.
+
+
+
+
+
+
+
+
+
+
+ #
+
+
+
+
+
+
+
+
+
+
+ # @param [Number] count of objects to limit in resulset.
+
+
+
+
+
+
+
+
+
+
+ #
+
+
+
+
+
+
+
+
+
+
+ # Example
+
+
+
+
+
+
+
+
+
+
+ # @query = @stack.content_type('category').query
+
+
+
+
+
+
+
+
+
+
+ # @query.limit(50)
+
+
+
+
+
+
+
+
+
+
+ #
+
+
+
+
+
+
+
+
+
+
+ # @return [Contentstack::Query]
+
+
+
+
+
+ 1
+
+
+
+
+ def limit(count=10)
+
+
+
+
+
+ 1
+
+
+
+
+ @query[:limit] = count
+
+
+
+
+
+ 1
+
+
+
+
+ self
+
+
+
+
+
+
+
+
+
+
+ end
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ # Retrieve only count of entries in result.
+
+
+
+
+
+
+
+
+
+
+ #
+
+
+
+
+
+
+
+
+
+
+ # Example
+
+
+
+
+
+
+
+
+
+
+ # @query = @stack.content_type('category').query
+
+
+
+
+
+
+
+
+
+
+ # @query.count
+
+
+
+
+
+
+
+
+
+
+ #
+
+
+
+
+
+
+
+
+
+
+ # @return [Integer]
+
+
+
+
+
+ 1
+
+
+
+
+ def count
+
+
+
+
+
+ 1
+
+
+
+
+ include_count
+
+
+
+
+
+ 1
+
+
+
+
+ fetch.count
+
+
+
+
+
+
+
+
+
+
+ end
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ # Retrieve count and data of objects in result.
+
+
+
+
+
+
+
+
+
+
+ #
+
+
+
+
+
+
+
+
+
+
+ # Example
+
+
+
+
+
+
+
+
+
+
+ # @query = @stack.content_type('category').query
+
+
+
+
+
+
+
+
+
+
+ # @query.include_count
+
+
+
+
+
+
+
+
+
+
+ #
+
+
+
+
+
+
+
+
+
+
+ # @return [Contentstack::Query]
+
+
+
+
+
+ 1
+
+
+
+
+ def include_count(flag=true)
+
+
+
+
+
+ 8
+
+
+
+
+ @query[:include_count] = flag
+
+
+
+
+
+ 8
+
+
+
+
+ self
+
+
+
+
+
+
+
+
+
+
+ end
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ # Sort the results in ascending order with the given key.
+
+
+
+
+
+
+
+
+
+
+ # Sort the returned entries in ascending order of the provided key.
+
+
+
+
+
+
+
+
+
+
+ #
+
+
+
+
+
+
+
+
+
+
+ # @param [String] field_uid The key to order by
+
+
+
+
+
+
+
+
+
+
+ #
+
+
+
+
+
+
+
+
+
+
+ # Example
+
+
+
+
+
+
+
+
+
+
+ # @query = @stack.content_type('category').query
+
+
+
+
+
+
+
+
+
+
+ # @query.ascending
+
+
+
+
+
+
+
+
+
+
+ #
+
+
+
+
+
+
+
+
+
+
+ # @return [Contentstack::Query]
+
+
+
+
+
+ 1
+
+
+
+
+ def ascending(field_uid)
+
+
+
+
+
+ 1
+
+
+
+
+ @query.delete(:desc)
+
+
+
+
+
+ 1
+
+
+
+
+ @query[:asc] = field_uid
+
+
+
+
+
+ 1
+
+
+
+
+ self
+
+
+
+
+
+
+
+
+
+
+ end
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ # Sort the results in descending order with the given key.
+
+
+
+
+
+
+
+
+
+
+ # Sort the returned entries in descending order of the provided key.
+
+
+
+
+
+
+
+
+
+
+ #
+
+
+
+
+
+
+
+
+
+
+ # @param [String] field_uid The key to order by
+
+
+
+
+
+
+
+
+
+
+ #
+
+
+
+
+
+
+
+
+
+
+ # Example
+
+
+
+
+
+
+
+
+
+
+ # @query = @stack.content_type('category').query
+
+
+
+
+
+
+
+
+
+
+ # @query.descending
+
+
+
+
+
+
+
+
+
+
+ #
+
+
+
+
+
+
+
+
+
+
+ # @return [Contentstack::Query]
+
+
+
+
+
+ 1
+
+
+
+
+ def descending(field_uid)
+
+
+
+
+
+ 1
+
+
+
+
+ @query.delete(:asc)
+
+
+
+
+
+ 1
+
+
+
+
+ @query[:desc] = field_uid
+
+
+
+
+
+ 1
+
+
+
+
+ self
+
+
+
+
+
+
+
+
+
+
+ end
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ # Get entries from the specified locale.
+
+
+
+
+
+
+
+
+
+
+ #
+
+
+
+
+
+
+
+
+
+
+ # @param [String] code The locale code of the entry
+
+
+
+
+
+
+
+
+
+
+ #
+
+
+
+
+
+
+
+
+
+
+ # Example
+
+
+
+
+
+
+
+
+
+
+ # @query = @stack.content_type('category').query
+
+
+
+
+
+
+
+
+
+
+ # @query.locale('en-us')
+
+
+
+
+
+
+
+
+
+
+ #
+
+
+
+
+
+
+
+
+
+
+ # @return [Contentstack::Query]
+
+
+
+
+
+ 1
+
+
+
+
+ def locale(code)
+
+
+
+
+
+ 1
+
+
+
+
+ @query[:locale] = code
+
+
+
+
+
+ 1
+
+
+
+
+ self
+
+
+
+
+
+
+
+
+
+
+ end
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ # Specifies an array of 'only' keys in BASE object that would be 'included' in the response.
+
+
+
+
+
+
+
+
+
+
+ #
+
+
+
+
+
+
+
+
+
+
+ # @param [Array] fields Array of the 'only' reference keys to be included in response.
+
+
+
+
+
+
+
+
+
+
+ # @param [Array] fields_with_base Can be used to denote 'only' fields of the reference class
+
+
+
+
+
+
+
+
+
+
+ #
+
+
+
+
+
+
+
+
+
+
+ # Example
+
+
+
+
+
+
+
+
+
+
+ # # Include only title and description field in response
+
+
+
+
+
+
+
+
+
+
+ # @query = @stack.content_type('category').query
+
+
+
+
+
+
+
+
+
+
+ # @query.only(['title', 'description'])
+
+
+
+
+
+
+
+
+
+
+ #
+
+
+
+
+
+
+
+
+
+
+ # # Query product and include only the title and description from category reference
+
+
+
+
+
+
+
+
+
+
+ # @query = @stack.content_type('product').query
+
+
+
+
+
+
+
+
+
+
+ # @query.include_reference('category')
+
+
+
+
+
+
+
+
+
+
+ # .only('category', ['title', 'description'])
+
+
+
+
+
+
+
+
+
+
+ #
+
+
+
+
+
+
+
+
+
+
+ # @return [Contentstack::Query]
+
+
+
+
+
+ 1
+
+
+
+
+ def only(fields, fields_with_base=nil)
+
+
+
+
+
+ 3
+
+
+
+
+ q = {}
+
+
+
+
+
+ 3
+
+
+
+
+ if [Array, String].include?(fields_with_base.class)
+
+
+
+
+
+ 1
+
+
+
+
+ fields_with_base = [fields_with_base] if fields_with_base.class == String
+
+
+
+
+
+ 1
+
+
+
+
+ q[fields.to_sym] = fields_with_base
+
+
+
+
+
+
+
+
+
+
+ else
+
+
+
+
+
+ 2
+
+
+
+
+ fields = [fields] if fields.class == String
+
+
+
+
+
+ 2
+
+
+
+
+ q = {BASE: fields}
+
+
+
+
+
+
+
+
+
+
+ end
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 3
+
+
+
+
+ @query[:only] = q
+
+
+
+
+
+ 3
+
+
+
+
+ self
+
+
+
+
+
+
+
+
+
+
+ end
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ # Specifies list of field uids that would be 'excluded' from the response.
+
+
+
+
+
+
+
+
+
+
+ #
+
+
+
+
+
+
+
+
+
+
+ # @param [Array] fields Array of field uid which get 'excluded' from the response.
+
+
+
+
+
+
+
+
+
+
+ # @param [Array] fields_with_base Can be used to denote 'except' fields of the reference class
+
+
+
+
+
+
+
+
+
+
+ #
+
+
+
+
+
+
+
+
+
+
+ # Example
+
+
+
+
+
+
+
+
+
+
+ # # Exclude 'description' field in response
+
+
+
+
+
+
+
+
+
+
+ # @query = @stack.content_type('category').query
+
+
+
+
+
+
+
+
+
+
+ # @query.except(['description'])
+
+
+
+
+
+
+
+
+
+
+ #
+
+
+
+
+
+
+
+
+
+
+ # # Query product and exclude the 'description' from category reference
+
+
+
+
+
+
+
+
+
+
+ # @query = @stack.content_type('product').query
+
+
+
+
+
+
+
+
+
+
+ # @query.include_reference('category')
+
+
+
+
+
+
+
+
+
+
+ # .except('category', ['description'])
+
+
+
+
+
+
+
+
+
+
+ #
+
+
+
+
+
+
+
+
+
+
+ # @return [Contentstack::Query]
+
+
+
+
+
+ 1
+
+
+
+
+ def except(fields, fields_with_base=nil)
+
+
+
+
+
+ 3
+
+
+
+
+ q = {}
+
+
+
+
+
+ 3
+
+
+
+
+ if [Array, String].include?(fields_with_base.class)
+
+
+
+
+
+ 1
+
+
+
+
+ fields_with_base = [fields_with_base] if fields_with_base.class == String
+
+
+
+
+
+ 1
+
+
+
+
+ q[fields.to_sym] = fields_with_base
+
+
+
+
+
+
+
+
+
+
+ else
+
+
+
+
+
+ 2
+
+
+
+
+ fields = [fields] if fields.class == String
+
+
+
+
+
+ 2
+
+
+
+
+ q = {BASE: fields}
+
+
+
+
+
+
+
+
+
+
+ end
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 3
+
+
+
+
+ @query[:except] = q
+
+
+
+
+
+ 3
+
+
+
+
+ self
+
+
+
+
+
+
+
+
+
+
+ end
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ # Add a constraint that requires a particular reference key details.
+
+
+
+
+
+
+
+
+
+
+ #
+
+
+
+
+
+
+
+
+
+
+ # @param [String/Array] reference_field_uids Pass string or array of reference fields that must be included in the response
+
+
+
+
+
+
+
+
+
+
+ #
+
+
+
+
+
+
+
+
+
+
+ # Example
+
+
+
+
+
+
+
+
+
+
+ #
+
+
+
+
+
+
+
+
+
+
+ # # Include reference of 'category'
+
+
+
+
+
+
+
+
+
+
+ # @query = @stack.content_type('product').query
+
+
+
+
+
+
+
+
+
+
+ # @query.include_reference('category')
+
+
+
+
+
+
+
+
+
+
+ #
+
+
+
+
+
+
+
+
+
+
+ # # Include reference of 'category' and 'reviews'
+
+
+
+
+
+
+
+
+
+
+ # @query = @stack.content_type('product').query
+
+
+
+
+
+
+
+
+
+
+ # @query.include_reference(['category', 'reviews'])
+
+
+
+
+
+
+
+
+
+
+ #
+
+
+
+
+
+
+
+
+
+
+ # @return [Contentstack::Query]
+
+
+
+
+
+ 1
+
+
+
+
+ def include_reference(reference_field_uids)
+
+
+
+
+
+ 3
+
+
+
+
+ self.include(reference_field_uids)
+
+
+
+
+
+
+
+
+
+
+ end
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ # Include schemas of all returned objects along with objects themselves.
+
+
+
+
+
+
+
+
+
+
+ #
+
+
+
+
+
+
+
+
+
+
+ # Example
+
+
+
+
+
+
+
+
+
+
+ #
+
+
+
+
+
+
+
+
+
+
+ # @query = @stack.content_type('product').query
+
+
+
+
+
+
+
+
+
+
+ # @query.include_schema
+
+
+
+
+
+
+
+
+
+
+ #
+
+
+
+
+
+
+
+
+
+
+ # @return [Contentstack::Query]
+
+
+
+
+
+ 1
+
+
+
+
+ def include_schema(flag=true)
+
+
+
+
+
+ 1
+
+
+
+
+ @query[:include_schema] = flag
+
+
+
+
+
+ 1
+
+
+
+
+ self
+
+
+
+
+
+
+
+
+
+
+ end
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ # Include object owner's profile in the objects data.
+
+
+
+
+
+
+
+
+
+
+ #
+
+
+
+
+
+
+
+
+
+
+ # Example
+
+
+
+
+
+
+
+
+
+
+ #
+
+
+
+
+
+
+
+
+
+
+ # @query = @stack.content_type('product').query
+
+
+
+
+
+
+
+
+
+
+ # @query.include_owner
+
+
+
+
+
+
+
+
+
+
+ #
+
+
+
+
+
+
+
+
+
+
+ # @return [Contentstack::Query]
+
+
+
+
+
+ 1
+
+
+
+
+ def include_owner(flag=true)
+
+
+
+
+
+ 1
+
+
+
+
+ @query[:include_owner] = flag
+
+
+
+
+
+ 1
+
+
+
+
+ self
+
+
+
+
+
+
+
+
+
+
+ end
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ # Include object's content_type in response
+
+
+
+
+
+
+
+
+
+
+ #
+
+
+
+
+
+
+
+
+
+
+ # Example
+
+
+
+
+
+
+
+
+
+
+ #
+
+
+
+
+
+
+
+
+
+
+ # @query = @stack.content_type('product').query
+
+
+
+
+
+
+
+
+
+
+ # @query.include_content_type
+
+
+
+
+
+
+
+
+
+
+ #
+
+
+
+
+
+
+
+
+
+
+ # @return [Contentstack::Query]
+
+
+
+
+
+ 1
+
+
+
+
+ def include_content_type(flag=true)
+
+
+
+
+
+ 1
+
+
+
+
+ @query[:include_content_type] = flag
+
+
+
+
+
+ 1
+
+
+
+
+ self
+
+
+
+
+
+
+
+
+
+
+ end
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ # Include objects in 'Draft' mode in response
+
+
+
+
+
+
+
+
+
+
+ #
+
+
+
+
+
+
+
+
+
+
+ # Example
+
+
+
+
+
+
+
+
+
+
+ #
+
+
+
+
+
+
+
+
+
+
+ # @query = @stack.content_type('product').query
+
+
+
+
+
+
+
+
+
+
+ # @query.include_draft
+
+
+
+
+
+
+
+
+
+
+ #
+
+
+
+
+
+
+
+
+
+
+ # @return [Contentstack::Query]
+
+
+
+
+
+ 1
+
+
+
+
+ def include_draft(flag=true)
+
+
+
+
+
+ 1
+
+
+
+
+ @query[:include_draft] = flag
+
+
+
+
+
+ 1
+
+
+
+
+ self
+
+
+
+
+
+
+
+
+
+
+ end
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ #
+
+
+
+
+
+
+
+
+
+
+ # @return [Contentstack::Query]
+
+
+
+
+
+ 1
+
+
+
+
+ def include(field_uids)
+
+
+
+
+
+ 3
+
+
+
+
+ field_uids = [field_uids] if field_uids.class == String
+
+
+
+
+
+ 3
+
+
+
+
+ @query[:include] ||= []
+
+
+
+
+
+ 3
+
+
+
+
+ @query[:include] = @query[:include] | field_uids
+
+
+
+
+
+ 3
+
+
+
+
+ self
+
+
+
+
+
+
+
+
+
+
+ end
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ # Include tags with which to search entries.
+
+
+
+
+
+
+
+
+
+
+ #
+
+
+
+
+
+
+
+
+
+
+ # @param [Array] tags_array Array of tags using which search must be performed
+
+
+
+
+
+
+
+
+
+
+ #
+
+
+
+
+
+
+
+
+
+
+ # Example
+
+
+
+
+
+
+
+
+
+
+ #
+
+
+
+
+
+
+
+
+
+
+ # @query = @stack.content_type('product').query
+
+
+
+
+
+
+
+
+
+
+ # @query.tags(["tag1", "tag2"])
+
+
+
+
+
+
+
+
+
+
+ #
+
+
+
+
+
+
+
+
+
+
+ # @return [Contentstack::Query]
+
+
+
+
+
+ 1
+
+
+
+
+ def tags(tags_array)
+
+
+
+
+
+ 1
+
+
+
+
+ @query[:tags] = tags_array
+
+
+
+
+
+ 1
+
+
+
+
+ self
+
+
+
+
+
+
+
+
+
+
+ end
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ # Execute query
+
+
+
+
+
+
+
+
+
+
+ #
+
+
+
+
+
+
+
+
+
+
+ # Example
+
+
+
+
+
+
+
+
+
+
+ #
+
+
+
+
+
+
+
+
+
+
+ # @query = @stack.content_type('product').query
+
+
+
+
+
+
+
+
+
+
+ # @query.tags(["tag1", "tag2"])
+
+
+
+
+
+
+
+
+
+
+ # .fetch
+
+
+
+
+
+
+
+
+
+
+ #
+
+
+
+
+
+
+
+
+
+
+ # @return [Contentstack::EntryCollection]
+
+
+
+
+
+ 1
+
+
+
+
+ def fetch
+
+
+
+
+
+ 47
+
+
+
+
+ entries = API.fetch_entries(@content_type, @query)
+
+
+
+
+
+ 47
+
+
+
+
+ EntryCollection.new(entries, @content_type)
+
+
+
+
+
+
+
+
+
+
+ end
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ # Execute a Query and get the single matching object
+
+
+
+
+
+
+
+
+
+
+ #
+
+
+
+
+
+
+
+
+
+
+ # Example
+
+
+
+
+
+
+
+
+
+
+ #
+
+
+
+
+
+
+
+
+
+
+ # @query = @stack.content_type('product').query
+
+
+
+
+
+
+
+
+
+
+ # @query.tags(["tag1", "tag2"])
+
+
+
+
+
+
+
+
+
+
+ # .find_one
+
+
+
+
+
+
+
+
+
+
+ #
+
+
+
+
+
+
+
+
+
+
+ # @return [Contentstack::Entry]
+
+
+
+
+
+ 1
+
+
+
+
+ def find_one
+
+
+
+
+
+
+
+
+
+
+ limit 1
+
+
+
+
+
+
+
+
+
+
+ fetch.first
+
+
+
+
+
+
+
+
+
+
+ end
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 1
+
+
+
+
+ alias_method :find, :fetch
+
+
+
+
+
+ 1
+
+
+
+
+ alias_method :in, :contained_in
+
+
+
+
+
+ 1
+
+
+
+
+ alias_method :not_in, :not_contained_in
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 1
+
+
+
+
+ private
+
+
+
+
+
+ 1
+
+
+
+
+ def add_query_hash(query_hash)
+
+
+
+
+
+ 19
+
+
+
+
+ q = ActiveSupport::JSON.decode(@query[:query])
+
+
+
+
+
+ 19
+
+
+
+
+ q.merge!(query_hash)
+
+
+
+
+
+ 19
+
+
+
+
+ @query[:query] = ActiveSupport::JSON.encode(q)
+
+
+
+
+
+ 19
+
+
+
+
+ self
+
+
+
+
+
+
+
+
+
+
+ end
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 1
+
+
+
+
+ def concat_queries(queries)
+
+
+
+
+
+ 2
+
+
+
+
+ this_queries = []
+
+
+
+
+
+ 2
+
+
+
+
+ this_query = ActiveSupport::JSON.decode(@query[:query])
+
+
+
+
+
+ 2
+
+
+
+
+ if this_query.keys.length > 0
+
+
+
+
+
+
+
+
+
+
+ this_queries = [this_query]
+
+
+
+
+
+
+
+
+
+
+ end
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 2
+
+
+
+
+ if queries.class == Array
+
+
+
+
+
+ 2
+
+
+
+
+ queries.map do |query_object|
+
+
+
+
+
+ 4
+
+
+
+
+ if query_object.class == Contentstack::Query && query_object.content_type == @content_type
+
+
+
+
+
+ 4
+
+
+
+
+ q = ActiveSupport::JSON.decode(query_object.query[:query])
+
+
+
+
+
+ 4
+
+
+
+
+ this_queries.push(q.symbolize_keys)
+
+
+
+
+
+
+
+
+
+
+ end
+
+
+
+
+
+
+
+
+
+
+ end
+
+
+
+
+
+
+
+
+
+
+ end
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 2
+
+
+
+
+ this_queries
+
+
+
+
+
+
+
+
+
+
+ end
+
+
+
+
+
+
+
+
+
+
+ end
+
+
+
+
+
+
+
+
+
+
+ end
+
+
-
-
-
-
-
-
-
- 1
-
- require 'contentstack/entry_collection'
-
-
-
-
-
-
-
-
-
- 1
-
- module Contentstack
-
-
-
-
-
- # A class that defines a query that is used to query for Entry instance.
-
-
-
- 1
-
- class Query
-
-
-
-
-
- # @!attribute [r] query
-
-
-
-
-
- # Attribute which has all the information about the query which will be executed against Contentstack API
-
-
-
-
-
-
-
-
-
-
-
- # @!attribute [r] content_type
-
-
-
-
-
- # Denotes which `content_type` should the query be executed for
-
-
-
-
-
-
-
-
-
- 1
-
- attr_reader :query, :content_type
-
-
-
-
-
-
-
-
-
-
-
- # Initialize the Query instance
-
-
-
-
-
- # @param [String] content_type
-
-
-
-
-
- #
-
-
-
-
-
- # Example:
-
-
-
-
-
- # @query = @stack.content_type('blog').query
-
-
-
-
-
- # @entries = @query.where('author', 'John Doe').fetch
-
-
-
-
-
- #
-
-
-
-
-
- # @return [Contentstack::Query]
-
-
-
- 1
-
- def initialize(content_type)
-
-
-
- 52
-
- @content_type = content_type
-
-
-
- 52
-
- @query = {
-
-
-
-
-
- query: "{}",
-
-
-
-
-
- include_count: false,
-
-
-
-
-
- skip: 0,
-
-
-
-
-
- count: 10,
-
-
-
-
-
- desc: 'created_at'
-
-
-
-
-
- }
-
-
-
-
-
- end
-
-
-
-
-
-
-
-
-
-
-
- # Add a custom query against specified key.
-
-
-
-
-
- # @param [String] field_uid
-
-
-
-
-
- # @param [String/Number/Boolean/Hash] value
-
-
-
-
-
- #
-
-
-
-
-
- # Example:
-
-
-
-
-
- # @query = @stack.content_type('blog').query
-
-
-
-
-
- # @query.add_query('author', "Jane Doe")
-
-
-
-
-
- #
-
-
-
-
-
- # @return [Contentstack::Query]
-
-
-
- 1
-
- def add_query(field_uid, value)
-
-
-
-
-
- add_query_hash({:"#{field_uid}" => value})
-
-
-
-
-
- end
-
-
-
-
-
-
-
-
-
-
-
- # Remove provided query key from custom query if exist.
-
-
-
-
-
- # @param [String] field_uid
-
-
-
-
-
- #
-
-
-
-
-
- # Example:
-
-
-
-
-
- # @query = @stack.content_type('blog').query
-
-
-
-
-
- # @query.remove_query('author')
-
-
-
-
-
- #
-
-
-
-
-
- # @return [Contentstack::Query]
-
-
-
- 1
-
- def remove_query(field_uid)
-
-
-
-
-
- q = ActiveSupport::JSON.decode(@query[:query])
-
-
-
-
-
- q.delete(field_uid)
-
-
-
-
-
- @query[:query] = ActiveSupport::JSON.encode(q)
-
-
-
-
-
- self
-
-
-
-
-
- end
-
-
-
-
-
-
-
-
-
-
-
- # Add a constraint to fetch all entries that contains given value against specified key.
-
-
-
-
-
- # @param [Hash] query_hash
-
-
-
-
-
- #
-
-
-
-
-
- # Example:
-
-
-
-
-
- # @query = @stack.content_type('blog').query
-
-
-
-
-
- # @query.where({:author => "Jane Doe"})
-
-
-
-
-
- #
-
-
-
-
-
- # @return [Contentstack::Query]
-
-
-
- 1
-
- def where(query_hash)
-
-
-
- 2
-
- add_query_hash(query_hash)
-
-
-
-
-
- end
-
-
-
-
-
-
-
-
-
-
-
- # Add a regular expression constraint for finding string values that match the provided regular expression. This may be slow for large data sets.
-
-
-
-
-
- # @param [String] field_uid The key to be constrained.
-
-
-
-
-
- # @param [String] pattern The regular expression pattern to match.
-
-
-
-
-
- # @param [String] options Regex options
-
-
-
-
-
- #
-
-
-
-
-
- # Example:
-
-
-
-
-
- # @query = @stack.content_type('product').query
-
-
-
-
-
- # @query.regex('title', '.*Mobile.*', 'i') # Search without case sensitivity
-
-
-
-
-
- #
-
-
-
-
-
- # @return [Contentstack::Query]
-
-
-
- 1
-
- def regex(field_uid, pattern, options="")
-
-
-
- 4
-
- hash = {
-
-
-
-
-
- "#{field_uid}" => {
-
-
-
-
-
- "$regex": pattern
-
-
-
-
-
- }
-
-
-
-
-
- }
-
-
-
-
-
-
-
-
-
- 4
-
- hash["#{field_uid}"]["$options"] = options if !options.empty? || !options.nil?
-
-
-
-
-
-
-
-
-
- 4
-
- add_query_hash(hash)
-
-
-
-
-
- end
-
-
-
-
-
-
-
-
-
-
-
- # Add a constraint that requires, a specified key exists in response.
-
-
-
-
-
- # @param [String] field_uid The key to be constrained.
-
-
-
-
-
- #
-
-
-
-
-
- # Example:
-
-
-
-
-
- # @query = @stack.content_type('product').query
-
-
-
-
-
- # @query.exists?('product_image') # only fetch products which have a `product_image`
-
-
-
-
-
- #
-
-
-
-
-
- # @return [Contentstack::Query]
-
-
-
- 1
-
- def exists?(field_uid)
-
-
-
- 1
-
- add_query_hash({:"#{field_uid}" => {"$exists" => true}})
-
-
-
-
-
- end
-
-
-
-
-
-
-
-
-
-
-
- # Add a constraint that requires, a specified key does not exists in response.
-
-
-
-
-
- # @param [String] field_uid The key to be constrained.
-
-
-
-
-
- #
-
-
-
-
-
- # Example:
-
-
-
-
-
- # @query = @stack.content_type('product').query
-
-
-
-
-
- # @query.not_exists?('product_image') # only fetch products which do not have a `product_image`
-
-
-
-
-
- #
-
-
-
-
-
- # @return [Contentstack::Query]
-
-
-
- 1
-
- def not_exists?(field_uid)
-
-
-
- 1
-
- add_query_hash({:"#{field_uid}" => {"$exists" => false}})
-
-
-
- 1
-
- self
-
-
-
-
-
- end
-
-
-
-
-
-
-
-
-
-
-
- # Combines all the queries together using AND operator.
-
-
-
-
-
- #
-
-
-
-
-
- # @param [Array] queries Array of instances of the Query class
-
-
-
-
-
- #
-
-
-
-
-
- # Each query should be an instance of the Contentstack::Query class, and belong to the same `content_type`
-
-
-
-
-
- # Example:
-
-
-
-
-
- # @query1 = @stack.content_type('category').query
-
-
-
-
-
- # @query1.where('title', 'Electronics')
-
-
-
-
-
- #
-
-
-
-
-
- # @query2 = @stack.content_type('category').query
-
-
-
-
-
- # @query2.regex('description', '.*Electronics.*')
-
-
-
-
-
- #
-
-
-
-
-
- # query_array = [@query1, @query2]
-
-
-
-
-
- #
-
-
-
-
-
- # @query = @stack.content_type('category').query
-
-
-
-
-
- # @query.and(query_array)
-
-
-
-
-
- #
-
-
-
-
-
- # @return [Contentstack::Query]
-
-
-
- 1
-
- def and(queries)
-
-
-
- 1
-
- add_query_hash({"$and" => concat_queries(queries)})
-
-
-
- 1
-
- self
-
-
-
-
-
- end
-
-
-
-
-
-
-
-
-
-
-
- # Combines all the queries together using OR operator.
-
-
-
-
-
- #
-
-
-
-
-
- # @param [Array] queries Array of instances of the Query class
-
-
-
-
-
- #
-
-
-
-
-
- # Each query should be an instance of the Contentstack::Query class, and belong to the same `content_type`
-
-
-
-
-
- # Example:
-
-
-
-
-
- # @query1 = @stack.content_type('category').query
-
-
-
-
-
- # @query1.where('title', 'Electronics')
-
-
-
-
-
- #
-
-
-
-
-
- # @query2 = @stack.content_type('category').query
-
-
-
-
-
- # @query2.where('title', 'Apparel')
-
-
-
-
-
- #
-
-
-
-
-
- # query_array = [@query1, @query2]
-
-
-
-
-
- #
-
-
-
-
-
- # @query = @stack.content_type('category').query
-
-
-
-
-
- # @query.or(query_array)
-
-
-
-
-
- #
-
-
-
-
-
- # @return [Contentstack::Query]
-
-
-
- 1
-
- def or(queries)
-
-
-
- 1
-
- add_query_hash({"$or" => concat_queries(queries)})
-
-
-
- 1
-
- self
-
-
-
-
-
- end
-
-
-
-
-
-
-
-
-
-
-
- # Add a constraint to the query that requires a particular key entry to be less than the provided value.
-
-
-
-
-
- #
-
-
-
-
-
- # @param [String] field_uid UID of the field for which query should be executed
-
-
-
-
-
- #
-
-
-
-
-
- # @param [String/Number] value Value that provides an upper bound
-
-
-
-
-
- #
-
-
-
-
-
- # Example
-
-
-
-
-
- # @query = @stack.content_type('product').query
-
-
-
-
-
- # @query.less_than('price', '100')
-
-
-
-
-
- #
-
-
-
-
-
- # @return [Contentstack::Query]
-
-
-
- 1
-
- def less_than(field_uid, value)
-
-
-
- 1
-
- add_query_hash({:"#{field_uid}" => {"$lt" => value}})
-
-
-
- 1
-
- self
-
-
-
-
-
- end
-
-
-
-
-
-
-
-
-
-
-
- # Add a constraint to the query that requires a particular key entry to be less than or equal to the provided value.
-
-
-
-
-
- #
-
-
-
-
-
- # @param [String] field_uid UID of the field for which query should be executed
-
-
-
-
-
- #
-
-
-
-
-
- # @param [String/Number] value Value that provides an upper bound
-
-
-
-
-
- #
-
-
-
-
-
- # Example
-
-
-
-
-
- # @query = @stack.content_type('product').query
-
-
-
-
-
- # @query.less_than_or_equal('price', '100')
-
-
-
-
-
- #
-
-
-
-
-
- # @return [Contentstack::Query]
-
-
-
- 1
-
- def less_than_or_equal(field_uid, value)
-
-
-
- 1
-
- add_query_hash({:"#{field_uid}" => {"$lte" => value}})
-
-
-
- 1
-
- self
-
-
-
-
-
- end
-
-
-
-
-
-
-
-
-
-
-
- # Add a constraint to the query that requires a particular key entry to be greater than the provided value.
-
-
-
-
-
- #
-
-
-
-
-
- # @param [String] field_uid UID of the field for which query should be executed
-
-
-
-
-
- #
-
-
-
-
-
- # @param [String/Number] value Value that provides a lower bound
-
-
-
-
-
- #
-
-
-
-
-
- # Example
-
-
-
-
-
- # @query = @stack.content_type('product').query
-
-
-
-
-
- # @query.greater_than('price', '100')
-
-
-
-
-
- #
-
-
-
-
-
- # @return [Contentstack::Query]
-
-
-
- 1
-
- def greater_than(field_uid, value)
-
-
-
- 1
-
- add_query_hash({:"#{field_uid}" => {"$gt" => value}})
-
-
-
- 1
-
- self
-
-
-
-
-
- end
-
-
-
-
-
-
-
-
-
-
-
- # Add a constraint to the query that requires a particular key entry to be greater than or equal to the provided value.
-
-
-
-
-
- #
-
-
-
-
-
- # @param [String] field_uid UID of the field for which query should be executed
-
-
-
-
-
- #
-
-
-
-
-
- # @param [String/Number] value Value that provides a lower bound
-
-
-
-
-
- #
-
-
-
-
-
- # Example
-
-
-
-
-
- # @query = @stack.content_type('product').query
-
-
-
-
-
- # @query.greater_than_or_equal('price', '100')
-
-
-
-
-
- #
-
-
-
-
-
- # @return [Contentstack::Query]
-
-
-
- 1
-
- def greater_than_or_equal(field_uid, value)
-
-
-
- 1
-
- add_query_hash({:"#{field_uid}" => {"$gte" => value}})
-
-
-
- 1
-
- self
-
-
-
-
-
- end
-
-
-
-
-
-
-
-
-
-
-
- # Add a constraint to the query that requires a particular key's entry to be not equal to the provided value.
-
-
-
-
-
- #
-
-
-
-
-
- # @param [String] field_uid UID of the field for which query should be executed
-
-
-
-
-
- # @param [String] value The object that must not be equaled.
-
-
-
-
-
- #
-
-
-
-
-
- # Example
-
-
-
-
-
- # @query = @stack.content_type('product').query
-
-
-
-
-
- # @query.not_equal_to('price', '100')
-
-
-
-
-
- #
-
-
-
-
-
- # @return [Contentstack::Query]
-
-
-
- 1
-
- def not_equal_to(field_uid, value)
-
-
-
- 1
-
- add_query_hash({:"#{field_uid}" => {"$ne" => value}})
-
-
-
- 1
-
- self
-
-
-
-
-
- end
-
-
-
-
-
-
-
-
-
-
-
- # Add a constraint to the query that requires a particular key's entry to be contained in the provided array.
-
-
-
-
-
- #
-
-
-
-
-
- # @param [String] field_uid UID of the field for which query should be executed
-
-
-
-
-
- # @param [String] values The possible values for the key's object
-
-
-
-
-
- #
-
-
-
-
-
- # Example
-
-
-
-
-
- # @query = @stack.content_type('category').query
-
-
-
-
-
- # @query.contained_in("title", ["Electronics", "Apparel"])
-
-
-
-
-
- #
-
-
-
-
-
- # @return [Contentstack::Query]
-
-
-
- 1
-
- def contained_in(field_uid, values)
-
-
-
- 2
-
- add_query_hash({:"#{field_uid}" => {"$in" => values}})
-
-
-
- 2
-
- self
-
-
-
-
-
- end
-
-
-
-
-
-
-
-
-
-
-
- # Add a constraint to the query that requires a particular key entry's value not be contained in the provided array.
-
-
-
-
-
- #
-
-
-
-
-
- # @param [String] field_uid UID of the field for which query should be executed
-
-
-
-
-
- # @param [String] values The possible values for the key's object
-
-
-
-
-
- #
-
-
-
-
-
- # Example
-
-
-
-
-
- # @query = @stack.content_type('category').query
-
-
-
-
-
- # @query.not_contained_in("title", ["Electronics", "Apparel"])
-
-
-
-
-
- #
-
-
-
-
-
- # @return [Contentstack::Query]
-
-
-
- 1
-
- def not_contained_in(field_uid, values)
-
-
-
- 2
-
- add_query_hash({:"#{field_uid}" => {"$nin" => values}})
-
-
-
- 2
-
- self
-
-
-
-
-
- end
-
-
-
-
-
-
-
-
-
-
-
- # The number of objects to skip before returning any.
-
-
-
-
-
- #
-
-
-
-
-
- # @param [Number] count of objects to skip from resulset.
-
-
-
-
-
- #
-
-
-
-
-
- # Example
-
-
-
-
-
- # @query = @stack.content_type('category').query
-
-
-
-
-
- # @query.skip(50)
-
-
-
-
-
- #
-
-
-
-
-
- # @return [Contentstack::Query]
-
-
-
- 1
-
- def skip(count)
-
-
-
- 1
-
- @query[:skip] = count
-
-
-
- 1
-
- self
-
-
-
-
-
- end
-
-
-
-
-
-
-
-
-
-
-
- # This method provides only the entries matching the specified value.
-
-
-
-
-
- #
-
-
-
-
-
- # @param [String] text value used to match or compare
-
-
-
-
-
- #
-
-
-
-
-
- # Example
-
-
-
-
-
- # @query = @stack.content_type('product').query
-
-
-
-
-
- # @query.search("This is an awesome product")
-
-
-
-
-
- #
-
-
-
-
-
- # @return [Contentstack::Query]
-
-
-
- 1
-
- def search(text)
-
-
-
- 1
-
- @query[:typeahead] = text
-
-
-
- 1
-
- self
-
-
-
-
-
- end
-
-
-
-
-
-
-
-
-
-
-
- # A limit on the number of objects to return.
-
-
-
-
-
- #
-
-
-
-
-
- # @param [Number] count of objects to limit in resulset.
-
-
-
-
-
- #
-
-
-
-
-
- # Example
-
-
-
-
-
- # @query = @stack.content_type('category').query
-
-
-
-
-
- # @query.limit(50)
-
-
-
-
-
- #
-
-
-
-
-
- # @return [Contentstack::Query]
-
-
-
- 1
-
- def limit(count=10)
-
-
-
- 1
-
- @query[:limit] = count
-
-
-
- 1
-
- self
-
-
-
-
-
- end
-
-
-
-
-
-
-
-
-
-
-
- # Retrieve only count of entries in result.
-
-
-
-
-
- #
-
-
-
-
-
- # Example
-
-
-
-
-
- # @query = @stack.content_type('category').query
-
-
-
-
-
- # @query.count
-
-
-
-
-
- #
-
-
-
-
-
- # @return [Integer]
-
-
-
- 1
-
- def count
-
-
-
- 1
-
- include_count
-
-
-
- 1
-
- fetch.count
-
-
-
-
-
- end
-
-
-
-
-
-
-
-
-
-
-
- # Retrieve count and data of objects in result.
-
-
-
-
-
- #
-
-
-
-
-
- # Example
-
-
-
-
-
- # @query = @stack.content_type('category').query
-
-
-
-
-
- # @query.include_count
-
-
-
-
-
- #
-
-
-
-
-
- # @return [Contentstack::Query]
-
-
-
- 1
-
- def include_count(flag=true)
-
-
-
- 8
-
- @query[:include_count] = flag
-
-
-
- 8
-
- self
-
-
-
-
-
- end
-
-
-
-
-
-
-
-
-
-
-
- # Sort the results in ascending order with the given key.
-
-
-
-
-
- # Sort the returned entries in ascending order of the provided key.
-
-
-
-
-
- #
-
-
-
-
-
- # @param [String] field_uid The key to order by
-
-
-
-
-
- #
-
-
-
-
-
- # Example
-
-
-
-
-
- # @query = @stack.content_type('category').query
-
-
-
-
-
- # @query.ascending
-
-
-
-
-
- #
-
-
-
-
-
- # @return [Contentstack::Query]
-
-
-
- 1
-
- def ascending(field_uid)
-
-
-
- 1
-
- @query.delete(:desc)
-
-
-
- 1
-
- @query[:asc] = field_uid
-
-
-
- 1
-
- self
-
-
-
-
-
- end
-
-
-
-
-
-
-
-
-
-
-
- # Sort the results in descending order with the given key.
-
-
-
-
-
- # Sort the returned entries in descending order of the provided key.
-
-
-
-
-
- #
-
-
-
-
-
- # @param [String] field_uid The key to order by
-
-
-
-
-
- #
-
-
-
-
-
- # Example
-
-
-
-
-
- # @query = @stack.content_type('category').query
-
-
-
-
-
- # @query.descending
-
-
-
-
-
- #
-
-
-
-
-
- # @return [Contentstack::Query]
-
-
-
- 1
-
- def descending(field_uid)
-
-
-
- 1
-
- @query.delete(:asc)
-
-
-
- 1
-
- @query[:desc] = field_uid
-
-
-
- 1
-
- self
-
-
-
-
-
- end
-
-
-
-
-
-
-
-
-
-
-
- # Get entries from the specified locale.
-
-
-
-
-
- #
-
-
-
-
-
- # @param [String] code The locale code of the entry
-
-
-
-
-
- #
-
-
-
-
-
- # Example
-
-
-
-
-
- # @query = @stack.content_type('category').query
-
-
-
-
-
- # @query.locale('en-us')
-
-
-
-
-
- #
-
-
-
-
-
- # @return [Contentstack::Query]
-
-
-
- 1
-
- def locale(code)
-
-
-
- 1
-
- @query[:locale] = code
-
-
-
- 1
-
- self
-
-
-
-
-
- end
-
-
-
-
-
-
-
-
-
-
-
- # Specifies an array of 'only' keys in BASE object that would be 'included' in the response.
-
-
-
-
-
- #
-
-
-
-
-
- # @param [Array] fields Array of the 'only' reference keys to be included in response.
-
-
-
-
-
- # @param [Array] fields_with_base Can be used to denote 'only' fields of the reference class
-
-
-
-
-
- #
-
-
-
-
-
- # Example
-
-
-
-
-
- # # Include only title and description field in response
-
-
-
-
-
- # @query = @stack.content_type('category').query
-
-
-
-
-
- # @query.only(['title', 'description'])
-
-
-
-
-
- #
-
-
-
-
-
- # # Query product and include only the title and description from category reference
-
-
-
-
-
- # @query = @stack.content_type('product').query
-
-
-
-
-
- # @query.include_reference('category')
-
-
-
-
-
- # .only('category', ['title', 'description'])
-
-
-
-
-
- #
-
-
-
-
-
- # @return [Contentstack::Query]
-
-
-
- 1
-
- def only(fields, fields_with_base=nil)
-
-
-
- 3
-
- q = {}
-
-
-
- 3
-
- if [Array, String].include?(fields_with_base.class)
-
-
-
- 1
-
- fields_with_base = [fields_with_base] if fields_with_base.class == String
-
-
-
- 1
-
- q[fields.to_sym] = fields_with_base
-
-
-
-
-
- else
-
-
-
- 2
-
- fields = [fields] if fields.class == String
-
-
-
- 2
-
- q = {BASE: fields}
-
-
-
-
-
- end
-
-
-
-
-
-
-
-
-
- 3
-
- @query[:only] = q
-
-
-
- 3
-
- self
-
-
-
-
-
- end
-
-
-
-
-
-
-
-
-
-
-
- # Specifies list of field uids that would be 'excluded' from the response.
-
-
-
-
-
- #
-
-
-
-
-
- # @param [Array] fields Array of field uid which get 'excluded' from the response.
-
-
-
-
-
- # @param [Array] fields_with_base Can be used to denote 'except' fields of the reference class
-
-
-
-
-
- #
-
-
-
-
-
- # Example
-
-
-
-
-
- # # Exclude 'description' field in response
-
-
-
-
-
- # @query = @stack.content_type('category').query
-
-
-
-
-
- # @query.except(['description'])
-
-
-
-
-
- #
-
-
-
-
-
- # # Query product and exclude the 'description' from category reference
-
-
-
-
-
- # @query = @stack.content_type('product').query
-
-
-
-
-
- # @query.include_reference('category')
-
-
-
-
-
- # .except('category', ['description'])
-
-
-
-
-
- #
-
-
-
-
-
- # @return [Contentstack::Query]
-
-
-
- 1
-
- def except(fields, fields_with_base=nil)
-
-
-
- 3
-
- q = {}
-
-
-
- 3
-
- if [Array, String].include?(fields_with_base.class)
-
-
-
- 1
-
- fields_with_base = [fields_with_base] if fields_with_base.class == String
-
-
-
- 1
-
- q[fields.to_sym] = fields_with_base
-
-
-
-
-
- else
-
-
-
- 2
-
- fields = [fields] if fields.class == String
-
-
-
- 2
-
- q = {BASE: fields}
-
-
-
-
-
- end
-
-
-
-
-
-
-
-
-
- 3
-
- @query[:except] = q
-
-
-
- 3
-
- self
-
-
-
-
-
- end
-
-
-
-
-
-
-
-
-
-
-
- # Add a constraint that requires a particular reference key details.
-
-
-
-
-
- #
-
-
-
-
-
- # @param [String/Array] reference_field_uids Pass string or array of reference fields that must be included in the response
-
-
-
-
-
- #
-
-
-
-
-
- # Example
-
-
-
-
-
- #
-
-
-
-
-
- # # Include reference of 'category'
-
-
-
-
-
- # @query = @stack.content_type('product').query
-
-
-
-
-
- # @query.include_reference('category')
-
-
-
-
-
- #
-
-
-
-
-
- # # Include reference of 'category' and 'reviews'
-
-
-
-
-
- # @query = @stack.content_type('product').query
-
-
-
-
-
- # @query.include_reference(['category', 'reviews'])
-
-
-
-
-
- #
-
-
-
-
-
- # @return [Contentstack::Query]
-
-
-
- 1
-
- def include_reference(reference_field_uids)
-
-
-
- 3
-
- self.include(reference_field_uids)
-
-
-
-
-
- end
-
-
-
-
-
-
-
-
-
-
-
- # Include schemas of all returned objects along with objects themselves.
-
-
-
-
-
- #
-
-
-
-
-
- # Example
-
-
-
-
-
- #
-
-
-
-
-
- # @query = @stack.content_type('product').query
-
-
-
-
-
- # @query.include_schema
-
-
-
-
-
- #
-
-
-
-
-
- # @return [Contentstack::Query]
-
-
-
- 1
-
- def include_schema(flag=true)
-
-
-
- 1
-
- @query[:include_schema] = flag
-
-
-
- 1
-
- self
-
-
-
-
-
- end
-
-
-
-
-
-
-
-
-
-
-
- # Include object owner's profile in the objects data.
-
-
-
-
-
- #
-
-
-
-
-
- # Example
-
-
-
-
-
- #
-
-
-
-
-
- # @query = @stack.content_type('product').query
-
-
-
-
-
- # @query.include_owner
-
-
-
-
-
- #
-
-
-
-
-
- # @return [Contentstack::Query]
-
-
-
- 1
-
- def include_owner(flag=true)
-
-
-
- 1
-
- @query[:include_owner] = flag
-
-
-
- 1
-
- self
-
-
-
-
-
- end
-
-
-
-
-
-
-
-
-
-
-
- # Include object's content_type in response
-
-
-
-
-
- #
-
-
-
-
-
- # Example
-
-
-
-
-
- #
-
-
-
-
-
- # @query = @stack.content_type('product').query
-
-
-
-
-
- # @query.include_content_type
-
-
-
-
-
- #
-
-
-
-
-
- # @return [Contentstack::Query]
-
-
-
- 1
-
- def include_content_type(flag=true)
-
-
-
- 1
-
- @query[:include_content_type] = flag
-
-
-
- 1
-
- self
-
-
-
-
-
- end
-
-
-
-
-
-
-
-
-
-
-
- # Include objects in 'Draft' mode in response
-
-
-
-
-
- #
-
-
-
-
-
- # Example
-
-
-
-
-
- #
-
-
-
-
-
- # @query = @stack.content_type('product').query
-
-
-
-
-
- # @query.include_draft
-
-
-
-
-
- #
-
-
-
-
-
- # @return [Contentstack::Query]
-
-
-
- 1
-
- def include_draft(flag=true)
-
-
-
- 1
-
- @query[:include_draft] = flag
-
-
-
- 1
-
- self
-
-
-
-
-
- end
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- #
-
-
-
-
-
- # @return [Contentstack::Query]
-
-
-
- 1
-
- def include(field_uids)
-
-
-
- 3
-
- field_uids = [field_uids] if field_uids.class == String
-
-
-
- 3
-
- @query[:include] ||= []
-
-
-
- 3
-
- @query[:include] = @query[:include] | field_uids
-
-
-
- 3
-
- self
-
-
-
-
-
- end
-
-
-
-
-
-
-
-
-
-
-
- # Include tags with which to search entries.
-
-
-
-
-
- #
-
-
-
-
-
- # @param [Array] tags_array Array of tags using which search must be performed
-
-
-
-
-
- #
-
-
-
-
-
- # Example
-
-
-
-
-
- #
-
-
-
-
-
- # @query = @stack.content_type('product').query
-
-
-
-
-
- # @query.tags(["tag1", "tag2"])
-
-
-
-
-
- #
-
-
-
-
-
- # @return [Contentstack::Query]
-
-
-
- 1
-
- def tags(tags_array)
-
-
-
- 1
-
- @query[:tags] = tags_array
-
-
-
- 1
-
- self
-
-
-
-
-
- end
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- # Execute query
-
-
-
-
-
- #
-
-
-
-
-
- # Example
-
-
-
-
-
- #
-
-
-
-
-
- # @query = @stack.content_type('product').query
-
-
-
-
-
- # @query.tags(["tag1", "tag2"])
-
-
-
-
-
- # .fetch
-
-
-
-
-
- #
-
-
-
-
-
- # @return [Contentstack::EntryCollection]
-
-
-
- 1
-
- def fetch
-
-
-
- 47
-
- entries = API.fetch_entries(@content_type, @query)
-
-
-
- 47
-
- EntryCollection.new(entries, @content_type)
-
-
-
-
-
- end
-
-
-
-
-
-
-
-
-
-
-
- # Execute a Query and get the single matching object
-
-
-
-
-
- #
-
-
-
-
-
- # Example
-
-
-
-
-
- #
-
-
-
-
-
- # @query = @stack.content_type('product').query
-
-
-
-
-
- # @query.tags(["tag1", "tag2"])
-
-
-
-
-
- # .find_one
-
-
-
-
-
- #
-
-
-
-
-
- # @return [Contentstack::Entry]
-
-
-
- 1
-
- def find_one
-
-
-
-
-
- limit 1
-
-
-
-
-
- fetch.first
-
-
-
-
-
- end
-
-
-
-
-
-
-
-
-
- 1
-
- alias_method :find, :fetch
-
-
-
- 1
-
- alias_method :in, :contained_in
-
-
-
- 1
-
- alias_method :not_in, :not_contained_in
-
-
-
-
-
-
-
-
-
- 1
-
- private
-
-
-
- 1
-
- def add_query_hash(query_hash)
-
-
-
- 19
-
- q = ActiveSupport::JSON.decode(@query[:query])
-
-
-
- 19
-
- q.merge!(query_hash)
-
-
-
- 19
-
- @query[:query] = ActiveSupport::JSON.encode(q)
-
-
-
- 19
-
- self
-
-
-
-
-
- end
-
-
-
-
-
-
-
-
-
- 1
-
- def concat_queries(queries)
-
-
-
- 2
-
- this_queries = []
-
-
-
- 2
-
- this_query = ActiveSupport::JSON.decode(@query[:query])
-
-
-
- 2
-
- if this_query.keys.length > 0
-
-
-
-
-
- this_queries = [this_query]
-
-
-
-
-
- end
-
-
-
-
-
-
-
-
-
- 2
-
- if queries.class == Array
-
-
-
- 2
-
- queries.map do |query_object|
-
-
-
- 4
-
- if query_object.class == Contentstack::Query && query_object.content_type == @content_type
-
-
-
- 4
-
- q = ActiveSupport::JSON.decode(query_object.query[:query])
-
-
-
- 4
-
- this_queries.push(q.symbolize_keys)
-
-
-
-
-
- end
-
-
-
-
-
- end
-
-
-
-
-
- end
-
-
-
-
-
-
-
-
-
- 2
-
- this_queries
-
-
-
-
-
- end
-
-
-
-
-
- end
-
-
-
-
-
- end
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- 1
-
- module Contentstack
-
-
-
- 1
-
- class Region
-
-
-
- 1
-
- EU='eu'
-
-
-
- 1
-
- US='us'
-
-
-
-
-
- end
-
-
-
-
-
- end
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- 1
-
- module Contentstack
-
-
-
- 1
-
- VERSION = "0.0.4"
-
-
-
-
-
- end
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- 1
-
- require 'spec_helper'
-
-
-
- 1
-
- require_relative '../lib/contentstack.rb'
-
-
-
-
-
-
-
-
-
- 1
-
- describe Contentstack::Asset do
-
-
-
- 8
-
- let(:client) { create_client }
-
-
-
-
-
-
-
-
-
- 1
-
- it "has attribute called `uid`" do
-
-
-
- 1
-
- @uid = "blt3ca1a3470787ba63"
-
-
-
- 1
-
- @asset = client.asset(@uid).fetch
-
-
-
- 1
-
- expect(@asset.uid).not_to be nil
-
-
-
-
-
- end
-
-
-
-
-
-
-
-
-
- 1
-
- it "should match uid" do
-
-
-
- 1
-
- @uid = "blt3ca1a3470787ba63"
-
-
-
- 1
-
- @asset = client.asset(@uid).fetch
-
-
-
- 1
-
- expect(@asset.uid).to eq @uid
-
-
-
-
-
- end
-
-
-
-
-
-
-
-
-
- 1
-
- it "has attribute called `url`" do
-
-
-
- 1
-
- @uid = "blt3ca1a3470787ba63"
-
-
-
- 1
-
- @asset = client.asset(@uid).fetch
-
-
-
- 1
-
- expect(@asset.url).not_to be nil
-
-
-
-
-
- end
-
-
-
-
-
-
-
-
-
- 1
-
- it "has attribute called `tags`" do
-
-
-
- 1
-
- @uid = "blt3ca1a3470787ba63"
-
-
-
- 1
-
- @asset = client.asset(@uid).fetch
-
-
-
- 1
-
- expect(@asset.tags).not_to be nil
-
-
-
-
-
- end
-
-
-
-
-
-
-
-
-
- 1
-
- it "has attribute called `file_size`" do
-
-
-
- 1
-
- @uid = "blt3ca1a3470787ba63"
-
-
-
- 1
-
- @asset = client.asset(@uid).fetch
-
-
-
- 1
-
- expect(@asset.file_size).not_to be nil
-
-
-
-
-
- end
-
-
-
-
-
-
-
-
-
- 1
-
- it "has attribute called `filename`" do
-
-
-
- 1
-
- @uid = "blt3ca1a3470787ba63"
-
-
-
- 1
-
- @asset = client.asset(@uid).fetch
-
-
-
- 1
-
- expect(@asset.filename).not_to be nil
-
-
-
-
-
- end
-
-
-
-
-
-
-
-
-
- 1
-
- it "has attribute called `content_type`" do
-
-
-
- 1
-
- @uid = "blt3ca1a3470787ba63"
-
-
-
- 1
-
- @asset = client.asset(@uid).fetch
-
-
-
- 1
-
- expect(@asset.content_type).not_to be nil
-
-
-
-
-
- end
-
-
-
-
-
- end
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- 1
-
- require 'spec_helper'
-
-
-
- 1
-
- require_relative '../lib/contentstack.rb'
-
-
-
-
-
-
-
-
-
- 1
-
- describe Contentstack::ContentType do
-
-
-
- 7
-
- let(:client) { create_client }
-
-
-
- 2
-
- let(:eu_client) { create_client('ACCESS_TOKEN', 'API_KEY', 'STACK_ENV', {region: Contentstack::Region::EU}) }
-
-
-
- 2
-
- let(:custom_host_client) { create_client('ACCESS_TOKEN', 'API_KEY', 'STACK_ENV', {host: "https://custom-cdn.contentstack.com"}) }
-
-
-
-
-
-
-
-
-
- 1
-
- describe "Fetch data from API" do
-
-
-
- 1
-
- it "has class as Contentstack::ContentType" do
-
-
-
- 1
-
- @data = client.content_types.first
-
-
-
- 1
-
- expect(@data.class).to eq Contentstack::ContentType
-
-
-
-
-
- end
-
-
-
-
-
-
-
-
-
- 1
-
- it "has method called title with data" do
-
-
-
- 1
-
- @data = client.content_types.first
-
-
-
- 1
-
- expect(@data.title).not_to be nil
-
-
-
-
-
- end
-
-
-
-
-
-
-
-
-
- 1
-
- it "has method called title with data from eu" do
-
-
-
- 1
-
- @data = eu_client.content_types.first
-
-
-
- 1
-
- expect(@data.title).not_to be nil
-
-
-
-
-
- end
-
-
-
-
-
-
-
-
-
- 1
-
- it "has method called title with data from custom client" do
-
-
-
- 1
-
- @data = custom_host_client.content_types.first
-
-
-
- 1
-
- expect(@data.title).not_to be nil
-
-
-
-
-
- end
-
-
-
-
-
-
-
-
-
- 1
-
- it "has method called uid with data" do
-
-
-
- 1
-
- @data = client.content_types.first
-
-
-
- 1
-
- expect(@data.uid).not_to be nil
-
-
-
-
-
- end
-
-
-
-
-
-
-
-
-
- 1
-
- it "has method called created_at with data" do
-
-
-
- 1
-
- @data = client.content_types.first
-
-
-
- 1
-
- expect(@data.created_at).not_to be nil
-
-
-
-
-
- end
-
-
-
-
-
-
-
-
-
- 1
-
- it "has method called updated_at with data" do
-
-
-
- 1
-
- @data = client.content_types.first
-
-
-
- 1
-
- expect(@data.updated_at).not_to be nil
-
-
-
-
-
- end
-
-
-
-
-
-
-
-
-
- 1
-
- it "has method called attributes with data" do
-
-
-
- 1
-
- @data = client.content_types.first
-
-
-
- 1
-
- expect(@data.attributes).not_to be nil
-
-
-
-
-
- end
-
-
-
-
-
- end
-
-
-
-
-
-
-
-
-
- 1
-
- describe "Initialized using class" do
-
-
-
- 1
-
- before(:each) do
-
-
-
- 5
-
- @data = Contentstack::ContentType.new({uid: "DummyUID"})
-
-
-
-
-
- end
-
-
-
-
-
-
-
-
-
- 1
-
- it "has method called title without data" do
-
-
-
- 1
-
- expect(@data.title).to be nil
-
-
-
-
-
- end
-
-
-
-
-
-
-
-
-
- 1
-
- it "has method called uid with data" do
-
-
-
- 1
-
- expect(@data.uid).not_to be nil
-
-
-
-
-
- end
-
-
-
-
-
-
-
-
-
- 1
-
- it "has method called created_at without data" do
-
-
-
- 1
-
- expect(@data.created_at).to be nil
-
-
-
-
-
- end
-
-
-
-
-
-
-
-
-
- 1
-
- it "has method called updated_at without data" do
-
-
-
- 1
-
- expect(@data.updated_at).to be nil
-
-
-
-
-
- end
-
-
-
-
-
-
-
-
-
- 1
-
- it "has method called attributes without data" do
-
-
-
- 1
-
- expect(@data.attributes).not_to be nil
-
-
-
-
-
- end
-
-
-
-
-
- end
-
-
-
-
-
- end
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- 1
-
- require 'spec_helper'
-
-
-
- 1
-
- require_relative '../lib/contentstack.rb'
-
-
-
-
-
-
-
-
-
- 1
-
- describe Contentstack do
-
-
-
- 2
-
- let(:client) { create_client }
-
-
-
- 2
-
- let(:eu_client) { create_client('ACCESS_TOKEN', 'API_KEY', 'STACK_ENV', {region: Contentstack::Region::EU}) }
-
-
-
- 2
-
- let(:custom_host_client) { create_client('ACCESS_TOKEN', 'API_KEY', 'STACK_ENV', {host: "https://custom-cdn.contentstack.com"}) }
-
-
-
-
-
-
-
-
-
- 1
-
- it "has a version number" do
-
-
-
- 1
-
- expect(Contentstack::VERSION).not_to be nil
-
-
-
-
-
- end
-
-
-
-
-
-
-
-
-
- 1
-
- it "has region data" do
-
-
-
- 1
-
- expect(Contentstack::Region::EU).not_to be 'eu'
-
-
-
- 1
-
- expect(Contentstack::Region::US).not_to be 'us'
-
-
-
-
-
- end
-
-
-
-
-
-
-
-
-
- 1
-
- it "has default host and region" do
-
-
-
- 1
-
- expect(client.region).to eq Contentstack::Region::US
-
-
-
- 1
-
- expect(client.host).to eq 'https://cdn.contentstack.io'
-
-
-
-
-
- end
-
-
-
-
-
-
-
-
-
- 1
-
- it "has custom region with region host" do
-
-
-
- 1
-
- expect(eu_client.region).to eq Contentstack::Region::EU
-
-
-
- 1
-
- expect(eu_client.host).to eq 'https://eu-cdn.contentstack.com'
-
-
-
-
-
- end
-
-
-
-
-
-
-
-
-
- 1
-
- it "has custom host" do
-
-
-
- 1
-
- expect(custom_host_client.host).to eq 'https://custom-cdn.contentstack.com'
-
-
-
-
-
- end
-
-
-
-
-
-
-
-
-
-
-
- end
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- 1
-
- require 'spec_helper'
-
-
-
- 1
-
- require_relative '../lib/contentstack.rb'
-
-
-
-
-
-
-
-
-
- 1
-
- describe Contentstack::EntryCollection do
-
-
-
- 7
-
- let(:client) { create_client }
-
-
-
-
-
-
-
-
-
- 1
-
- it "has no instance variable `count`" do
-
-
-
- 1
-
- @data = client.content_type("category").query.fetch
-
-
-
- 1
-
- @countdata = client.content_type("category").query.include_count.fetch
-
-
-
- 1
-
- expect(@data.count).to be nil
-
-
-
-
-
- end
-
-
-
-
-
-
-
-
-
- 1
-
- it "has instance variable `count`" do
-
-
-
- 1
-
- @data = client.content_type("category").query.fetch
-
-
-
- 1
-
- @countdata = client.content_type("category").query.include_count.fetch
-
-
-
- 1
-
- expect(@countdata.count).not_to be nil
-
-
-
-
-
- end
-
-
-
-
-
-
-
-
-
- 1
-
- it "has instance variable `entries`" do
-
-
-
- 1
-
- @data = client.content_type("category").query.fetch
-
-
-
- 1
-
- @countdata = client.content_type("category").query.include_count.fetch
-
-
-
- 1
-
- expect(@data.entries).not_to be nil
-
-
-
-
-
- end
-
-
-
-
-
-
-
-
-
- 1
-
- it "has the same entry using `first` method" do
-
-
-
- 1
-
- @data = client.content_type("category").query.fetch
-
-
-
- 1
-
- @countdata = client.content_type("category").query.include_count.fetch
-
-
-
- 1
-
- expect(@data.entries[0].uid).to eq @data.first.uid
-
-
-
-
-
- end
-
-
-
-
-
-
-
-
-
- 1
-
- it "has the same entry using `last` method" do
-
-
-
- 1
-
- @data = client.content_type("category").query.fetch
-
-
-
- 1
-
- @countdata = client.content_type("category").query.include_count.fetch
-
-
-
- 1
-
- expect(@data.entries[-1].uid).to eq @data.last.uid
-
-
-
-
-
- end
-
-
-
-
-
-
-
-
-
- 1
-
- it "has the same entry using `get` method" do
-
-
-
- 1
-
- @data = client.content_type("category").query.fetch
-
-
-
- 1
-
- @countdata = client.content_type("category").query.include_count.fetch
-
-
-
- 1
-
- expect(@data.entries[3].uid).to eq @data.get(3).uid
-
-
-
-
-
- end
-
-
-
-
-
- end
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- 1
-
- require 'spec_helper'
-
-
-
- 1
-
- require_relative '../lib/contentstack.rb'
-
-
-
-
-
-
-
-
-
- 1
-
- describe Contentstack::Entry do
-
-
-
- 4
-
- let(:client) { create_client }
-
-
-
-
-
-
-
-
-
- 1
-
- it "Contentstack::EntryCollection should have Contentstack::Entry instance" do
-
-
-
- 1
-
- data = client.content_type("category").query.fetch
-
-
-
- 1
-
- expect(data.class).to eq Contentstack::EntryCollection
-
-
-
- 1
-
- expect(data.first.class).to eq Contentstack::Entry
-
-
-
-
-
- end
-
-
-
-
-
-
-
-
-
- 1
-
- it "is an instance of Contentstack::Entry if single entry is fetched" do
-
-
-
- 1
-
- data = client.content_type("category").entry("blt05056a2f5e0ebf76").fetch
-
-
-
- 1
-
- expect(data.class).to eq Contentstack::Entry
-
-
-
-
-
- end
-
-
-
-
-
-
-
-
-
- 1
-
- it 'has a method `get` to get attributes data' do
-
-
-
- 1
-
- uid = "blt05056a2f5e0ebf76"
-
-
-
- 1
-
- data = client.content_type("category").entry(uid).fetch
-
-
-
- 1
-
- expect(data.get('uid')).to eq uid
-
-
-
-
-
- end
-
-
-
-
-
- end
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- 1
-
- require 'spec_helper'
-
-
-
- 1
-
- require_relative '../lib/contentstack.rb'
-
-
-
-
-
-
-
-
-
- 1
-
- describe Contentstack::Query do
-
-
-
- 36
-
- let(:client) { create_client }
-
-
-
- 23
-
- let(:category_query) {client.content_type("category").query}
-
-
-
- 14
-
- let(:product_query) {client.content_type("product").query}
-
-
-
-
-
-
-
-
-
- 1
-
- it "should get data using `where` method" do
-
-
-
- 1
-
- data = category_query.where({title: "Electronics"}).fetch
-
-
-
- 1
-
- expect(data.length).to eq 5
-
-
-
-
-
- end
-
-
-
-
-
-
-
-
-
- 1
-
- it "should get data using `regex` method" do
-
-
-
- 1
-
- data = category_query.regex("title", "App.*").fetch
-
-
-
- 1
-
- expect(data.length).to eq 5
-
-
-
-
-
- end
-
-
-
-
-
-
-
-
-
- 1
-
- it "should get data using `less_than` method" do
-
-
-
- 1
-
- data = product_query.less_than("price", 150).fetch
-
-
-
- 1
-
- expect(data.length).to eq 3
-
-
-
-
-
- end
-
-
-
-
-
-
-
-
-
- 1
-
- it "should get data using `less_than_or_equal` method" do
-
-
-
- 1
-
- data = product_query.less_than_or_equal("price", 166).fetch
-
-
-
- 1
-
- expect(data.length).to eq 3
-
-
-
-
-
- end
-
-
-
-
-
-
-
-
-
- 1
-
- it "should get data using `greater_than` method" do
-
-
-
- 1
-
- data = product_query.greater_than("price", 120).fetch
-
-
-
- 1
-
- expect(data.length).to eq 3
-
-
-
-
-
- end
-
-
-
-
-
-
-
-
-
- 1
-
- it "should get data using `greater_than_or_equal` method" do
-
-
-
- 1
-
- data = product_query.greater_than_or_equal("price", 166).fetch
-
-
-
- 1
-
- expect(data.length).to eq 3
-
-
-
-
-
- end
-
-
-
-
-
-
-
-
-
- 1
-
- it "should get data using `not_equal_to` method" do
-
-
-
- 1
-
- data = product_query.not_equal_to("price", 166).fetch
-
-
-
- 1
-
- expect(data.length).to eq 3
-
-
-
-
-
- end
-
-
-
-
-
-
-
-
-
- 1
-
- it "should get data using `limit` method" do
-
-
-
- 1
-
- data = category_query.limit(2).fetch
-
-
-
- 1
-
- expect(data.length).to eq 5
-
-
-
-
-
- end
-
-
-
-
-
-
-
-
-
- 1
-
- it "should get data using `skip` method" do
-
-
-
- 1
-
- data = category_query.skip(5).fetch
-
-
-
- 1
-
- expect(data.length).to eq 5
-
-
-
-
-
- end
-
-
-
-
-
-
-
-
-
- 1
-
- it "should get data using `include_count` method" do
-
-
-
- 1
-
- data = category_query.include_count.fetch
-
-
-
- 1
-
- expect(data.count).not_to be nil
-
-
-
- 1
-
- expect(data.count).to eq 5
-
-
-
-
-
- end
-
-
-
-
-
-
-
-
-
- 1
-
- it "should get data using `only` method with string parameter" do
-
-
-
- 1
-
- data = category_query.only("title").fetch
-
-
-
- 1
-
- expect(data.first.fields[:title]).not_to be nil
-
-
-
- 1
-
- expect(data.first.fields[:uid]).not_to be nil
-
-
-
-
-
- end
-
-
-
-
-
-
-
-
-
- 1
-
- it "should get data using `only` method with array parameter" do
-
-
-
- 1
-
- data = category_query.only(["title"]).fetch
-
-
-
- 1
-
- expect(data.first.fields[:title]).not_to be nil
-
-
-
- 1
-
- expect(data.first.fields[:uid]).not_to be nil
-
-
-
-
-
- end
-
-
-
-
-
-
-
-
-
- 1
-
- it "should get data using `except` method with string parameter" do
-
-
-
- 1
-
- data = category_query.except("category_tags").fetch
-
-
-
- 1
-
- expect(data.first.fields[:category_tags]).to be nil
-
-
-
-
-
- end
-
-
-
-
-
-
-
-
-
- 1
-
- it "should get data using `except` method with array parameter" do
-
-
-
- 1
-
- data = category_query.except(["description"]).fetch
-
-
-
- 1
-
- expect(data.first.fields[:description]).to be nil
-
-
-
-
-
- end
-
-
-
-
-
-
-
-
-
- 1
-
- it "should get data using `tags` method" do
-
-
-
- 1
-
- data = category_query.tags(["tag1"]).fetch
-
-
-
- 1
-
- expect(data.length).to eq 5
-
-
-
-
-
- end
-
-
-
-
-
-
-
-
-
- 1
-
- it "should get data using `contained_in` method" do
-
-
-
- 1
-
- data = category_query.contained_in("title", ["Electronics", "Apparel"]).fetch
-
-
-
- 1
-
- expect(data.length).to eq 5
-
-
-
- 1
-
- expect(data.first.fields[:title]).to eq "Home & Appliances"
-
-
-
- 1
-
- expect(data.last.fields[:title]).to eq "Headphones"
-
-
-
-
-
- end
-
-
-
-
-
-
-
-
-
- 1
-
- it "should get data using `not_contained_in` method" do
-
-
-
- 1
-
- data = category_query.not_contained_in("title", ["Electronics", "Apparel"]).fetch
-
-
-
- 1
-
- expect(data.length).to eq 5
-
-
-
-
-
- end
-
-
-
-
-
-
-
-
-
- 1
-
- it "should get data using `in` method" do
-
-
-
- 1
-
- data = category_query.contained_in("title", ["Electronics", "Apparel"]).fetch
-
-
-
- 1
-
- expect(data.length).to eq 5
-
-
-
-
-
- end
-
-
-
-
-
-
-
-
-
- 1
-
- it "should get data using `not_in` method" do
-
-
-
- 1
-
- data = category_query.not_contained_in("title", ["Electronics", "Apparel"]).fetch
-
-
-
- 1
-
- expect(data.length).to eq 5
-
-
-
-
-
- end
-
-
-
-
-
-
-
-
-
- 1
-
- it "should get data using `ascending` method" do
-
-
-
- 1
-
- data = product_query.ascending("price").fetch
-
-
-
- 1
-
- expect(data.first.fields[:title]).to eq "Motorola Moto X4"
-
-
-
-
-
- end
-
-
-
-
-
-
-
-
-
- 1
-
- it "should get data using `descending` method" do
-
-
-
- 1
-
- data = product_query.descending("price").fetch
-
-
-
- 1
-
- expect(data.first.fields[:title]).to eq "Motorola Moto X4"
-
-
-
-
-
- end
-
-
-
-
-
-
-
-
-
- 1
-
- it "should get data using `only` method for reference fields" do
-
-
-
- 1
-
- data = product_query.include_reference('categories').only("categories", ["title", "description"]).fetch
-
-
-
- 1
-
- expect(data.first.fields[:categories][0][:title]).to eq "Smartphones"
-
-
-
-
-
- end
-
-
-
-
-
-
-
-
-
- 1
-
- it "should get data using `except` method for reference fields" do
-
-
-
- 1
-
- data = product_query.include_reference('categories').except("categories", "title").fetch
-
-
-
- 1
-
- expect(data.first.fields[:categories][0][:title]).to eq 'Smartphones'
-
-
-
-
-
- end
-
-
-
-
-
-
-
-
-
- 1
-
- it "should get data using `include_schema` method" do
-
-
-
- 1
-
- data = category_query.include_schema.fetch
-
-
-
- 1
-
- expect(data.schema).not_to be nil
-
-
-
-
-
- end
-
-
-
-
-
-
-
-
-
- 1
-
- it "should get data using `include_content_type` method" do
-
-
-
- 1
-
- data = category_query.include_content_type.fetch
-
-
-
- 1
-
- expect(data.content_type).not_to be nil
-
-
-
-
-
- end
-
-
-
-
-
-
-
-
-
- 1
-
- it "should get data using `include_reference` method" do
-
-
-
- 1
-
- data = product_query.include_reference('categories').fetch
-
-
-
- 1
-
- puts data.first.get("categories.title")
-
-
-
- 1
-
- expect(data.first.fields[:categories][0][:title]).not_to be nil
-
-
-
-
-
- end
-
-
-
-
-
-
-
-
-
- 1
-
- it "should get data using `include_owner` method" do
-
-
-
- 1
-
- data = product_query.include_owner.fetch
-
-
-
- 1
-
- expect(data.first.fields[:_owner]).not_to be nil
-
-
-
-
-
- end
-
-
-
-
-
-
-
-
-
- 1
-
- it "should get data using `include_draft` method" do
-
-
-
- 1
-
- data = category_query.include_draft.fetch
-
-
-
- 1
-
- expect(data.length).to eq 5
-
-
-
-
-
- end
-
-
-
-
-
-
-
-
-
- 1
-
- it "should get data using `search` method" do
-
-
-
- 1
-
- data = category_query.search("App").fetch
-
-
-
- 1
-
- expect(data.length).to eq 5
-
-
-
-
-
- end
-
-
-
-
-
-
-
-
-
- 1
-
- it "should get data using `count` method" do
-
-
-
- 1
-
- data = category_query.count
-
-
-
- 1
-
- expect(data).to eq 5
-
-
-
-
-
- end
-
-
-
-
-
-
-
-
-
- 1
-
- it "should get data using `exists` method" do
-
-
-
- 1
-
- data = category_query.exists?('description').fetch
-
-
-
- 1
-
- expect(data.length).to eq 5
-
+
+
+
+
-
-
-
- end
-
+
+
+
+
+
-
-
-
-
-
+
+
+ 1
+
+
+
+
+ module Contentstack
+
+
+
+
+
+ 1
+
+
+
+
+ class Region
+
+
+
+
+
+ 1
+
+
+
+
+ EU='eu'
+
+
+
+
+
+ 1
+
+
+
+
+ US='us'
+
+
+
+
+
+
+
+
+
+
+ end
+
+
+
+
+
+
+
+
+
+
+ end
+
+
-
- 1
-
- it "should get data using `not_exists` method" do
-
+
+
+
+
-
- 1
-
- data = product_query.not_exists?('banner_image').fetch
-
+
+
+
+
+
-
- 1
-
- expect(data.length).to eq 3
-
+
+
+ 1
+
+
+
+
+ module Contentstack
+
+
+
+
+
+ 1
+
+
+
+
+ VERSION = "0.0.4"
+
+
+
+
+
+
+
+
+
+
+ end
+
+
-
-
-
- end
-
+
+
+
+
-
-
-
-
-
+
+
+
+
+
-
- 1
-
- it "should get data using `and` method" do
-
+
+
+ 1
+
+
+
+
+ class Hash
+
+
+
+
+
+ 1
+
+
+
+
+ def to_query(namespace = nil)
+
+
+
+
+
+ 72
+
+
+
+
+ collect do |key, value|
+
+
+
+
+
+ 323
+
+
+
+
+ value.to_query(namespace ? "#{namespace}[#{key}]" : key)
+
+
+
+
+
+
+
+
+
+
+ end.sort * '&'
+
+
+
+
+
+
+
+
+
+
+ end
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 1
+
+
+
+
+ def symbolize_keys
+
+
+
+
+
+ 3056
+
+
+
+
+ new_hash = {}
+
+
+
+
+
+ 3056
+
+
+
+
+ self.each do |key,value|
+
+
+
+
+
+ 15692
+
+
+
+
+ if [Hash, Array].include?(value.class)
+
+
+
+
+
+ 3118
+
+
+
+
+ new_hash[key.to_sym] = value.symbolize_keys
+
+
+
+
+
+
+
+
+
+
+ else
+
+
+
+
+
+ 12574
+
+
+
+
+ new_hash[key.to_sym] = value
+
+
+
+
+
+
+
+
+
+
+ end
+
+
+
+
+
+
+
+
+
+
+ end
+
+
+
+
+
+ 3056
+
+
+
+
+ new_hash
+
+
+
+
+
+
+
+
+
+
+ end
+
+
+
+
+
+
+
+
+
+
+ end
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 1
+
+
+
+
+ class Array
+
+
+
+
+
+ 1
+
+
+
+
+ def to_query(key)
+
+
+
+
+
+ 10
+
+
+
+
+ prefix = "#{key}[]"
+
+
+
+
+
+ 21
+
+
+
+
+ collect { |value| value.to_query(prefix) }.join '&'
+
+
+
+
+
+
+
+
+
+
+ end
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 1
+
+
+
+
+ def symbolize_keys
+
+
+
+
+
+ 1250
+
+
+
+
+ collect do |entry|
+
+
+
+
+
+ 1007
+
+
+
+
+ if entry.class == Hash
+
+
+
+
+
+ 801
+
+
+
+
+ entry.symbolize_keys
+
+
+
+
+
+
+
+
+
+
+ else
+
+
+
+
+
+ 206
+
+
+
+
+ entry
+
+
+
+
+
+
+
+
+
+
+ end
+
+
+
+
+
+
+
+
+
+
+ end
+
+
+
+
+
+
+
+
+
+
+ end
+
+
+
+
+
+
+
+
+
+
+ end
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 1
+
+
+
+
+ class String
+
+
+
+
+
+ 1
+
+
+
+
+ def to_query(key)
+
+
+
+
+
+ 172
+
+
+
+
+ require 'cgi' unless defined?(CGI) && defined?(CGI::escape)
+
+
+
+
+
+ 172
+
+
+
+
+ "#{CGI.escape(key.to_param)}=#{CGI.escape(to_param.to_s)}"
+
+
+
+
+
+
+
+
+
+
+ end
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 1
+
+
+
+
+ def to_param
+
+
+
+
+
+ 183
+
+
+
+
+ to_s
+
+
+
+
+
+
+
+
+
+
+ end
+
+
+
+
+
+
+
+
+
+
+ end
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 1
+
+
+
+
+ class Symbol
+
+
+
+
+
+ 1
+
+
+
+
+ def to_query(key)
+
+
+
+
+
+
+
+
+
+
+ to_s.to_query(key)
+
+
+
+
+
+
+
+
+
+
+ end
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 1
+
+
+
+
+ def to_param
+
+
+
+
+
+ 307
+
+
+
+
+ to_s
+
+
+
+
+
+
+
+
+
+
+ end
+
+
+
+
+
+
+
+
+
+
+ end
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 1
+
+
+
+
+ class NilClass
+
+
+
+
+
+ 1
+
+
+
+
+ def to_query(key)
+
+
+
+
+
+ 64
+
+
+
+
+ to_s.to_query(key)
+
+
+
+
+
+
+
+
+
+
+ end
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 1
+
+
+
+
+ def to_param
+
+
+
+
+
+
+
+
+
+
+ to_s
+
+
+
+
+
+
+
+
+
+
+ end
+
+
+
+
+
+
+
+
+
+
+ end
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 1
+
+
+
+
+ class TrueClass
+
+
+
+
+
+ 1
+
+
+
+
+ def to_query(key)
+
+
+
+
+
+
+
+
+
+
+ to_s.to_query(key)
+
+
+
+
+
+
+
+
+
+
+ end
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 1
+
+
+
+
+ def to_query(val)
+
+
+
+
+
+ 12
+
+
+
+
+ "#{CGI.escape(val.to_param)}=#{CGI.escape(to_s)}"
+
+
+
+
+
+
+
+
+
+
+ end
+
+
+
+
+
+
+
+
+
+
+ end
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 1
+
+
+
+
+ class FalseClass
+
+
+
+
+
+ 1
+
+
+
+
+ def to_query(key)
+
+
+
+
+
+
+
+
+
+
+ to_s.to_query(key)
+
+
+
+
+
+
+
+
+
+
+ end
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 1
+
+
+
+
+ def to_query(val)
+
+
+
+
+
+ 39
+
+
+
+
+ "#{CGI.escape(val.to_param)}=#{CGI.escape(to_s)}"
+
+
+
+
+
+
+
+
+
+
+ end
+
+
+
+
+
+
+
+
+
+
+ end
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 1
+
+
+
+
+ class Integer
+
+
+
+
+
+ 1
+
+
+
+
+ def to_query(key)
+
+
+
+
+
+
+
+
+
+
+ to_s.to_query(key)
+
+
+
+
+
+
+
+
+
+
+ end
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 1
+
+
+
+
+ def to_query(val)
+
+
+
+
+
+ 95
+
+
+
+
+ "#{CGI.escape(val.to_param)}=#{CGI.escape(to_s)}"
+
+
+
+
+
+
+
+
+
+
+ end
+
+
+
+
+
+
+
+
+
+
+ end
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 1
+
+
+
+
+ class Numeric
+
+
+
+
+
+ 1
+
+
+
+
+ def to_query(key)
+
+
+
+
+
+
+
+
+
+
+ to_s.to_query(key)
+
+
+
+
+
+
+
+
+
+
+ end
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 1
+
+
+
+
+ def to_query(val)
+
+
+
+
+
+
+
+
+
+
+ "#{CGI.escape(val.to_param)}=#{CGI.escape(to_s)}"
+
+
+
+
+
+
+
+
+
+
+ end
+
+
+
+
+
+
+
+
+
+
+ end
+
+
-
- 1
-
- q1 = client.content_type("category").query.regex("title", "App.*")
-
+
+
+
+
-
- 1
-
- q2 = client.content_type("category").query.where({"description"=>"Appliances Category"})
-
+
+
+
+
+
-
- 1
-
- data = category_query.and([q1,q2]).fetch
-
+
+
+ 1
+
+
+
+
+ require 'spec_helper'
+
+
+
+
+
+ 1
+
+
+
+
+ require_relative '../lib/contentstack.rb'
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 1
+
+
+
+
+ describe Contentstack::Asset do
+
+
+
+
+
+ 8
+
+
+
+
+ let(:client) { create_client }
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 1
+
+
+
+
+ it "has attribute called `uid`" do
+
+
+
+
+
+ 1
+
+
+
+
+ @uid = "blt3ca1a3470787ba63"
+
+
+
+
+
+ 1
+
+
+
+
+ @asset = client.asset(@uid).fetch
+
+
+
+
+
+ 1
+
+
+
+
+ expect(@asset.uid).not_to be nil
+
+
+
+
+
+
+
+
+
+
+ end
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 1
+
+
+
+
+ it "should match uid" do
+
+
+
+
+
+ 1
+
+
+
+
+ @uid = "blt3ca1a3470787ba63"
+
+
+
+
+
+ 1
+
+
+
+
+ @asset = client.asset(@uid).fetch
+
+
+
+
+
+ 1
+
+
+
+
+ expect(@asset.uid).to eq @uid
+
+
+
+
+
+
+
+
+
+
+ end
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 1
+
+
+
+
+ it "has attribute called `url`" do
+
+
+
+
+
+ 1
+
+
+
+
+ @uid = "blt3ca1a3470787ba63"
+
+
+
+
+
+ 1
+
+
+
+
+ @asset = client.asset(@uid).fetch
+
+
+
+
+
+ 1
+
+
+
+
+ expect(@asset.url).not_to be nil
+
+
+
+
+
+
+
+
+
+
+ end
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 1
+
+
+
+
+ it "has attribute called `tags`" do
+
+
+
+
+
+ 1
+
+
+
+
+ @uid = "blt3ca1a3470787ba63"
+
+
+
+
+
+ 1
+
+
+
+
+ @asset = client.asset(@uid).fetch
+
+
+
+
+
+ 1
+
+
+
+
+ expect(@asset.tags).not_to be nil
+
+
+
+
+
+
+
+
+
+
+ end
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 1
+
+
+
+
+ it "has attribute called `file_size`" do
+
+
+
+
+
+ 1
+
+
+
+
+ @uid = "blt3ca1a3470787ba63"
+
+
+
+
+
+ 1
+
+
+
+
+ @asset = client.asset(@uid).fetch
+
+
+
+
+
+ 1
+
+
+
+
+ expect(@asset.file_size).not_to be nil
+
+
+
+
+
+
+
+
+
+
+ end
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 1
+
+
+
+
+ it "has attribute called `filename`" do
+
+
+
+
+
+ 1
+
+
+
+
+ @uid = "blt3ca1a3470787ba63"
+
+
+
+
+
+ 1
+
+
+
+
+ @asset = client.asset(@uid).fetch
+
+
+
+
+
+ 1
+
+
+
+
+ expect(@asset.filename).not_to be nil
+
+
+
+
+
+
+
+
+
+
+ end
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 1
+
+
+
+
+ it "has attribute called `content_type`" do
+
+
+
+
+
+ 1
+
+
+
+
+ @uid = "blt3ca1a3470787ba63"
+
+
+
+
+
+ 1
+
+
+
+
+ @asset = client.asset(@uid).fetch
+
+
+
+
+
+ 1
+
+
+
+
+ expect(@asset.content_type).not_to be nil
+
+
+
+
+
+
+
+
+
+
+ end
+
+
+
+
+
+
+
+
+
+
+ end
+
+
-
- 1
-
- expect(data.length).to eq 5
-
+
+
+
+
-
-
-
- end
-
+
+
+
+
+
-
-
-
-
-
+
+
+ 1
+
+
+
+
+ require 'spec_helper'
+
+
+
+
+
+ 1
+
+
+
+
+ require_relative '../lib/contentstack.rb'
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 1
+
+
+
+
+ describe Contentstack::ContentType do
+
+
+
+
+
+ 7
+
+
+
+
+ let(:client) { create_client }
+
+
+
+
+
+ 2
+
+
+
+
+ let(:eu_client) { create_client('DELIVERY_TOKEN', 'API_KEY', 'STACK_ENV', {region: Contentstack::Region::EU}) }
+
+
+
+
+
+ 2
+
+
+
+
+ let(:custom_host_client) { create_client('DELIVERY_TOKEN', 'API_KEY', 'STACK_ENV', {host: "https://custom-cdn.contentstack.com"}) }
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 1
+
+
+
+
+ describe "Fetch data from API" do
+
+
+
+
+
+ 1
+
+
+
+
+ it "has class as Contentstack::ContentType" do
+
+
+
+
+
+ 1
+
+
+
+
+ @data = client.content_types.first
+
+
+
+
+
+ 1
+
+
+
+
+ expect(@data.class).to eq Contentstack::ContentType
+
+
+
+
+
+
+
+
+
+
+ end
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 1
+
+
+
+
+ it "has method called title with data" do
+
+
+
+
+
+ 1
+
+
+
+
+ @data = client.content_types.first
+
+
+
+
+
+ 1
+
+
+
+
+ expect(@data.title).not_to be nil
+
+
+
+
+
+
+
+
+
+
+ end
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 1
+
+
+
+
+ it "has method called title with data from eu" do
+
+
+
+
+
+ 1
+
+
+
+
+ @data = eu_client.content_types.first
+
+
+
+
+
+ 1
+
+
+
+
+ expect(@data.title).not_to be nil
+
+
+
+
+
+
+
+
+
+
+ end
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 1
+
+
+
+
+ it "has method called title with data from custom client" do
+
+
+
+
+
+ 1
+
+
+
+
+ @data = custom_host_client.content_types.first
+
+
+
+
+
+ 1
+
+
+
+
+ expect(@data.title).not_to be nil
+
+
+
+
+
+
+
+
+
+
+ end
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 1
+
+
+
+
+ it "has method called uid with data" do
+
+
+
+
+
+ 1
+
+
+
+
+ @data = client.content_types.first
+
+
+
+
+
+ 1
+
+
+
+
+ expect(@data.uid).not_to be nil
+
+
+
+
+
+
+
+
+
+
+ end
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 1
+
+
+
+
+ it "has method called created_at with data" do
+
+
+
+
+
+ 1
+
+
+
+
+ @data = client.content_types.first
+
+
+
+
+
+ 1
+
+
+
+
+ expect(@data.created_at).not_to be nil
+
+
+
+
+
+
+
+
+
+
+ end
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 1
+
+
+
+
+ it "has method called updated_at with data" do
+
+
+
+
+
+ 1
+
+
+
+
+ @data = client.content_types.first
+
+
+
+
+
+ 1
+
+
+
+
+ expect(@data.updated_at).not_to be nil
+
+
+
+
+
+
+
+
+
+
+ end
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 1
+
+
+
+
+ it "has method called attributes with data" do
+
+
+
+
+
+ 1
+
+
+
+
+ @data = client.content_types.first
+
+
+
+
+
+ 1
+
+
+
+
+ expect(@data.attributes).not_to be nil
+
+
+
+
+
+
+
+
+
+
+ end
+
+
+
+
+
+
+
+
+
+
+ end
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 1
+
+
+
+
+ describe "Initialized using class" do
+
+
+
+
+
+ 1
+
+
+
+
+ before(:each) do
+
+
+
+
+
+ 5
+
+
+
+
+ @data = Contentstack::ContentType.new({uid: "DummyUID"})
+
+
+
+
+
+
+
+
+
+
+ end
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 1
+
+
+
+
+ it "has method called title without data" do
+
+
+
+
+
+ 1
+
+
+
+
+ expect(@data.title).to be nil
+
+
+
+
+
+
+
+
+
+
+ end
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 1
+
+
+
+
+ it "has method called uid with data" do
+
+
+
+
+
+ 1
+
+
+
+
+ expect(@data.uid).not_to be nil
+
+
+
+
+
+
+
+
+
+
+ end
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 1
+
+
+
+
+ it "has method called created_at without data" do
+
+
+
+
+
+ 1
+
+
+
+
+ expect(@data.created_at).to be nil
+
+
+
+
+
+
+
+
+
+
+ end
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 1
+
+
+
+
+ it "has method called updated_at without data" do
+
+
+
+
+
+ 1
+
+
+
+
+ expect(@data.updated_at).to be nil
+
+
+
+
+
+
+
+
+
+
+ end
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 1
+
+
+
+
+ it "has method called attributes without data" do
+
+
+
+
+
+ 1
+
+
+
+
+ expect(@data.attributes).not_to be nil
+
+
+
+
+
+
+
+
+
+
+ end
+
+
+
+
+
+
+
+
+
+
+ end
+
+
+
+
+
+
+
+
+
+
+ end
+
+
-
- 1
-
- it "should get data using `or` method" do
-
+
+
+
+
-
- 1
-
- q1 = client.content_type("category").query.regex("title", "App.*")
-
+
+
+
+
+
-
- 1
-
- q2 = client.content_type("category").query.regex("description", "App*")
-
+
+
+ 1
+
+
+
+
+ require 'spec_helper'
+
+
+
+
+
+ 1
+
+
+
+
+ require_relative '../lib/contentstack.rb'
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 1
+
+
+
+
+ describe Contentstack do
+
+
+
+
+
+ 2
+
+
+
+
+ let(:client) { create_client }
+
+
+
+
+
+ 2
+
+
+
+
+ let(:eu_client) { create_client('DELIVERY_TOKEN_TOKEN', 'API_KEY', 'STACK_ENV', {region: Contentstack::Region::EU}) }
+
+
+
+
+
+ 2
+
+
+
+
+ let(:custom_host_client) { create_client('DELIVERY_TOKEN_TOKEN', 'API_KEY', 'STACK_ENV', {host: "https://custom-cdn.contentstack.com"}) }
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 1
+
+
+
+
+ it "has a version number" do
+
+
+
+
+
+ 1
+
+
+
+
+ expect(Contentstack::VERSION).not_to be nil
+
+
+
+
+
+
+
+
+
+
+ end
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 1
+
+
+
+
+ it "has region data" do
+
+
+
+
+
+ 1
+
+
+
+
+ expect(Contentstack::Region::EU).not_to be 'eu'
+
+
+
+
+
+ 1
+
+
+
+
+ expect(Contentstack::Region::US).not_to be 'us'
+
+
+
+
+
+
+
+
+
+
+ end
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 1
+
+
+
+
+ it "has default host and region" do
+
+
+
+
+
+ 1
+
+
+
+
+ expect(client.region).to eq Contentstack::Region::US
+
+
+
+
+
+ 1
+
+
+
+
+ expect(client.host).to eq 'https://cdn.contentstack.io'
+
+
+
+
+
+
+
+
+
+
+ end
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 1
+
+
+
+
+ it "has custom region with region host" do
+
+
+
+
+
+ 1
+
+
+
+
+ expect(eu_client.region).to eq Contentstack::Region::EU
+
+
+
+
+
+ 1
+
+
+
+
+ expect(eu_client.host).to eq 'https://eu-cdn.contentstack.com'
+
+
+
+
+
+
+
+
+
+
+ end
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 1
+
+
+
+
+ it "has custom host" do
+
+
+
+
+
+ 1
+
+
+
+
+ expect(custom_host_client.host).to eq 'https://custom-cdn.contentstack.com'
+
+
+
+
+
+
+
+
+
+
+ end
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ end
+
+
-
- 1
-
- data = category_query.or([q1,q2]).fetch
-
+
+
+
+
-
- 1
-
- expect(data.length).to eq 5
-
+
+
+
+
+
-
-
-
- end
-
+
+
+ 1
+
+
+
+
+ require 'spec_helper'
+
+
+
+
+
+ 1
+
+
+
+
+ require_relative '../lib/contentstack.rb'
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 1
+
+
+
+
+ describe Contentstack::EntryCollection do
+
+
+
+
+
+ 7
+
+
+
+
+ let(:client) { create_client }
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 1
+
+
+
+
+ it "has no instance variable `count`" do
+
+
+
+
+
+ 1
+
+
+
+
+ @data = client.content_type("category").query.fetch
+
+
+
+
+
+ 1
+
+
+
+
+ @countdata = client.content_type("category").query.include_count.fetch
+
+
+
+
+
+ 1
+
+
+
+
+ expect(@data.count).to be nil
+
+
+
+
+
+
+
+
+
+
+ end
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 1
+
+
+
+
+ it "has instance variable `count`" do
+
+
+
+
+
+ 1
+
+
+
+
+ @data = client.content_type("category").query.fetch
+
+
+
+
+
+ 1
+
+
+
+
+ @countdata = client.content_type("category").query.include_count.fetch
+
+
+
+
+
+ 1
+
+
+
+
+ expect(@countdata.count).not_to be nil
+
+
+
+
+
+
+
+
+
+
+ end
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 1
+
+
+
+
+ it "has instance variable `entries`" do
+
+
+
+
+
+ 1
+
+
+
+
+ @data = client.content_type("category").query.fetch
+
+
+
+
+
+ 1
+
+
+
+
+ @countdata = client.content_type("category").query.include_count.fetch
+
+
+
+
+
+ 1
+
+
+
+
+ expect(@data.entries).not_to be nil
+
+
+
+
+
+
+
+
+
+
+ end
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 1
+
+
+
+
+ it "has the same entry using `first` method" do
+
+
+
+
+
+ 1
+
+
+
+
+ @data = client.content_type("category").query.fetch
+
+
+
+
+
+ 1
+
+
+
+
+ @countdata = client.content_type("category").query.include_count.fetch
+
+
+
+
+
+ 1
+
+
+
+
+ expect(@data.entries[0].uid).to eq @data.first.uid
+
+
+
+
+
+
+
+
+
+
+ end
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 1
+
+
+
+
+ it "has the same entry using `last` method" do
+
+
+
+
+
+ 1
+
+
+
+
+ @data = client.content_type("category").query.fetch
+
+
+
+
+
+ 1
+
+
+
+
+ @countdata = client.content_type("category").query.include_count.fetch
+
+
+
+
+
+ 1
+
+
+
+
+ expect(@data.entries[-1].uid).to eq @data.last.uid
+
+
+
+
+
+
+
+
+
+
+ end
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 1
+
+
+
+
+ it "has the same entry using `get` method" do
+
+
+
+
+
+ 1
+
+
+
+
+ @data = client.content_type("category").query.fetch
+
+
+
+
+
+ 1
+
+
+
+
+ @countdata = client.content_type("category").query.include_count.fetch
+
+
+
+
+
+ 1
+
+
+
+
+ expect(@data.entries[3].uid).to eq @data.get(3).uid
+
+
+
+
+
+
+
+
+
+
+ end
+
+
+
+
+
+
+
+
+
+
+ end
+
+
-
-
-
-
-
+
+
+
+
-
- 1
-
- it "should set locale the in the request query" do
-
+
+
+
+
+
-
- 1
-
- data = product_query.locale('en-us')
-
+
+
+ 1
+
+
+
+
+ require 'spec_helper'
+
+
+
+
+
+ 1
+
+
+
+
+ require_relative '../lib/contentstack.rb'
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 1
+
+
+
+
+ describe Contentstack::Entry do
+
+
+
+
+
+ 4
+
+
+
+
+ let(:client) { create_client }
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 1
+
+
+
+
+ it "Contentstack::EntryCollection should have Contentstack::Entry instance" do
+
+
+
+
+
+ 1
+
+
+
+
+ data = client.content_type("category").query.fetch
+
+
+
+
+
+ 1
+
+
+
+
+ expect(data.class).to eq Contentstack::EntryCollection
+
+
+
+
+
+ 1
+
+
+
+
+ expect(data.first.class).to eq Contentstack::Entry
+
+
+
+
+
+
+
+
+
+
+ end
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 1
+
+
+
+
+ it "is an instance of Contentstack::Entry if single entry is fetched" do
+
+
+
+
+
+ 1
+
+
+
+
+ data = client.content_type("category").entry("blt05056a2f5e0ebf76").fetch
+
+
+
+
+
+ 1
+
+
+
+
+ expect(data.class).to eq Contentstack::Entry
+
+
+
+
+
+
+
+
+
+
+ end
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 1
+
+
+
+
+ it 'has a method `get` to get attributes data' do
+
+
+
+
+
+ 1
+
+
+
+
+ uid = "blt05056a2f5e0ebf76"
+
+
+
+
+
+ 1
+
+
+
+
+ data = client.content_type("category").entry(uid).fetch
+
+
+
+
+
+ 1
+
+
+
+
+ expect(data.get('uid')).to eq uid
+
+
+
+
+
+
+
+
+
+
+ end
+
+
+
+
+
+
+
+
+
+
+ end
+
+
-
- 1
-
- expect(data.query[:locale]).to eq 'en-us'
-
+
+
+
+
-
-
-
- end
-
+
+
+
+
+
-
-
-
- end
-
+
+
+ 1
+
+
+
+
+ require 'spec_helper'
+
+
+
+
+
+ 1
+
+
+
+
+ require_relative '../lib/contentstack.rb'
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 1
+
+
+
+
+ describe Contentstack::Query do
+
+
+
+
+
+ 36
+
+
+
+
+ let(:client) { create_client }
+
+
+
+
+
+ 23
+
+
+
+
+ let(:category_query) {client.content_type("category").query}
+
+
+
+
+
+ 14
+
+
+
+
+ let(:product_query) {client.content_type("product").query}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 1
+
+
+
+
+ it "should get data using `where` method" do
+
+
+
+
+
+ 1
+
+
+
+
+ data = category_query.where({title: "Electronics"}).fetch
+
+
+
+
+
+ 1
+
+
+
+
+ expect(data.length).to eq 5
+
+
+
+
+
+
+
+
+
+
+ end
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 1
+
+
+
+
+ it "should get data using `regex` method" do
+
+
+
+
+
+ 1
+
+
+
+
+ data = category_query.regex("title", "App.*").fetch
+
+
+
+
+
+ 1
+
+
+
+
+ expect(data.length).to eq 5
+
+
+
+
+
+
+
+
+
+
+ end
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 1
+
+
+
+
+ it "should get data using `less_than` method" do
+
+
+
+
+
+ 1
+
+
+
+
+ data = product_query.less_than("price", 150).fetch
+
+
+
+
+
+ 1
+
+
+
+
+ expect(data.length).to eq 3
+
+
+
+
+
+
+
+
+
+
+ end
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 1
+
+
+
+
+ it "should get data using `less_than_or_equal` method" do
+
+
+
+
+
+ 1
+
+
+
+
+ data = product_query.less_than_or_equal("price", 166).fetch
+
+
+
+
+
+ 1
+
+
+
+
+ expect(data.length).to eq 3
+
+
+
+
+
+
+
+
+
+
+ end
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 1
+
+
+
+
+ it "should get data using `greater_than` method" do
+
+
+
+
+
+ 1
+
+
+
+
+ data = product_query.greater_than("price", 120).fetch
+
+
+
+
+
+ 1
+
+
+
+
+ expect(data.length).to eq 3
+
+
+
+
+
+
+
+
+
+
+ end
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 1
+
+
+
+
+ it "should get data using `greater_than_or_equal` method" do
+
+
+
+
+
+ 1
+
+
+
+
+ data = product_query.greater_than_or_equal("price", 166).fetch
+
+
+
+
+
+ 1
+
+
+
+
+ expect(data.length).to eq 3
+
+
+
+
+
+
+
+
+
+
+ end
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 1
+
+
+
+
+ it "should get data using `not_equal_to` method" do
+
+
+
+
+
+ 1
+
+
+
+
+ data = product_query.not_equal_to("price", 166).fetch
+
+
+
+
+
+ 1
+
+
+
+
+ expect(data.length).to eq 3
+
+
+
+
+
+
+
+
+
+
+ end
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 1
+
+
+
+
+ it "should get data using `limit` method" do
+
+
+
+
+
+ 1
+
+
+
+
+ data = category_query.limit(2).fetch
+
+
+
+
+
+ 1
+
+
+
+
+ expect(data.length).to eq 5
+
+
+
+
+
+
+
+
+
+
+ end
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 1
+
+
+
+
+ it "should get data using `skip` method" do
+
+
+
+
+
+ 1
+
+
+
+
+ data = category_query.skip(5).fetch
+
+
+
+
+
+ 1
+
+
+
+
+ expect(data.length).to eq 5
+
+
+
+
+
+
+
+
+
+
+ end
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 1
+
+
+
+
+ it "should get data using `include_count` method" do
+
+
+
+
+
+ 1
+
+
+
+
+ data = category_query.include_count.fetch
+
+
+
+
+
+ 1
+
+
+
+
+ expect(data.count).not_to be nil
+
+
+
+
+
+ 1
+
+
+
+
+ expect(data.count).to eq 5
+
+
+
+
+
+
+
+
+
+
+ end
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 1
+
+
+
+
+ it "should get data using `only` method with string parameter" do
+
+
+
+
+
+ 1
+
+
+
+
+ data = category_query.only("title").fetch
+
+
+
+
+
+ 1
+
+
+
+
+ expect(data.first.fields[:title]).not_to be nil
+
+
+
+
+
+ 1
+
+
+
+
+ expect(data.first.fields[:uid]).not_to be nil
+
+
+
+
+
+
+
+
+
+
+ end
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 1
+
+
+
+
+ it "should get data using `only` method with array parameter" do
+
+
+
+
+
+ 1
+
+
+
+
+ data = category_query.only(["title"]).fetch
+
+
+
+
+
+ 1
+
+
+
+
+ expect(data.first.fields[:title]).not_to be nil
+
+
+
+
+
+ 1
+
+
+
+
+ expect(data.first.fields[:uid]).not_to be nil
+
+
+
+
+
+
+
+
+
+
+ end
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 1
+
+
+
+
+ it "should get data using `except` method with string parameter" do
+
+
+
+
+
+ 1
+
+
+
+
+ data = category_query.except("category_tags").fetch
+
+
+
+
+
+ 1
+
+
+
+
+ expect(data.first.fields[:category_tags]).to be nil
+
+
+
+
+
+
+
+
+
+
+ end
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 1
+
+
+
+
+ it "should get data using `except` method with array parameter" do
+
+
+
+
+
+ 1
+
+
+
+
+ data = category_query.except(["description"]).fetch
+
+
+
+
+
+ 1
+
+
+
+
+ expect(data.first.fields[:description]).to be nil
+
+
+
+
+
+
+
+
+
+
+ end
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 1
+
+
+
+
+ it "should get data using `tags` method" do
+
+
+
+
+
+ 1
+
+
+
+
+ data = category_query.tags(["tag1"]).fetch
+
+
+
+
+
+ 1
+
+
+
+
+ expect(data.length).to eq 5
+
+
+
+
+
+
+
+
+
+
+ end
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 1
+
+
+
+
+ it "should get data using `contained_in` method" do
+
+
+
+
+
+ 1
+
+
+
+
+ data = category_query.contained_in("title", ["Electronics", "Apparel"]).fetch
+
+
+
+
+
+ 1
+
+
+
+
+ expect(data.length).to eq 5
+
+
+
+
+
+ 1
+
+
+
+
+ expect(data.first.fields[:title]).to eq "Home & Appliances"
+
+
+
+
+
+ 1
+
+
+
+
+ expect(data.last.fields[:title]).to eq "Headphones"
+
+
+
+
+
+
+
+
+
+
+ end
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 1
+
+
+
+
+ it "should get data using `not_contained_in` method" do
+
+
+
+
+
+ 1
+
+
+
+
+ data = category_query.not_contained_in("title", ["Electronics", "Apparel"]).fetch
+
+
+
+
+
+ 1
+
+
+
+
+ expect(data.length).to eq 5
+
+
+
+
+
+
+
+
+
+
+ end
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 1
+
+
+
+
+ it "should get data using `in` method" do
+
+
+
+
+
+ 1
+
+
+
+
+ data = category_query.contained_in("title", ["Electronics", "Apparel"]).fetch
+
+
+
+
+
+ 1
+
+
+
+
+ expect(data.length).to eq 5
+
+
+
+
+
+
+
+
+
+
+ end
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 1
+
+
+
+
+ it "should get data using `not_in` method" do
+
+
+
+
+
+ 1
+
+
+
+
+ data = category_query.not_contained_in("title", ["Electronics", "Apparel"]).fetch
+
+
+
+
+
+ 1
+
+
+
+
+ expect(data.length).to eq 5
+
+
+
+
+
+
+
+
+
+
+ end
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 1
+
+
+
+
+ it "should get data using `ascending` method" do
+
+
+
+
+
+ 1
+
+
+
+
+ data = product_query.ascending("price").fetch
+
+
+
+
+
+ 1
+
+
+
+
+ expect(data.first.fields[:title]).to eq "Motorola Moto X4"
+
+
+
+
+
+
+
+
+
+
+ end
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 1
+
+
+
+
+ it "should get data using `descending` method" do
+
+
+
+
+
+ 1
+
+
+
+
+ data = product_query.descending("price").fetch
+
+
+
+
+
+ 1
+
+
+
+
+ expect(data.first.fields[:title]).to eq "Motorola Moto X4"
+
+
+
+
+
+
+
+
+
+
+ end
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 1
+
+
+
+
+ it "should get data using `only` method for reference fields" do
+
+
+
+
+
+ 1
+
+
+
+
+ data = product_query.include_reference('categories').only("categories", ["title", "description"]).fetch
+
+
+
+
+
+ 1
+
+
+
+
+ expect(data.first.fields[:categories][0][:title]).to eq "Smartphones"
+
+
+
+
+
+
+
+
+
+
+ end
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 1
+
+
+
+
+ it "should get data using `except` method for reference fields" do
+
+
+
+
+
+ 1
+
+
+
+
+ data = product_query.include_reference('categories').except("categories", "title").fetch
+
+
+
+
+
+ 1
+
+
+
+
+ expect(data.first.fields[:categories][0][:title]).to eq 'Smartphones'
+
+
+
+
+
+
+
+
+
+
+ end
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 1
+
+
+
+
+ it "should get data using `include_schema` method" do
+
+
+
+
+
+ 1
+
+
+
+
+ data = category_query.include_schema.fetch
+
+
+
+
+
+ 1
+
+
+
+
+ expect(data.schema).not_to be nil
+
+
+
+
+
+
+
+
+
+
+ end
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 1
+
+
+
+
+ it "should get data using `include_content_type` method" do
+
+
+
+
+
+ 1
+
+
+
+
+ data = category_query.include_content_type.fetch
+
+
+
+
+
+ 1
+
+
+
+
+ expect(data.content_type).not_to be nil
+
+
+
+
+
+
+
+
+
+
+ end
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 1
+
+
+
+
+ it "should get data using `include_reference` method" do
+
+
+
+
+
+ 1
+
+
+
+
+ data = product_query.include_reference('categories').fetch
+
+
+
+
+
+ 1
+
+
+
+
+ puts data.first.get("categories.title")
+
+
+
+
+
+ 1
+
+
+
+
+ expect(data.first.fields[:categories][0][:title]).not_to be nil
+
+
+
+
+
+
+
+
+
+
+ end
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 1
+
+
+
+
+ it "should get data using `include_owner` method" do
+
+
+
+
+
+ 1
+
+
+
+
+ data = product_query.include_owner.fetch
+
+
+
+
+
+ 1
+
+
+
+
+ expect(data.first.fields[:_owner]).not_to be nil
+
+
+
+
+
+
+
+
+
+
+ end
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 1
+
+
+
+
+ it "should get data using `include_draft` method" do
+
+
+
+
+
+ 1
+
+
+
+
+ data = category_query.include_draft.fetch
+
+
+
+
+
+ 1
+
+
+
+
+ expect(data.length).to eq 5
+
+
+
+
+
+
+
+
+
+
+ end
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 1
+
+
+
+
+ it "should get data using `search` method" do
+
+
+
+
+
+ 1
+
+
+
+
+ data = category_query.search("App").fetch
+
+
+
+
+
+ 1
+
+
+
+
+ expect(data.length).to eq 5
+
+
+
+
+
+
+
+
+
+
+ end
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 1
+
+
+
+
+ it "should get data using `count` method" do
+
+
+
+
+
+ 1
+
+
+
+
+ data = category_query.count
+
+
+
+
+
+ 1
+
+
+
+
+ expect(data).to eq 5
+
+
+
+
+
+
+
+
+
+
+ end
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 1
+
+
+
+
+ it "should get data using `exists` method" do
+
+
+
+
+
+ 1
+
+
+
+
+ data = category_query.exists?('description').fetch
+
+
+
+
+
+ 1
+
+
+
+
+ expect(data.length).to eq 5
+
+
+
+
+
+
+
+
+
+
+ end
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 1
+
+
+
+
+ it "should get data using `not_exists` method" do
+
+
+
+
+
+ 1
+
+
+
+
+ data = product_query.not_exists?('banner_image').fetch
+
+
+
+
+
+ 1
+
+
+
+
+ expect(data.length).to eq 3
+
+
+
+
+
+
+
+
+
+
+ end
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 1
+
+
+
+
+ it "should get data using `and` method" do
+
+
+
+
+
+ 1
+
+
+
+
+ q1 = client.content_type("category").query.regex("title", "App.*")
+
+
+
+
+
+ 1
+
+
+
+
+ q2 = client.content_type("category").query.where({"description"=>"Appliances Category"})
+
+
+
+
+
+ 1
+
+
+
+
+ data = category_query.and([q1,q2]).fetch
+
+
+
+
+
+ 1
+
+
+
+
+ expect(data.length).to eq 5
+
+
+
+
+
+
+
+
+
+
+ end
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 1
+
+
+
+
+ it "should get data using `or` method" do
+
+
+
+
+
+ 1
+
+
+
+
+ q1 = client.content_type("category").query.regex("title", "App.*")
+
+
+
+
+
+ 1
+
+
+
+
+ q2 = client.content_type("category").query.regex("description", "App*")
+
+
+
+
+
+ 1
+
+
+
+
+ data = category_query.or([q1,q2]).fetch
+
+
+
+
+
+ 1
+
+
+
+
+ expect(data.length).to eq 5
+
+
+
+
+
+
+
+
+
+
+ end
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 1
+
+
+
+
+ it "should set locale the in the request query" do
+
+
+
+
+
+ 1
+
+
+
+
+ data = product_query.locale('en-us')
+
+
+
+
+
+ 1
+
+
+
+
+ expect(data.query[:locale]).to eq 'en-us'
+
+
+
+
+
+
+
+
+
+
+ end
+
+
+
+
+
+
+
+
+
+
+ end
+
+
diff --git a/lib/contentstack.rb b/lib/contentstack.rb
index 7906af5..cbef2ca 100644
--- a/lib/contentstack.rb
+++ b/lib/contentstack.rb
@@ -6,16 +6,16 @@
require "util"
-# == Built.io Contentstack - Ruby SDK
-# Built.io Contentstack is a content management system that facilitates the process of publication by separating the content from site-related programming and design.
+# == Contentstack - Ruby SDK
+# Contentstack is a content management system that facilitates the process of publication by separating the content from site-related programming and design.
# == Installation
# gem install contentstack
# == Initialize the Stack
-# @stack = Contentstack::Client.new("site_api_key", "access_token", "enviroment_name")
+# @stack = Contentstack::Client.new("site_api_key", "delivery_token", "enviroment_name")
# == Initialize the Stack for EU region
-# @stack = Contentstack::Client.new("site_api_key", "access_token", "enviroment_name", {"region": Contentstack::Region::EU })
+# @stack = Contentstack::Client.new("site_api_key", "delivery_token", "enviroment_name", {"region": Contentstack::Region::EU })
# == Initialize the Stack for custom host
-# @stack = Contentstack::Client.new("site_api_key", "access_token", "enviroment_name", {"host": "https://custom-cdn.contentstack.com" })
+# @stack = Contentstack::Client.new("site_api_key", "delivery_token", "enviroment_name", {"host": "https://custom-cdn.contentstack.com" })
# == Usage
# ==== Get single entry
# @stack.content_type('blog').entry('
').fetch
diff --git a/lib/contentstack/api.rb b/lib/contentstack/api.rb
index ad044d8..ddab360 100644
--- a/lib/contentstack/api.rb
+++ b/lib/contentstack/api.rb
@@ -6,11 +6,13 @@
module Contentstack
class API
- def self.init_api(api_key, access_token, environment,host)
+ def self.init_api(api_key, delivery_token, environment,host)
@host = host
@api_version = '/v3'
@environment = environment
- @headers = {api_key: api_key, access_token: access_token, user_agent: "ruby-sdk/#{Contentstack::VERSION}", environment: @environment}
+ @api_key = api_key
+ @access_token = delivery_token
+ @headers = {environment: @environment}
end
def self.fetch_content_types(uid="")
@@ -47,7 +49,11 @@ def self.send_request(path, q=nil)
query = "?" + q.to_query
# puts "Request URL:- #{@host}#{@api_version}#{path}#{query} \n\n"
- ActiveSupport::JSON.decode(open("#{@host}#{@api_version}#{path}#{query}").read)
+ ActiveSupport::JSON.decode(open("#{@host}#{@api_version}#{path}#{query}",
+ "api_key" => @api_key,
+ "access_token"=> @access_token,
+ "user_agent"=> "ruby-sdk/#{Contentstack::VERSION}",
+ "x-user-agent" => "ruby-sdk/#{Contentstack::VERSION}").read)
end
end
-end
\ No newline at end of file
+end
diff --git a/lib/contentstack/client.rb b/lib/contentstack/client.rb
index a15fe36..0a4ffa5 100644
--- a/lib/contentstack/client.rb
+++ b/lib/contentstack/client.rb
@@ -5,11 +5,11 @@
module Contentstack
class Client
attr_reader :region, :host
- # Initialize "Built.io Contentstack" Client instance
- def initialize(api_key, access_token, environment, options={})
+ # Initialize "Contentstack" Client instance
+ def initialize(api_key, delivery_token, environment, options={})
@region = options[:region].nil? ? Contentstack::Region::US : options[:region]
@host = options[:host].nil? ? get_default_region_hosts(@region) : options[:host]
- API.init_api(api_key, access_token, environment, @host)
+ API.init_api(api_key, delivery_token, environment, @host)
end
diff --git a/lib/contentstack/entry.rb b/lib/contentstack/entry.rb
index b67cdbd..42ed642 100644
--- a/lib/contentstack/entry.rb
+++ b/lib/contentstack/entry.rb
@@ -1,3 +1,5 @@
+require 'active_support/core_ext'
+
module Contentstack
class Entry
attr_reader :fields, :content_type, :uid, :owner
diff --git a/lib/contentstack/version.rb b/lib/contentstack/version.rb
index 1a3d1ba..06b68d3 100644
--- a/lib/contentstack/version.rb
+++ b/lib/contentstack/version.rb
@@ -1,3 +1,3 @@
module Contentstack
- VERSION = "0.0.4"
+ VERSION = "0.1.0"
end
\ No newline at end of file
diff --git a/spec/content_type_spec.rb b/spec/content_type_spec.rb
index 3e16c16..8defdff 100644
--- a/spec/content_type_spec.rb
+++ b/spec/content_type_spec.rb
@@ -3,8 +3,8 @@
describe Contentstack::ContentType do
let(:client) { create_client }
- let(:eu_client) { create_client('ACCESS_TOKEN', 'API_KEY', 'STACK_ENV', {region: Contentstack::Region::EU}) }
- let(:custom_host_client) { create_client('ACCESS_TOKEN', 'API_KEY', 'STACK_ENV', {host: "https://custom-cdn.contentstack.com"}) }
+ let(:eu_client) { create_client('DELIVERY_TOKEN', 'API_KEY', 'STACK_ENV', {region: Contentstack::Region::EU}) }
+ let(:custom_host_client) { create_client('DELIVERY_TOKEN', 'API_KEY', 'STACK_ENV', {host: "https://custom-cdn.contentstack.com"}) }
describe "Fetch data from API" do
it "has class as Contentstack::ContentType" do
diff --git a/spec/contentstack_spec.rb b/spec/contentstack_spec.rb
index 9475cff..549a556 100644
--- a/spec/contentstack_spec.rb
+++ b/spec/contentstack_spec.rb
@@ -3,8 +3,8 @@
describe Contentstack do
let(:client) { create_client }
- let(:eu_client) { create_client('ACCESS_TOKEN', 'API_KEY', 'STACK_ENV', {region: Contentstack::Region::EU}) }
- let(:custom_host_client) { create_client('ACCESS_TOKEN', 'API_KEY', 'STACK_ENV', {host: "https://custom-cdn.contentstack.com"}) }
+ let(:eu_client) { create_client('DELIVERY_TOKEN_TOKEN', 'API_KEY', 'STACK_ENV', {region: Contentstack::Region::EU}) }
+ let(:custom_host_client) { create_client('DELIVERY_TOKEN_TOKEN', 'API_KEY', 'STACK_ENV', {host: "https://custom-cdn.contentstack.com"}) }
it "has a version number" do
expect(Contentstack::VERSION).not_to be nil
diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb
index 6945821..cfe372c 100644
--- a/spec/spec_helper.rb
+++ b/spec/spec_helper.rb
@@ -148,7 +148,7 @@
to_return(:status => 200, :body => File.read(File.dirname(__FILE__) + '/fixtures/category_entry.json'), :headers => {})
end
- def create_client(access_token = ENV['ACCESS_TOKEN'], api_key = ENV['API_KEY'], environment = ENV['STACK_ENV'], options = {})
- Contentstack::Client.new(access_token, api_key, environment, options)
+ def create_client(delivery_token = ENV['ACCESS_TOKEN'], api_key = ENV['API_KEY'], environment = ENV['STACK_ENV'], options = {})
+ Contentstack::Client.new(delivery_token, api_key, environment, options)
end
end
\ No newline at end of file