Module: SambaApi::Medias

Included in:
Init
Defined in:
lib/samba_api/medias.rb

Overview

medias class

Instance Method Summary collapse

Instance Method Details

#active_media(media_id, body) ⇒ Object



40
41
42
43
44
45
46
# File 'lib/samba_api/medias.rb', line 40

def active_media(media_id, body)
  #TODO better way to get project
  project_id = all_projects.last['id']
  endpoint_url = media_base_url + media_id.to_s + access_token + '&pid=' + project_id.to_s
  response = self.class.put(endpoint_url, body: body, headers: header_request)
  response = JSON.parse(response.body)
end

#all_medias(project_id) ⇒ Object



9
10
11
12
13
# File 'lib/samba_api/medias.rb', line 9

def all_medias(project_id)
  endpoint_url = base_url + 'medias' + access_token + '&pid=' + project_id.to_s
  response = self.class.get(endpoint_url)
  JSON.parse(response.body)
end

#delete_media(media_id, project_id) ⇒ Object



34
35
36
37
38
# File 'lib/samba_api/medias.rb', line 34

def delete_media(media_id, project_id)
  endpoint_url = media_base_url + media_id.to_s + access_token + '&pid=' + project_id.to_s
  response = self.class.delete(endpoint_url, header_request)
  JSON.parse(response.body)
end

#get_media(media_id, project_id) ⇒ Object



15
16
17
18
19
# File 'lib/samba_api/medias.rb', line 15

def get_media(media_id, project_id)
  endpoint_url = media_base_url + media_id.to_s + access_token + '&pid=' + project_id.to_s
  response = self.class.get(endpoint_url)
  JSON.parse(response.body)
end

#upload_media(media_path) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/samba_api/medias.rb', line 21

def upload_media(media_path)
  upload_url = prepare_upload['uploadUrl']
  stdin, stdout, stderr, wait_thr = *Open3.popen3(
    'curl', '--silent', '--show-error',
     '-X', 'POST', upload_url,
     '--header', 'Content-Type: multipart/form-data',
     '-F', "file=@#{media_path}"
  )
  wait_thr.join
  return false unless stderr.eof?
  return stdout.read
end