Class: ThreeScaleToolbox::Entities::Method
- Inherits:
-
Object
- Object
- ThreeScaleToolbox::Entities::Method
- Defined in:
- lib/3scale_toolbox/entities/method.rb
Instance Attribute Summary collapse
-
#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.
-
#service ⇒ Object
readonly
Returns the value of attribute service.
Class Method Summary collapse
- .create(service:, parent_id:, attrs:) ⇒ Object
-
.find(service:, parent_id:, ref:) ⇒ Object
ref can be system_name or method_id.
- .find_by_system_name(service:, parent_id:, system_name:) ⇒ Object
Instance Method Summary collapse
- #attrs ⇒ Object
- #delete ⇒ Object
- #disable ⇒ Object
- #enable ⇒ Object
-
#initialize(id:, parent_id:, service:, attrs: nil) ⇒ Method
constructor
A new instance of Method.
- #update(m_attrs) ⇒ Object
Constructor Details
#initialize(id:, parent_id:, service:, attrs: nil) ⇒ Method
Returns a new instance of Method.
32 33 34 35 36 37 38 |
# File 'lib/3scale_toolbox/entities/method.rb', line 32 def initialize(id:, parent_id:, service:, attrs: nil) @id = id.to_i @service = service @parent_id = parent_id @remote = service.remote @attrs = attrs end |
Instance Attribute Details
#id ⇒ Object (readonly)
Returns the value of attribute id.
30 31 32 |
# File 'lib/3scale_toolbox/entities/method.rb', line 30 def id @id end |
#parent_id ⇒ Object (readonly)
Returns the value of attribute parent_id.
30 31 32 |
# File 'lib/3scale_toolbox/entities/method.rb', line 30 def parent_id @parent_id end |
#remote ⇒ Object (readonly)
Returns the value of attribute remote.
30 31 32 |
# File 'lib/3scale_toolbox/entities/method.rb', line 30 def remote @remote end |
#service ⇒ Object (readonly)
Returns the value of attribute service.
30 31 32 |
# File 'lib/3scale_toolbox/entities/method.rb', line 30 def service @service end |
Class Method Details
.create(service:, parent_id:, attrs:) ⇒ Object
5 6 7 8 9 10 11 12 13 |
# File 'lib/3scale_toolbox/entities/method.rb', line 5 def create(service:, parent_id:, attrs:) method = service.remote.create_method service.id, parent_id, attrs if (errors = method['errors']) raise ThreeScaleToolbox::ThreeScaleApiError.new('Method has not been created', errors) end new(id: method.fetch('id'), parent_id: parent_id, service: service, attrs: method) end |
.find(service:, parent_id:, ref:) ⇒ Object
ref can be system_name or method_id
16 17 18 19 20 |
# File 'lib/3scale_toolbox/entities/method.rb', line 16 def find(service:, parent_id:, ref:) new(id: ref, parent_id: parent_id, service: service).tap(&:attrs) rescue ThreeScale::API::HttpClient::NotFoundError find_by_system_name(service: service, parent_id: parent_id, system_name: ref) end |
.find_by_system_name(service:, parent_id:, system_name:) ⇒ Object
22 23 24 25 26 27 |
# File 'lib/3scale_toolbox/entities/method.rb', line 22 def find_by_system_name(service:, parent_id:, system_name:) method = service.methods(parent_id).find { |m| m['system_name'] == system_name } return if method.nil? new(id: method.fetch('id'), parent_id: parent_id, service: service, attrs: method) end |
Instance Method Details
#attrs ⇒ Object
40 41 42 |
# File 'lib/3scale_toolbox/entities/method.rb', line 40 def attrs @attrs ||= method_attrs end |
#delete ⇒ Object
64 65 66 |
# File 'lib/3scale_toolbox/entities/method.rb', line 64 def delete remote.delete_method service.id, parent_id, id end |
#disable ⇒ Object
44 45 46 |
# File 'lib/3scale_toolbox/entities/method.rb', line 44 def disable Metric.new(id: id, service: service).disable end |
#enable ⇒ Object
48 49 50 |
# File 'lib/3scale_toolbox/entities/method.rb', line 48 def enable Metric.new(id: id, service: service).enable end |
#update(m_attrs) ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/3scale_toolbox/entities/method.rb', line 52 def update(m_attrs) new_attrs = remote.update_method(service.id, parent_id, id, m_attrs) if (errors = new_attrs['errors']) raise ThreeScaleToolbox::ThreeScaleApiError.new('Method has not been updated', errors) end # update current attrs @attrs = new_attrs new_attrs end |