Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch to application json content type #28

Merged
Merged
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
4 changes: 2 additions & 2 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
source 'https://rubygems.org'

# Specify your gem's dependencies in kontena-cli.gemspec
# Specify your gem's dependencies in kong.gemspec
gemspec
group :development, :test do
gem "rspec"
gem "rubocop"
gem "rubocop", "0.47"
end
10 changes: 5 additions & 5 deletions lib/kong/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,8 @@ def save

# Create resource
def create
headers = { 'Content-Type' => 'application/x-www-form-urlencoded' }
response = client.post(@api_end_point, nil, attributes, headers)
headers = { 'Content-Type' => 'application/json' }
response = client.post(@api_end_point, attributes, nil, headers)
init_attributes(response)
self
end
Expand All @@ -121,15 +121,15 @@ def create
# Data is sent to Kong in JSON format and HTTP PUT request is used
def create_or_update
headers = { 'Content-Type' => 'application/json' }
response = client.put("#{@api_end_point}", attributes, nil, headers)
response = client.put(@api_end_point, attributes, nil, headers)
init_attributes(response)
self
end

# Update resource
def update
headers = { 'Content-Type' => 'application/x-www-form-urlencoded' }
response = client.patch("#{@api_end_point}#{self.id}", nil, attributes, headers)
headers = { 'Content-Type' => 'application/json' }
response = client.patch("#{@api_end_point}#{self.id}", attributes, nil, headers)
init_attributes(response)
self
end
Expand Down
16 changes: 8 additions & 8 deletions spec/kong/base_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -94,18 +94,18 @@

describe '#create' do
it 'creates POST /:resource_end_point/ request with resource attributes' do
headers = { 'Content-Type' => 'application/x-www-form-urlencoded' }
headers = { 'Content-Type' => 'application/json' }
attributes = { 'name' => 'test object' }
expect(Kong::Client.instance).to receive(:post).with('/resources/', nil, attributes, headers)
expect(Kong::Client.instance).to receive(:post).with('/resources/', attributes, nil, headers)
.and_return(attributes)
subject.name = 'test object'
subject.create
end

it 'returns resource instance' do
headers = { 'Content-Type' => 'application/x-www-form-urlencoded' }
headers = { 'Content-Type' => 'application/json' }
attributes = { 'name' => 'test object' }
allow(Kong::Client.instance).to receive(:post).with('/resources/', nil, attributes, headers)
allow(Kong::Client.instance).to receive(:post).with('/resources/', attributes, nil, headers)
.and_return(attributes.merge({ 'id' => '12345' }))
subject.name = 'test object'
expect(subject.create).to eq(subject)
Expand Down Expand Up @@ -134,19 +134,19 @@

describe '#update' do
it 'creates PATCH /:resource_end_point/:resource_id request with resource attributes' do
headers = { 'Content-Type' => 'application/x-www-form-urlencoded' }
headers = { 'Content-Type' => 'application/json' }
subject.id = '12345'
subject.name = 'test object'
expect(Kong::Client.instance).to receive(:patch).with('/resources/12345', nil, subject.attributes, headers)
expect(Kong::Client.instance).to receive(:patch).with('/resources/12345', subject.attributes, nil, headers)
.and_return(subject.attributes)
subject.update
end

it 'returns resource instance' do
headers = { 'Content-Type' => 'application/x-www-form-urlencoded' }
headers = { 'Content-Type' => 'application/json' }
subject.id = '12345'
subject.name = 'test object'
allow(Kong::Client.instance).to receive(:patch).with('/resources/12345', nil, subject.attributes, headers)
allow(Kong::Client.instance).to receive(:patch).with('/resources/12345', subject.attributes, nil, headers)
.and_return(subject.attributes)
expect(subject.update).to eq(subject)
end
Expand Down
8 changes: 4 additions & 4 deletions spec/kong/plugin_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,19 @@

describe '#create' do
it 'transforms config keys to config.key format' do
headers = { 'Content-Type' => 'application/x-www-form-urlencoded' }
headers = { 'Content-Type' => 'application/json' }
attributes = { 'api_id' => ':api_id', 'config.anonymous' => '12345' }
expect(Kong::Client.instance).to receive(:post).with('/apis/:api_id/plugins/', nil, attributes, headers).and_return(attributes)
expect(Kong::Client.instance).to receive(:post).with('/apis/:api_id/plugins/', attributes, nil, headers).and_return(attributes)
subject = described_class.new({ api_id: ':api_id', config: { 'anonymous' => '12345' } })
subject.create
end
end

describe '#update' do
it 'transforms config keys to config.key format' do
headers = { 'Content-Type' => 'application/x-www-form-urlencoded' }
headers = { 'Content-Type' => 'application/json' }
attributes = { 'api_id' => ':api_id', 'config.anonymous' => '12345' }
expect(Kong::Client.instance).to receive(:patch).with('/apis/:api_id/plugins/', nil, attributes, headers).and_return(attributes)
expect(Kong::Client.instance).to receive(:patch).with('/apis/:api_id/plugins/', attributes, nil, headers).and_return(attributes)
subject = described_class.new({ api_id: ':api_id', config: { 'anonymous' => '12345' } })
subject.update
end
Expand Down