contentstack 0.4.3 → 0.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3a9752caee17d0a0685f86068d868e188beb0221e75c7580e97fe5957ee60af9
4
- data.tar.gz: 608036425d1fd793a8c4b0789628237a89c12ab29a981ffa6aeedd8fce31140d
3
+ metadata.gz: 8d05c5b008fe472ff0f8440f69c7226645ef13db5b6d6d75b1de0d4d2cf9dcec
4
+ data.tar.gz: 015ec71ca2e816f17f6f274e992b5273a04a5303e0eb1a67a1b6449743b8847f
5
5
  SHA512:
6
- metadata.gz: 777e224fb7794aa8cb5e810ebb04447a55168d5c7cd0f6d3134c6e78fd57ef88f99c6ff7b020ce1fb1baab51aebe4ea3d2e151182e43649e552a52e81c582621
7
- data.tar.gz: 47c32273f2510b09d0e46f656ebe7cdd91ee88c9caf32dd8baeb76fa712d829392d308a651d34edd465ee871b092a2eff03c15a49af4133dcc33fc2978035d13
6
+ metadata.gz: 380dee7e9afb6047034eff28239631bdeb6aacb964e1665aeee80dc9116c769c477f1f0c33a36dc0c701ec987df207e3fd1e747ba7edd37fc9a87de69590323e
7
+ data.tar.gz: 9d686de63a036bb5a5c159540148d8d3c305fca02967aaf4dd9ab1d5aeb1e038199ed1575a8f57a2ab15bf14e62d3bcc999dfe07f7587084e1e507d827746b54
@@ -0,0 +1,68 @@
1
+ # For most projects, this workflow file will not need changing; you simply need
2
+ # to commit it to your repository.
3
+ #
4
+ # You may wish to alter this file to override the set of languages analyzed,
5
+ # or to provide custom queries or build logic.
6
+ #
7
+ # ******** NOTE ********
8
+ # We have attempted to detect the languages in your repository. Please check
9
+ # the `language` matrix defined below to confirm you have the correct set of
10
+ # supported CodeQL languages.
11
+ #
12
+ name: "CodeQL"
13
+
14
+ on:
15
+ pull_request:
16
+ # The branches below must be a subset of the branches above
17
+ branches: '*'
18
+
19
+ jobs:
20
+ analyze:
21
+ name: Analyze
22
+ runs-on: ubuntu-latest
23
+ permissions:
24
+ actions: read
25
+ contents: read
26
+ security-events: write
27
+
28
+ strategy:
29
+ fail-fast: false
30
+ matrix:
31
+ language: [ 'ruby' ]
32
+ # CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python', 'ruby' ]
33
+ # Learn more about CodeQL language support at https://aka.ms/codeql-docs/language-support
34
+
35
+ steps:
36
+ - name: Checkout repository
37
+ uses: actions/checkout@v3
38
+
39
+ # Initializes the CodeQL tools for scanning.
40
+ - name: Initialize CodeQL
41
+ uses: github/codeql-action/init@v2
42
+ with:
43
+ languages: ${{ matrix.language }}
44
+ # If you wish to specify custom queries, you can do so here or in a config file.
45
+ # By default, queries listed here will override any specified in a config file.
46
+ # Prefix the list here with "+" to use these queries and those in the config file.
47
+
48
+ # Details on CodeQL's query packs refer to : https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/configuring-code-scanning#using-queries-in-ql-packs
49
+ # queries: security-extended,security-and-quality
50
+
51
+
52
+ # Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
53
+ # If this step fails, then you should remove it and run the build manually (see below)
54
+ - name: Autobuild
55
+ uses: github/codeql-action/autobuild@v2
56
+
57
+ # ℹ️ Command-line programs to run using the OS shell.
58
+ # 📚 See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun
59
+
60
+ # If the Autobuild fails above, remove it and uncomment the following three lines.
61
+ # modify them (or add more) to build your code if your project, please refer to the EXAMPLE below for guidance.
62
+
63
+ # - run: |
64
+ # echo "Run, Build Application using script"
65
+ # ./location_of_script_within_repo/buildscript.sh
66
+
67
+ - name: Perform CodeQL Analysis
68
+ uses: github/codeql-action/analyze@v2
@@ -0,0 +1,11 @@
1
+ name: SAST Scan
2
+ on:
3
+ pull_request:
4
+ types: [opened, synchronize, reopened]
5
+ jobs:
6
+ security:
7
+ runs-on: ubuntu-latest
8
+ steps:
9
+ - uses: actions/checkout@v2
10
+ - name: Horusec Scan
11
+ run: docker run -v /var/run/docker.sock:/var/run/docker.sock -v $(pwd):/src horuszup/horusec-cli:latest horusec start -p /src -P $(pwd)
@@ -0,0 +1,13 @@
1
+ name: Source Composition Analysis Scan
2
+ on:
3
+ pull_request:
4
+ types: [opened, synchronize, reopened]
5
+ jobs:
6
+ security:
7
+ runs-on: ubuntu-latest
8
+ steps:
9
+ - uses: actions/checkout@master
10
+ - name: Run Snyk to check for vulnerabilities
11
+ uses: snyk/actions/node@master
12
+ env:
13
+ SNYK_TOKEN: ${{ secrets.SNYK_TOKEN }}
@@ -0,0 +1,11 @@
1
+ name: Secrets Scan
2
+ on:
3
+ pull_request:
4
+ types: [opened, synchronize, reopened]
5
+ jobs:
6
+ security:
7
+ runs-on: ubuntu-latest
8
+ steps:
9
+ - uses: actions/checkout@v2
10
+ - name: Gittyleaks
11
+ uses: gupy-io/gittyleaks-action@v0.1
data/.gitignore CHANGED
@@ -9,3 +9,4 @@ coverage
9
9
  .bundle/
10
10
  **/rspec_results.html
11
11
  vendor/
12
+ .dccache
data/.talismanrc ADDED
@@ -0,0 +1 @@
1
+ threshold: medium
data/Gemfile.lock CHANGED
@@ -1,14 +1,14 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- contentstack (0.4.1)
4
+ contentstack (0.6.0)
5
5
  activesupport (>= 3.2, < 6.2)
6
6
  contentstack_utils (~> 1.0, >= 1.0.1)
7
7
 
8
8
  GEM
9
9
  remote: https://rubygems.org/
10
10
  specs:
11
- activesupport (6.1.4)
11
+ activesupport (6.1.6.1)
12
12
  concurrent-ruby (~> 1.0, >= 1.0.2)
13
13
  i18n (>= 1.6, < 2)
14
14
  minitest (>= 5.1)
@@ -16,8 +16,8 @@ GEM
16
16
  zeitwerk (~> 2.3)
17
17
  addressable (2.8.0)
18
18
  public_suffix (>= 2.0.2, < 5.0)
19
- concurrent-ruby (1.1.9)
20
- contentstack_utils (1.0.2)
19
+ concurrent-ruby (1.1.10)
20
+ contentstack_utils (1.1.0)
21
21
  activesupport (>= 3.2, < 6.2)
22
22
  nokogiri (~> 1.11, >= 1.11.0)
23
23
  crack (0.4.5)
@@ -25,15 +25,15 @@ GEM
25
25
  diff-lcs (1.4.4)
26
26
  docile (1.4.0)
27
27
  hashdiff (1.0.1)
28
- i18n (1.8.10)
28
+ i18n (1.12.0)
29
29
  concurrent-ruby (~> 1.0)
30
- mini_portile2 (2.5.3)
31
- minitest (5.14.4)
32
- nokogiri (1.11.7)
33
- mini_portile2 (~> 2.5.0)
30
+ mini_portile2 (2.8.0)
31
+ minitest (5.16.2)
32
+ nokogiri (1.13.4)
33
+ mini_portile2 (~> 2.8.0)
34
34
  racc (~> 1.4)
35
35
  public_suffix (4.0.6)
36
- racc (1.5.2)
36
+ racc (1.6.0)
37
37
  rexml (3.2.5)
38
38
  rspec (3.10.0)
39
39
  rspec-core (~> 3.10.0)
@@ -54,14 +54,14 @@ GEM
54
54
  simplecov_json_formatter (~> 0.1)
55
55
  simplecov-html (0.12.3)
56
56
  simplecov_json_formatter (0.1.3)
57
- tzinfo (2.0.4)
57
+ tzinfo (2.0.5)
58
58
  concurrent-ruby (~> 1.0)
59
59
  webmock (3.11.3)
60
60
  addressable (>= 2.3.6)
61
61
  crack (>= 0.3.2)
62
62
  hashdiff (>= 0.4.0, < 2.0.0)
63
63
  yard (0.9.26)
64
- zeitwerk (2.4.2)
64
+ zeitwerk (2.6.0)
65
65
 
66
66
  PLATFORMS
67
67
  ruby
data/LICENSE.txt CHANGED
@@ -1,6 +1,6 @@
1
1
  The MIT License (MIT)
2
2
 
3
- Copyright (c) 2012-2021 Contentstack. All Rights Reserved
3
+ Copyright (c) 2012-2022 Contentstack. All Rights Reserved
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
data/README.md CHANGED
@@ -116,7 +116,7 @@ In a single instance, the [Get Multiple Entries](https://www.contentstack.com/do
116
116
 
117
117
  We have introduced Image Delivery APIs that let you retrieve images and then manipulate and optimize them for your digital properties. It lets you perform a host of other actions such as crop, trim, resize, rotate, overlay, and so on.
118
118
 
119
- For example, if you want to crop an image (with width as 300 and height as 400), you simply need to append query parameters at the end of the image URL, such as, https://images.contentstack.io/v3/assets/blteae40eb499811073/bltc5064f36b5855343/59e0c41ac0eddd140d5a8e3e/download?crop=300,400. There are several more parameters that you can use for your images.
119
+ For example, if you want to crop an image (with width as 300 and height as 400), you simply need to append query parameters at the end of the image URL, such as, https://images.contentstack.io/v3/download?crop=300,400. There are several more parameters that you can use for your images.
120
120
 
121
121
  [Read Image Delivery API documentation](https://www.contentstack.com/docs/apis/image-delivery-api/).
122
122
 
data/SECURITY.md ADDED
@@ -0,0 +1,27 @@
1
+ ## Security
2
+
3
+ Contentstack takes the security of our software products and services seriously, which includes all source code repositories managed through our GitHub organizations.
4
+
5
+ If you believe you have found a security vulnerability in any Contentstack-owned repository, please report it to us as described below.
6
+
7
+ ## Reporting Security Issues
8
+
9
+ **Please do not report security vulnerabilities through public GitHub issues.**
10
+
11
+ Send email to [security@contentstack.com](mailto:security@contentstack.com).
12
+
13
+ You should receive a response within 24 hours. If for some reason you do not, please follow up via email to ensure we received your original message.
14
+
15
+ Please include the requested information listed below (as much as you can provide) to help us better understand the nature and scope of the possible issue:
16
+
17
+ * Type of issue (e.g. buffer overflow, SQL injection, cross-site scripting, etc.)
18
+ * Full paths of source file(s) related to the manifestation of the issue
19
+ * The location of the affected source code (tag/branch/commit or direct URL)
20
+ * Any special configuration required to reproduce the issue
21
+ * Step-by-step instructions to reproduce the issue
22
+ * Proof-of-concept or exploit code (if possible)
23
+ * Impact of the issue, including how an attacker might exploit the issue
24
+
25
+ This information will help us triage your report more quickly.
26
+
27
+ [https://www.contentstack.com/trust/](https://www.contentstack.com/trust/)
@@ -7,13 +7,25 @@ require 'util'
7
7
  module Contentstack
8
8
  class API
9
9
  using Utility
10
- def self.init_api(api_key, delivery_token, environment,host)
10
+ def self.init_api(api_key, delivery_token, environment, host, branch, live_preview, proxy, retry_options)
11
11
  @host = host
12
12
  @api_version = '/v3'
13
13
  @environment = environment
14
14
  @api_key = api_key
15
15
  @access_token = delivery_token
16
+ @branch = branch
16
17
  @headers = {environment: @environment}
18
+ @live_preview = live_preview
19
+ @proxy_details = proxy
20
+ @timeout = retry_options["timeout"]
21
+ @retryDelay = retry_options["retryDelay"]
22
+ @retryLimit = retry_options["retryLimit"]
23
+ @errorRetry = retry_options["errorRetry"]
24
+ end
25
+
26
+ def self.live_preview_query(query= {})
27
+ @live_preview[:content_type_uid] = query[:content_type_uid]
28
+ @live_preview[:live_preview] = query[:live_preview]
17
29
  end
18
30
 
19
31
  def self.fetch_content_types(uid="")
@@ -22,31 +34,56 @@ module Contentstack
22
34
  else
23
35
  path = "/content_types"
24
36
  end
25
- send_request(path, {})
37
+ fetch_retry(path, {})
26
38
  end
27
39
 
28
40
  def self.fetch_entries(content_type, query)
29
- path = "/content_types/#{content_type}/entries"
30
- send_request(path, query)
41
+ if @live_preview[:enable] && @live_preview[:content_type_uid] == content_type
42
+ path = "/content_types/#{content_type}/entries"
43
+ send_preview_request(path, query)
44
+ else
45
+ path = "/content_types/#{content_type}/entries"
46
+ fetch_retry(path, query)
47
+ end
31
48
  end
32
49
 
33
50
  def self.fetch_entry(content_type, entry_uid, query)
34
- path = "/content_types/#{content_type}/entries/#{entry_uid}"
35
- send_request(path, query)
51
+ if @live_preview[:enable] && @live_preview[:content_type_uid] == content_type
52
+ path = "/content_types/#{content_type}/entries/#{entry_uid}"
53
+ send_preview_request(path, query)
54
+ else
55
+ path = "/content_types/#{content_type}/entries/#{entry_uid}"
56
+ fetch_retry(path, query)
57
+ end
36
58
  end
37
59
 
38
60
  def self.get_assets(asset_uid=nil)
39
61
  path = "/assets"
40
62
  path += "/#{asset_uid}" if !asset_uid.nil?
41
- send_request(path)
63
+ fetch_retry(path)
42
64
  end
43
65
 
44
66
  def self.get_sync_items(query)
45
67
  path = "/stacks/sync"
46
- send_request(path, query)
68
+ fetch_retry(path, query)
47
69
  end
48
70
 
49
71
  private
72
+ def self.fetch_retry(path, query=nil, count=0)
73
+ response = send_request(path, query)
74
+ if @errorRetry.include?(response["status_code"].to_i)
75
+ if count < @retryLimit
76
+ retryDelay_in_seconds = @retryDelay / 1000 #converting retry_delay from milliseconds into seconds
77
+ sleep(retryDelay_in_seconds.to_i) #sleep method requires time in seconds as parameter
78
+ response = fetch_retry(path, query, (count + 1))
79
+ else
80
+ raise Contentstack::Error.new(response) #Retry Limit exceeded
81
+ end
82
+ else
83
+ response
84
+ end
85
+ end
86
+
50
87
  def self.send_request(path, q=nil)
51
88
  q ||= {}
52
89
 
@@ -54,12 +91,98 @@ module Contentstack
54
91
 
55
92
  query = "?" + q.to_query
56
93
  # puts "Request URL:- #{@host}#{@api_version}#{path}#{query} \n\n"
57
-
58
- ActiveSupport::JSON.decode(URI.open("#{@host}#{@api_version}#{path}#{query}",
59
- "api_key" => @api_key,
60
- "access_token"=> @access_token,
61
- "user_agent"=> "ruby-sdk/#{Contentstack::VERSION}",
62
- "x-user-agent" => "ruby-sdk/#{Contentstack::VERSION}").read)
94
+ params = {
95
+ "api_key" => @api_key,
96
+ "access_token"=> @access_token,
97
+ "user_agent"=> "ruby-sdk/#{Contentstack::VERSION}",
98
+ "x-user-agent" => "ruby-sdk/#{Contentstack::VERSION}",
99
+ "read_timeout" => @timeout
100
+ }
101
+ if !@branch.nil? && !@branch.empty?
102
+ params["branch"] = @branch
103
+ end
104
+
105
+ begin
106
+ if @proxy_details.empty?
107
+ ActiveSupport::JSON.decode(URI.open("#{@host}#{@api_version}#{path}#{query}", params).read)
108
+ elsif @proxy_details.present? && @proxy_details[:url].present? && @proxy_details[:port].present? && @proxy_details[:username].present? && @proxy_details[:password].present?
109
+ proxy_uri = URI.parse("http://#{@proxy_details[:url]}:#{@proxy_details[:port]}/")
110
+ proxy_username = @proxy_details[:username]
111
+ proxy_password = @proxy_details[:password]
112
+
113
+ if !@branch.nil? && !@branch.empty?
114
+ ActiveSupport::JSON.decode(URI.open("#{@host}#{@api_version}#{path}#{query}", :proxy_http_basic_authentication => [proxy_uri, proxy_username, proxy_password], "api_key" => @api_key, "access_token"=> @access_token, "user_agent"=> "ruby-sdk/#{Contentstack::VERSION}", "x-user-agent" => "ruby-sdk/#{Contentstack::VERSION}", "read_timeout" => @timeout, "branch" => @branch).read)
115
+ else
116
+ ActiveSupport::JSON.decode(URI.open("#{@host}#{@api_version}#{path}#{query}", :proxy_http_basic_authentication => [proxy_uri, proxy_username, proxy_password], "api_key" => @api_key, "access_token"=> @access_token, "user_agent"=> "ruby-sdk/#{Contentstack::VERSION}", "x-user-agent" => "ruby-sdk/#{Contentstack::VERSION}", "read_timeout" => @timeout).read)
117
+ end
118
+ elsif @proxy_details.present? && @proxy_details[:url].present? && @proxy_details[:port].present? && @proxy_details[:username].empty? && @proxy_details[:password].empty?
119
+ proxy_uri = URI.parse("http://#{@proxy_details[:url]}:#{@proxy_details[:port]}/")
120
+
121
+ if !@branch.nil? && !@branch.empty?
122
+ ActiveSupport::JSON.decode(URI.open("#{@host}#{@api_version}#{path}#{query}", "proxy" => proxy_uri, "api_key" => @api_key, "access_token"=> @access_token, "user_agent"=> "ruby-sdk/#{Contentstack::VERSION}", "x-user-agent" => "ruby-sdk/#{Contentstack::VERSION}", "read_timeout" => @timeout, "branch" => @branch).read)
123
+ else
124
+ ActiveSupport::JSON.decode(URI.open("#{@host}#{@api_version}#{path}#{query}", "proxy" => proxy_uri, "api_key" => @api_key, "access_token"=> @access_token, "user_agent"=> "ruby-sdk/#{Contentstack::VERSION}", "x-user-agent" => "ruby-sdk/#{Contentstack::VERSION}", "read_timeout" => @timeout).read)
125
+ end
126
+ end
127
+ rescue OpenURI::HTTPError => error
128
+ response = error.io
129
+ #response.status
130
+ # => ["503", "Service Unavailable"]
131
+ error_response = JSON.parse(response.string)
132
+ error_status = {"status_code" => response.status[0], "status_message" => response.status[1]}
133
+ error = error_response.merge(error_status)
134
+ raise Contentstack::Error.new(error.to_s)
135
+ end
136
+ end
137
+
138
+ def self.send_preview_request(path, q=nil)
139
+ q ||= {}
140
+
141
+ q.merge!({live_preview: (!@live_preview.key?(:live_preview) ? 'init' : @live_preview[:live_preview]),})
142
+
143
+ query = "?" + q.to_query
144
+ preview_host = @live_preview[:host]
145
+ params = {
146
+ "api_key" => @api_key,
147
+ "authorization" => @live_preview[:management_token],
148
+ "user_agent"=> "ruby-sdk/#{Contentstack::VERSION}",
149
+ "x-user-agent" => "ruby-sdk/#{Contentstack::VERSION}",
150
+ "read_timeout" => @timeout
151
+ }
152
+ if !@branch.nil? && !@branch.empty?
153
+ params["branch"] = @branch
154
+ end
155
+ begin
156
+ if @proxy_details.empty?
157
+ ActiveSupport::JSON.decode(URI.open("#{preview_host}#{@api_version}#{path}#{query}",params).read)
158
+ elsif @proxy_details.present? && @proxy_details[:url].present? && @proxy_details[:port].present? && @proxy_details[:username].present? && @proxy_details[:password].present?
159
+ proxy_uri = URI.parse("http://#{@proxy_details[:url]}:#{@proxy_details[:port]}/")
160
+ proxy_username = @proxy_details[:username]
161
+ proxy_password = @proxy_details[:password]
162
+
163
+ if !@branch.nil? && !@branch.empty?
164
+ ActiveSupport::JSON.decode(URI.open("#{preview_host}#{@api_version}#{path}#{query}", :proxy_http_basic_authentication => [proxy_uri, proxy_username, proxy_password], "api_key" => @api_key, "authorization" => @live_preview[:management_token], "user_agent"=> "ruby-sdk/#{Contentstack::VERSION}", "x-user-agent" => "ruby-sdk/#{Contentstack::VERSION}", "read_timeout" => @timeout, "branch" => @branch).read)
165
+ else
166
+ ActiveSupport::JSON.decode(URI.open("#{preview_host}#{@api_version}#{path}#{query}", :proxy_http_basic_authentication => [proxy_uri, proxy_username, proxy_password], "api_key" => @api_key, "authorization" => @live_preview[:management_token], "user_agent"=> "ruby-sdk/#{Contentstack::VERSION}", "x-user-agent" => "ruby-sdk/#{Contentstack::VERSION}", "read_timeout" => @timeout).read)
167
+ end
168
+ elsif @proxy_details.present? && @proxy_details[:url].present? && @proxy_details[:port].present? && @proxy_details[:username].empty? && @proxy_details[:password].empty?
169
+ proxy_uri = URI.parse("http://#{@proxy_details[:url]}:#{@proxy_details[:port]}/")
170
+
171
+ if !@branch.nil? && !@branch.empty?
172
+ ActiveSupport::JSON.decode(URI.open("#{preview_host}#{@api_version}#{path}#{query}", "proxy" => proxy_uri, "api_key" => @api_key, "authorization" => @live_preview[:management_token], "user_agent"=> "ruby-sdk/#{Contentstack::VERSION}", "x-user-agent" => "ruby-sdk/#{Contentstack::VERSION}", "read_timeout" => @timeout, "branch" => @branch).read)
173
+ else
174
+ ActiveSupport::JSON.decode(URI.open("#{preview_host}#{@api_version}#{path}#{query}", "proxy" => proxy_uri, "api_key" => @api_key, "authorization" => @live_preview[:management_token], "user_agent"=> "ruby-sdk/#{Contentstack::VERSION}", "x-user-agent" => "ruby-sdk/#{Contentstack::VERSION}", "read_timeout" => @timeout).read)
175
+ end
176
+ end
177
+ rescue OpenURI::HTTPError => error
178
+ response = error.io
179
+ #response.status
180
+ # => ["503", "Service Unavailable"]
181
+ error_response = JSON.parse(response.string)
182
+ error_status = {"status_code" => response.status[0], "status_message" => response.status[1]}
183
+ error = error_response.merge(error_status)
184
+ raise Contentstack::Error.new(error.to_s)
185
+ end
63
186
  end
64
187
  end
65
188
  end
@@ -3,15 +3,37 @@ require 'contentstack/content_type'
3
3
  require 'contentstack/asset_collection'
4
4
  require 'contentstack/sync_result'
5
5
  require 'util'
6
+ require 'contentstack/error'
6
7
  module Contentstack
7
8
  class Client
8
9
  using Utility
9
10
  attr_reader :region, :host
10
11
  # Initialize "Contentstack" Client instance
11
12
  def initialize(api_key, delivery_token, environment, options={})
13
+ raise Contentstack::Error.new("Api Key is not valid") if api_key.class != String
14
+ raise Contentstack::Error.new("Api Key Field Should not be Empty") if api_key.empty?
15
+ raise Contentstack::Error.new("Delivery Token is not valid") if delivery_token.class != String
16
+ raise Contentstack::Error.new("Delivery Token Field Should not be Empty") if delivery_token.empty?
17
+ raise Contentstack::Error.new("Envirnoment Field is not valid") if environment.class != String
18
+ raise Contentstack::Error.new("Envirnoment Field Should not be Empty") if environment.empty?
12
19
  @region = options[:region].nil? ? Contentstack::Region::US : options[:region]
13
20
  @host = options[:host].nil? ? get_default_region_hosts(@region) : options[:host]
14
- API.init_api(api_key, delivery_token, environment, @host)
21
+ @live_preview = !options.key?(:live_preview) ? {} : options[:live_preview]
22
+ @branch = options[:branch].nil? ? "" : options[:branch]
23
+ @proxy_details = options[:proxy].nil? ? "" : options[:proxy]
24
+ @timeout = options[:timeout].nil? ? 3000 : options[:timeout]
25
+ @retryDelay = options[:retryDelay].nil? ? 3000 : options[:retryDelay]
26
+ @retryLimit = options[:retryLimit].nil? ? 5 : options[:retryLimit]
27
+ @errorRetry = options[:errorRetry].nil? ? [408, 429] : options[:errorRetry]
28
+ retry_options = {
29
+ "timeout" => @timeout.to_s,
30
+ "retryDelay"=> @retryDelay,
31
+ "retryLimit"=> @retryLimit,
32
+ "errorRetry" => @errorRetry
33
+ }
34
+ raise Contentstack::Error.new("Proxy URL Should not be Empty") if @proxy_details.present? && @proxy_details[:url].empty?
35
+ raise Contentstack::Error.new("Proxy Port Should not be Empty") if @proxy_details.present? && @proxy_details[:port].empty?
36
+ API.init_api(api_key, delivery_token, environment, @host, @branch, @live_preview, @proxy_details, retry_options)
15
37
  end
16
38
 
17
39
  def content_types
@@ -30,6 +52,9 @@ module Contentstack
30
52
  Asset.new(uid)
31
53
  end
32
54
 
55
+ def live_preview_query(query={})
56
+ API.live_preview_query(query)
57
+ end
33
58
 
34
59
  # Syncs your Contentstack data with your app and ensures that the data is always up-to-date by providing delta updates
35
60
  #
@@ -43,9 +68,9 @@ module Contentstack
43
68
  #
44
69
  # Stack.sync({'init': true, 'type': 'entry_published'}) // Use the type parameter to get a specific type of content.Supports 'asset_published', 'entry_published', 'asset_unpublished', 'entry_unpublished', 'asset_deleted', 'entry_deleted', 'content_type_deleted'.
45
70
  #
46
- # Stack.sync({'pagination_token': '<btlsomething>'}) // For fetching the next batch of entries using pagination token
71
+ # Stack.sync({'pagination_token': '<pagination>'}) // For fetching the next batch of entries using pagination token
47
72
  #
48
- # Stack.sync({'sync_token': '<btlsomething>'}) // For performing subsequent sync after initial sync
73
+ # Stack.sync({'sync_token': '<sync>'}) // For performing subsequent sync after initial sync
49
74
  #
50
75
  # @param params [Hash] params is an object that supports ‘locale’, ‘start_date’, ‘content_type_uid’, and ‘type’ queries.
51
76
  def sync(params)
@@ -154,6 +154,19 @@ module Contentstack
154
154
  self
155
155
  end
156
156
 
157
+ # Include the branch for publish content.
158
+ #
159
+ # Example
160
+ #
161
+ # @entry = @stack.content_type('product').entry(entry_uid)
162
+ # @entry.include_branch
163
+ #
164
+ # @return [Contentstack::Entry]
165
+ def include_branch(flag=true)
166
+ @query[:include_branch] = flag
167
+ self
168
+ end
169
+
157
170
  # Include Embedded Objects (Entries and Assets) along with entry/entries details.
158
171
  #
159
172
  # Example
@@ -249,10 +249,14 @@ module Contentstack
249
249
  # @param [String] field_uid UID of the field for which query should be executed
250
250
  # @param [String] values The possible values for the key's object
251
251
  #
252
- # Example
252
+ # Example 1 - Array Equals Operator Within Group
253
253
  # @query = @stack.content_type('category').query
254
254
  # @query.contained_in("title", ["Electronics", "Apparel"])
255
255
  #
256
+ # Example 2 - Array Equals Operator Within Modular Blocks
257
+ # @query = @stack.content_type('category').query
258
+ # @query.contained_in("additional_info.deals.deal_name", ["Christmas Deal", "Summer Deal"])
259
+ #
256
260
  # @return [Contentstack::Query]
257
261
  def contained_in(field_uid, values)
258
262
  add_query_hash({:"#{field_uid}" => {"$in" => values}})
@@ -264,10 +268,14 @@ module Contentstack
264
268
  # @param [String] field_uid UID of the field for which query should be executed
265
269
  # @param [String] values The possible values for the key's object
266
270
  #
267
- # Example
271
+ # Example 1 - Array Not-equals Operator Within Group
268
272
  # @query = @stack.content_type('category').query
269
273
  # @query.not_contained_in("title", ["Electronics", "Apparel"])
270
274
  #
275
+ # Example 2 - Array Not-equals Operator Within Modular Blocks
276
+ # @query = @stack.content_type('category').query
277
+ # @query.not_contained_in("additional_info.deals.deal_name", ["Christmas Deal", "Summer Deal"])
278
+ #
271
279
  # @return [Contentstack::Query]
272
280
  def not_contained_in(field_uid, values)
273
281
  add_query_hash({:"#{field_uid}" => {"$nin" => values}})
@@ -289,7 +297,7 @@ module Contentstack
289
297
  end
290
298
 
291
299
  # This method provides only the entries matching the specified value.
292
- #
300
+ # @deprecated since version 0.5.0
293
301
  # @param [String] text value used to match or compare
294
302
  #
295
303
  # Example
@@ -377,6 +385,7 @@ module Contentstack
377
385
  # @param [String] code The locale code of the entry
378
386
  #
379
387
  # Example
388
+ # Change language method
380
389
  # @query = @stack.content_type('category').query
381
390
  # @query.locale('en-us')
382
391
  #
@@ -518,6 +527,19 @@ module Contentstack
518
527
  self
519
528
  end
520
529
 
530
+ # Include the branch for publish content.
531
+ #
532
+ # Example
533
+ #
534
+ # @query = @stack.content_type('product').query
535
+ # @query.include_branch
536
+ #
537
+ # @return [Contentstack::Entry]
538
+ def include_branch(flag=true)
539
+ @query[:include_branch] = flag
540
+ self
541
+ end
542
+
521
543
  # Include Embedded Objects (Entries and Assets) along with entry/entries details.
522
544
  #
523
545
  # Example
@@ -1,3 +1,3 @@
1
1
  module Contentstack
2
- VERSION = "0.4.3"
2
+ VERSION = "0.6.0"
3
3
  end
data/lib/contentstack.rb CHANGED
@@ -15,6 +15,8 @@ require "contentstack_utils"
15
15
  # @stack = Contentstack::Client.new("site_api_key", "delivery_token", "enviroment_name", {"region": Contentstack::Region::EU })
16
16
  # == Initialize the Stack for custom host
17
17
  # @stack = Contentstack::Client.new("site_api_key", "delivery_token", "enviroment_name", {"host": "https://custom-cdn.contentstack.com" })
18
+ # == Initialize the Stack for EU region
19
+ # @stack = Contentstack::Client.new("site_api_key", "delivery_token", "enviroment_name", {"branch":"branch_name" })
18
20
  # == Usage
19
21
  # ==== Get single entry
20
22
  # @stack.content_type('blog').entry('<entry_uid_here>').fetch
data/spec/asset_spec.rb CHANGED
@@ -5,43 +5,43 @@ describe Contentstack::Asset do
5
5
  let(:client) { create_client }
6
6
 
7
7
  it "has attribute called `uid`" do
8
- @uid = "blt3ca1a3470787ba63"
8
+ @uid = "image_1"
9
9
  @asset = client.asset(@uid).fetch
10
10
  expect(@asset.uid).not_to be nil
11
11
  end
12
12
 
13
13
  it "should match uid" do
14
- @uid = "blt3ca1a3470787ba63"
14
+ @uid = "image_1"
15
15
  @asset = client.asset(@uid).fetch
16
16
  expect(@asset.uid).to eq @uid
17
17
  end
18
18
 
19
19
  it "has attribute called `url`" do
20
- @uid = "blt3ca1a3470787ba63"
20
+ @uid = "image_1"
21
21
  @asset = client.asset(@uid).fetch
22
22
  expect(@asset.url).not_to be nil
23
23
  end
24
24
 
25
25
  it "has attribute called `tags`" do
26
- @uid = "blt3ca1a3470787ba63"
26
+ @uid = "image_1"
27
27
  @asset = client.asset(@uid).fetch
28
28
  expect(@asset.tags).not_to be nil
29
29
  end
30
30
 
31
31
  it "has attribute called `file_size`" do
32
- @uid = "blt3ca1a3470787ba63"
32
+ @uid = "image_1"
33
33
  @asset = client.asset(@uid).fetch
34
34
  expect(@asset.file_size).not_to be nil
35
35
  end
36
36
 
37
37
  it "has attribute called `filename`" do
38
- @uid = "blt3ca1a3470787ba63"
38
+ @uid = "image_1"
39
39
  @asset = client.asset(@uid).fetch
40
40
  expect(@asset.filename).not_to be nil
41
41
  end
42
42
 
43
43
  it "has attribute called `content_type`" do
44
- @uid = "blt3ca1a3470787ba63"
44
+ @uid = "image_1"
45
45
  @asset = client.asset(@uid).fetch
46
46
  expect(@asset.content_type).not_to be nil
47
47
  end