class ThreeScaleToolbox::Entities::Application
Attributes
id[R]
remote[R]
Public Class Methods
create(remote:, account_id:, plan_id:, app_attrs: nil)
click to toggle source
# File lib/3scale_toolbox/entities/application.rb, line 5 def create(remote:, account_id:, plan_id:, app_attrs: nil) attrs = remote.create_application(account_id, app_attrs, plan_id: plan_id) if (errors = attrs['errors']) raise ThreeScaleToolbox::ThreeScaleApiError.new('Application has not been created', errors) end new(id: attrs.fetch('id'), remote: remote, attrs: attrs) end
find(remote:, service_id: nil, ref:)
click to toggle source
ref can be
-
User_key (API key)
-
App_id (from app_id/app_key pair) / Client ID (for OAuth and OpenID Connect authentication modes)
-
Application
internal id
# File lib/3scale_toolbox/entities/application.rb, line 18 def find(remote:, service_id: nil, ref:) app = find_by_user_key(remote, service_id, ref) return app unless app.nil? app = find_by_app_id(remote, service_id, ref) return app unless app.nil? app = find_by_id(remote, service_id, ref) return app unless app.nil? nil end
find_by_app_id(remote, service_id, app_id)
click to toggle source
# File lib/3scale_toolbox/entities/application.rb, line 39 def find_by_app_id(remote, service_id, app_id) generic_find(remote, service_id, :application_id, app_id) end
find_by_id(remote, service_id, id)
click to toggle source
# File lib/3scale_toolbox/entities/application.rb, line 31 def find_by_id(remote, service_id, id) generic_find(remote, service_id, :id, id) end
find_by_user_key(remote, service_id, user_key)
click to toggle source
# File lib/3scale_toolbox/entities/application.rb, line 35 def find_by_user_key(remote, service_id, user_key) generic_find(remote, service_id, :user_key, user_key) end
new(id:, remote:, attrs: nil)
click to toggle source
# File lib/3scale_toolbox/entities/application.rb, line 61 def initialize(id:, remote:, attrs: nil) @id = id.to_i @remote = remote @attrs = attrs end
Private Class Methods
generic_find(remote, service_id, type, ref)
click to toggle source
# File lib/3scale_toolbox/entities/application.rb, line 45 def generic_find(remote, service_id, type, ref) # find_application criteria only accepts one parameter. # Otherwise unexpected behavior attrs = remote.find_application(service_id: service_id, type => ref) if (errors = attrs['errors']) raise ThreeScaleToolbox::ThreeScaleApiError.new('Application find error', errors) end new(id: attrs.fetch('id'), remote: remote, attrs: attrs) rescue ThreeScale::API::HttpClient::NotFoundError nil end
Public Instance Methods
attrs()
click to toggle source
# File lib/3scale_toolbox/entities/application.rb, line 67 def attrs @attrs ||= application_attrs end
delete()
click to toggle source
# File lib/3scale_toolbox/entities/application.rb, line 108 def delete remote.delete_application account_id, id end
live?()
click to toggle source
# File lib/3scale_toolbox/entities/application.rb, line 112 def live? attrs.fetch('state') == 'live' end
resume()
click to toggle source
# File lib/3scale_toolbox/entities/application.rb, line 82 def resume return attrs if live? new_attrs = remote.resume_application(account_id, id) if (errors = new_attrs['errors']) raise ThreeScaleToolbox::ThreeScaleApiError.new('Application has not been resumed', errors) end @attrs = new_attrs new_attrs end
suspend()
click to toggle source
# File lib/3scale_toolbox/entities/application.rb, line 95 def suspend return attrs unless live? new_attrs = remote.suspend_application(account_id, id) if (errors = new_attrs['errors']) raise ThreeScaleToolbox::ThreeScaleApiError.new('Application has not been suspended', errors) end @attrs = new_attrs new_attrs end
update(app_attrs)
click to toggle source
# File lib/3scale_toolbox/entities/application.rb, line 71 def update(app_attrs) new_attrs = remote.update_application(account_id, id, app_attrs) if (errors = new_attrs['errors']) raise ThreeScaleToolbox::ThreeScaleApiError.new('Application has not been updated', errors) end @attrs = new_attrs new_attrs end
Private Instance Methods
account_id()
click to toggle source
# File lib/3scale_toolbox/entities/application.rb, line 118 def account_id attrs.fetch('account_id') end
application_attrs()
click to toggle source
# File lib/3scale_toolbox/entities/application.rb, line 122 def application_attrs remote.show_application(id).tap do |application| if (errors = application['errors']) raise ThreeScaleToolbox::ThreeScaleApiError.new('Application attrs not read', errors) end end end