lib/misp/sharing_group.rb in misp-0.1.0 vs lib/misp/sharing_group.rb in misp-0.1.1
- old
+ new
@@ -1,23 +1,44 @@
# frozen_string_literal: true
module MISP
- class SharingGroup < Server
+ class SharingGroup < Base
+ # @return [String]
attr_reader :id
+ # @return [String]
attr_reader :name
+ # @return [String]
attr_reader :releasability
+ # @return [String]
attr_reader :description
+ # @return [String]
attr_reader :uuid
+ # @return [String]
attr_reader :organisation_uuid
+ # @return [String]
attr_reader :org_id
+ # @return [String]
attr_reader :sync_user_id
+ # @return [Boolean]
attr_reader :active
+ # @return [String]
attr_reader :created
+ # @return [String]
attr_reader :modified
+ # @return [Boolean]
attr_reader :local
+ # @return [Boolean]
attr_reader :roaming
+ # @return [MISP::Org, nil]
+ attr_reader :organization
+
+ # @return [Array<MISP::SharingGroupOrg>]
+ attr_reader :sharing_group_orgs
+ # @return [Array<MISP::SharingGroupServer>]
+ attr_reader :sharing_group_servers
+
def initialize(**attributes)
attributes = normalize_attributes(attributes)
@id = attributes.dig(:id)
@name = attributes.dig(:name) || "default name"
@@ -31,16 +52,21 @@
@created = attributes.dig(:created)
@modified = attributes.dig(:modified)
@local = attributes.dig(:local)
@roaming = attributes.dig(:roaming)
- @_organisation = attributes.dig(:Organisation)
+ @organisation = build_attribute(item: attributes.dig(:Organization), klass: Org)
@sharing_group_orgs = build_plural_attribute(items: attributes.dig(:SharingGroupOrg), klass: SharingGroupOrg)
@sharing_group_servers = build_plural_attribute(items: attributes.dig(:SharingGroupServer), klass: SharingGroupServer)
end
+ #
+ # Returns a hash representation of the attribute data.
+ #
+ # @return [Hash]
+ #
def to_h
{
id: id,
name: name,
releasability: releasability,
@@ -58,27 +84,41 @@
SharingGroupOrg: sharing_group_orgs.map(&:to_h),
SharingGroupServer: sharing_group_servers.map(&:to_h)
}.compact
end
+ #
+ # List sharing groups
+ #
+ # @return [Array<MISP::SharingGroup>]
+ #
def list
_get("/sharing_groups/") do |res|
- sharing_groups = res.dig("response") || []
+ sharing_groups = res.dig(:response) || []
sharing_groups.map do |sharing_group|
- SharingGroup.new symbolize_keys(sharing_group)
+ SharingGroup.new sharing_group
end
end
end
- def self.list
- new.list
- end
-
+ #
+ # Create a sharing group
+ #
+ # @param [Hash] **attributes attributes
+ #
+ # @return [MISP::SharingGroup]
+ #
def create(**attributes)
- _post("/sharing_groups/add", wrap(attributes)) { |sharing_group| SharingGroup.new symbolize_keys(sharing_group) }
+ _post("/sharing_groups/add", wrap(attributes)) { |sharing_group| SharingGroup.new sharing_group }
end
- def self.create(attributes)
- new.create attributes
+ class << self
+ def list
+ new.list
+ end
+
+ def create(**attributes)
+ new.create attributes
+ end
end
end
end