module Safrano::MediaEntity

Public Instance Methods

edit_media() click to toggle source
# File lib/odata/entity.rb, line 329
def edit_media
  "#{uri}/$value"
end
media_src() click to toggle source
# File lib/odata/entity.rb, line 324
def media_src
  version = self.class.media_handler.ressource_version(self)
  "#{uri}/$value?version=#{version}"
end
metadata_h() click to toggle source

media entity metadata for json h

# File lib/odata/entity.rb, line 316
def metadata_h
  {   uri: uri,
      type: type_name,
      media_src: media_src,
      edit_media: edit_media,
      content_type: @values[:content_type] }
end
odata_delete(req) click to toggle source
# File lib/odata/entity.rb, line 339
def odata_delete(req)
  if req.accept?(APPJSON)
    # delete the MR
    # delegate to the media handler on collection(ie class) level
    # TODO error handling

    self.class.media_handler.odata_delete(entity: self)
    # delete the relation(s)  to parent(s) (if any) and then entity
    odata_delete_relation_and_entity(req, @navattr_reflection, @nav_parent)
    # result
    [200, EMPTY_HASH, [{ 'd' => req.service.get_emptycoll_odata_h }.to_json]]
  else # TODO: other formats
    415
  end
end
odata_media_value_get(req) click to toggle source

real implementation for returning $value for a media entity

# File lib/odata/entity.rb, line 356
def odata_media_value_get(req)
  # delegate to the media handler on collection(ie class) level
  self.class.media_handler.odata_get(request: req, entity: self)
end
odata_media_value_put(req) click to toggle source

real implementation for replacing $value for a media entity

# File lib/odata/entity.rb, line 362
def odata_media_value_put(req)
  model = self.class
  req.with_media_data do |data, mimetype, filename|
    emdata = { content_type: mimetype }
    if req.in_changeset
      set_fields(emdata, model.data_fields, missing: :skip)
      save(transaction: false)
    else

      update_fields(emdata, model.data_fields, missing: :skip)

    end
    model.media_handler.replace_file(data: data,
                                     entity: self,
                                     filename: filename)

    ARY_204_EMPTY_HASH_ARY
  end
end
values_for_odata() click to toggle source
# File lib/odata/entity.rb, line 333
def values_for_odata
  ret = values.dup
  ret.delete(:content_type)
  ret
end