ruby-kong 0.1.0a

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,280 @@
1
+ module RubyKong
2
+ module Request
3
+ module Plugin
4
+ class << self
5
+ def create(*args)
6
+ path = RubyKong.paths[:plugin][:create]
7
+ path.gsub!(':api_id', args[0][:api])
8
+ Request.post(path, args[0][:plugin])
9
+ end
10
+
11
+ def list(*args)
12
+ path = RubyKong.paths[:plugin][:list]
13
+ Request.get(path, args[0])
14
+ end
15
+
16
+ def list_by_api(*args)
17
+ path = RubyKong.paths[:plugin][:list_by_api]
18
+ path.gsub!(':api_id', args[0][:api])
19
+ Request.get(path, args[0][:filter])
20
+ end
21
+
22
+ def retrieve(*args)
23
+ plugin_id = args[0][:id]
24
+ path = RubyKong.paths[:plugin][:retrieve]
25
+ path.gsub!(':plugin_id', plugin_id)
26
+ Request.get(path)
27
+ end
28
+
29
+ def retrieve_enabled(*args)
30
+ path = RubyKong.paths[:plugin][:retrieve_enabled]
31
+ Request.get(path)
32
+ end
33
+
34
+ def retrieve_schema(*args)
35
+ plugin_name = args[0][:plugin_name]
36
+ path = RubyKong.paths[:plugin][:retrieve_schema]
37
+ path.gsub!(':plugin_name', plugin_name)
38
+ Request.get(path)
39
+ end
40
+
41
+ def update(*args)
42
+ api_id = args[0][:api]
43
+ plugin_id = args[0][:plugin]
44
+ path = RubyKong.paths[:plugin][:update]
45
+ path.gsub!(':api_id', api_id)
46
+ path.gsub!(':plugin_id', plugin_id)
47
+
48
+ Request.patch(path, args[0][:params])
49
+ end
50
+
51
+ def delete(*args)
52
+ resource = args[0][:username] || args[0][:id]
53
+ path = RubyKong.paths[:plugin][:update] + resource
54
+ Request.delete(path, args[0])
55
+ end
56
+ end
57
+
58
+ class Stub
59
+ # def self.delete
60
+ # # Mock with /plugins/lamdt path
61
+ # path = RubyKong.paths[:plugin][:delete] + 'lamdt'
62
+ # url = RubyKong::Utils.endpoint_builder(path)
63
+ #
64
+ # RubyKong::Stub.request(
65
+ # :method => :delete,
66
+ # :url => url,
67
+ # :response => {
68
+ # :status => 204,
69
+ # :body => ""
70
+ # }
71
+ # )
72
+ # end
73
+ #
74
+ def self.update
75
+ path = RubyKong.paths[:plugin][:update]
76
+ path.gsub!(':api_id', 'shipit')
77
+ path.gsub!(':plugin_id', '90e6e8f4-2d51-444d-ac28-3f1dc1b3b3ed')
78
+ url = RubyKong::Utils.endpoint_builder(path)
79
+
80
+ RubyKong::Stub.request(
81
+ :method => :patch,
82
+ :url => url,
83
+ :request => {
84
+ :body => {}
85
+ },
86
+ :response => {
87
+ :status => 200,
88
+ :body => {
89
+ 'api_id' => 'ec60e4c9-11e2-4748-817d-56b2bf69bd60',
90
+ 'id' => '90e6e8f4-2d51-444d-ac28-3f1dc1b3b3ed',
91
+ 'created_at' => 1458809572000,
92
+ 'enabled' => true,
93
+ 'name' => 'key-auth',
94
+ 'config' => {
95
+ 'key_names' => ['apikey'],
96
+ 'hide_credentials' => false
97
+ }
98
+ }.to_s
99
+ }
100
+ )
101
+ end
102
+
103
+ def self.retrieve
104
+ path = RubyKong.paths[:plugin][:retrieve]
105
+ path.gsub!(':plugin_id', '90e6e8f4-2d51-444d-ac28-3f1dc1b3b3ed')
106
+ url = RubyKong::Utils.endpoint_builder(path)
107
+
108
+ RubyKong::Stub.request(
109
+ :method => :get,
110
+ :url => url,
111
+ :response => {
112
+ :status => 200,
113
+ :body => {
114
+ 'api_id' => 'ec60e4c9-11e2-4748-817d-56b2bf69bd60',
115
+ 'id' => '90e6e8f4-2d51-444d-ac28-3f1dc1b3b3ed',
116
+ 'created_at' => 1458809572000,
117
+ 'enabled' => true,
118
+ 'name' => 'key-auth',
119
+ 'config' => {
120
+ 'key_names' => ['apikey'],
121
+ 'hide_credentials' => false
122
+ }
123
+ }.to_s
124
+ }
125
+ )
126
+ end
127
+
128
+ def self.retrieve_enabled
129
+ path = RubyKong.paths[:plugin][:retrieve_enabled]
130
+ url = RubyKong::Utils.endpoint_builder(path)
131
+
132
+ RubyKong::Stub.request(
133
+ :method => :get,
134
+ :url => url,
135
+ :response => {
136
+ :status => 200,
137
+ :body => {
138
+ "enabled_plugins": [
139
+ "ssl",
140
+ "jwt",
141
+ "acl",
142
+ "cors",
143
+ "oauth2",
144
+ "tcp-log",
145
+ "udp-log",
146
+ "file-log",
147
+ "http-log",
148
+ "key-auth",
149
+ "hmac-auth",
150
+ "basic-auth",
151
+ "ip-restriction",
152
+ "mashape-analytics",
153
+ "request-transformer",
154
+ "response-transformer",
155
+ "request-size-limiting",
156
+ "rate-limiting",
157
+ "response-ratelimiting"
158
+ ]
159
+ }.to_s
160
+ }
161
+ )
162
+ end
163
+
164
+ def self.retrieve_schema
165
+ path = RubyKong.paths[:plugin][:retrieve_schema]
166
+ path.gsub!(':plugin_name', 'basic-auth')
167
+ url = RubyKong::Utils.endpoint_builder(path)
168
+
169
+ RubyKong::Stub.request(
170
+ :method => :get,
171
+ :url => url,
172
+ :response => {
173
+ :status => 200,
174
+ :body => {
175
+ "fields": {
176
+ "hide_credentials": {
177
+ "type":"boolean",
178
+ "default":false
179
+ }
180
+ },
181
+ "no_consumer":true
182
+ }.to_s
183
+ }
184
+ )
185
+ end
186
+
187
+ def self.list
188
+ path = RubyKong.paths[:plugin][:list]
189
+ url = RubyKong::Utils.endpoint_builder(path)
190
+
191
+ RubyKong::Stub.request(
192
+ :method => :get,
193
+ :url => url,
194
+ :response => {
195
+ :status => 200,
196
+ :body => {
197
+ "data" =>
198
+ [
199
+ {
200
+ 'api_id' => 'ec60e4c9-11e2-4748-817d-56b2bf69bd60',
201
+ 'id' => '90e6e8f4-2d51-444d-ac28-3f1dc1b3b3ed',
202
+ 'created_at' => 1458809572000,
203
+ 'enabled' => true,
204
+ 'name' => 'key-auth',
205
+ 'config' => {
206
+ 'key_names' => ['apikey'],
207
+ 'hide_credentials' => false
208
+ }
209
+ }
210
+ ],
211
+ "total" => 1
212
+ }.to_s
213
+ }
214
+ )
215
+ end
216
+
217
+ def self.list_by_api
218
+ path = RubyKong.paths[:plugin][:list_by_api]
219
+ path.gsub!(':api_id', 'shipit')
220
+ url = RubyKong::Utils.endpoint_builder(path)
221
+
222
+ RubyKong::Stub.request(
223
+ :method => :get,
224
+ :url => url,
225
+ :response => {
226
+ :status => 200,
227
+ :body => {
228
+ "data" =>
229
+ [
230
+ {
231
+ 'api_id' => 'ec60e4c9-11e2-4748-817d-56b2bf69bd60',
232
+ 'id' => '90e6e8f4-2d51-444d-ac28-3f1dc1b3b3ed',
233
+ 'created_at' => 1458809572000,
234
+ 'enabled' => true,
235
+ 'name' => 'key-auth',
236
+ 'config' => {
237
+ 'key_names' => ['apikey'],
238
+ 'hide_credentials' => false
239
+ }
240
+ }
241
+ ],
242
+ "total" => 1
243
+ }.to_s
244
+ }
245
+ )
246
+ end
247
+
248
+ def self.create
249
+ path = RubyKong.paths[:plugin][:create]
250
+ path.gsub!(':api_id', 'shipit')
251
+ url = RubyKong::Utils.endpoint_builder(path)
252
+
253
+ RubyKong::Stub.request(
254
+ :method => :post,
255
+ :url => url,
256
+ :request => {
257
+ :body => {
258
+ :name => 'key-auth'
259
+ }
260
+ },
261
+ :response => {
262
+ :status => 201,
263
+ :body => {
264
+ 'api_id' => 'ec60e4c9-11e2-4748-817d-56b2bf69bd60',
265
+ 'id' => '90e6e8f4-2d51-444d-ac28-3f1dc1b3b3ed',
266
+ 'created_at' => 1458809572000,
267
+ 'enabled' => true,
268
+ 'name' => 'key-auth',
269
+ 'config' => {
270
+ 'key_names' => ['apikey'],
271
+ 'hide_credentials' => false
272
+ }
273
+ }.to_s
274
+ }
275
+ )
276
+ end # End of Stub.create method
277
+ end # End of Stub module
278
+ end # end of Consumer
279
+ end # End of Request
280
+ end # End of RubyKong
@@ -0,0 +1,42 @@
1
+ module RubyKong
2
+ class << self
3
+ attr_accessor :url
4
+
5
+ def paths
6
+ {
7
+ :node => {
8
+ :info => '/',
9
+ :status => '/status'
10
+ },
11
+ :api => {
12
+ :create => '/apis',
13
+ :list => '/apis',
14
+ :retrieve => '/apis/',
15
+ :update => '/apis/',
16
+ :delete => '/apis/'
17
+ },
18
+ :consumer => {
19
+ :create => '/consumers',
20
+ :list => '/consumers',
21
+ :retrieve => '/consumers/',
22
+ :update => '/consumers/',
23
+ :delete => '/consumers/'
24
+ },
25
+ :plugin => {
26
+ :create => '/apis/:api_id/plugins',
27
+ :list => '/plugins',
28
+ :list_by_api => '/apis/:api_id/plugins',
29
+ :retrieve => '/plugins/:plugin_id',
30
+ :retrieve_enabled => '/plugins/enabled',
31
+ :retrieve_schema => '/plugins/schema/:plugin_name',
32
+ :update => '/apis/:api_id/plugins/:plugin_id',
33
+ :delete => '/apis/:api_id/plugins/:plugin_id'
34
+ }
35
+ }
36
+ end
37
+
38
+ def mockurl
39
+ @mockurl = 'http://mockdomain:8001'
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,28 @@
1
+ module RubyKong
2
+ module Stub
3
+ class << self
4
+ def request(method:, url:, request: {}, response: {})
5
+ if request.empty?
6
+ stub_request(method, url)
7
+ .to_return(response)
8
+ else
9
+ stub_request(method, url)
10
+ .with(request)
11
+ .to_return(response)
12
+ end
13
+ end # End of def requets
14
+
15
+ def reopen_real_connection!
16
+ WebMock.allow_net_connect!
17
+ end
18
+
19
+ def enable!
20
+ WebMock.enable!
21
+ end
22
+
23
+ def disable
24
+ WebMock.disable!
25
+ end
26
+ end # End of class self
27
+ end # End of Stub module
28
+ end # End of RubyKong module
@@ -0,0 +1,9 @@
1
+ module RubyKong
2
+ module Utils
3
+ class << self
4
+ def endpoint_builder(path)
5
+ RubyKong.url + path
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,3 @@
1
+ module RubyKong
2
+ VERSION = '0.1.0a'.freeze
3
+ end
@@ -0,0 +1,37 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'ruby-kong/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "ruby-kong"
8
+ spec.version = RubyKong::VERSION
9
+ spec.authors = ["Dang Tung Lam"]
10
+ spec.email = ["dangtunglam14@gmail.com"]
11
+
12
+ spec.summary = "A Ruby client for the Kong API (https://getkong.org/)"
13
+ spec.description = "A Ruby client for the Kong API"
14
+ spec.homepage = "https://github.com/tunglam14/ruby-kong"
15
+ spec.license = "MIT"
16
+
17
+ # Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
18
+ # delete this section to allow pushing this gem to any host.
19
+ # if spec.respond_to?(:metadata)
20
+ # spec.metadata['allowed_push_host'] = " 'http://mygemserver.com'"
21
+ # else
22
+ # raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
23
+ # end
24
+
25
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
26
+ spec.bindir = "exe"
27
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
28
+ spec.require_paths = ["lib"]
29
+
30
+ spec.add_development_dependency "bundler", "~> 1.11"
31
+ spec.add_development_dependency "rake", "~> 10.0"
32
+ spec.add_development_dependency "rspec", "~> 3.0"
33
+ spec.add_development_dependency "pry", "0.10.3"
34
+ spec.add_development_dependency "webmock", "1.24.2"
35
+
36
+ spec.add_dependency "unirest", '1.1.2'
37
+ end
metadata ADDED
@@ -0,0 +1,156 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ruby-kong
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0a
5
+ platform: ruby
6
+ authors:
7
+ - Dang Tung Lam
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-04-22 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.11'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.11'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: pry
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '='
60
+ - !ruby/object:Gem::Version
61
+ version: 0.10.3
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '='
67
+ - !ruby/object:Gem::Version
68
+ version: 0.10.3
69
+ - !ruby/object:Gem::Dependency
70
+ name: webmock
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '='
74
+ - !ruby/object:Gem::Version
75
+ version: 1.24.2
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '='
81
+ - !ruby/object:Gem::Version
82
+ version: 1.24.2
83
+ - !ruby/object:Gem::Dependency
84
+ name: unirest
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - '='
88
+ - !ruby/object:Gem::Version
89
+ version: 1.1.2
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - '='
95
+ - !ruby/object:Gem::Version
96
+ version: 1.1.2
97
+ description: A Ruby client for the Kong API
98
+ email:
99
+ - dangtunglam14@gmail.com
100
+ executables: []
101
+ extensions: []
102
+ extra_rdoc_files: []
103
+ files:
104
+ - ".codeclimate.yml"
105
+ - ".gitignore"
106
+ - ".rspec"
107
+ - ".rubocop.yml"
108
+ - ".travis.yml"
109
+ - Gemfile
110
+ - Gemfile.lock
111
+ - LICENSE.txt
112
+ - README.md
113
+ - Rakefile
114
+ - bin/console
115
+ - bin/setup
116
+ - lib/ruby-kong.rb
117
+ - lib/ruby-kong/api.rb
118
+ - lib/ruby-kong/consumer.rb
119
+ - lib/ruby-kong/kong.rb
120
+ - lib/ruby-kong/node.rb
121
+ - lib/ruby-kong/plugin.rb
122
+ - lib/ruby-kong/request.rb
123
+ - lib/ruby-kong/request/api.rb
124
+ - lib/ruby-kong/request/consumer.rb
125
+ - lib/ruby-kong/request/node.rb
126
+ - lib/ruby-kong/request/plugin.rb
127
+ - lib/ruby-kong/spec.rb
128
+ - lib/ruby-kong/stub.rb
129
+ - lib/ruby-kong/utils.rb
130
+ - lib/ruby-kong/version.rb
131
+ - ruby-kong.gemspec
132
+ homepage: https://github.com/tunglam14/ruby-kong
133
+ licenses:
134
+ - MIT
135
+ metadata: {}
136
+ post_install_message:
137
+ rdoc_options: []
138
+ require_paths:
139
+ - lib
140
+ required_ruby_version: !ruby/object:Gem::Requirement
141
+ requirements:
142
+ - - ">="
143
+ - !ruby/object:Gem::Version
144
+ version: '0'
145
+ required_rubygems_version: !ruby/object:Gem::Requirement
146
+ requirements:
147
+ - - ">"
148
+ - !ruby/object:Gem::Version
149
+ version: 1.3.1
150
+ requirements: []
151
+ rubyforge_project:
152
+ rubygems_version: 2.6.1
153
+ signing_key:
154
+ specification_version: 4
155
+ summary: A Ruby client for the Kong API (https://getkong.org/)
156
+ test_files: []