Sha256: 27bdfa5d390c2f321c7b6108ced5ee05e5b7b62b4d6c14246459c29fc425dcde

Contents?: true

Size: 1.25 KB

Versions: 1

Compression:

Stored size: 1.25 KB

Contents

# frozen_string_literal: true

module MISP
  class Galaxy < Base
    attr_reader :id
    attr_reader :uuid
    attr_reader :name
    attr_reader :type
    attr_reader :description
    attr_reader :version

    attr_reader :galaxy_clusters

    def initialize(**attributes)
      attributes = normalize_attributes(attributes)

      @id = attributes.dig(:id)
      @uuid = attributes.dig(:uuid)
      @name = attributes.dig(:name)
      @type = attributes.dig(:type)
      @description = attributes.dig(:description)
      @version = attributes.dig(:version)

      @galaxy_clusters = build_plural_attribute(items: attributes.dig(:GalaxyCluster), klass: GalaxyCluster)
    end

    def to_h
      {
        id: id,
        uuid: uuid,
        name: name,
        type: type,
        description: description,
        version: version,
        GalaxyCluster: galaxy_clusters.map(&:to_h)
      }.compact
    end

    def list
      _get("/galaxies/") do |galaxies|
        galaxies.map do |galaxy|
          Galaxy.new symbolize_keys(galaxy)
        end
      end
    end

    def self.list
      new.list
    end

    def get
      _get("/galaxies/view/#{id}") { |galaxy| Galaxy.new symbolize_keys(galaxy) }
    end

    def self.get(id)
      new(id: id).get
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
misp-0.1.0 lib/misp/galaxy.rb