Class: Samba
Overview
samba_class
Constant Summary collapse
- BASE_API_URL =
'https://api.sambavideos.sambatech.com/v1'.freeze
Instance Method Summary collapse
- #active_media(media_id, body) ⇒ Object
- #get_all_categries ⇒ Object
- #get_category_chiligum ⇒ Object
- #get_project(project_id) ⇒ Object
-
#initialize(attributes) ⇒ Samba
constructor
A new instance of Samba.
- #media_upload_data ⇒ Object
- #upload_media(video_path) ⇒ Object
Constructor Details
#initialize(attributes) ⇒ Samba
Returns a new instance of Samba.
8 9 10 |
# File 'lib/samba_api/samba.rb', line 8 def initialize(attributes) @options = { 'access_token' => attributes[:access_token], 'Content-Type' => 'application/json' } end |
Instance Method Details
#active_media(media_id, body) ⇒ Object
40 41 42 43 44 45 |
# File 'lib/samba_api/samba.rb', line 40 def active_media(media_id, body) project_id = get_projects.first["id"] url = Samba::BASE_API_URL+"/medias/#{media_id}?access_token=#{@options["access_token"]}&pid=#{project_id}" response = self.class.put(url, headers: @options, body: body) response = JSON.parse(response.body) end |
#get_all_categries ⇒ Object
47 48 49 50 51 |
# File 'lib/samba_api/samba.rb', line 47 def get_all_categries project_id = get_projects.first["id"] url = Samba::BASE_API_URL+"/categories?access_token=#{@options["access_token"]}&pid=#{project_id}" response = self.class.get(url, headers: @options ) end |
#get_category_chiligum ⇒ Object
53 54 55 56 57 58 |
# File 'lib/samba_api/samba.rb', line 53 def get_category_chiligum project_id = get_projects.first["id"] url = Samba::BASE_API_URL+"/categories/33?&access_token=#{@options["access_token"]}&pid=#{project_id}" response = self.class.get(url, headers: @options) response = JSON.parse(response.body) end |
#get_project(project_id) ⇒ Object
12 13 14 15 16 |
# File 'lib/samba_api/samba.rb', line 12 def get_project(project_id) endpoint_project = Samba::BASE_API_URL+"/projects/#{project_id}?access_token=#{@options["access_token"]}" response = self.class.get(endpoint_project) response = JSON.parse(response.body) end |
#media_upload_data ⇒ Object
18 19 20 21 22 23 24 25 |
# File 'lib/samba_api/samba.rb', line 18 def media_upload_data body = '{ "qualifier": "VIDEO" }' #TODO better way to get project project_id = get_projects.first["id"] url = Samba::BASE_API_URL+"/medias?access_token=#{@options["access_token"]}&pid=#{project_id}" response = self.class.post(url, headers: @options, body: body) response = JSON.parse(response.body) end |
#upload_media(video_path) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/samba_api/samba.rb', line 27 def upload_media(video_path) upload_url = media_upload_data["uploadUrl"] stdin, stdout, stderr, wait_thr = *Open3.popen3( 'curl', '--silent', '--show-error', '-X', 'POST', upload_url, '--header', 'Content-Type: multipart/form-data', '-F', "file=@#{video_path}" ) wait_thr.join return false unless stderr.eof? return stdout.read end |