Skip to content

Commit 7db588e

Browse files
authored
Merge pull request #43 from bishosilwal/fix-purge-cache-file
Fix purge cache file
2 parents 1eee108 + 01d2066 commit 7db588e

File tree

3 files changed

+15
-2
lines changed

3 files changed

+15
-2
lines changed

lib/imagekitio/request.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ def request(method, url, headers = create_headers, payload = nil)
3636
headers ||= create_headers
3737
response = {}
3838
begin
39-
if(method.downcase.to_sym == :post)
39+
if(method.downcase.to_sym == :post && payload.is_a?(Hash) && payload[:multipart])
4040
uri = URI.parse(url)
4141
http = Net::HTTP.new(uri.host, uri.port)
4242
http.use_ssl = (uri.scheme == 'https')

lib/imagekitio/sdk/version.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
module ImageKitIo
22
module Sdk
3-
VERSION = '2.1.0'
3+
VERSION = '2.1.1'
44
end
55
end

test/imagekit/request_test.rb

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,5 +65,18 @@
6565
expect(response).to_not have_key(:error)
6666
expect(response).to have_key(:response)
6767
end
68+
69+
it 'test_request_method_JSON_success_with_multipart_post' do
70+
stub_request(:post, 'https://www.exampleservererror/upload').to_return(status: 200, body: '{"id": "1"}', headers: {content_type: 'application/json'})
71+
response = @request_obj.request(:post, 'https://www.exampleservererror/upload', nil, { multipart: true })
72+
expect(response).to_not have_key(:error)
73+
expect(response).to have_key(:response)
74+
end
75+
76+
it 'test_request_method_non_JSON_fail_with_multipart_post' do
77+
stub_request(:post, 'https://www.exampleservererror/upload').to_return(status: 400, body: '{"message": "Server failed"}', headers: {content_type: 'application/json'})
78+
response = @request_obj.request(:post, 'https://www.exampleservererror/upload', nil, { multipart: true })
79+
expect(response).to have_key(:error)
80+
end
6881
end
6982
end

0 commit comments

Comments
 (0)