contentstack 0.5.0 → 0.6.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.github/workflows/codeql-analysis.yml +68 -0
- data/.github/workflows/sast-scan.yml +11 -0
- data/.github/workflows/sca-scan.yml +13 -0
- data/.github/workflows/secrets-scan.yml +11 -0
- data/.gitignore +1 -1
- data/.talismanrc +1 -0
- data/CHANGELOG.md +1 -6
- data/Gemfile.lock +8 -8
- data/LICENSE.txt +1 -1
- data/README.md +1 -1
- data/SECURITY.md +27 -0
- data/lib/contentstack/api.rb +119 -12
- data/lib/contentstack/client.rb +21 -1
- data/lib/contentstack/query.rb +11 -2
- data/lib/contentstack/version.rb +1 -1
- metadata +12 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e9d052813dd2aa06d66dbda39f4c26d0a963721339e7ea33c35af69fa16bfba1
|
4
|
+
data.tar.gz: bd7612b96005d0382166828a3c386033d60ff27867cb5b9c66424758672a6116
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bd282b3954a34b18df200adea469dba22ba4ec56705a5682857efc45f7057979be6c5e7312d9b68a3e5e5a6e33057127eb6787a5e9bf04d7fc96ab008a0febac
|
7
|
+
data.tar.gz: fe7742a7f855b3d34cb510cefc839f07d6e4d8f2acc097701e757c0337842f530c292d13d20f814dae5becc63917b907beaa50102603b91d1262c17b8f8c5f6c
|
@@ -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 }}
|
data/.gitignore
CHANGED
data/.talismanrc
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
threshold: medium
|
data/CHANGELOG.md
CHANGED
@@ -1,10 +1,4 @@
|
|
1
1
|
## CHANGELOG
|
2
|
-
------------------------------------------------
|
3
|
-
## Version 0.5.0
|
4
|
-
### Date: 14th-Oct-2021
|
5
|
-
### New Features
|
6
|
-
- Live Preview feature support added
|
7
|
-
|
8
2
|
------------------------------------------------
|
9
3
|
## Version 0.4.3
|
10
4
|
### Date: 17th-Sept-2021
|
@@ -24,6 +18,7 @@
|
|
24
18
|
- Updated gemspec dependency
|
25
19
|
|
26
20
|
------------------------------------------------
|
21
|
+
|
27
22
|
## Version 0.4.0
|
28
23
|
### Date: 16th-Apr-2021
|
29
24
|
### New Features
|
data/Gemfile.lock
CHANGED
@@ -8,7 +8,7 @@ PATH
|
|
8
8
|
GEM
|
9
9
|
remote: https://rubygems.org/
|
10
10
|
specs:
|
11
|
-
activesupport (6.1.
|
11
|
+
activesupport (6.1.5)
|
12
12
|
concurrent-ruby (~> 1.0, >= 1.0.2)
|
13
13
|
i18n (>= 1.6, < 2)
|
14
14
|
minitest (>= 5.1)
|
@@ -16,7 +16,7 @@ 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.
|
19
|
+
concurrent-ruby (1.1.10)
|
20
20
|
contentstack_utils (1.1.0)
|
21
21
|
activesupport (>= 3.2, < 6.2)
|
22
22
|
nokogiri (~> 1.11, >= 1.11.0)
|
@@ -25,12 +25,12 @@ GEM
|
|
25
25
|
diff-lcs (1.4.4)
|
26
26
|
docile (1.4.0)
|
27
27
|
hashdiff (1.0.1)
|
28
|
-
i18n (1.
|
28
|
+
i18n (1.10.0)
|
29
29
|
concurrent-ruby (~> 1.0)
|
30
|
-
mini_portile2 (2.
|
31
|
-
minitest (5.
|
32
|
-
nokogiri (1.
|
33
|
-
mini_portile2 (~> 2.
|
30
|
+
mini_portile2 (2.8.0)
|
31
|
+
minitest (5.15.0)
|
32
|
+
nokogiri (1.13.4)
|
33
|
+
mini_portile2 (~> 2.8.0)
|
34
34
|
racc (~> 1.4)
|
35
35
|
public_suffix (4.0.6)
|
36
36
|
racc (1.6.0)
|
@@ -61,7 +61,7 @@ GEM
|
|
61
61
|
crack (>= 0.3.2)
|
62
62
|
hashdiff (>= 0.4.0, < 2.0.0)
|
63
63
|
yard (0.9.26)
|
64
|
-
zeitwerk (2.5.
|
64
|
+
zeitwerk (2.5.4)
|
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-
|
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/
|
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/)
|
data/lib/contentstack/api.rb
CHANGED
@@ -7,7 +7,7 @@ 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, branch, live_preview)
|
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
|
@@ -16,11 +16,21 @@ module Contentstack
|
|
16
16
|
@branch = branch
|
17
17
|
@headers = {environment: @environment}
|
18
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"]
|
19
24
|
end
|
20
25
|
|
21
26
|
def self.live_preview_query(query= {})
|
22
|
-
@live_preview[:content_type_uid] = query[:content_type_uid]
|
23
|
-
@live_preview[:live_preview] = query[:live_preview]
|
27
|
+
@live_preview[:content_type_uid] = query[:content_type_uid] || query["content_type_uid"]
|
28
|
+
@live_preview[:live_preview] = query[:live_preview] || query["live_preview"]
|
29
|
+
@live_preview[:entry_uid] = query[:entry_uid] || query["entry_uid"]
|
30
|
+
if @live_preview[:content_type_uid].present? && @live_preview[:entry_uid].present?
|
31
|
+
path = "/content_types/#{@live_preview[:content_type_uid]}/entries/#{@live_preview[:entry_uid]}"
|
32
|
+
@live_preview_response = send_preview_request(path)
|
33
|
+
end
|
24
34
|
end
|
25
35
|
|
26
36
|
def self.fetch_content_types(uid="")
|
@@ -29,7 +39,7 @@ module Contentstack
|
|
29
39
|
else
|
30
40
|
path = "/content_types"
|
31
41
|
end
|
32
|
-
|
42
|
+
fetch_retry(path, {})
|
33
43
|
end
|
34
44
|
|
35
45
|
def self.fetch_entries(content_type, query)
|
@@ -38,7 +48,7 @@ module Contentstack
|
|
38
48
|
send_preview_request(path, query)
|
39
49
|
else
|
40
50
|
path = "/content_types/#{content_type}/entries"
|
41
|
-
|
51
|
+
fetch_retry(path, query)
|
42
52
|
end
|
43
53
|
end
|
44
54
|
|
@@ -48,22 +58,37 @@ module Contentstack
|
|
48
58
|
send_preview_request(path, query)
|
49
59
|
else
|
50
60
|
path = "/content_types/#{content_type}/entries/#{entry_uid}"
|
51
|
-
|
61
|
+
fetch_retry(path, query)
|
52
62
|
end
|
53
63
|
end
|
54
64
|
|
55
65
|
def self.get_assets(asset_uid=nil)
|
56
66
|
path = "/assets"
|
57
67
|
path += "/#{asset_uid}" if !asset_uid.nil?
|
58
|
-
|
68
|
+
fetch_retry(path)
|
59
69
|
end
|
60
70
|
|
61
71
|
def self.get_sync_items(query)
|
62
72
|
path = "/stacks/sync"
|
63
|
-
|
73
|
+
fetch_retry(path, query)
|
64
74
|
end
|
65
75
|
|
66
76
|
private
|
77
|
+
def self.fetch_retry(path, query=nil, count=0)
|
78
|
+
response = send_request(path, query)
|
79
|
+
if @errorRetry.include?(response["status_code"].to_i)
|
80
|
+
if count < @retryLimit
|
81
|
+
retryDelay_in_seconds = @retryDelay / 1000 #converting retry_delay from milliseconds into seconds
|
82
|
+
sleep(retryDelay_in_seconds.to_i) #sleep method requires time in seconds as parameter
|
83
|
+
response = fetch_retry(path, query, (count + 1))
|
84
|
+
else
|
85
|
+
raise Contentstack::Error.new(response) #Retry Limit exceeded
|
86
|
+
end
|
87
|
+
else
|
88
|
+
to_render_content(response)
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
67
92
|
def self.send_request(path, q=nil)
|
68
93
|
q ||= {}
|
69
94
|
|
@@ -75,12 +100,44 @@ module Contentstack
|
|
75
100
|
"api_key" => @api_key,
|
76
101
|
"access_token"=> @access_token,
|
77
102
|
"user_agent"=> "ruby-sdk/#{Contentstack::VERSION}",
|
78
|
-
"x-user-agent" => "ruby-sdk/#{Contentstack::VERSION}"
|
103
|
+
"x-user-agent" => "ruby-sdk/#{Contentstack::VERSION}",
|
104
|
+
"read_timeout" => @timeout
|
79
105
|
}
|
80
106
|
if !@branch.nil? && !@branch.empty?
|
81
107
|
params["branch"] = @branch
|
82
108
|
end
|
83
|
-
|
109
|
+
|
110
|
+
begin
|
111
|
+
if @proxy_details.empty?
|
112
|
+
ActiveSupport::JSON.decode(URI.open("#{@host}#{@api_version}#{path}#{query}", params).read)
|
113
|
+
elsif @proxy_details.present? && @proxy_details[:url].present? && @proxy_details[:port].present? && @proxy_details[:username].present? && @proxy_details[:password].present?
|
114
|
+
proxy_uri = URI.parse("http://#{@proxy_details[:url]}:#{@proxy_details[:port]}/")
|
115
|
+
proxy_username = @proxy_details[:username]
|
116
|
+
proxy_password = @proxy_details[:password]
|
117
|
+
|
118
|
+
if !@branch.nil? && !@branch.empty?
|
119
|
+
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)
|
120
|
+
else
|
121
|
+
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)
|
122
|
+
end
|
123
|
+
elsif @proxy_details.present? && @proxy_details[:url].present? && @proxy_details[:port].present? && @proxy_details[:username].empty? && @proxy_details[:password].empty?
|
124
|
+
proxy_uri = URI.parse("http://#{@proxy_details[:url]}:#{@proxy_details[:port]}/")
|
125
|
+
|
126
|
+
if !@branch.nil? && !@branch.empty?
|
127
|
+
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)
|
128
|
+
else
|
129
|
+
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)
|
130
|
+
end
|
131
|
+
end
|
132
|
+
rescue OpenURI::HTTPError => error
|
133
|
+
response = error.io
|
134
|
+
#response.status
|
135
|
+
# => ["503", "Service Unavailable"]
|
136
|
+
error_response = JSON.parse(response.string)
|
137
|
+
error_status = {"status_code" => response.status[0], "status_message" => response.status[1]}
|
138
|
+
error = error_response.merge(error_status)
|
139
|
+
raise Contentstack::Error.new(error.to_s)
|
140
|
+
end
|
84
141
|
end
|
85
142
|
|
86
143
|
def self.send_preview_request(path, q=nil)
|
@@ -94,12 +151,62 @@ module Contentstack
|
|
94
151
|
"api_key" => @api_key,
|
95
152
|
"authorization" => @live_preview[:management_token],
|
96
153
|
"user_agent"=> "ruby-sdk/#{Contentstack::VERSION}",
|
97
|
-
"x-user-agent" => "ruby-sdk/#{Contentstack::VERSION}"
|
154
|
+
"x-user-agent" => "ruby-sdk/#{Contentstack::VERSION}",
|
155
|
+
"read_timeout" => @timeout
|
98
156
|
}
|
99
157
|
if !@branch.nil? && !@branch.empty?
|
100
158
|
params["branch"] = @branch
|
101
159
|
end
|
102
|
-
|
160
|
+
begin
|
161
|
+
if @proxy_details.empty?
|
162
|
+
ActiveSupport::JSON.decode(URI.open("#{preview_host}#{@api_version}#{path}#{query}",params).read)
|
163
|
+
elsif @proxy_details.present? && @proxy_details[:url].present? && @proxy_details[:port].present? && @proxy_details[:username].present? && @proxy_details[:password].present?
|
164
|
+
proxy_uri = URI.parse("http://#{@proxy_details[:url]}:#{@proxy_details[:port]}/")
|
165
|
+
proxy_username = @proxy_details[:username]
|
166
|
+
proxy_password = @proxy_details[:password]
|
167
|
+
|
168
|
+
if !@branch.nil? && !@branch.empty?
|
169
|
+
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)
|
170
|
+
else
|
171
|
+
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)
|
172
|
+
end
|
173
|
+
elsif @proxy_details.present? && @proxy_details[:url].present? && @proxy_details[:port].present? && @proxy_details[:username].empty? && @proxy_details[:password].empty?
|
174
|
+
proxy_uri = URI.parse("http://#{@proxy_details[:url]}:#{@proxy_details[:port]}/")
|
175
|
+
|
176
|
+
if !@branch.nil? && !@branch.empty?
|
177
|
+
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)
|
178
|
+
else
|
179
|
+
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)
|
180
|
+
end
|
181
|
+
end
|
182
|
+
rescue OpenURI::HTTPError => error
|
183
|
+
response = error.io
|
184
|
+
#response.status
|
185
|
+
# => ["503", "Service Unavailable"]
|
186
|
+
error_response = JSON.parse(response.string)
|
187
|
+
error_status = {"status_code" => response.status[0], "status_message" => response.status[1]}
|
188
|
+
error = error_response.merge(error_status)
|
189
|
+
raise Contentstack::Error.new(error.to_s)
|
190
|
+
end
|
191
|
+
end
|
192
|
+
|
193
|
+
def self.to_render_content(resp)
|
194
|
+
if resp.class == Hash
|
195
|
+
if resp.key?('uid') && resp['uid'] == @live_preview[:entry_uid]
|
196
|
+
resp = resp.merge(@live_preview_response)
|
197
|
+
else
|
198
|
+
resp_keys = resp.keys
|
199
|
+
resp_keys.each {|key|
|
200
|
+
resp[key] = to_render_content(resp[key])
|
201
|
+
}
|
202
|
+
end
|
203
|
+
elsif resp.class == Array
|
204
|
+
resp.each_with_index {|value, index|
|
205
|
+
resp[index] = to_render_content(value)
|
206
|
+
}
|
207
|
+
end
|
208
|
+
resp
|
103
209
|
end
|
210
|
+
|
104
211
|
end
|
105
212
|
end
|
data/lib/contentstack/client.rb
CHANGED
@@ -3,17 +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
21
|
@live_preview = !options.key?(:live_preview) ? {} : options[:live_preview]
|
15
22
|
@branch = options[:branch].nil? ? "" : options[:branch]
|
16
|
-
|
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)
|
17
37
|
end
|
18
38
|
|
19
39
|
def content_types
|
data/lib/contentstack/query.rb
CHANGED
@@ -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}})
|
@@ -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
|
#
|
data/lib/contentstack/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: contentstack
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.6.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Contentstack
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-09-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -113,7 +113,12 @@ executables: []
|
|
113
113
|
extensions: []
|
114
114
|
extra_rdoc_files: []
|
115
115
|
files:
|
116
|
+
- ".github/workflows/codeql-analysis.yml"
|
117
|
+
- ".github/workflows/sast-scan.yml"
|
118
|
+
- ".github/workflows/sca-scan.yml"
|
119
|
+
- ".github/workflows/secrets-scan.yml"
|
116
120
|
- ".gitignore"
|
121
|
+
- ".talismanrc"
|
117
122
|
- ".yardopts"
|
118
123
|
- CHANGELOG.md
|
119
124
|
- CODEOWNERS
|
@@ -122,6 +127,7 @@ files:
|
|
122
127
|
- Gemfile.lock
|
123
128
|
- LICENSE.txt
|
124
129
|
- README.md
|
130
|
+
- SECURITY.md
|
125
131
|
- contentstack.gemspec
|
126
132
|
- lib/contentstack.rb
|
127
133
|
- lib/contentstack/api.rb
|
@@ -161,7 +167,7 @@ homepage: https://github.com/contentstack/contentstack-ruby
|
|
161
167
|
licenses:
|
162
168
|
- MIT
|
163
169
|
metadata: {}
|
164
|
-
post_install_message:
|
170
|
+
post_install_message:
|
165
171
|
rdoc_options: []
|
166
172
|
require_paths:
|
167
173
|
- lib
|
@@ -176,8 +182,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
176
182
|
- !ruby/object:Gem::Version
|
177
183
|
version: '0'
|
178
184
|
requirements: []
|
179
|
-
rubygems_version: 3.
|
180
|
-
signing_key:
|
185
|
+
rubygems_version: 3.1.6
|
186
|
+
signing_key:
|
181
187
|
specification_version: 4
|
182
188
|
summary: Contentstack Ruby client for the Content Delivery API
|
183
189
|
test_files: []
|