Class: ThreeScaleToolbox::Entities::BackendMethod
- Inherits:
-
Object
- Object
- ThreeScaleToolbox::Entities::BackendMethod
- Defined in:
- lib/3scale_toolbox/entities/backend_method.rb
Constant Summary collapse
- VALID_PARAMS =
%w[friendly_name system_name description].freeze
Instance Attribute Summary collapse
-
#backend ⇒ Object
readonly
Returns the value of attribute backend.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#parent_id ⇒ Object
readonly
Returns the value of attribute parent_id.
-
#remote ⇒ Object
readonly
Returns the value of attribute remote.
Class Method Summary collapse
- .create(backend:, parent_id:, attrs:) ⇒ Object
-
.find(backend:, parent_id:, ref:) ⇒ Object
ref can be system_name or method_id.
- .find_by_system_name(backend:, parent_id:, system_name:) ⇒ Object
Instance Method Summary collapse
- #attrs ⇒ Object
- #delete ⇒ Object
- #friendly_name ⇒ Object
-
#initialize(id:, parent_id:, backend:, attrs: nil) ⇒ BackendMethod
constructor
A new instance of BackendMethod.
- #system_name ⇒ Object
- #update(m_attrs) ⇒ Object
Constructor Details
#initialize(id:, parent_id:, backend:, attrs: nil) ⇒ BackendMethod
Returns a new instance of BackendMethod.
33 34 35 36 37 38 39 |
# File 'lib/3scale_toolbox/entities/backend_method.rb', line 33 def initialize(id:, parent_id:, backend:, attrs: nil) @id = id.to_i @backend = backend @parent_id = parent_id @remote = backend.remote @attrs = process_attrs(attrs) end |
Instance Attribute Details
#backend ⇒ Object (readonly)
Returns the value of attribute backend.
31 32 33 |
# File 'lib/3scale_toolbox/entities/backend_method.rb', line 31 def backend @backend end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
31 32 33 |
# File 'lib/3scale_toolbox/entities/backend_method.rb', line 31 def id @id end |
#parent_id ⇒ Object (readonly)
Returns the value of attribute parent_id.
31 32 33 |
# File 'lib/3scale_toolbox/entities/backend_method.rb', line 31 def parent_id @parent_id end |
#remote ⇒ Object (readonly)
Returns the value of attribute remote.
31 32 33 |
# File 'lib/3scale_toolbox/entities/backend_method.rb', line 31 def remote @remote end |
Class Method Details
.create(backend:, parent_id:, attrs:) ⇒ Object
8 9 10 11 12 13 14 15 16 17 |
# File 'lib/3scale_toolbox/entities/backend_method.rb', line 8 def create(backend:, parent_id:, attrs:) method = backend.remote.create_backend_method(backend.id, parent_id, Helper.filter_params(VALID_PARAMS, attrs)) if (errors = method['errors']) raise ThreeScaleToolbox::ThreeScaleApiError.new('Backend Method has not been created', errors) end new(id: method.fetch('id'), parent_id: parent_id, backend: backend, attrs: method) end |
.find(backend:, parent_id:, ref:) ⇒ Object
ref can be system_name or method_id
20 21 22 23 24 |
# File 'lib/3scale_toolbox/entities/backend_method.rb', line 20 def find(backend:, parent_id:, ref:) new(id: ref, parent_id: parent_id, backend: backend).tap(&:attrs) rescue ThreeScaleToolbox::InvalidIdError, ThreeScale::API::HttpClient::NotFoundError find_by_system_name(backend: backend, parent_id: parent_id, system_name: ref) end |
.find_by_system_name(backend:, parent_id:, system_name:) ⇒ Object
26 27 28 |
# File 'lib/3scale_toolbox/entities/backend_method.rb', line 26 def find_by_system_name(backend:, parent_id:, system_name:) backend.methods(parent_id).find { |m| m.system_name == system_name } end |
Instance Method Details
#attrs ⇒ Object
41 42 43 |
# File 'lib/3scale_toolbox/entities/backend_method.rb', line 41 def attrs @attrs ||= process_attrs(method_attrs) end |
#delete ⇒ Object
65 66 67 |
# File 'lib/3scale_toolbox/entities/backend_method.rb', line 65 def delete remote.delete_backend_method backend.id, parent_id, id end |
#friendly_name ⇒ Object
49 50 51 |
# File 'lib/3scale_toolbox/entities/backend_method.rb', line 49 def friendly_name @attrs['friendly_name'] end |
#system_name ⇒ Object
45 46 47 |
# File 'lib/3scale_toolbox/entities/backend_method.rb', line 45 def system_name @attrs['system_name'] end |
#update(m_attrs) ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/3scale_toolbox/entities/backend_method.rb', line 53 def update(m_attrs) new_attrs = remote.update_backend_method(backend.id, parent_id, id, Helper.filter_params(VALID_PARAMS, m_attrs)) if (errors = new_attrs['errors']) raise ThreeScaleToolbox::ThreeScaleApiError.new('Backend Method has not been updated', errors) end # update current attrs @attrs = process_attrs(new_attrs) end |