class ThreeScaleToolbox::Entities::ActiveDocs
Attributes
id[R]
remote[R]
Public Class Methods
create(remote:, attrs:)
click to toggle source
# File lib/3scale_toolbox/entities/activedocs.rb, line 5 def create(remote:, attrs:) activedocs_res = create_activedocs(remote: remote, attrs: attrs) new(id: activedocs_res.fetch('id'), remote: remote, attrs: activedocs_res) end
find(remote:, ref:)
click to toggle source
ref can be system_name
or activedocs_id
# File lib/3scale_toolbox/entities/activedocs.rb, line 11 def find(remote:, ref:) new(id: ref, remote: remote).tap(&:attrs) rescue ThreeScaleToolbox::ActiveDocsNotFoundError find_by_system_name(remote: remote, system_name: ref) end
find_by_system_name(remote:, system_name:)
click to toggle source
# File lib/3scale_toolbox/entities/activedocs.rb, line 17 def find_by_system_name(remote:, system_name:) activedocs_list = remote.list_activedocs if activedocs_list.respond_to?(:has_key?) && (errors = activedocs_list['errors']) raise ThreeScaleToolbox::ThreeScaleApiError.new('ActiveDocs list not read', errors) end res_attrs = activedocs_list.find { |svc| svc['system_name'] == system_name } return if res_attrs.nil? new(id: res_attrs.fetch('id'), remote: remote, attrs: res_attrs) end
new(id:, remote:, attrs: nil)
click to toggle source
# File lib/3scale_toolbox/entities/activedocs.rb, line 44 def initialize(id:, remote:, attrs: nil) @id = id.to_i @remote = remote @attrs = attrs end
Private Class Methods
create_activedocs(remote:, attrs:)
click to toggle source
# File lib/3scale_toolbox/entities/activedocs.rb, line 32 def create_activedocs(remote:, attrs:) activedocs_res = remote.create_activedocs(attrs) if (errors = activedocs_res['errors']) raise ThreeScaleToolbox::ThreeScaleApiError.new('ActiveDocs has not been created', errors) end activedocs_res end
Public Instance Methods
attrs()
click to toggle source
# File lib/3scale_toolbox/entities/activedocs.rb, line 50 def attrs @attrs ||= activedoc_attrs end
body()
click to toggle source
# File lib/3scale_toolbox/entities/activedocs.rb, line 58 def body attrs['body'] end
delete()
click to toggle source
# File lib/3scale_toolbox/entities/activedocs.rb, line 66 def delete remote.delete_activedocs id end
name()
click to toggle source
# File lib/3scale_toolbox/entities/activedocs.rb, line 62 def name attrs['name'] end
system_name()
click to toggle source
# File lib/3scale_toolbox/entities/activedocs.rb, line 54 def system_name attrs['system_name'] end
update(a_attrs)
click to toggle source
# File lib/3scale_toolbox/entities/activedocs.rb, line 70 def update(a_attrs) new_attrs = remote.update_activedocs(id, a_attrs) if (errors = new_attrs['errors']) raise ThreeScaleToolbox::ThreeScaleApiError.new('ActiveDocs has not been updated', errors) end # update current attrs @attrs = new_attrs new_attrs end
Private Instance Methods
activedoc_attrs()
click to toggle source
# File lib/3scale_toolbox/entities/activedocs.rb, line 84 def activedoc_attrs activedocs_list = remote.list_activedocs if activedocs_list.respond_to?(:has_key?) && (errors = activedocs_list['errors']) raise ThreeScaleToolbox::ThreeScaleApiError.new('ActiveDocs list not read', errors) end res_attrs = activedocs_list.find { |adocs| adocs.fetch('id') == id } if res_attrs.nil? raise ThreeScaleToolbox::ActiveDocsNotFoundError.new(id) end res_attrs end