Class: ThreeScale::API::Client
- Inherits:
-
Object
- Object
- ThreeScale::API::Client
- Defined in:
- lib/3scale/api/client.rb
Instance Attribute Summary collapse
-
#http_client ⇒ Object
readonly
Returns the value of attribute http_client.
Instance Method Summary collapse
-
#create_application(account_id, attributes = {}, plan_id:, **rest) ⇒ Hash
An Application.
- #create_application_plan(service_id, attributes) ⇒ Hash
- #create_application_plan_limit(application_plan_id, metric_id, attributes) ⇒ Hash
- #create_mapping_rule(service_id, attributes) ⇒ Array<Hash>
- #create_method(service_id, metric_id, attributes) ⇒ Hash
- #create_metric(service_id, attributes) ⇒ Hash
- #create_service(attributes) ⇒ Hash
-
#customize_application_plan(account_id, application_id) ⇒ Hash
A Plan.
- #delete_application_plan(service_id, application_plan_id) ⇒ Bool
- #delete_application_plan_limit(application_plan_id, metric_id, limit_id) ⇒ Object
- #delete_mapping_rule(service_id, id) ⇒ Array<Hash>
- #delete_service(id) ⇒ Object
- #find_application(id: nil, user_key: nil, application_id: nil) ⇒ Hash
-
#initialize(http_client) ⇒ Client
constructor
A new instance of Client.
- #list_application_plan_limits(application_plan_id) ⇒ Array<Hash>
- #list_applications(service_id: nil) ⇒ Array<Hash>
- #list_mapping_rules(service_id) ⇒ Array<Hash>
- #list_methods(service_id, metric_id) ⇒ Array<Hash>
- #list_metrics(service_id) ⇒ Array<Hash>
- #list_service_application_plans(service_id) ⇒ Array<Hash>
- #list_services ⇒ Array<Hash>
- #show_application(id) ⇒ Hash
- #show_mapping_rule(service_id, id) ⇒ Array<Hash>
- #show_proxy(service_id) ⇒ Hash
- #show_service(id) ⇒ Hash
-
#signup(attributes = {}, name:, username:, **rest) ⇒ Hash
An Account.
- #update_mapping_rule(service_id, id, attributes) ⇒ Array<Hash>
- #update_proxy(service_id, attributes) ⇒ Hash
- #update_service(service_id, attributes) ⇒ Hash
Constructor Details
#initialize(http_client) ⇒ Client
Returns a new instance of Client.
8 9 10 |
# File 'lib/3scale/api/client.rb', line 8 def initialize(http_client) @http_client = http_client end |
Instance Attribute Details
#http_client ⇒ Object (readonly)
Returns the value of attribute http_client.
4 5 6 |
# File 'lib/3scale/api/client.rb', line 4 def http_client @http_client end |
Instance Method Details
#create_application(account_id, attributes = {}, plan_id:, **rest) ⇒ Hash
Returns an Application.
70 71 72 73 74 |
# File 'lib/3scale/api/client.rb', line 70 def create_application(account_id, attributes = {}, plan_id:, **rest) body = { plan_id: plan_id }.merge(attributes).merge(rest) response = http_client.post("/admin/api/accounts/#{account_id}/applications", body: body) extract(entity: 'application', from: response) end |
#create_application_plan(service_id, attributes) ⇒ Hash
246 247 248 249 250 |
# File 'lib/3scale/api/client.rb', line 246 def create_application_plan(service_id, attributes) response = http_client.post("/admin/api/services/#{service_id}/application_plans", body: { application_plan: attributes }) extract(entity: 'application_plan', from: response) end |
#create_application_plan_limit(application_plan_id, metric_id, attributes) ⇒ Hash
278 279 280 281 282 |
# File 'lib/3scale/api/client.rb', line 278 def create_application_plan_limit(application_plan_id, metric_id, attributes) response = http_client.post("/admin/api/application_plans/#{application_plan_id}/metrics/#{metric_id}/limits", body: { usage_limit: attributes }) extract(entity: 'limit', from: response) end |
#create_mapping_rule(service_id, attributes) ⇒ Array<Hash>
163 164 165 166 167 |
# File 'lib/3scale/api/client.rb', line 163 def create_mapping_rule(service_id, attributes) response = http_client.post("/admin/api/services/#{service_id}/proxy/mapping_rules", body: { mapping_rule: attributes }) extract(entity: 'mapping_rule', from: response) end |
#create_method(service_id, metric_id, attributes) ⇒ Hash
226 227 228 229 230 |
# File 'lib/3scale/api/client.rb', line 226 def create_method(service_id, metric_id, attributes) response = http_client.post("/admin/api/services/#{service_id}/metrics/#{metric_id}/methods", body: { metric: attributes }) extract(entity: 'method', from: response) end |
#create_metric(service_id, attributes) ⇒ Hash
206 207 208 209 |
# File 'lib/3scale/api/client.rb', line 206 def create_metric(service_id, attributes) response = http_client.post("/admin/api/services/#{service_id}/metrics", body: { metric: attributes }) extract(entity: 'metric', from: response) end |
#create_service(attributes) ⇒ Hash
106 107 108 109 |
# File 'lib/3scale/api/client.rb', line 106 def create_service(attributes) response = http_client.post('/admin/api/services', body: { service: attributes }) extract(entity: 'service', from: response) end |
#customize_application_plan(account_id, application_id) ⇒ Hash
Returns a Plan.
80 81 82 83 |
# File 'lib/3scale/api/client.rb', line 80 def customize_application_plan(account_id, application_id) response = http_client.put("/admin/api/accounts/#{account_id}/applications/#{application_id}/customize_plan") extract(entity: 'application_plan', from: response) end |
#delete_application_plan(service_id, application_plan_id) ⇒ Bool
257 258 259 260 |
# File 'lib/3scale/api/client.rb', line 257 def delete_application_plan(service_id,application_plan_id) http_client.delete("/admin/api/services/#{service_id}/application_plans/#{application_plan_id}") true end |
#delete_application_plan_limit(application_plan_id, metric_id, limit_id) ⇒ Object
287 288 289 290 |
# File 'lib/3scale/api/client.rb', line 287 def delete_application_plan_limit(application_plan_id, metric_id, limit_id) http_client.delete("/admin/api/application_plans/#{application_plan_id}/metrics/#{metric_id}/limits/#{limit_id}") true end |
#delete_mapping_rule(service_id, id) ⇒ Array<Hash>
173 174 175 176 |
# File 'lib/3scale/api/client.rb', line 173 def delete_mapping_rule(service_id, id) http_client.delete("/admin/api/services/#{service_id}/proxy/mapping_rules/#{id}") true end |
#delete_service(id) ⇒ Object
29 30 31 32 |
# File 'lib/3scale/api/client.rb', line 29 def delete_service(id) http_client.delete("/admin/api/services/#{id}") true end |
#find_application(id: nil, user_key: nil, application_id: nil) ⇒ Hash
55 56 57 58 59 |
# File 'lib/3scale/api/client.rb', line 55 def find_application(id: nil, user_key: nil, application_id: nil) params = { application_id: id, user_key: user_key, app_id: application_id }.reject { |_, value| value.nil? } response = http_client.get('/admin/api/applications/find', params: params) extract(entity: 'application', from: response) end |
#list_application_plan_limits(application_plan_id) ⇒ Array<Hash>
265 266 267 268 269 |
# File 'lib/3scale/api/client.rb', line 265 def list_application_plan_limits(application_plan_id) response = http_client.get("/admin/api/application_plans/#{application_plan_id}/limits") extract(collection: 'limits', entity: 'limit', from: response) end |
#list_applications(service_id: nil) ⇒ Array<Hash>
37 38 39 40 41 |
# File 'lib/3scale/api/client.rb', line 37 def list_applications(service_id: nil) params = service_id ? { service_id: service_id } : nil response = http_client.get('/admin/api/applications', params: params) extract(collection: 'applications', entity: 'application', from: response) end |
#list_mapping_rules(service_id) ⇒ Array<Hash>
141 142 143 144 |
# File 'lib/3scale/api/client.rb', line 141 def list_mapping_rules(service_id) response = http_client.get("/admin/api/services/#{service_id}/proxy/mapping_rules") extract(entity: 'mapping_rule', collection: 'mapping_rules', from: response) end |
#list_methods(service_id, metric_id) ⇒ Array<Hash>
215 216 217 218 |
# File 'lib/3scale/api/client.rb', line 215 def list_methods(service_id, metric_id) response = http_client.get("/admin/api/services/#{service_id}/metrics/#{metric_id}/methods") extract(collection: 'methods', entity: 'method', from: response) end |
#list_metrics(service_id) ⇒ Array<Hash>
196 197 198 199 |
# File 'lib/3scale/api/client.rb', line 196 def list_metrics(service_id) response = http_client.get("/admin/api/services/#{service_id}/metrics") extract(collection: 'metrics', entity: 'metric', from: response) end |
#list_service_application_plans(service_id) ⇒ Array<Hash>
235 236 237 238 239 |
# File 'lib/3scale/api/client.rb', line 235 def list_service_application_plans(service_id) response = http_client.get("/admin/api/services/#{service_id}/application_plans") extract(collection: 'plans', entity: 'application_plan', from: response) end |
#list_services ⇒ Array<Hash>
22 23 24 25 |
# File 'lib/3scale/api/client.rb', line 22 def list_services response = http_client.get('/admin/api/services') extract(collection: 'services', entity: 'service', from: response) end |
#show_application(id) ⇒ Hash
46 47 48 |
# File 'lib/3scale/api/client.rb', line 46 def show_application(id) find_application(id: id) end |
#show_mapping_rule(service_id, id) ⇒ Array<Hash>
150 151 152 153 |
# File 'lib/3scale/api/client.rb', line 150 def show_mapping_rule(service_id, id) response = http_client.get("/admin/api/services/#{service_id}/proxy/mapping_rules/#{id}") extract(entity: 'mapping_rule', from: response) end |
#show_proxy(service_id) ⇒ Hash
124 125 126 127 |
# File 'lib/3scale/api/client.rb', line 124 def show_proxy(service_id) response = http_client.get("/admin/api/services/#{service_id}/proxy") extract(entity: 'proxy', from: response) end |
#show_service(id) ⇒ Hash
15 16 17 18 |
# File 'lib/3scale/api/client.rb', line 15 def show_service(id) response = http_client.get("/admin/api/services/#{id}") extract(entity: 'service', from: response) end |
#signup(attributes = {}, name:, username:, **rest) ⇒ Hash
Returns an Account.
95 96 97 98 99 100 |
# File 'lib/3scale/api/client.rb', line 95 def signup(attributes = {}, name:, username:, **rest) body = { org_name: name, username: username }.merge(attributes).merge(rest) response = http_client.post('/admin/api/signup', body: body) extract(entity: 'account', from: response) end |
#update_mapping_rule(service_id, id, attributes) ⇒ Array<Hash>
187 188 189 190 191 |
# File 'lib/3scale/api/client.rb', line 187 def update_mapping_rule(service_id, id, attributes) response = http_client.patch("/admin/api/services/#{service_id}/mapping_rules/#{id}", body: { mapping_rule: attributes }) extract(entity: 'mapping_rule', from: response) end |
#update_proxy(service_id, attributes) ⇒ Hash
132 133 134 135 136 |
# File 'lib/3scale/api/client.rb', line 132 def update_proxy(service_id, attributes) response = http_client.patch("/admin/api/services/#{service_id}/proxy", body: { proxy: attributes }) extract(entity: 'proxy', from: response) end |
#update_service(service_id, attributes) ⇒ Hash
116 117 118 119 |
# File 'lib/3scale/api/client.rb', line 116 def update_service(service_id, attributes) response = http_client.put("/admin/api/services/#{service_id}", body: { service: attributes }) extract(entity: 'service', from: response) end |