Class: Bandwidth::Media
- Inherits:
-
Object
- Object
- Bandwidth::Media
- Extended by:
- ClientWrapper
- Defined in:
- lib/bandwidth/media.rb
Overview
The Media resource lets you upload your media files to Bandwidth API servers
Class Method Summary collapse
-
.delete(client, name) ⇒ Object
Remove file from the Bandwidth API server.
-
.download(client, name) ⇒ Array
Download file from Bandwidth API server.
-
.get_info(client, name) ⇒ Hash
Get information about a media file.
-
.list(client, query = nil) ⇒ Array
Get a list of your media files.
-
.upload(client, name, io, media_type = nil) ⇒ Object
Upload file to the Bandwidth API server.
Methods included from ClientWrapper
Class Method Details
.delete(client, name) ⇒ Object
Remove file from the Bandwidth API server
58 59 60 |
# File 'lib/bandwidth/media.rb', line 58 def self.delete(client, name) client.make_request(:delete, client.concat_user_path("#{MEDIA_PATH}/#{URI.encode(name)}"))[0] end |
.download(client, name) ⇒ Array
Download file from Bandwidth API server
45 46 47 48 49 |
# File 'lib/bandwidth/media.rb', line 45 def self.download(client, name) connection = client.create_connection() response = connection.get("/#{client.api_version}#{client.concat_user_path(MEDIA_PATH)}/#{URI.encode(name)}") [response.body, response.headers['Content-Type'] || 'application/octet-stream'] end |
.get_info(client, name) ⇒ Hash
Get information about a media file
69 70 71 72 73 |
# File 'lib/bandwidth/media.rb', line 69 def self.get_info(client, name) headers = client.make_request(:head, client.concat_user_path("#{MEDIA_PATH}/#{URI.encode(name)}"))[1] puts headers {:content_type => headers[:content_type], :content_length => headers[:content_length]} end |
.list(client, query = nil) ⇒ Array
Get a list of your media files
14 15 16 |
# File 'lib/bandwidth/media.rb', line 14 def self.list(client, query = nil) client.make_request(:get, client.concat_user_path(MEDIA_PATH), query)[0] end |
.upload(client, name, io, media_type = nil) ⇒ Object
Upload file to the Bandwidth API server
26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/bandwidth/media.rb', line 26 def self.upload(client, name, io, media_type = nil) connection = client.create_connection() # FIXME use streams directly when Faraday will be support streaming buf = io.read() response = connection.put("/#{client.api_version}#{client.concat_user_path(MEDIA_PATH)}/#{URI.encode(name)}") do |req| req.headers['Content-Length'] = buf.size.to_s req.headers['Content-Type'] = media_type || 'application/octet-stream' req.body = buf end client.check_response(response) end |