lib/3scale/api/client.rb in 3scale-api-0.4.0 vs lib/3scale/api/client.rb in 3scale-api-0.5.0
- old
+ new
@@ -30,14 +30,15 @@
http_client.delete("/admin/api/services/#{id}")
true
end
# @api public
- # @return [Array<Hash>]
# @param [Fixnum] service_id Service ID
- def list_applications(service_id: nil)
- params = service_id ? { service_id: service_id } : nil
+ # @param [Fixnum] plan_id Application Plan ID
+ # @return [Array<Hash>]
+ def list_applications(service_id: nil, plan_id: nil)
+ params = { service_id: service_id, plan_id: plan_id }.compact
response = http_client.get('/admin/api/applications', params: params)
extract(collection: 'applications', entity: 'application', from: response)
end
# @api public
@@ -72,10 +73,20 @@
response = http_client.post("/admin/api/accounts/#{account_id}/applications", body: body)
extract(entity: 'application', from: response)
end
# @api public
+ # @param [Fixnum] account_id Account ID
+ # @param [Fixnum] id Application ID
+ # @param [Hash] attrs Application Attributes
+ # @return [Hash] an Application
+ def update_application(account_id, id, attrs)
+ response = http_client.put("/admin/api/accounts/#{account_id}/applications/#{id}", body: attrs)
+ extract(entity: 'application', from: response)
+ end
+
+ # @api public
# @return [Hash] a Plan
# @param [Fixnum] account_id Account ID
# @param [Fixnum] application_id Application ID
def customize_application_plan(account_id, application_id)
response = http_client.put("/admin/api/accounts/#{account_id}/applications/#{application_id}/customize_plan")
@@ -137,27 +148,49 @@
# @api public
# @return [Hash]
# @param [Fixnum] service_id Service ID
# @param [String] environment. Must be 'sandbox' or 'production'
- def proxy_config_list(service_id, environment='sandbox')
+ def proxy_config_list(service_id, environment = 'sandbox')
response = http_client.get("/admin/api/services/#{service_id}/proxy/configs/#{environment}")
- extract(entity: 'proxy', from: response)
+ extract(collection: 'proxy_configs', entity: 'proxy_config', from: response)
end
# @api public
# @return [Hash]
# @param [Fixnum] service_id Service ID
# @param [String] environment. Must be 'sandbox' or 'production'
- def proxy_config_latest(service_id, environment='sandbox')
+ def proxy_config_latest(service_id, environment = 'sandbox')
response = http_client.get("/admin/api/services/#{service_id}/proxy/configs/#{environment}/latest")
- extract(entity: 'proxy', from: response)
+ extract(entity: 'proxy_config', from: response)
end
# @api public
# @return [Hash]
# @param [Fixnum] service_id Service ID
+ # @param [String] environment. Must be 'sandbox' or 'production'
+ # @param [Fixnum] proxy configuration version
+ def show_proxy_config(service_id, environment, version)
+ response = http_client.get("/admin/api/services/#{service_id}/proxy/configs/#{environment}/#{version}")
+ extract(entity: 'proxy_config', from: response)
+ end
+
+ # @api public
+ # @return [Hash]
+ # @param [Fixnum] service_id Service ID
+ # @param [String] environment. Must be 'sandbox' or 'production'
+ # @param [Fixnum] proxy configuration version to promote
+ # @param [Fixnum] proxy configuration to which the specified proxy configuration will be promoted to
+ def promote_proxy_config(service_id, environment, version, to)
+ response = http_client.post("/admin/api/services/#{service_id}/proxy/configs/#{environment}/#{version}/promote",
+ body: { to: to })
+ extract(entity: 'proxy_config', from: response)
+ end
+
+ # @api public
+ # @return [Hash]
+ # @param [Fixnum] service_id Service ID
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
@@ -217,11 +250,11 @@
extract(entity: 'mapping_rule', from: response)
end
# @api public
# @param [Fixnum] service_id Service ID
- # @param [Fixnum] id Metric ID
+ # @param [Fixnum] id Metric ID
# @return [Hash]
def show_metric(service_id, id)
response = http_client.get("/admin/api/services/#{service_id}/metrics/#{id}")
extract(entity: 'metric', from: response)
end
@@ -267,22 +300,22 @@
true
end
# @api public
# @param [Fixnum] service_id Service ID
- # @param [Fixnum] id Parent metric ID
- # @param [Fixnum] id Method ID
+ # @param [Fixnum] id Parent metric ID
+ # @param [Fixnum] id Method ID
# @return [Hash]
def show_method(service_id, parent_id, id)
response = http_client.get("/admin/api/services/#{service_id}/metrics/#{parent_id}/methods/#{id}")
extract(entity: 'method', from: response)
end
# @api public
# @return [Hash]
# @param [Fixnum] service_id Service ID
- # @param [Fixnum] parent_id Parent metric ID
+ # @param [Fixnum] parent_id Parent metric ID
# @param [Fixnum] id Method ID
# @param [Hash] attributes Method Attributes
def update_method(service_id, parent_id, id, attributes)
response = http_client.put("/admin/api/services/#{service_id}/metrics/#{parent_id}/methods/#{id}",
body: { metric: attributes })
@@ -311,18 +344,17 @@
end
# @api public
# @return [Bool]
# @param [Fixnum] service_id Service ID
- # @param [Fixnum] parent_id Parent metric ID
+ # @param [Fixnum] parent_id Parent metric ID
# @param [Fixnum] metric_id Metric ID
def delete_method(service_id, parent_id, id)
http_client.delete("/admin/api/services/#{service_id}/metrics/#{parent_id}/methods/#{id}")
true
end
-
# @api public
# @param [Fixnum] application_plan_id Application Plan ID
# @param [Fixnum] metric_id Metric ID
# @return [Hash]
def list_metric_limits(application_plan_id, metric_id)
@@ -372,11 +404,11 @@
# @api public
# @return [Bool]
# @param [Fixnum] service_id Service ID
# @param [Fixnum] application_plan_id Application Plan ID
- def delete_application_plan(service_id,application_plan_id)
+ def delete_application_plan(service_id, application_plan_id)
http_client.delete("/admin/api/services/#{service_id}/application_plans/#{application_plan_id}")
true
end
# @api public
@@ -414,11 +446,11 @@
# @param [Fixnum] metric_id Metric ID
# @param [Fixnum] limit_id Usage Limit ID
# @param [Hash] attributes Limit Attributes
def update_application_plan_limit(application_plan_id, metric_id, limit_id, attributes)
response = http_client.put("/admin/api/application_plans/#{application_plan_id}/metrics/#{metric_id}/limits/#{limit_id}",
- body: { usage_limit: attributes })
+ body: { usage_limit: attributes })
extract(entity: 'limit', from: response)
end
# @param [Fixnum] application_plan_id Application Plan ID
# @param [Fixnum] metric_id Metric ID
@@ -435,10 +467,18 @@
response = http_client.get('/admin/api/accounts/find', params: criteria)
extract(entity: 'account', from: response)
end
# @api public
+ # @param [Fixnum] id Account Id
+ # @return [Hash]
+ def show_account(id)
+ response = http_client.get("/admin/api/accounts/#{id}")
+ extract(entity: 'account', from: response)
+ end
+
+ # @api public
# @return [Array]
# @param [Fixnum] id Service ID
def show_policies(id)
response = http_client.get("/admin/api/services/#{id}/proxy/policies")
extract(entity: 'policies_config', from: response)
@@ -530,11 +570,11 @@
def delete_application(account_id, id)
http_client.delete("/admin/api/accounts/#{account_id}/applications/#{id}")
true
end
- # @api public
+ # @api public
# @param [Fixnum] id Service ID
# @return [Array<Hash>]
def show_oidc(service_id)
response = http_client.get("/admin/api/services/#{service_id}/proxy/oidc_configuration")
extract(entity: 'oidc_configuration', from: response)
@@ -588,11 +628,11 @@
# @param [Fixnum] id Service ID
# @param [Hash] attributes Feature Attributes
# @return [Hash]
def create_service_feature(id, attributes)
response = http_client.post("/admin/api/services/#{id}/features",
- body: { feature: attributes})
+ body: { feature: attributes })
extract(entity: 'feature', from: response)
end
# @api public
# @param [Fixnum] service_id Service ID
@@ -619,9 +659,157 @@
# @param [Fixnum] id Feature ID
# @return [Boolean]
def delete_service_feature(service_id, id)
http_client.delete("/admin/api/services/#{service_id}/features/#{id}")
true
+ end
+
+ # @api public
+ # @param [Fixnum] account_id Account ID
+ # @param [String] state State
+ # @param [String] role Role
+ # @return [Array<Hash>]
+ def list_users(account_id, state: nil, role: nil)
+ params = { state: state, role: role }.reject { |_, value| value.nil? }
+ response = http_client.get("/admin/api/accounts/#{account_id}/users", params: params)
+ extract(collection: 'users', entity: 'user', from: response)
+ end
+
+ # @api public
+ # @param [String] account_id Account ID
+ # @param [String] email User email
+ # @param [String] username User Username
+ # @param [String] password User password
+ # @param [Hash] attributes User Attributes
+ # @return [Hash]
+ def create_user(account_id:, email:, username:, password:, **rest)
+ body = { email: email, username: username, password: password }.merge(rest)
+ response = http_client.post("/admin/api/accounts/#{account_id}/users", body: body)
+ extract(entity: 'user', from: response)
+ end
+
+ # @api public
+ # @param [String] account_id Account ID
+ # @param [String] user_id User ID
+ # @return [Hash]
+ def activate_user(account_id, user_id)
+ response = http_client.put("/admin/api/accounts/#{account_id}/users/#{user_id}/activate")
+ extract(entity: 'user', from: response)
+ end
+
+ # @api public
+ # @param [String] account_id Account ID
+ # @return [Hash]
+ def approve_account(account_id)
+ response = http_client.put("/admin/api/accounts/#{account_id}/approve")
+ extract(entity: 'account', from: response)
+ end
+
+ # @api public
+ # @param [String] account_id Account ID
+ # @return [Array<Hash>]
+ def list_account_applications(account_id)
+ response = http_client.get("/admin/api/accounts/#{account_id}/applications")
+ extract(collection: 'applications', entity: 'application', from: response)
+ end
+
+ # @api public
+ # @return [Array<Hash]
+ def list_application_plans
+ response = http_client.get("/admin/api/application_plans")
+ extract(collection: 'plans', entity: 'application_plan', from: response)
+ end
+
+ # @api public
+ # @param [String] account_id Account ID
+ # @param [String] application_id Application ID
+ # @return [Array<Hash>]
+ def list_application_keys(account_id, application_id)
+ response = http_client.get("/admin/api/accounts/#{account_id}/applications/#{application_id}/keys")
+ extract(collection: 'keys', entity: 'key', from: response)
+ end
+
+ # @api public
+ # @param [String] account_id Account ID
+ # @param [String] application_id Application ID
+ # @param [String] key Key
+ # @return [Hash]
+ def create_application_key(account_id, application_id, key)
+ response = http_client.post("/admin/api/accounts/#{account_id}/applications/#{application_id}/keys", body: {key: key})
+ extract(entity: 'application', from: response)
+ end
+
+ # @api public
+ # @param [String] account_id Account ID
+ # @param [String] application_id Application ID
+ # @return [Hash] application Application
+ def accept_application(account_id, application_id)
+ response = http_client.put("/admin/api/accounts/#{account_id}/applications/#{application_id}/accept")
+ extract(entity: 'application', from: response)
+ end
+
+ # @api public
+ # @param [String] account_id Account ID
+ # @param [String] application_id Application ID
+ # @return [Hash] application Application
+ def suspend_application(account_id, application_id)
+ response = http_client.put("/admin/api/accounts/#{account_id}/applications/#{application_id}/suspend")
+ extract(entity: 'application', from: response)
+ end
+
+ # @api public
+ # @param [String] account_id Account ID
+ # @param [String] application_id Application ID
+ # @return [Hash] application Application
+ def resume_application(account_id, application_id)
+ response = http_client.put("/admin/api/accounts/#{account_id}/applications/#{application_id}/resume")
+ extract(entity: 'application', from: response)
+ end
+
+ # @api public
+ # @return [Array<Hash>]
+ def list_policy_registry
+ response = http_client.get('/admin/api/registry/policies')
+ extract(collection: 'policies', entity: 'policy', from: response)
+ end
+
+ # @api public
+ # @param [Hash] attributes Policy Registry Attributes
+ # @return [Hash]
+ def create_policy_registry(attributes)
+ response = http_client.post('/admin/api/registry/policies', body: attributes)
+ extract(entity: 'policy', from: response)
+ end
+
+ # @api public
+ # @return [Hash]
+ # @param [Fixnum] id Policy Registry Id
+ def show_policy_registry(id)
+ response = http_client.get("/admin/api/registry/policies/#{id}")
+ extract(entity: 'policy', from: response)
+ end
+
+ # @api public
+ # @return [Hash]
+ # @param [Fixnum] id Policy Registry Id
+ # @param [Hash] attributes Policy Registry Attributes
+ def update_policy_registry(id, attributes)
+ response = http_client.put("/admin/api/registry/policies/#{id}", body: attributes)
+ extract(entity: 'policy', from: response)
+ end
+
+ # @api public
+ # @param [Fixnum] id Policy Registry Id
+ def delete_policy_registry(id)
+ http_client.delete("/admin/api/registry/policies/#{id}")
+ true
+ end
+
+ # @api public
+ # @return [Hash]
+ def show_provider
+ response = http_client.get('/admin/api/provider')
+ extract(entity: 'account', from: response)
end
protected
def extract(collection: nil, entity:, from:)