class FmRest::Spyke::ContainerField

Attributes

name[R]

@return [String] the name of the container field

Public Class Methods

new(base, name) click to toggle source

@param base [FmRest::Spyke::Base] the record this container belongs to @param name [Symbol] the name of the container field

# File lib/fmrest/spyke/container_field.rb, line 12
def initialize(base, name)
  @base = base
  @name = name
end

Public Instance Methods

download() click to toggle source

@return (see FmRest::V1::ContainerFields#fetch_container_data)

# File lib/fmrest/spyke/container_field.rb, line 23
def download
  FmRest::V1.fetch_container_data(url, @base.class.connection)
end
upload(filename_or_io, options = {}) click to toggle source

@param filename_or_io [String, IO] a path to the file to upload or an

IO object

@param options [Hash] @option options [Integer] :repetition (1) The repetition to pass to the

upload URL

@option (see FmRest::V1::ContainerFields#upload_container_data)

# File lib/fmrest/spyke/container_field.rb, line 33
def upload(filename_or_io, options = {})
  raise ArgumentError, "Record needs to be saved before uploading to a container field" unless @base.persisted?

  response =
    FmRest::V1.upload_container_data(
      @base.class.connection,
      upload_path(options[:repetition] || 1),
      filename_or_io,
      options
    )

  # Update mod id on record
  @base.__mod_id = response.body[:data][:__mod_id]

  true
end
url() click to toggle source

@return [String] the URL for the container

# File lib/fmrest/spyke/container_field.rb, line 18
def url
  @base.attributes[name]
end

Private Instance Methods

upload_path(repetition) click to toggle source

@param repetition [Integer] @return [String] the path for uploading a file to the container

# File lib/fmrest/spyke/container_field.rb, line 54
def upload_path(repetition)
  FmRest::V1.container_field_path(@base.class.layout, @base.__record_id, name, repetition)
end