Skip to content

Commit 7346be4

Browse files
authored
Merge pull request #27 from contentstack/ruby_core_request_change
Core Request changes in Ruby SDK
2 parents 9bd1e30 + dadfd78 commit 7346be4

File tree

4 files changed

+75
-63
lines changed

4 files changed

+75
-63
lines changed

.github/workflows/release-gem.yml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
name: Ruby Gem
2+
3+
on:
4+
release:
5+
types: [created]
6+
7+
jobs:
8+
build:
9+
name: Build + Publish
10+
runs-on: ubuntu-latest
11+
permissions:
12+
contents: read
13+
packages: write
14+
15+
steps:
16+
- uses: actions/checkout@v3
17+
- name: Set up Ruby 2.6
18+
uses: actions/setup-ruby@v1
19+
with:
20+
ruby-version: 2.6.x
21+
22+
- name: Publish to RubyGems
23+
run: |
24+
mkdir -p $HOME/.gem
25+
touch $HOME/.gem/credentials
26+
chmod 0600 $HOME/.gem/credentials
27+
printf -- "---\n:rubygems_api_key: ${GEM_HOST_API_KEY}\n" > $HOME/.gem/credentials
28+
gem build *.gemspec
29+
gem push *.gem
30+
env:
31+
GEM_HOST_API_KEY: "${{secrets.RUBYGEMS_AUTH_TOKEN}}"

Gemfile.lock

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,67 +1,69 @@
11
PATH
22
remote: .
33
specs:
4-
contentstack (0.5.0)
4+
contentstack (0.6.1)
55
activesupport (>= 3.2, < 6.2)
66
contentstack_utils (~> 1.0, >= 1.0.1)
77

88
GEM
99
remote: https://rubygems.org/
1010
specs:
11-
activesupport (6.1.5)
11+
activesupport (6.1.7)
1212
concurrent-ruby (~> 1.0, >= 1.0.2)
1313
i18n (>= 1.6, < 2)
1414
minitest (>= 5.1)
1515
tzinfo (~> 2.0)
1616
zeitwerk (~> 2.3)
17-
addressable (2.8.0)
18-
public_suffix (>= 2.0.2, < 5.0)
17+
addressable (2.8.1)
18+
public_suffix (>= 2.0.2, < 6.0)
1919
concurrent-ruby (1.1.10)
20-
contentstack_utils (1.1.0)
20+
contentstack_utils (1.1.1)
2121
activesupport (>= 3.2, < 6.2)
2222
nokogiri (~> 1.11, >= 1.11.0)
2323
crack (0.4.5)
2424
rexml
25-
diff-lcs (1.4.4)
25+
diff-lcs (1.5.0)
2626
docile (1.4.0)
2727
hashdiff (1.0.1)
28-
i18n (1.10.0)
28+
i18n (1.12.0)
2929
concurrent-ruby (~> 1.0)
3030
mini_portile2 (2.8.0)
31-
minitest (5.15.0)
32-
nokogiri (1.13.4)
31+
minitest (5.16.3)
32+
nokogiri (1.13.9)
3333
mini_portile2 (~> 2.8.0)
3434
racc (~> 1.4)
35-
public_suffix (4.0.6)
35+
public_suffix (5.0.0)
3636
racc (1.6.0)
3737
rexml (3.2.5)
3838
rspec (3.10.0)
3939
rspec-core (~> 3.10.0)
4040
rspec-expectations (~> 3.10.0)
4141
rspec-mocks (~> 3.10.0)
42-
rspec-core (3.10.1)
42+
rspec-core (3.10.2)
4343
rspec-support (~> 3.10.0)
44-
rspec-expectations (3.10.1)
44+
rspec-expectations (3.10.2)
4545
diff-lcs (>= 1.2.0, < 2.0)
4646
rspec-support (~> 3.10.0)
47-
rspec-mocks (3.10.2)
47+
rspec-mocks (3.10.3)
4848
diff-lcs (>= 1.2.0, < 2.0)
4949
rspec-support (~> 3.10.0)
50-
rspec-support (3.10.2)
50+
rspec-support (3.10.3)
5151
simplecov (0.21.2)
5252
docile (~> 1.1)
5353
simplecov-html (~> 0.11)
5454
simplecov_json_formatter (~> 0.1)
5555
simplecov-html (0.12.3)
56-
simplecov_json_formatter (0.1.3)
57-
tzinfo (2.0.4)
56+
simplecov_json_formatter (0.1.4)
57+
tzinfo (2.0.5)
5858
concurrent-ruby (~> 1.0)
5959
webmock (3.11.3)
6060
addressable (>= 2.3.6)
6161
crack (>= 0.3.2)
6262
hashdiff (>= 0.4.0, < 2.0.0)
63-
yard (0.9.26)
64-
zeitwerk (2.5.4)
63+
webrick (1.7.0)
64+
yard (0.9.28)
65+
webrick (~> 1.7.0)
66+
zeitwerk (2.6.6)
6567

6668
PLATFORMS
6769
ruby
@@ -74,4 +76,4 @@ DEPENDENCIES
7476
yard (~> 0.9.26)
7577

7678
BUNDLED WITH
77-
2.2.7
79+
2.1.4

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ We have introduced Image Delivery APIs that let you retrieve images and then man
118118

119119
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.
120120

121-
[Read Image Delivery API documentation](https://www.contentstack.com/docs/apis/image-delivery-api/).
121+
[Read Image Delivery API documentation](https://www.contentstack.com/docs/developers/apis/image-delivery-api/).
122122

123123

124124
## **Using the Sync API with Ruby SDK**

lib/contentstack/api.rb

Lines changed: 22 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -107,29 +107,18 @@ def self.send_request(path, q=nil)
107107
params["branch"] = @branch
108108
end
109109

110+
if @proxy_details.present? && @proxy_details[:url].present? && @proxy_details[:port].present? && @proxy_details[:username].empty? && @proxy_details[:password].empty?
111+
params["proxy"] = URI.parse("http://#{@proxy_details[:url]}:#{@proxy_details[:port]}/").to_s
112+
end
113+
114+
if @proxy_details.present? && @proxy_details[:url].present? && @proxy_details[:port].present? && @proxy_details[:username].present? && @proxy_details[:password].present?
115+
proxy_uri = URI.parse("http://#{@proxy_details[:url]}:#{@proxy_details[:port]}/").to_s
116+
params[:proxy_http_basic_authentication] = [proxy_uri, @proxy_details[:username], @proxy_details[:password]]
117+
end
118+
110119
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
120+
ActiveSupport::JSON.decode(URI.open("#{@host}#{@api_version}#{path}#{query}", params).read)
121+
rescue OpenURI::HTTPError => error
133122
response = error.io
134123
#response.status
135124
# => ["503", "Service Unavailable"]
@@ -157,28 +146,18 @@ def self.send_preview_request(path, q=nil)
157146
if !@branch.nil? && !@branch.empty?
158147
params["branch"] = @branch
159148
end
149+
150+
if @proxy_details.present? && @proxy_details[:url].present? && @proxy_details[:port].present? && @proxy_details[:username].empty? && @proxy_details[:password].empty?
151+
params["proxy"] = URI.parse("http://#{@proxy_details[:url]}:#{@proxy_details[:port]}/").to_s
152+
end
153+
154+
if @proxy_details.present? && @proxy_details[:url].present? && @proxy_details[:port].present? && @proxy_details[:username].present? && @proxy_details[:password].present?
155+
proxy_uri = URI.parse("http://#{@proxy_details[:url]}:#{@proxy_details[:port]}/").to_s
156+
params[:proxy_http_basic_authentication] = [proxy_uri, @proxy_details[:username], @proxy_details[:password]]
157+
end
158+
160159
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
160+
ActiveSupport::JSON.decode(URI.open("#{preview_host}#{@api_version}#{path}#{query}",params).read)
182161
rescue OpenURI::HTTPError => error
183162
response = error.io
184163
#response.status

0 commit comments

Comments
 (0)