Class: Plivo::Resources::MediaInterface
- Inherits:
-
Base::ResourceInterface
- Object
- Base::ResourceInterface
- Plivo::Resources::MediaInterface
- Defined in:
- lib/plivo/resources/media.rb
Constant Summary
Constants included from Utils
Instance Method Summary collapse
-
#get(media_id) ⇒ Media
Get an Media.
-
#initialize(client, resource_list_json = nil) ⇒ MediaInterface
constructor
A new instance of MediaInterface.
-
#list(options = nil) ⇒ Hash
List all Media.
-
#upload(filepath) ⇒ Object
Create a new upload.
Methods included from Utils
GetSortedQueryParamString?, compute_signatureV3?, expected_type?, expected_value?, generate_url?, getMapFromQueryString?, is_one_among_string_url?, multi_valid_param?, raise_invalid_request, valid_account?, valid_date_format?, valid_mainaccount?, valid_multiple_destination_integers?, valid_multiple_destination_nos?, valid_param?, valid_range?, valid_signature?, valid_signatureV3?, valid_subaccount?, valid_url?
Constructor Details
#initialize(client, resource_list_json = nil) ⇒ MediaInterface
Returns a new instance of MediaInterface.
25 26 27 28 29 30 |
# 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 |
Instance Method Details
#get(media_id) ⇒ Media
Get an Media
36 37 38 39 |
# 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) ⇒ Hash
List all Media
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/plivo/resources/media.rb', line 47 def list(=nil) return perform_list_without_object if .nil? params = {} %i[offset limit].each do |param| if .key?(param) && valid_param?(param, [param], [Integer], true) params[param] = [param] end end if .key?(:limit) && ([:limit] > 20 || [: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 .key?(:offset) && [:offset] < 0 raise_invalid_request("Offset can't be negative") end perform_list_without_object(params) end |
#upload(filepath) ⇒ Object
Create a new upload
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
# 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 |