Skip to content

Commit

Permalink
Implement Kong server info endpoints (#14)
Browse files Browse the repository at this point in the history
  • Loading branch information
nevalla committed Apr 20, 2017
1 parent 2264be9 commit 75df30b
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 0 deletions.
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,16 @@ consumer = Kong::Consumer.find_by_username('testuser')
consumer.acls
```

#### Server Information

```ruby
Kong::Server.info
Kong::Server.version
Kong::Server.status
Kong::Server.cluster
Kong::Server.remove_node(node_name)
```

## Contributing

1. Fork it ( https://github.com/kontena/kong-client-ruby/fork )
Expand Down
1 change: 1 addition & 0 deletions lib/kong.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@
require_relative 'kong/key_auth'
require_relative 'kong/jwt'
require_relative 'kong/acl'
require_relative 'kong/server'
23 changes: 23 additions & 0 deletions lib/kong/server.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
module Kong
class Server
def self.version
self.info['version'] rescue nil
end

def self.info
Client.instance.get('/')
end

def self.status
Client.instance.get('/status')
end

def self.cluster
Client.instance.get('/cluster')
end

def self.remove_node(name)
Client.instance.delete("/cluster/nodes/#{name}")
end
end
end
39 changes: 39 additions & 0 deletions spec/kong/server_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
require_relative "../spec_helper"

describe Kong::Server do
describe '.info' do
it 'makes GET / request' do
expect(Kong::Client.instance).to receive(:get).with('/')
described_class.info
end
end

describe '.version' do
it 'returns version information' do
allow(Kong::Client.instance).to receive(:get).with('/')
.and_return({ 'version' => '0.10.0' })
expect(described_class.version).to eq('0.10.0')
end
end

describe '.status' do
it 'makes GET /status request' do
expect(Kong::Client.instance).to receive(:get).with('/status')
described_class.status
end
end

describe '.cluster' do
it 'makes GET /cluster request' do
expect(Kong::Client.instance).to receive(:get).with('/cluster')
described_class.cluster
end
end

describe '.remove_node' do
it 'makes DELETE /cluster/nodes/:name request' do
expect(Kong::Client.instance).to receive(:delete).with('/cluster/nodes/:name')
described_class.remove_node(':name')
end
end
end

0 comments on commit 75df30b

Please sign in to comment.