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_limit(application_plan_id, metric_id, limit_id) ⇒ Object
- #delete_mapping_rule(service_id, id) ⇒ Array<Hash>
- #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
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.
63 64 65 66 67 |
# File 'lib/3scale/api/client.rb', line 63 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
229 230 231 232 233 |
# File 'lib/3scale/api/client.rb', line 229 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
251 252 253 254 255 |
# File 'lib/3scale/api/client.rb', line 251 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>
146 147 148 149 150 |
# File 'lib/3scale/api/client.rb', line 146 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
209 210 211 212 213 |
# File 'lib/3scale/api/client.rb', line 209 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
189 190 191 192 |
# File 'lib/3scale/api/client.rb', line 189 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
99 100 101 102 |
# File 'lib/3scale/api/client.rb', line 99 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.
73 74 75 76 |
# File 'lib/3scale/api/client.rb', line 73 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_limit(application_plan_id, metric_id, limit_id) ⇒ Object
260 261 262 263 |
# File 'lib/3scale/api/client.rb', line 260 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>
156 157 158 159 |
# File 'lib/3scale/api/client.rb', line 156 def delete_mapping_rule(service_id, id) http_client.delete("/admin/api/services/#{service_id}/proxy/mapping_rules/#{id}") true end |
#find_application(id: nil, user_key: nil, application_id: nil) ⇒ Hash
48 49 50 51 52 |
# File 'lib/3scale/api/client.rb', line 48 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>
238 239 240 241 242 |
# File 'lib/3scale/api/client.rb', line 238 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>
30 31 32 33 34 |
# File 'lib/3scale/api/client.rb', line 30 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>
124 125 126 127 |
# File 'lib/3scale/api/client.rb', line 124 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>
198 199 200 201 |
# File 'lib/3scale/api/client.rb', line 198 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>
179 180 181 182 |
# File 'lib/3scale/api/client.rb', line 179 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>
218 219 220 221 222 |
# File 'lib/3scale/api/client.rb', line 218 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
39 40 41 |
# File 'lib/3scale/api/client.rb', line 39 def show_application(id) find_application(id: id) end |
#show_mapping_rule(service_id, id) ⇒ Array<Hash>
133 134 135 136 |
# File 'lib/3scale/api/client.rb', line 133 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
107 108 109 110 |
# File 'lib/3scale/api/client.rb', line 107 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.
88 89 90 91 92 93 |
# File 'lib/3scale/api/client.rb', line 88 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>
170 171 172 173 174 |
# File 'lib/3scale/api/client.rb', line 170 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
115 116 117 118 119 |
# File 'lib/3scale/api/client.rb', line 115 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 |