pisoni 1.23.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/CHANGELOG.md +9 -0
- data/Gemfile +16 -0
- data/LICENSE +202 -0
- data/Makefile +73 -0
- data/NOTICE +15 -0
- data/README.md +47 -0
- data/Rakefile +27 -0
- data/lib/3scale/core/alert_limit.rb +32 -0
- data/lib/3scale/core/api_client/attributes.rb +56 -0
- data/lib/3scale/core/api_client/collection.rb +19 -0
- data/lib/3scale/core/api_client/operations.rb +233 -0
- data/lib/3scale/core/api_client/resource.rb +52 -0
- data/lib/3scale/core/api_client/support.rb +55 -0
- data/lib/3scale/core/api_client.rb +5 -0
- data/lib/3scale/core/application.rb +67 -0
- data/lib/3scale/core/application_key.rb +34 -0
- data/lib/3scale/core/application_referrer_filter.rb +33 -0
- data/lib/3scale/core/errors.rb +130 -0
- data/lib/3scale/core/event.rb +26 -0
- data/lib/3scale/core/logger.rb +12 -0
- data/lib/3scale/core/metric.rb +32 -0
- data/lib/3scale/core/service.rb +82 -0
- data/lib/3scale/core/service_error.rb +34 -0
- data/lib/3scale/core/service_token.rb +39 -0
- data/lib/3scale/core/transaction.rb +26 -0
- data/lib/3scale/core/usage_limit.rb +40 -0
- data/lib/3scale/core/user.rb +47 -0
- data/lib/3scale/core/utilization.rb +28 -0
- data/lib/3scale/core/version.rb +5 -0
- data/lib/3scale/core.rb +63 -0
- data/lib/3scale_core.rb +1 -0
- data/lib/pisoni.rb +5 -0
- data/pisoni.gemspec +43 -0
- data/spec/alert_limit_spec.rb +72 -0
- data/spec/application_key_spec.rb +97 -0
- data/spec/application_referrer_filter_spec.rb +57 -0
- data/spec/application_spec.rb +188 -0
- data/spec/event_spec.rb +82 -0
- data/spec/metric_spec.rb +115 -0
- data/spec/private_endpoints/event.rb +9 -0
- data/spec/private_endpoints/service_error.rb +10 -0
- data/spec/private_endpoints/transaction.rb +16 -0
- data/spec/service_error_spec.rb +128 -0
- data/spec/service_spec.rb +159 -0
- data/spec/service_token_spec.rb +121 -0
- data/spec/spec_helper.rb +15 -0
- data/spec/transaction_spec.rb +71 -0
- data/spec/usagelimit_spec.rb +52 -0
- data/spec/user_spec.rb +164 -0
- data/spec/utilization_spec.rb +113 -0
- metadata +182 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 0c0d644f09f13b9842035dd8d79c81d5a3b96dda73ef5f6be9ea3cfde25f04e4
|
4
|
+
data.tar.gz: 439dbc720c9b97fa4d0233873e63ee9fce07530c68aa7f09b5a569109e372bf1
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 497ff1601eb48abaf834ef26284d34e4115d939e5abe069351a5188856a027fe720fd3880ed2961b459d1494b988787b7fa12d1849836863a809fd1a68890534
|
7
|
+
data.tar.gz: b3cd58bb92cfa762a74ed1a2eecebba56e78ff2b3c584af7aa3580501569db54217bb0ec435941182f66b6d2711300d820edf453b04b69c8c3bf7beed3155ddf
|
data/CHANGELOG.md
ADDED
data/Gemfile
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
source "https://rubygems.org"
|
2
|
+
|
3
|
+
gemspec
|
4
|
+
|
5
|
+
group :test do
|
6
|
+
gem 'turn', '~> 0.9.7'
|
7
|
+
gem 'minitest'
|
8
|
+
gem "codeclimate-test-reporter", require: nil
|
9
|
+
end
|
10
|
+
|
11
|
+
group :development, :test do
|
12
|
+
gem 'pry', '~> 0.10.0'
|
13
|
+
gem 'pry-doc', '~> 0.6.0'
|
14
|
+
gem 'pry-byebug', '~> 2.0.0'
|
15
|
+
gem 'license_finder', '~> 5', require: false
|
16
|
+
end
|
data/LICENSE
ADDED
@@ -0,0 +1,202 @@
|
|
1
|
+
|
2
|
+
Apache License
|
3
|
+
Version 2.0, January 2004
|
4
|
+
http://www.apache.org/licenses/
|
5
|
+
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
7
|
+
|
8
|
+
1. Definitions.
|
9
|
+
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
12
|
+
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
14
|
+
the copyright owner that is granting the License.
|
15
|
+
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
17
|
+
other entities that control, are controlled by, or are under common
|
18
|
+
control with that entity. For the purposes of this definition,
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
20
|
+
direction or management of such entity, whether by contract or
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
23
|
+
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
25
|
+
exercising permissions granted by this License.
|
26
|
+
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
28
|
+
including but not limited to software source code, documentation
|
29
|
+
source, and configuration files.
|
30
|
+
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
32
|
+
transformation or translation of a Source form, including but
|
33
|
+
not limited to compiled object code, generated documentation,
|
34
|
+
and conversions to other media types.
|
35
|
+
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
37
|
+
Object form, made available under the License, as indicated by a
|
38
|
+
copyright notice that is included in or attached to the work
|
39
|
+
(an example is provided in the Appendix below).
|
40
|
+
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
47
|
+
the Work and Derivative Works thereof.
|
48
|
+
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
50
|
+
the original version of the Work and any modifications or additions
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
62
|
+
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
65
|
+
subsequently incorporated within the Work.
|
66
|
+
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
73
|
+
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
79
|
+
where such license applies only to those patent claims licensable
|
80
|
+
by such Contributor that are necessarily infringed by their
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
83
|
+
institute patent litigation against any entity (including a
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
86
|
+
or contributory patent infringement, then any patent licenses
|
87
|
+
granted to You under this License for that Work shall terminate
|
88
|
+
as of the date such litigation is filed.
|
89
|
+
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
92
|
+
modifications, and in Source or Object form, provided that You
|
93
|
+
meet the following conditions:
|
94
|
+
|
95
|
+
(a) You must give any other recipients of the Work or
|
96
|
+
Derivative Works a copy of this License; and
|
97
|
+
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
99
|
+
stating that You changed the files; and
|
100
|
+
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
103
|
+
attribution notices from the Source form of the Work,
|
104
|
+
excluding those notices that do not pertain to any part of
|
105
|
+
the Derivative Works; and
|
106
|
+
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
109
|
+
include a readable copy of the attribution notices contained
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
112
|
+
of the following places: within a NOTICE text file distributed
|
113
|
+
as part of the Derivative Works; within the Source form or
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
115
|
+
within a display generated by the Derivative Works, if and
|
116
|
+
wherever such third-party notices normally appear. The contents
|
117
|
+
of the NOTICE file are for informational purposes only and
|
118
|
+
do not modify the License. You may add Your own attribution
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
121
|
+
that such additional attribution notices cannot be construed
|
122
|
+
as modifying the License.
|
123
|
+
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
125
|
+
may provide additional or different license terms and conditions
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
129
|
+
the conditions stated in this License.
|
130
|
+
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
134
|
+
this License, without any additional terms or conditions.
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
136
|
+
the terms of any separate license agreement you may have executed
|
137
|
+
with Licensor regarding such Contributions.
|
138
|
+
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
141
|
+
except as required for reasonable and customary use in describing the
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
143
|
+
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
153
|
+
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
159
|
+
incidental, or consequential damages of any character arising as a
|
160
|
+
result of this License or out of the use or inability to use the
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
163
|
+
other commercial damages or losses), even if such Contributor
|
164
|
+
has been advised of the possibility of such damages.
|
165
|
+
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
169
|
+
or other liability obligations and/or rights consistent with this
|
170
|
+
License. However, in accepting such obligations, You may act only
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
175
|
+
of your accepting any such warranty or additional liability.
|
176
|
+
|
177
|
+
END OF TERMS AND CONDITIONS
|
178
|
+
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
180
|
+
|
181
|
+
To apply the Apache License to your work, attach the following
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
183
|
+
replaced with your own identifying information. (Don't include
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
185
|
+
comment syntax for the file format. We also recommend that a
|
186
|
+
file or class name and description of purpose be included on the
|
187
|
+
same "printed page" as the copyright notice for easier
|
188
|
+
identification within third-party archives.
|
189
|
+
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
191
|
+
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
193
|
+
you may not use this file except in compliance with the License.
|
194
|
+
You may obtain a copy of the License at
|
195
|
+
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
197
|
+
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
201
|
+
See the License for the specific language governing permissions and
|
202
|
+
limitations under the License.
|
data/Makefile
ADDED
@@ -0,0 +1,73 @@
|
|
1
|
+
MKFILE_PATH := $(abspath $(lastword $(MAKEFILE_LIST)))
|
2
|
+
PROJECT_PATH := $(patsubst %/,%,$(dir $(MKFILE_PATH)))
|
3
|
+
|
4
|
+
include $(PROJECT_PATH)/.env
|
5
|
+
|
6
|
+
include $(PROJECT_PATH)/mk/compose.mk
|
7
|
+
COMPOSE := $(COMPOSE_BIN) -f $(PROJECT_PATH)/docker/docker-compose.yml
|
8
|
+
|
9
|
+
CI_IMAGE_REPO ?= quay.io/3scale
|
10
|
+
CI_IMAGE_NAME ?= pisoni-ci
|
11
|
+
CI_IMAGE ?= $(CI_IMAGE_REPO)/$(CI_IMAGE_NAME)
|
12
|
+
CI_DOCKERFILE ?= $(PROJECT_PATH)/docker/Dockerfile.ci
|
13
|
+
|
14
|
+
include $(PROJECT_PATH)/mk/ci-image.mk
|
15
|
+
|
16
|
+
all: clean pull build test
|
17
|
+
|
18
|
+
.PHONY: compose-config
|
19
|
+
compose-config: compose
|
20
|
+
$(COMPOSE) config
|
21
|
+
|
22
|
+
.PHONY: test
|
23
|
+
test: run_test clean
|
24
|
+
|
25
|
+
.PHONY: bash
|
26
|
+
bash: run clean
|
27
|
+
|
28
|
+
.PHONY: dev
|
29
|
+
dev: run
|
30
|
+
|
31
|
+
.PHONY: run
|
32
|
+
run: compose
|
33
|
+
$(COMPOSE) run --rm test /bin/bash
|
34
|
+
|
35
|
+
.PHONY: run_test
|
36
|
+
run_test: compose
|
37
|
+
$(COMPOSE) run --rm -e COVERAGE=$(COVERAGE) test
|
38
|
+
|
39
|
+
.PHONY: license_finder
|
40
|
+
license_finder: compose
|
41
|
+
$(COMPOSE) run --rm -e COVERAGE=$(COVERAGE) test bundle exec rake license_finder:check
|
42
|
+
|
43
|
+
.PHONY: build
|
44
|
+
build: compose
|
45
|
+
$(COMPOSE) build
|
46
|
+
|
47
|
+
.PHONY: pull
|
48
|
+
pull: compose
|
49
|
+
$(COMPOSE) pull
|
50
|
+
|
51
|
+
.PHONY: stop
|
52
|
+
stop: compose
|
53
|
+
$(COMPOSE) stop
|
54
|
+
|
55
|
+
.PHONY: clean
|
56
|
+
clean: stop
|
57
|
+
- $(COMPOSE) rm -f -v
|
58
|
+
|
59
|
+
.PHONY: up
|
60
|
+
up: compose
|
61
|
+
$(COMPOSE) up --abort-on-container-exit --exit-code-from test -t 2 --remove-orphans
|
62
|
+
|
63
|
+
.PHONY: down
|
64
|
+
down: clean
|
65
|
+
- $(COMPOSE) down
|
66
|
+
|
67
|
+
.PHONY: destroy
|
68
|
+
destroy: clean
|
69
|
+
$(COMPOSE) down -v --remove-orphans --rmi local
|
70
|
+
|
71
|
+
.PHONY: destroy-all
|
72
|
+
destroy-all: clean
|
73
|
+
$(COMPOSE) down -v --remove-orphans --rmi all
|
data/NOTICE
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
pisoni - Apisonator internal API Ruby client
|
2
|
+
Copyright (c) 2010-2016 3scale, Inc
|
3
|
+
Copyright (c) 2016-2018 Red Hat, Inc.
|
4
|
+
|
5
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
6
|
+
you may not use this file except in compliance with the License.
|
7
|
+
You may obtain a copy of the License at
|
8
|
+
|
9
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
10
|
+
|
11
|
+
Unless required by applicable law or agreed to in writing, software
|
12
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
13
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14
|
+
See the License for the specific language governing permissions and
|
15
|
+
limitations under the License.
|
data/README.md
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
# Pisoni
|
2
|
+
|
3
|
+
Pisoni is a Ruby client for the internal API of the
|
4
|
+
[Apisonator](https://github.com/3scale/apisonator) component of the 3scale API
|
5
|
+
Management software. This API allows third parties to push model data to the
|
6
|
+
Apisonator data store.
|
7
|
+
|
8
|
+
## License
|
9
|
+
|
10
|
+
This Ruby gem is licensed under the Apache 2.0 license.
|
11
|
+
|
12
|
+
## Install
|
13
|
+
|
14
|
+
You can add this gem to your Gemfile, or install it in your system with:
|
15
|
+
|
16
|
+
> $ gem install pisoni -v '= x.y.z'
|
17
|
+
|
18
|
+
where x.y.z is the version you aim for.
|
19
|
+
|
20
|
+
## Development
|
21
|
+
|
22
|
+
### Environment set up
|
23
|
+
|
24
|
+
We are using [Docker Compose](https://docs.docker.com/compose/) to run the tests
|
25
|
+
in an isolated environment.
|
26
|
+
|
27
|
+
You should first `make pull build` to download the needed images and build the
|
28
|
+
one used for actual testing and development.
|
29
|
+
|
30
|
+
You can then run `make test` to run the test suite, and `make dev` to enter
|
31
|
+
a container in which the code is sync'ed back to your host.
|
32
|
+
|
33
|
+
For cleaning up containers, volumes and networks you can run `make clean` and
|
34
|
+
`make destroy`. If you want to also get rid of pulled images, run `make
|
35
|
+
destroy-all`.
|
36
|
+
|
37
|
+
### Running tests
|
38
|
+
|
39
|
+
You can run both tests & specs with:
|
40
|
+
|
41
|
+
> $ bundle exec rake
|
42
|
+
|
43
|
+
You can also test against a different Apisonator instance. Use the environment
|
44
|
+
variable `THREESCALE_CORE_INTERNAL_API` to point the tests to your running
|
45
|
+
backend instance:
|
46
|
+
|
47
|
+
> $ THREESCALE_CORE_INTERNAL_API=http://user:passwd@172.17.42.1:8081/internal bundle exec rake
|
data/Rakefile
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'rake/testtask'
|
3
|
+
require 'bundler/gem_tasks'
|
4
|
+
|
5
|
+
task :default => :test
|
6
|
+
|
7
|
+
desc 'Runs tests'
|
8
|
+
task :test do
|
9
|
+
Rake::TestTask.new do |task|
|
10
|
+
ENV['THREESCALE_CORE_INTERNAL_API'] ||= 'http://backend:3000/internal/'
|
11
|
+
task.test_files = FileList['spec/**/*_spec.rb']
|
12
|
+
task.libs = [ 'lib', File.expand_path('.') ]
|
13
|
+
task.verbose = true
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
namespace :license_finder do
|
18
|
+
desc 'Check license compliance of dependencies'
|
19
|
+
task :check do
|
20
|
+
STDOUT.puts "Checking license compliance\n"
|
21
|
+
unless system("license_finder --decisions-file=#{File.dirname(__FILE__)}" \
|
22
|
+
"/.dependency_decisions.yml")
|
23
|
+
STDERR.puts "\n*** License compliance test failed ***\n"
|
24
|
+
exit 1
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
module ThreeScale
|
2
|
+
module Core
|
3
|
+
class AlertLimit < APIClient::Resource
|
4
|
+
attributes :service_id, :value
|
5
|
+
|
6
|
+
default_uri '/internal/services/'
|
7
|
+
|
8
|
+
def self.load_all(service_id)
|
9
|
+
results = api_do_get({}, rprefix: :alert_limits, uri: alert_limit_uri(service_id))
|
10
|
+
results[:attributes].map { |attrs| new(attrs) }
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.base_uri(service_id)
|
14
|
+
"#{default_uri}#{service_id}/alert_limits/"
|
15
|
+
end
|
16
|
+
private_class_method :base_uri
|
17
|
+
|
18
|
+
def self.alert_limit_uri(service_id, value = nil)
|
19
|
+
"#{base_uri(service_id)}#{value}"
|
20
|
+
end
|
21
|
+
private_class_method :alert_limit_uri
|
22
|
+
|
23
|
+
def self.save(service_id, value)
|
24
|
+
api_save({value: value}, uri: alert_limit_uri(service_id), prefix: :alert_limit)
|
25
|
+
end
|
26
|
+
|
27
|
+
def self.delete(service_id, value)
|
28
|
+
api_delete({}, uri: alert_limit_uri(service_id, value))
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
require 'time'
|
2
|
+
|
3
|
+
module ThreeScale
|
4
|
+
module Core
|
5
|
+
module APIClient
|
6
|
+
module Attributes
|
7
|
+
def self.included(base)
|
8
|
+
base.extend ClassMethods
|
9
|
+
end
|
10
|
+
|
11
|
+
def attributes
|
12
|
+
attrs = {}
|
13
|
+
self.class.attributes.each do |attr|
|
14
|
+
attrs[attr] = send(attr)
|
15
|
+
end
|
16
|
+
attrs
|
17
|
+
end
|
18
|
+
alias_method :to_hash, :attributes
|
19
|
+
|
20
|
+
def update_attributes(attributes)
|
21
|
+
self.class.attributes.each do |attr|
|
22
|
+
send("#{attr}=", attributes[attr])
|
23
|
+
end
|
24
|
+
self
|
25
|
+
end
|
26
|
+
|
27
|
+
def dirty?
|
28
|
+
@dirty
|
29
|
+
end
|
30
|
+
|
31
|
+
private
|
32
|
+
|
33
|
+
def dirty=(val)
|
34
|
+
@dirty = val
|
35
|
+
end
|
36
|
+
|
37
|
+
module ClassMethods
|
38
|
+
TIME_ATTRIBUTES = [:timestamp]
|
39
|
+
|
40
|
+
def attributes(*attributes)
|
41
|
+
return @attributes if attributes.empty?
|
42
|
+
attributes.each do |attr|
|
43
|
+
attr_reader attr
|
44
|
+
define_method "#{attr}=" do |val|
|
45
|
+
self.dirty = true
|
46
|
+
val = Time.parse(val) if TIME_ATTRIBUTES.include? attr.to_sym
|
47
|
+
instance_variable_set "@#{attr}", val
|
48
|
+
end
|
49
|
+
end
|
50
|
+
@attributes = attributes
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module ThreeScale
|
2
|
+
module Core
|
3
|
+
module APIClient
|
4
|
+
class Collection
|
5
|
+
include Enumerable
|
6
|
+
extend Forwardable
|
7
|
+
|
8
|
+
attr_reader :total
|
9
|
+
|
10
|
+
def initialize(resources=[], total=resources.size)
|
11
|
+
@resources = resources
|
12
|
+
@total = total
|
13
|
+
end
|
14
|
+
|
15
|
+
def_delegators :@resources, :map, :each, :[], :size, :empty?
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|