class Plivo::Resources::MediaInterface

Public Class Methods

new(client, resource_list_json = nil) click to toggle source
Calls superclass method Plivo::Base::ResourceInterface::new
# File lib/plivo/resources/media.rb, line 25
def initialize(client, resource_list_json = nil)
  @_name = 'Media'
  @_resource_type = Media
  @_identifier_string = 'media_id'
  super
end

Public Instance Methods

get(media_id) click to toggle source

Get an Media @param [String] media_id @return [Media] Media

# File lib/plivo/resources/media.rb, line 36
def get(media_id)
  valid_param?(:media_id, media_id, [String, Symbol], true)
  perform_get(media_id)
end
list(options=nil) click to toggle source

List all Media @param [Hash] options @option options [Int] :offset @option options [Int] :limit @return [Hash]

# File lib/plivo/resources/media.rb, line 47
def list(options=nil)
  return perform_list_without_object if options.nil?

  params = {}
  %i[offset limit].each do |param|
    if options.key?(param) && valid_param?(param, options[param],
                                           [Integer], true)
      params[param] = options[param]
    end
  end

  if options.key?(:limit) && (options[:limit] > 20 || options[:limit] <= 0)
    raise_invalid_request('The maximum number of results that can be '\
    "fetched is 20. limit can't be more than 20 or less than 1")
  end

  if options.key?(:offset) && options[:offset] < 0
    raise_invalid_request("Offset can't be negative")
  end

  perform_list_without_object(params)
end
upload(filepath) click to toggle source

Create a new upload

# File lib/plivo/resources/media.rb, line 72
def upload(filepath)
  params = {}
  for file_to_upload in filepath do
    unless file_to_upload.nil?
    file_extension = file_to_upload.split('.')[-1]

    content_type = case file_extension
                     when 'jpeg' then 'image/jpeg'
                     when 'jpg' then 'image/jpeg'
                     when 'png' then 'image/png'
                     when 'pdf' then 'application/pdf'
                     when 'xcf' then 'image/xcf'
                     when 'text' then 'text/plain'
                     when 'mpeg' then 'video/mpeg'
                     when 'mp4' then 'video/mp4'
                     else raise_invalid_request("#{file_extension} is not yet supported for upload")
                   end

    params[:file] = Faraday::UploadIO.new(file_to_upload, content_type)
    end
  end
  perform_create(params, true)
end