Class: Api::V2::QcFileResource

Inherits:
BaseResource
  • Object
show all
Defined in:
app/resources/api/v2/qc_file_resource.rb

Overview

Note:

Access this resource via the /api/v2/qc_files/ endpoint.

Note:

This resource cannot be modified after creation: its endpoint will not accept PATCH requests.

Note:

Known issue

Occasionally, encoding failures may occur resulting in 500 Internal Server errors mentioning from ASCII-8BIT to UTF-8. If this occurs, try re-requesting the resource without including the contents attribute, for example: /api/v2/qc_files/1?fields[qc_files]=filename,uuid,created_at

Provides a JSON:API representation of QcFile which contains the QC data previously added to a piece of Labware. The file contents are stored in the database using the DbFile model.

For more information about JSON:API see the JSON:API Specifications or look at the JSONAPI::Resources package for Sequencescape's implementation of the JSON:API standard.

Examples:

POST request

POST /api/v2/qc_files/
{
  "data": {
    "type": "qc_files",
    "attributes": {
      "filename": "a_test_file.csv",
      "contents": "Hello"
    },
    "relationships": {
      // "asset": {
      //   "data": {
      //     "type": "labware",
      //     "id": 26
      //   }
      // }
    }
  }
}

GET request for all QcFile resources

GET /api/v2/qc_files/

GET request for a QcFile with ID 123

GET /api/v2/qc_files/123/

GET request for all QcFile resources associated with a Plate with ID 123

GET /api/v2/plates/123/qc_files/

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from BaseResource

apply_includes, creatable_fields, default_includes, #fetchable_fields, inclusions, resolve_relationship_names_to_relations, updatable_fields

Instance Attribute Details

#content_typeString (readonly)

Returns The content type, or MIME type, of the QC file.

Returns:

  • (String)

    The content type, or MIME type, of the QC file.



56
# File 'app/resources/api/v2/qc_file_resource.rb', line 56

attribute :content_type, readonly: true

#contentsString

Returns the file contents as UTF-8.

Not all uploaded files contain encoding information, causing encoding errors on less-common characters. See background at yehudakatz.com/2010/05/05/ruby-1-9-encodings-a-primer-and-the-solution-for-rails/

Returns:

  • (String)

    The contents of the QC file.



96
# File 'app/resources/api/v2/qc_file_resource.rb', line 96

attribute :contents, write_once: true

#created_atDateTime (readonly)

Returns The date and time the QC file was created.

Returns:

  • (DateTime)

    The date and time the QC file was created.



60
# File 'app/resources/api/v2/qc_file_resource.rb', line 60

attribute :created_at, readonly: true

#filenameString

Returns The filename of the QC file. This can only be written once on creation.

Returns:

  • (String)

    The filename of the QC file. This can only be written once on creation.



114
# File 'app/resources/api/v2/qc_file_resource.rb', line 114

attribute :filename, write_once: true

#labwareLabwareResource

Returns The Labware which this QcFile belongs to.

Returns:



76
# File 'app/resources/api/v2/qc_file_resource.rb', line 76

has_one :labware, relation_name: :asset, foreign_key: :asset_id, write_once: true

#sizeInteger (readonly)

Returns The size of the QC file in bytes.

Returns:

  • (Integer)

    The size of the QC file in bytes.



64
# File 'app/resources/api/v2/qc_file_resource.rb', line 64

attribute :size, readonly: true

#uuidString (readonly)

Returns The UUID of the bulk transfers operation.

Returns:

  • (String)

    The UUID of the bulk transfers operation.



68
# File 'app/resources/api/v2/qc_file_resource.rb', line 68

attribute :uuid, readonly: true

Class Method Details

.create(context) ⇒ Object



117
118
119
120
# File 'app/resources/api/v2/qc_file_resource.rb', line 117

def self.create(context)
  opts = { uploaded_data: context.slice(:filename, :tempfile) }
  new(QcFile.new(opts), context)
end

Instance Method Details

#filter_uuidObject

Filter the QcFile resources by UUID.

Examples:

GET request with UUID filter

GET /api/v2/qc_files?filter[uuid]=12345678-1234-1234-1234-123456789012


86
# File 'app/resources/api/v2/qc_file_resource.rb', line 86

filter :uuid, apply: ->(records, value, _options) { records.with_uuid(value) }