client.rb
1.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
require 'httparty'
module ApiClient::Client
include HTTMultiParty
default_timeout 10 * 60
def self.submit(request, files)
o = { query: request.params.clone }
o[:query].merge!({ :servico => request.service_type })
o[:query].merge!({ :callback => "http://150.165.205.192:3000/v_libras/requests/callback?request_id=#{request.id}" })
o[:query].merge!({ :video => files[:video].file.to_file })
unless files[:subtitle].file.nil?
o[:query].merge!({ :legenda => files[:subtitle].file.to_file })
o[:query].merge!({ :linguagem => 'portugues' })
end
Delayed::Worker.logger.debug "[VLibras::Request] Options: #{o}"
response = self.post(ApiClient::API_URL, o)
Delayed::Worker.logger.debug "[VLibras::Request] Status #{response.response.code}"
if response.response.code == '200'
else
request.update!(:response => response.body, :status => 'error')
end
rescue
end
private
def self.url_with_service(service)
URI.encode("#{ApiClient::API_URL}?servico=#{service}")
end
end