class ThreeScaleToolbox::Entities::Method

Attributes

id[R]
remote[R]
service[R]

Public Class Methods

create(service:, attrs:) click to toggle source
# 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:) click to toggle source

ref can be system_name or method_id

# 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:) click to toggle source
# 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
new(id:, service:, attrs: nil) click to toggle source
# 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

Public Instance Methods

attrs() click to toggle source
# File lib/3scale_toolbox/entities/method.rb, line 37
def attrs
  @attrs ||= method_attrs
end
delete() click to toggle source
# File lib/3scale_toolbox/entities/method.rb, line 73
def delete
  remote.delete_method service.id, hits_id, id
end
description() click to toggle source
# File lib/3scale_toolbox/entities/method.rb, line 49
def description
  attrs['description']
end
disable() click to toggle source
# File lib/3scale_toolbox/entities/method.rb, line 53
def disable
  Metric.new(id: id, service: service).disable
end
enable() click to toggle source
# File lib/3scale_toolbox/entities/method.rb, line 57
def enable
  Metric.new(id: id, service: service).enable
end
friendly_name() click to toggle source
# File lib/3scale_toolbox/entities/method.rb, line 45
def friendly_name
  attrs['friendly_name']
end
system_name() click to toggle source
# File lib/3scale_toolbox/entities/method.rb, line 41
def system_name
  attrs['system_name']
end
update(m_attrs) click to toggle source
# 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

Private Instance Methods

hits_id() click to toggle source
# File lib/3scale_toolbox/entities/method.rb, line 80
def hits_id
  service.hits.id
end
method_attrs() click to toggle source
# File lib/3scale_toolbox/entities/method.rb, line 84
def method_attrs
  method = remote.show_method service.id, hits_id, id
  if (errors = method['errors'])
    raise ThreeScaleToolbox::ThreeScaleApiError.new('Method not read', errors)
  end

  method
end