kongkit 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 65dfeec66a7dc94c44664cfe5015c4f5019ae9cf
4
+ data.tar.gz: acef509ae84acf22be2a179dd1b90926b86e9f2f
5
+ SHA512:
6
+ metadata.gz: bb4984f1b2499ead42b6a9703a211095c65d675d585ad5d3cc8a892d8d44487cf4d95cb61c669be27c7b9963a18d34e537e463e4e3bd914394b88cbf7b499240
7
+ data.tar.gz: 25bf9d1087184ac1ebb6d4fcbd17509cd759ba12c646106e4ca6477583fe4a08eab6cd58bfc205da0b4c0a0388d0348012c960811c5bb76af72c7801b673a0e2
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.3.1
5
+ before_install: gem install bundler -v 1.12.5
@@ -0,0 +1,49 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, and in the interest of
4
+ fostering an open and welcoming community, we pledge to respect all people who
5
+ contribute through reporting issues, posting feature requests, updating
6
+ documentation, submitting pull requests or patches, and other activities.
7
+
8
+ We are committed to making participation in this project a harassment-free
9
+ experience for everyone, regardless of level of experience, gender, gender
10
+ identity and expression, sexual orientation, disability, personal appearance,
11
+ body size, race, ethnicity, age, religion, or nationality.
12
+
13
+ Examples of unacceptable behavior by participants include:
14
+
15
+ * The use of sexualized language or imagery
16
+ * Personal attacks
17
+ * Trolling or insulting/derogatory comments
18
+ * Public or private harassment
19
+ * Publishing other's private information, such as physical or electronic
20
+ addresses, without explicit permission
21
+ * Other unethical or unprofessional conduct
22
+
23
+ Project maintainers have the right and responsibility to remove, edit, or
24
+ reject comments, commits, code, wiki edits, issues, and other contributions
25
+ that are not aligned to this Code of Conduct, or to ban temporarily or
26
+ permanently any contributor for other behaviors that they deem inappropriate,
27
+ threatening, offensive, or harmful.
28
+
29
+ By adopting this Code of Conduct, project maintainers commit themselves to
30
+ fairly and consistently applying these principles to every aspect of managing
31
+ this project. Project maintainers who do not follow or enforce the Code of
32
+ Conduct may be permanently removed from the project team.
33
+
34
+ This code of conduct applies both within project spaces and in public spaces
35
+ when an individual is representing the project or its community.
36
+
37
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
38
+ reported by contacting a project maintainer at mettler.fabian@gmail.com. All
39
+ complaints will be reviewed and investigated and will result in a response that
40
+ is deemed necessary and appropriate to the circumstances. Maintainers are
41
+ obligated to maintain confidentiality with regard to the reporter of an
42
+ incident.
43
+
44
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage],
45
+ version 1.3.0, available at
46
+ [http://contributor-covenant.org/version/1/3/0/][version]
47
+
48
+ [homepage]: http://contributor-covenant.org
49
+ [version]: http://contributor-covenant.org/version/1/3/0/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in kongkit.gemspec
4
+ gemspec
data/LICENSE.md ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Fabian Mettler
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,65 @@
1
+ # Kongkit
2
+
3
+ Ruby library for the Kong API.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'kongkit'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install kongkit
20
+
21
+ ## Usage
22
+
23
+ ```ruby
24
+ # List APIs (default kong url: http://localhost:8001)
25
+ apis = Kongkit.apis
26
+
27
+ # Create consumer (default kong url: http://localhost:8001)
28
+ Kongkit.add_consumer(username: 'fabian')
29
+ ```
30
+
31
+ or
32
+
33
+ ```ruby
34
+ # Add API
35
+ client = Kongkit::Client.new('https://kong.enterprise.io:8001')
36
+ client.add_api(name: 'mockbin', request_host: 'mockbin.com', upstream_url: 'http://mockbin.com', preserve_host: true)
37
+
38
+ # Add Plugin
39
+ client.add_plugin('mockbin', name: 'rate-limiting', config.minute: 20, config.hour: 500)
40
+ ```
41
+
42
+ ### Pagination
43
+ When the returned resource contains a next value then the next page can be retrieved by calling the `next` method on the resource:
44
+
45
+ ```ruby
46
+ # List APIs (default kong url: http://localhost:8001)
47
+ first_page = Kongkit.apis(size: 5)
48
+
49
+ next_page = first_page.next
50
+ ```
51
+
52
+
53
+ ## Development
54
+
55
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
56
+
57
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
58
+
59
+ ## Contributing
60
+
61
+ Bug reports and pull requests are welcome on GitHub at https://github.com/maveonair/kongkit. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
62
+
63
+ ## License
64
+
65
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,24 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ Rake::TestTask.new(:test) do |t|
5
+ t.libs << "test"
6
+ t.libs << "lib"
7
+ t.test_files = FileList['test/**/*_test.rb']
8
+ end
9
+
10
+ task :default => :test
11
+
12
+ namespace :doc do
13
+ begin
14
+ require 'yard'
15
+ YARD::Rake::YardocTask.new do |task|
16
+ task.files = ['lib/**/*.rb']
17
+ task.options = [
18
+ '--output-dir', 'doc/yard',
19
+ '--markup', 'markdown',
20
+ ]
21
+ end
22
+ rescue LoadError
23
+ end
24
+ end
data/bin/console ADDED
@@ -0,0 +1,11 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "kongkit"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ require "pry"
11
+ Pry.start
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
data/kongkit.gemspec ADDED
@@ -0,0 +1,30 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'kongkit/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "kongkit"
8
+ spec.version = Kongkit::VERSION
9
+ spec.authors = ["Fabian Mettler"]
10
+ spec.email = ["mettler.fabian@gmail.com"]
11
+
12
+ spec.summary = %q{Ruby library for the Kong API.}
13
+ spec.description = spec.summary
14
+ spec.homepage = "https://github.com/maveonair/kongkit"
15
+ spec.license = "MIT"
16
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
17
+ spec.bindir = "exe"
18
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_runtime_dependency "httparty", "~> 0.14"
22
+
23
+ spec.add_development_dependency "bundler", "~> 1.12"
24
+ spec.add_development_dependency "rake", "~> 10.0"
25
+ spec.add_development_dependency "minitest", "~> 5.0"
26
+ spec.add_development_dependency "minitest-reporters", "~> 1.1"
27
+ spec.add_development_dependency "pry-byebug", "~> 3.4"
28
+ spec.add_development_dependency "webmock", "~> 2.1"
29
+ spec.add_development_dependency "yard", "~> 0.9"
30
+ end
@@ -0,0 +1,77 @@
1
+ module Kongkit
2
+ class Client
3
+ module ApiObject
4
+ # List APIs
5
+ #
6
+ # @see https://getkong.org/docs/0.8.x/admin-api/#list-apis
7
+ # @option options [String] :id A filter on the list based on the apis `id` field
8
+ # @option options [String] :name A filter on the list based on the apis `name` field
9
+ # @option options [String] :request_host A filter on the list based on the apis `request_host` field
10
+ # @option options [String] :request_path A filter on the list based on the apis `request_path` field
11
+ # @option options [String] :upstream_url A filter on the list based on the apis `upstream_url` field
12
+ # @option options [Integer] :size A limit on the number of objects to be returned, default: 100
13
+ # @option options [String] :offset A cursor used for pagination. Offset is an object identifier that defines a place in the list.
14
+ # @return [Hash] API Objects
15
+ def apis(options = {})
16
+ get('/apis', query: options)
17
+ end
18
+
19
+ # Retrieve API
20
+ #
21
+ # @see https://getkong.org/docs/0.8.x/admin-api/#retrieve-api
22
+ # @param identifier [String] The unique identifier or the name of the API to retrieve
23
+ # @return [Hash] API Object
24
+ def api(identifier)
25
+ get(api_path(identifier))
26
+ end
27
+
28
+ # Add API
29
+ #
30
+ # @note At least request_host or request_path or both should be specified.
31
+ #
32
+ # @see https://getkong.org/docs/0.8.x/admin-api/#add-api
33
+ # @option attributes [String] :name The API name (optional)
34
+ # @option attributes [String] :request_host The public DNS address that points to your API (semi-optional)
35
+ # @option attributes [String] :request_path The public path that points to your API (semi-optional)
36
+ # @option attributes [String] :strip_request_path Strip the request_path value before proxying the request to the final API (optional)
37
+ # @option attributes [String] :preserve_host Preserves the original Host header sent by the client, instead of replacing it with the hostname of the upstream_url (optional)
38
+ # @option attributes [String] :upstream_url The base target URL that points to your API server, this URL will be used for proxying requests
39
+ # @return [Hash] API Object
40
+ def add_api(attributes)
41
+ post('/apis', body: attributes)
42
+ end
43
+
44
+ # Edit API
45
+ #
46
+ # @note At least request_host or request_path or both should be specified.
47
+ #
48
+ # @see https://getkong.org/docs/0.8.x/admin-api/#update-api
49
+ # @param identifier [String] The unique identifier or the name of the API to update
50
+ # @option attributes [String] :name The API name (optional)
51
+ # @option attributes [String] :request_host The public DNS address that points to your API (semi-optional)
52
+ # @option attributes [String] :request_path The public path that points to your API (semi-optional)
53
+ # @option attributes [String] :strip_request_path Strip the request_path value before proxying the request to the final API (optional)
54
+ # @option attributes [String] :preserve_host Preserves the original Host header sent by the client, instead of replacing it with the hostname of the upstream_url (optional)
55
+ # @option attributes [String] :upstream_url The base target URL that points to your API server, this URL will be used for proxying requests
56
+ # @return [Hash] API Object
57
+ def edit_api(identifier, attributes)
58
+ patch(api_path(identifier), body: attributes)
59
+ end
60
+
61
+ # Delete API
62
+ #
63
+ # @see https://getkong.org/docs/0.8.x/admin-api/#delete-api
64
+ # @param identifier [String] The unique identifier or the name of the API to delete
65
+ # @return [Boolean] `true` if successfully deleted
66
+ def delete_api(identifier)
67
+ delete(api_path(identifier))
68
+ end
69
+
70
+ private
71
+
72
+ def api_path(identifier)
73
+ "/apis/#{identifier}"
74
+ end
75
+ end
76
+ end
77
+ end
@@ -0,0 +1,26 @@
1
+ module Kongkit
2
+ class Client
3
+ module Cluster
4
+ # Retrieve cluster status
5
+ #
6
+ # Retrieve the cluster status, returning information for each node in the cluster.
7
+ #
8
+ # @see https://getkong.org/docs/0.8.x/admin-api/#retrieve-cluster-status
9
+ # @return [Hash] Cluster status
10
+ def cluster_status
11
+ get('/cluster')
12
+ end
13
+
14
+ # Forcibly remove a node
15
+ #
16
+ # Forcibly remove a node from the cluster.
17
+ #
18
+ # @see https://getkong.org/docs/0.8.x/admin-api/#forcibly-remove-a-node
19
+ # @param name [String] Name of the node
20
+ # @return [Boolean] `true` if successfully removed
21
+ def remove_node(name)
22
+ delete('/cluster', query: { name: name })
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,67 @@
1
+ module Kongkit
2
+ class Client
3
+ module Consumer
4
+ # List consumers
5
+ #
6
+ # @see https://getkong.org/docs/0.8.x/admin-api/#list-consumers
7
+ # @option options [String] :id A filter on the list based on the consumer `id` field
8
+ # @option options [String] :custom_id A filter on the list based on the consumer `custom_id` field
9
+ # @option options [String] :username A filter on the list based on the consumer `username` field
10
+ # @option options [Integer] :size A limit on the number of objects to be returned, default: 100
11
+ # @option options [String] :offset A cursor used for pagination. Offset is an object identifier that defines a place in the list.
12
+ # @return [Hash] API Objects
13
+ def consumers(options = {})
14
+ get('/consumers', query: options)
15
+ end
16
+
17
+ # Retrieve consumer
18
+ #
19
+ # @see https://getkong.org/docs/0.8.x/admin-api/#retrieve-consumer
20
+ # @param identifier [String] The unique identifier or the username of the consumer to retrieve
21
+ # @return [Hash] Consumer
22
+ def consumer(identifier)
23
+ get(consumer_path(identifier))
24
+ end
25
+
26
+ # Create consumer
27
+ #
28
+ # @note At least username or custom_id should be specified.
29
+ #
30
+ # @see https://getkong.org/docs/0.8.x/admin-api/#create-consumer
31
+ # @option attributes [String] :username The username of the consumer (semi-optional)
32
+ # @option attributes [String] :custom_id Field for storing an existing ID for the consumer, useful for mapping Kong with users in your existing database (semi-optional)
33
+ # @return [Hash] Consumer
34
+ def create_consumer(attributes)
35
+ post('/consumers', body: attributes)
36
+ end
37
+
38
+ # Edit consumer
39
+ #
40
+ # @note At least username or custom_id should be specified.
41
+ #
42
+ # @see https://getkong.org/docs/0.8.x/admin-api/#update-consumer
43
+ # @param identifier [String] The unique identifier or the name of the consumer to update
44
+ # @option attributes [String] :username The username of the consumer (semi-optional)
45
+ # @option attributes [String] :custom_id Field for storing an existing ID for the consumer, useful for mapping Kong with users in your existing database (semi-optional)
46
+ # @return [Hash] Consumer
47
+ def edit_consumer(identifier, attributes)
48
+ patch(consumer_path(identifier), body: attributes)
49
+ end
50
+
51
+ # Delete Consumer
52
+ #
53
+ # @see https://getkong.org/docs/0.8.x/admin-api/#delete-consumer
54
+ # @param identifier [String] The unique identifier or the name of the consumer to delete
55
+ # @return [Boolean] `true` if successfully deleted
56
+ def delete_consumer(identifier)
57
+ delete(consumer_path(identifier))
58
+ end
59
+
60
+ private
61
+
62
+ def consumer_path(identifier)
63
+ "/consumers/#{identifier}"
64
+ end
65
+ end
66
+ end
67
+ end
@@ -0,0 +1,31 @@
1
+ module Kongkit
2
+ class Client
3
+ module Node
4
+ # Retrieve node information
5
+ #
6
+ # Retrieve generic details about a node.
7
+ #
8
+ # @see https://getkong.org/docs/0.8.x/admin-api/#retrieve-node-information
9
+ # @return [Hash] Node information
10
+ def node_information
11
+ get('/')
12
+ end
13
+
14
+ # Retrieve node status
15
+ #
16
+ # Retrieve usage information about a node, with some basic information
17
+ # about the connections being processed by the underlying nginx process,
18
+ # and the number of entities stored in the datastore collections
19
+ # (including plugin's collections).
20
+ #
21
+ # If you want to monitor the Kong process, since Kong is built on top of nginx,
22
+ # every existing nginx monitoring tool or agent can be used.
23
+ #
24
+ # @see https://getkong.org/docs/0.8.x/admin-api/#retrieve-node-status
25
+ # @return [Hash] Node status
26
+ def node_status
27
+ get('/status')
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,111 @@
1
+ module Kongkit
2
+ class Client
3
+ module PluginObject
4
+ # List all Plugins
5
+ #
6
+ # @see https://getkong.org/docs/0.8.x/admin-api/#list-all-plugins
7
+ # @option options [String] :id A filter on the list based on the `id` field
8
+ # @option options [String] :name A filter on the list based on the `name` field
9
+ # @option options [String] :api_id A filter on the list based on the `api_id` field
10
+ # @option options [String] :consumer_id A filter on the list based on the `consumer_id` field
11
+ # @option options [Integer] :size A limit on the number of objects to be returned, default: 100
12
+ # @option options [offset] :offset A cursor used for pagination. offset is an object identifier that defines a place in the list.
13
+ # @return [Hash] Plugin Objects
14
+ def plugins(options = {})
15
+ get('/plugins', options)
16
+ end
17
+
18
+ # List enabled Plugins
19
+ #
20
+ # Retrieve a list of all installed plugins on the Kong node.
21
+ #
22
+ # @see https://getkong.org/docs/0.8.x/admin-api/#list-enabled-plugins
23
+ # @return [Hash] Plugin Objects
24
+ def enabled_plugins
25
+ get('/plugins/enabled')
26
+ end
27
+
28
+ # Retrieve Plugin Schema
29
+ #
30
+ # Retrieve the schema of a plugin's configuration.
31
+ # This is useful to understand what fields a plugin accepts,
32
+ # and can be used for building third-party integrations to the Kong's plugin system.
33
+ #
34
+ # @see https://getkong.org/docs/0.8.x/admin-api/#list-enabled-plugins
35
+ # @param name [String] The name of the plugin to retrieve its schema
36
+ # @return [Hash] Plugin Objects
37
+ def plugin_schema(name)
38
+ get("/plugins/schema/#{name}")
39
+ end
40
+
41
+ # Retrieve Plugin
42
+ #
43
+ # @see https://getkong.org/docs/0.8.x/admin-api/#retrieve-plugin
44
+ # @param id [String] The unique identifier of the plugin to retrieve
45
+ # @return [Hash] Plugin Object
46
+ def plugin(id)
47
+ get("/plugins/#{id}")
48
+ end
49
+
50
+ # List Plugins per API
51
+ #
52
+ # @see https://getkong.org/docs/0.8.x/admin-api/#list-plugins-per-api
53
+ # @param api_identifier [String] The unique identifier or the name of the API
54
+ # @option options [String] :id A filter on the list based on the `id` field
55
+ # @option options [String] :name A filter on the list based on the `name` field
56
+ # @option options [String] :api_id A filter on the list based on the `api_id` field
57
+ # @option options [String] :consumer_id A filter on the list based on the `consumer_id` field
58
+ # @option options [Integer] :size A limit on the number of objects to be returned, default: 100
59
+ # @option options [offset] :offset A cursor used for pagination. offset is an object identifier that defines a place in the list.
60
+ # @return [Hash] Plugin Objects
61
+ def api_plugins(api_identifier, options = {})
62
+ get(api_plugins_path(api_identifier), options)
63
+ end
64
+
65
+ # Add plugin
66
+ #
67
+ # @see https://getkong.org/docs/0.8.x/admin-api/#add-plugin
68
+ # @param api_identifier [String] The unique identifier or the name of the API on which to add a plugin configuration
69
+ # @option attributes [String] :name The name of the Plugin that's going to be added.
70
+ # @option attributes [String] :consumer_id The unique identifier of the consumer that overrides the existing settings for this specific consumer on incoming requests (optional)
71
+ # @option attributes [String] :config.{property} The configuration properties for the Plugin.
72
+ # @return [Hash] Plugin Object
73
+ def add_plugin(api_identifier, attributes)
74
+ post(api_plugins_path(api_identifier), body: attributes)
75
+ end
76
+
77
+ # Edit plugin
78
+ #
79
+ # @see https://getkong.org/docs/0.8.x/admin-api/#update-plugin
80
+ # @param api_identifier [String] The unique identifier or the name of the API for which to update the plugin configuration
81
+ # @param id [String] he unique identifier of the plugin configuration to update on this API
82
+ # @option attributes [String] :name The name of the Plugin that's going to be added.
83
+ # @option attributes [String] :consumer_id The unique identifier of the consumer that overrides the existing settings for this specific consumer on incoming requests (optional)
84
+ # @option attributes [String] :config.{property} The configuration properties for the Plugin.
85
+ # @return [Hash] Plugin Object
86
+ def edit_plugin(api_identifier, id, attributes)
87
+ patch(api_plugin_path(api_identifier, id), body: attributes)
88
+ end
89
+
90
+ # Remove plugin
91
+ #
92
+ # @see https://getkong.org/docs/0.8.x/admin-api/#delete-plugin
93
+ # @param api_identifier [String] The unique identifier or the name of the API for which to remove the plugin configuration
94
+ # @param id [String] The unique identifier of the plugin configuration to update on this API
95
+ # @return [Boolean] `true` if successfully removed
96
+ def remove_plugin(api_identifier, id)
97
+ delete(api_plugin_path(api_identifier, id))
98
+ end
99
+
100
+ private
101
+
102
+ def api_plugins_path(api_identifier)
103
+ "/apis/#{api_identifier}/plugins"
104
+ end
105
+
106
+ def api_plugin_path(api_identifier, id)
107
+ "#{api_plugins_path(api_identifier)}/#{id}"
108
+ end
109
+ end
110
+ end
111
+ end
@@ -0,0 +1,51 @@
1
+ module Kongkit
2
+ class Client
3
+ module Request
4
+ # HTTP GET request
5
+ #
6
+ # @param path [String] The API path
7
+ # @param options [Hash] The options
8
+ # @return [Kongkit::Client::Resource] Resource
9
+ def get(path, options = {})
10
+ response = self.class.get(path, options)
11
+ parse(response)
12
+ end
13
+
14
+ # HTTP POST request
15
+ #
16
+ # @param path [String] The API path
17
+ # @param options [Hash] The options
18
+ # @return [Kongkit::Client::Resource] Resource
19
+ def post(path, options = {})
20
+ response = self.class.post(path, options)
21
+ parse(response)
22
+ end
23
+
24
+ # HTTP PATCH request
25
+ #
26
+ # @param path [String] The API path
27
+ # @param options [Hash] The options
28
+ # @return [Kongkit::Client::Resource] Resource
29
+ def patch(path, options = {})
30
+ response = self.class.patch(path, options)
31
+ parse(response)
32
+ end
33
+
34
+ # HTTP DELETE request
35
+ #
36
+ # @param path [String] The API path
37
+ # @param options [Hash] The options
38
+ # @return [Boolean] `true` if successfully respondeds
39
+ def delete(path, options = {})
40
+ response = self.class.delete(path, options)
41
+ response.success?
42
+ end
43
+
44
+ private
45
+
46
+ def parse(response)
47
+ Kongkit::Client::Resource.new(self, JSON.parse(response.body, symbolize_names: true))
48
+ end
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,39 @@
1
+ module Kongkit
2
+ class Client
3
+ class Resource
4
+ def initialize(client, data)
5
+ @client = client
6
+ @data = data
7
+ end
8
+
9
+ # Allow fields to be retrieved via Hash notation
10
+ #
11
+ # @param key [Symbol] A symbol key
12
+ # @return [Object] from data if exists
13
+ def [](key)
14
+ data[key]
15
+ rescue NoMethodError
16
+ nil
17
+ end
18
+
19
+ # Retrieves the next resource
20
+ #
21
+ # @return [Kongkit::Client::Resource] Resource
22
+ def next
23
+ return nil if data[:next].nil?
24
+ client.get(data[:next])
25
+ end
26
+
27
+ # Returns a string containing a human-readable representation of this object
28
+ #
29
+ # @return [String] human-readable representation of this object
30
+ def inspect
31
+ data.inspect
32
+ end
33
+
34
+ private
35
+
36
+ attr_reader :client, :data
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,34 @@
1
+ require 'httparty'
2
+ require 'json'
3
+
4
+ require 'kongkit/client/api_object'
5
+ require 'kongkit/client/cluster'
6
+ require 'kongkit/client/consumer'
7
+ require 'kongkit/client/plugin_object'
8
+ require 'kongkit/client/node'
9
+ require 'kongkit/client/request'
10
+ require 'kongkit/client/resource'
11
+
12
+ module Kongkit
13
+ class Client
14
+ include HTTParty
15
+
16
+ include ApiObject
17
+ include Cluster
18
+ include Consumer
19
+ include PluginObject
20
+ include Node
21
+ include Request
22
+
23
+ def initialize(url = 'http://localhost:8001')
24
+ @url = url
25
+
26
+ self.class.base_uri(@url)
27
+ self.class.headers('Accept' => 'application/json')
28
+ end
29
+
30
+ def same_url?(url)
31
+ @url == url
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,3 @@
1
+ module Kongkit
2
+ VERSION = "0.1.0"
3
+ end
data/lib/kongkit.rb ADDED
@@ -0,0 +1,30 @@
1
+ require 'kongkit/client'
2
+ require 'kongkit/version'
3
+
4
+ module Kongkit
5
+ class << self
6
+ # API client
7
+ #
8
+ # @param url [String] Kong admin url
9
+ # @return [Kongkit::Client] API wrapper
10
+ def client(url = 'http://localhost:8001')
11
+ return @client if defined?(@client) && @client.same_url?(url)
12
+
13
+ @client = Kongkit::Client.new(url)
14
+ end
15
+
16
+ private
17
+
18
+ def respond_to_missing?(method_name, include_private = false)
19
+ client.respond_to?(method_name, include_private)
20
+ end
21
+
22
+ def method_missing(method_name, *args, &block)
23
+ if client.respond_to?(method_name)
24
+ return client.send(method_name, *args, &block)
25
+ end
26
+
27
+ super
28
+ end
29
+ end
30
+ end
metadata ADDED
@@ -0,0 +1,176 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: kongkit
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Fabian Mettler
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-08-16 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: httparty
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '0.14'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '0.14'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.12'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.12'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: minitest
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '5.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '5.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: minitest-reporters
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '1.1'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '1.1'
83
+ - !ruby/object:Gem::Dependency
84
+ name: pry-byebug
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '3.4'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '3.4'
97
+ - !ruby/object:Gem::Dependency
98
+ name: webmock
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '2.1'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '2.1'
111
+ - !ruby/object:Gem::Dependency
112
+ name: yard
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: '0.9'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: '0.9'
125
+ description: Ruby library for the Kong API.
126
+ email:
127
+ - mettler.fabian@gmail.com
128
+ executables: []
129
+ extensions: []
130
+ extra_rdoc_files: []
131
+ files:
132
+ - ".gitignore"
133
+ - ".travis.yml"
134
+ - CODE_OF_CONDUCT.md
135
+ - Gemfile
136
+ - LICENSE.md
137
+ - README.md
138
+ - Rakefile
139
+ - bin/console
140
+ - bin/setup
141
+ - kongkit.gemspec
142
+ - lib/kongkit.rb
143
+ - lib/kongkit/client.rb
144
+ - lib/kongkit/client/api_object.rb
145
+ - lib/kongkit/client/cluster.rb
146
+ - lib/kongkit/client/consumer.rb
147
+ - lib/kongkit/client/node.rb
148
+ - lib/kongkit/client/plugin_object.rb
149
+ - lib/kongkit/client/request.rb
150
+ - lib/kongkit/client/resource.rb
151
+ - lib/kongkit/version.rb
152
+ homepage: https://github.com/maveonair/kongkit
153
+ licenses:
154
+ - MIT
155
+ metadata: {}
156
+ post_install_message:
157
+ rdoc_options: []
158
+ require_paths:
159
+ - lib
160
+ required_ruby_version: !ruby/object:Gem::Requirement
161
+ requirements:
162
+ - - ">="
163
+ - !ruby/object:Gem::Version
164
+ version: '0'
165
+ required_rubygems_version: !ruby/object:Gem::Requirement
166
+ requirements:
167
+ - - ">="
168
+ - !ruby/object:Gem::Version
169
+ version: '0'
170
+ requirements: []
171
+ rubyforge_project:
172
+ rubygems_version: 2.6.4
173
+ signing_key:
174
+ specification_version: 4
175
+ summary: Ruby library for the Kong API.
176
+ test_files: []