Class: ThreeScaleToolbox::Entities::Method
- Inherits:
-
Object
- Object
- ThreeScaleToolbox::Entities::Method
- Includes:
- CRD::MethodSerializer
- Defined in:
- lib/3scale_toolbox/entities/method.rb
Instance Attribute Summary collapse
-
#id ⇒ Object
readonly
Returns the value of attribute 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:, attrs:) ⇒ Object
-
.find(service:, ref:) ⇒ Object
ref can be system_name or method_id.
- .find_by_system_name(service:, system_name:) ⇒ Object
Instance Method Summary collapse
- #attrs ⇒ Object
- #delete ⇒ Object
- #description ⇒ Object
- #disable ⇒ Object
- #enable ⇒ Object
- #friendly_name ⇒ Object
-
#initialize(id:, service:, attrs: nil) ⇒ Method
constructor
A new instance of Method.
- #system_name ⇒ Object
- #update(m_attrs) ⇒ Object
Methods included from CRD::MethodSerializer
Constructor Details
#initialize(id:, service:, attrs: nil) ⇒ Method
Returns a new instance of Method.
30 31 32 33 34 35 |
# File 'lib/3scale_toolbox/entities/method.rb', line 30 def initialize(id:, service:, attrs: nil) @id = id.to_i @service = service @remote = service.remote @attrs = attrs end |
Instance Attribute Details
#id ⇒ Object (readonly)
Returns the value of attribute id.
28 29 30 |
# File 'lib/3scale_toolbox/entities/method.rb', line 28 def id @id end |
#remote ⇒ Object (readonly)
Returns the value of attribute remote.
28 29 30 |
# File 'lib/3scale_toolbox/entities/method.rb', line 28 def remote @remote end |
#service ⇒ Object (readonly)
Returns the value of attribute service.
28 29 30 |
# File 'lib/3scale_toolbox/entities/method.rb', line 28 def service @service end |
Class Method Details
.create(service:, attrs:) ⇒ Object
7 8 9 10 11 12 13 14 |
# File 'lib/3scale_toolbox/entities/method.rb', line 7 def create(service:, attrs:) method_attrs = service.remote.create_method service.id, service.hits.id, attrs if (errors = method_attrs['errors']) raise ThreeScaleToolbox::ThreeScaleApiError.new('Method has not been created', errors) end new(id: method_attrs.fetch('id'), service: service, attrs: method_attrs) end |
.find(service:, ref:) ⇒ Object
ref can be system_name or method_id
17 18 19 20 21 |
# File 'lib/3scale_toolbox/entities/method.rb', line 17 def find(service:, ref:) new(id: ref, service: service).tap(&:attrs) rescue ThreeScale::API::HttpClient::NotFoundError find_by_system_name(service: service, system_name: ref) end |
.find_by_system_name(service:, system_name:) ⇒ Object
23 24 25 |
# File 'lib/3scale_toolbox/entities/method.rb', line 23 def find_by_system_name(service:, system_name:) service.methods.find { |m| m.system_name == system_name } end |
Instance Method Details
#attrs ⇒ Object
37 38 39 |
# File 'lib/3scale_toolbox/entities/method.rb', line 37 def attrs @attrs ||= method_attrs end |
#delete ⇒ Object
73 74 75 |
# File 'lib/3scale_toolbox/entities/method.rb', line 73 def delete remote.delete_method service.id, hits_id, id end |
#description ⇒ Object
49 50 51 |
# File 'lib/3scale_toolbox/entities/method.rb', line 49 def description attrs['description'] end |
#disable ⇒ Object
53 54 55 |
# File 'lib/3scale_toolbox/entities/method.rb', line 53 def disable Metric.new(id: id, service: service).disable end |
#enable ⇒ Object
57 58 59 |
# File 'lib/3scale_toolbox/entities/method.rb', line 57 def enable Metric.new(id: id, service: service).enable end |
#friendly_name ⇒ Object
45 46 47 |
# File 'lib/3scale_toolbox/entities/method.rb', line 45 def friendly_name attrs['friendly_name'] end |
#system_name ⇒ Object
41 42 43 |
# File 'lib/3scale_toolbox/entities/method.rb', line 41 def system_name attrs['system_name'] end |
#update(m_attrs) ⇒ Object
61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/3scale_toolbox/entities/method.rb', line 61 def update(m_attrs) new_attrs = remote.update_method(service.id, hits_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 |