Class: ThreeScaleToolbox::Entities::Application
- Inherits:
-
Object
- Object
- ThreeScaleToolbox::Entities::Application
- Defined in:
- lib/3scale_toolbox/entities/application.rb
Instance Attribute Summary collapse
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#remote ⇒ Object
readonly
Returns the value of attribute remote.
Class Method Summary collapse
- .create(remote:, account_id:, plan_id:, app_attrs: nil) ⇒ Object
-
.find(remote:, service_id: nil, ref:) ⇒ Object
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.
- .find_by_app_id(remote, service_id, app_id) ⇒ Object
- .find_by_id(remote, service_id, id) ⇒ Object
- .find_by_user_key(remote, service_id, user_key) ⇒ Object
Instance Method Summary collapse
- #attrs ⇒ Object
- #delete ⇒ Object
-
#initialize(id:, remote:, attrs: nil) ⇒ Application
constructor
A new instance of Application.
- #live? ⇒ Boolean
- #resume ⇒ Object
- #suspend ⇒ Object
- #update(app_attrs) ⇒ Object
Constructor Details
#initialize(id:, remote:, attrs: nil) ⇒ Application
Returns a new instance of Application.
61 62 63 64 65 |
# File 'lib/3scale_toolbox/entities/application.rb', line 61 def initialize(id:, remote:, attrs: nil) @id = id.to_i @remote = remote @attrs = attrs end |
Instance Attribute Details
#id ⇒ Object (readonly)
Returns the value of attribute id.
59 60 61 |
# File 'lib/3scale_toolbox/entities/application.rb', line 59 def id @id end |
#remote ⇒ Object (readonly)
Returns the value of attribute remote.
59 60 61 |
# File 'lib/3scale_toolbox/entities/application.rb', line 59 def remote @remote end |
Class Method Details
.create(remote:, account_id:, plan_id:, app_attrs: nil) ⇒ Object
5 6 7 8 9 10 11 12 |
# 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:) ⇒ Object
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
18 19 20 21 22 23 24 25 26 27 28 29 |
# 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) ⇒ Object
39 40 41 |
# 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) ⇒ Object
31 32 33 |
# 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) ⇒ Object
35 36 37 |
# 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 |
Instance Method Details
#attrs ⇒ Object
67 68 69 |
# File 'lib/3scale_toolbox/entities/application.rb', line 67 def attrs @attrs ||= application_attrs end |
#delete ⇒ Object
108 109 110 |
# File 'lib/3scale_toolbox/entities/application.rb', line 108 def delete remote.delete_application account_id, id end |
#live? ⇒ Boolean
112 113 114 |
# File 'lib/3scale_toolbox/entities/application.rb', line 112 def live? attrs.fetch('state') == 'live' end |
#resume ⇒ Object
82 83 84 85 86 87 88 89 90 91 92 93 |
# 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 ⇒ Object
95 96 97 98 99 100 101 102 103 104 105 106 |
# 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) ⇒ Object
71 72 73 74 75 76 77 78 79 80 |
# 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 |