Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion lib/convertkit/connection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ def default_headers(options)

def process_request(method, params)
return params if method == :get
return params if params.empty?
# Faraday writes the body verbatim, so an empty payload still has to be a String.
return '' if params.empty?

JSON.generate(params)
end
Expand Down
2 changes: 1 addition & 1 deletion lib/convertkit/resources/broadcasts.rb
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ def update(id, options= {})
# See https://developers.convertkit.com/#destroy-a-broadcast for details.
# @param id [Integer] The id of the broadcast to delete.
def delete(id)
response = @client.delete("#{PATH}/#{id}")
response = @client.delete("#{PATH}/#{id}", '', true)

response.success?
end
Expand Down
2 changes: 1 addition & 1 deletion lib/convertkit/resources/custom_fields.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def update(id, label)
# See https://developers.convertkit.com/#destroy-field for details
# @param [Integer] id The id of the custom field to delete
def delete(id)
response = @client.delete("#{PATH}/#{id}")
response = @client.delete("#{PATH}/#{id}", '', true)

response.success?
end
Expand Down
25 changes: 25 additions & 0 deletions spec/lib/convertkit/connection_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,13 @@

ConvertKit::Connection.new(url).post('test_path', {hash: 'request_hash'})
end

it 'sends an empty body when no params are given' do
expect(connection).to receive(:post).with('test_path', '').and_return(response)
allow(env).to receive(:body=).with({"message" => "response_hash"})

ConvertKit::Connection.new(url).post('test_path')
end
end

describe '#post_form' do
Expand Down Expand Up @@ -93,6 +100,17 @@

ConvertKit::Connection.new(url).delete('test_path', {hash: 'request_hash'})
end

it 'sends an empty body when no params are given' do
expect_any_instance_of(Faraday::Connection).to receive(:delete).with('test_path').and_call_original
expect(builder).to receive(:build_response) do |connection, request|
expect(request.body).to eq('')
end.and_return(response)

allow(env).to receive(:body=).with({"message" => "response_hash"})

ConvertKit::Connection.new(url).delete('test_path')
end
end

describe '#put' do
Expand All @@ -111,6 +129,13 @@

ConvertKit::Connection.new(url).put('test_path', {hash: 'request_hash'})
end

it 'sends an empty body when no params are given' do
expect(connection).to receive(:put).with('test_path', '').and_return(response)
allow(env).to receive(:body=).with({"message" => "response_hash"})

ConvertKit::Connection.new(url).put('test_path')
end
end

describe 'when the response is not successful' do
Expand Down
2 changes: 1 addition & 1 deletion spec/lib/convertkit/resources/broadcasts_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@
let(:response) { double('response', success?: true) }

it 'deletes a broadcast' do
expect(client).to receive(:delete).with('broadcasts/1').and_return(response)
expect(client).to receive(:delete).with('broadcasts/1', '', true).and_return(response)
expect(broadcasts.delete(1)).to be(true)
end
end
Expand Down
2 changes: 1 addition & 1 deletion spec/lib/convertkit/resources/custom_fields_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
let(:response) { double('response', success?: true) }

it 'deletes a custom field' do
expect(client).to receive(:delete).with('custom_fields/1').and_return(response)
expect(client).to receive(:delete).with('custom_fields/1', '', true).and_return(response)
expect(custom_fields.delete(1)).to be true
end
end
Expand Down