Class: ManyfoldApi::V0::UploadedModelDeserializer

Inherits:
BaseDeserializer show all
Defined in:
app/deserializers/manyfold_api/v0/uploaded_model_deserializer.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from BaseDeserializer

#dereference, #initialize, schema_ref, schema_ref_name

Constructor Details

This class inherits a constructor from ManyfoldApi::V0::BaseDeserializer

Class Method Details

.schema ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'app/deserializers/manyfold_api/v0/uploaded_model_deserializer.rb', line 16

def self.schema
  {
    type: :object,
    properties: {
      name: {type: :string, example: "My New Model", description: "Used as model name if any files are uploaded that aren't compressed archives"},
      files: {
        type: :array,
        items: {
          type: :object,
          properties: {
            id: {type: :string, description: "The ID of a completed upload, obtained from the upload endpoints", example: "http://example.com/uploads/abc123456def"},
            name: {type: :string, example: "model.stl"}
          },
          required: [:id, :name, :type, :size]
        }
      },
      creator: {
        type: :object,
        properties: {
          "@id": {type: :string, example: "https://example.com/creators/abc123"},
          "@type": {type: :string, example: "Organization"}
        },
        required: ["@id"]
      },
      isPartOf: {
        type: :object,
        properties: {
          "@id": {type: :string, example: "https://example.com/collections/abc123"},
          "@type": {type: :string, example: "Collection"}
        },
        required: ["@id"]
      },
      "spdx:license": {"$ref" => "#/components/schemas/spdxLicense"},
      sensitive: {type: :boolean, example: true},
      keywords: {type: :array, items: {type: :string, example: "tag"}}
    },
    required: [:files]
  }
end

Instance Method Details

#deserialize ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
# File 'app/deserializers/manyfold_api/v0/uploaded_model_deserializer.rb', line 3

def deserialize
  return unless @object
  {
    name: @object["name"],
    file: @object.dig("files")&.each_with_index.to_h.invert,
    creator_id: dereference(@object.dig("creator", "@id"), Creator)&.id,
    collections: @object["isPartOf"]&.filter_map { dereference(it["@id"], Collection) },
    license: @object.dig("spdx:license", "licenseId"),
    sensitive: @object["sensitive"] ? "1" : "0",
    tag_list: @object["keywords"]
  }.compact
end