Commit f8418da0749fba1daf5d354c30e73e4a3f030099

Authored by Fernando Brito
1 parent 31a10546
Exists in master and in 2 other branches v2, wikilibras

VLibras Rapid implementation

Gemfile
... ... @@ -12,7 +12,7 @@ gem 'sass-rails', '~> 4.0.3'
12 12 gem 'twitter-bootstrap-rails'
13 13 gem 'less-rails'
14 14  
15   -gem 'httparty'
  15 +gem 'httmultiparty'
16 16  
17 17 gem 'uglifier', '>= 1.3.0'
18 18 gem 'coffee-rails', '~> 4.0.0'
... ... @@ -29,7 +29,9 @@ gem 'simple_form'
29 29 gem 'inherited_resources'
30 30  
31 31 gem 'delayed_job_active_record'
  32 +gem 'delayed_job_web'
32 33 gem 'foreman'
  34 +gem 'carrierwave'
33 35  
34 36 group :development do
35 37 gem 'better_errors'
... ...
Gemfile.lock
... ... @@ -69,6 +69,11 @@ GEM
69 69 rack (>= 1.0.0)
70 70 rack-test (>= 0.5.4)
71 71 xpath (~> 2.0)
  72 + carrierwave (0.10.0)
  73 + activemodel (>= 3.2.0)
  74 + activesupport (>= 3.2.0)
  75 + json (>= 1.7)
  76 + mime-types (>= 1.16)
72 77 celluloid (0.15.2)
73 78 timers (~> 1.1.0)
74 79 celluloid-io (0.15.0)
... ... @@ -100,6 +105,10 @@ GEM
100 105 delayed_job_active_record (4.0.1)
101 106 activerecord (>= 3.0, < 4.2)
102 107 delayed_job (>= 3.0, < 4.1)
  108 + delayed_job_web (1.2.9)
  109 + activerecord (> 3.0.0)
  110 + delayed_job (> 2.0.3)
  111 + sinatra (>= 1.4.4)
103 112 devise (3.2.4)
104 113 bcrypt (~> 3.0)
105 114 orm_adapter (~> 0.1)
... ... @@ -163,6 +172,10 @@ GEM
163 172 haml (>= 4.0.0.rc.1)
164 173 hpricot (~> 0.8.6)
165 174 ruby_parser (~> 3.1.1)
  175 + httmultiparty (0.3.14)
  176 + httparty (>= 0.7.3)
  177 + mimemagic
  178 + multipart-post
166 179 http_parser.rb (0.6.0)
167 180 httparty (0.13.1)
168 181 json (~> 1.8)
... ... @@ -200,10 +213,12 @@ GEM
200 213 treetop (~> 1.4.8)
201 214 method_source (0.8.2)
202 215 mime-types (1.25.1)
  216 + mimemagic (0.2.1)
203 217 mini_portile (0.5.3)
204 218 minitest (5.3.3)
205 219 multi_json (1.10.0)
206 220 multi_xml (0.5.5)
  221 + multipart-post (2.0.0)
207 222 mysql2 (0.3.15)
208 223 nio4r (1.0.0)
209 224 nokogiri (1.6.2)
... ... @@ -229,6 +244,8 @@ GEM
229 244 rack (1.5.2)
230 245 rack-livereload (0.3.15)
231 246 rack
  247 + rack-protection (1.5.3)
  248 + rack
232 249 rack-test (0.6.2)
233 250 rack (>= 1.0)
234 251 rails (4.1.1)
... ... @@ -304,6 +321,10 @@ GEM
304 321 simple_form (3.0.2)
305 322 actionpack (~> 4.0)
306 323 activemodel (~> 4.0)
  324 + sinatra (1.4.5)
  325 + rack (~> 1.4)
  326 + rack-protection (~> 1.4)
  327 + tilt (~> 1.3, >= 1.3.4)
307 328 slop (3.5.0)
308 329 spring (1.1.3)
309 330 sprockets (2.11.0)
... ... @@ -356,9 +377,11 @@ DEPENDENCIES
356 377 binding_of_caller
357 378 cancan
358 379 capybara
  380 + carrierwave
359 381 coffee-rails (~> 4.0.0)
360 382 database_cleaner
361 383 delayed_job_active_record
  384 + delayed_job_web
362 385 devise
363 386 factory_girl_rails
364 387 faker
... ... @@ -369,7 +392,7 @@ DEPENDENCIES
369 392 guard-rspec
370 393 haml-rails
371 394 html2haml
372   - httparty
  395 + httmultiparty
373 396 inherited_resources
374 397 jquery-rails
375 398 launchy
... ...
app/admin/user.rb
1 1 ActiveAdmin.register User do
  2 + menu :priority => 80
  3 +
2 4 permit_params :email, :password, :password_confirmation
3 5  
4 6 index do
... ...
app/admin/v_libras_request.rb 0 → 100644
... ... @@ -0,0 +1,18 @@
  1 +ActiveAdmin.register VLibras::Request do
  2 + menu :priority => 10
  3 +
  4 +
  5 + # See permitted parameters documentation:
  6 + # https://github.com/gregbell/active_admin/blob/master/docs/2-resource-customization.md#setting-up-strong-parameters
  7 + #
  8 + # permit_params :list, :of, :attributes, :on, :model
  9 + #
  10 + # or
  11 + #
  12 + # permit_params do
  13 + # permitted = [:permitted, :attributes]
  14 + # permitted << :other if resource.something?
  15 + # permitted
  16 + # end
  17 +
  18 +end
... ...
app/admin/v_libras_video.rb 0 → 100644
... ... @@ -0,0 +1,17 @@
  1 +ActiveAdmin.register VLibras::Video do
  2 + menu :priority => 15
  3 +
  4 + # See permitted parameters documentation:
  5 + # https://github.com/gregbell/active_admin/blob/master/docs/2-resource-customization.md#setting-up-strong-parameters
  6 + #
  7 + # permit_params :list, :of, :attributes, :on, :model
  8 + #
  9 + # or
  10 + #
  11 + # permit_params do
  12 + # permitted = [:permitted, :attributes]
  13 + # permitted << :other if resource.something?
  14 + # permitted
  15 + # end
  16 +
  17 +end
... ...
app/assets/stylesheets/application.css.scss
... ... @@ -11,6 +11,7 @@
11 11 * file per style scope.
12 12 *
13 13 *= require 'bootstrap'
  14 + *= require 'bootstrap_overrides'
14 15 *= require 'v_libras/videos'
15 16 *= require_self
16 17 */
... ...
app/assets/stylesheets/bootstrap_overrides.css.scss 0 → 100644
... ... @@ -0,0 +1,46 @@
  1 +.breadcrumb {
  2 + padding: 7px 14px;
  3 + margin: 0 0 18px;
  4 + background-color: #fbfbfb;
  5 + background-image: -moz-linear-gradient(top, #ffffff, #f5f5f5);
  6 + background-image: -ms-linear-gradient(top, #ffffff, #f5f5f5);
  7 + background-image: -webkit-gradient(linear, 0 0, 0 100%, from(#ffffff), to(#f5f5f5));
  8 + background-image: -webkit-linear-gradient(top, #ffffff, #f5f5f5);
  9 + background-image: -o-linear-gradient(top, #ffffff, #f5f5f5);
  10 + background-image: linear-gradient(top, #ffffff, #f5f5f5);
  11 + background-repeat: repeat-x;
  12 + filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#ffffff', endColorstr='#f5f5f5', GradientType=0);
  13 + background-color: #fbfbfb;
  14 + background-image: -moz-linear-gradient(top, #ffffff, #f5f5f5);
  15 + background-image: -ms-linear-gradient(top, #ffffff, #f5f5f5);
  16 + background-image: -webkit-gradient(linear, 0 0, 0 100%, from(#ffffff), to(#f5f5f5));
  17 + background-image: -webkit-linear-gradient(top, #ffffff, #f5f5f5);
  18 + background-image: -o-linear-gradient(top, #ffffff, #f5f5f5);
  19 + background-image: linear-gradient(top, #ffffff, #f5f5f5);
  20 + background-repeat: repeat-x;
  21 + filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#ffffff', endColorstr='#f5f5f5', GradientType=0);
  22 + border: 1px solid #ddd;
  23 + -webkit-border-radius: 3px;
  24 + -moz-border-radius: 3px;
  25 + border-radius: 3px;
  26 + -webkit-border-radius: 3px;
  27 + -moz-border-radius: 3px;
  28 + border-radius: 3px;
  29 + -webkit-box-shadow: inset 0 1px 0 #ffffff;
  30 + -moz-box-shadow: inset 0 1px 0 #ffffff;
  31 + box-shadow: inset 0 1px 0 #ffffff;
  32 + -webkit-box-shadow: inset 0 1px 0 #ffffff;
  33 + -moz-box-shadow: inset 0 1px 0 #ffffff;
  34 + box-shadow: inset 0 1px 0 #ffffff;
  35 +}
  36 +.breadcrumb li {
  37 + display: inline-block;
  38 + text-shadow: 0 1px 0 #ffffff;
  39 +}
  40 +.breadcrumb .divider {
  41 + padding: 0 5px;
  42 + color: #999999;
  43 +}
  44 +.breadcrumb .active a {
  45 + color: #333333;
  46 +}
0 47 \ No newline at end of file
... ...
app/controllers/application_controller.rb
... ... @@ -3,11 +3,10 @@ class ApplicationController &lt; ActionController::Base
3 3 # For APIs, you may want to use :null_session instead.
4 4 protect_from_forgery with: :exception
5 5  
6   -
7 6 protected
8 7 def check_vlibras_api_status
9 8 unless ApiClient.check_status
10   - flash[:error] = 'SEAaaS API is down :('
  9 + flash[:error] = t('error.api.offline')
11 10 redirect_to home_path
12 11 end
13 12 end
... ...
app/controllers/v_libras/requests_controller.rb
1 1 class VLibras::RequestsController < ApplicationController
2   - before_filter :check_vlibras_api_status
  2 + protect_from_forgery with: :null_session, :only => [ :callback ]
  3 + before_filter :check_vlibras_api_status, :only => [ :rapid, :create ]
3 4  
4 5 def rapid
5 6 @request = VLibras::Request.new
... ... @@ -8,16 +9,29 @@ class VLibras::RequestsController &lt; ApplicationController
8 9 def create
9 10 @request = VLibras::Request.build_from_params(params, current_user)
10 11  
  12 + video = FileUploader.new
  13 + video.cache!(params[:video])
  14 +
  15 + subtitle = FileUploader.new
  16 + subtitle.cache!(params[:subtitle])
  17 +
  18 + files = { :video => video, :subtitle => subtitle }
  19 +
  20 +
11 21 if @request.save
12   - @request.perform_request
  22 + @request.perform_request(files)
13 23  
14 24 flash[:success] = 'Sua requisição foi submetida com sucesso!'
15   - redirect_to :action => :rapid
  25 + redirect_to v_libras_videos_path
16 26 else
17 27 flash[:error] = 'Algo deu errado com a sua requisição.'
18 28 render :action => :rapid
19 29 end
  30 + end
20 31  
  32 + def callback
  33 + ApiClient::CallbackProcessor.process(params)
21 34  
  35 + render :text => "OK!"
22 36 end
23 37 end
... ...
app/controllers/v_libras/videos_controller.rb
1 1 class VLibras::VideosController < ApplicationController
2   - before_filter :check_vlibras_api_status
  2 + before_filter :check_vlibras_api_status, :only => [ :index ]
3 3  
4 4 def index
5 5 @videos = current_user.videos
... ...
app/models/v_libras/request.rb
... ... @@ -2,18 +2,20 @@
2 2 #
3 3 # Table name: v_libras_requests
4 4 #
5   -# id :integer not null, primary key
6   -# status :string(255)
7   -# service_type :string(255)
8   -# owner_id :integer
9   -# params :text
10   -# response :text
11   -# created_at :datetime
12   -# updated_at :datetime
  5 +# id :integer not null, primary key
  6 +# status :string(255)
  7 +# service_type :string(255)
  8 +# owner_id :integer
  9 +# params :text
  10 +# response :text
  11 +# created_at :datetime
  12 +# updated_at :datetime
  13 +# video_filename :string(255)
13 14 #
14 15  
15 16 class VLibras::Request < ActiveRecord::Base
16 17 serialize :params
  18 + attr_accessor :video
17 19  
18 20 belongs_to :owner, :class => User
19 21  
... ... @@ -21,13 +23,13 @@ class VLibras::Request &lt; ActiveRecord::Base
21 23  
22 24 validates :service_type,
23 25 presence: true,
24   - inclusion: { in: %w(video-subtitle video), message: "%{value} is not a valid service type" }
  26 + inclusion: { in: %w(video-legenda video), message: "%{value} is not a valid service type" }
25 27  
26 28 validates :status,
27 29 presence: true,
28   - inclusion: { in: %w(created processing error success), message: "%{value} is not a valid service type" }
  30 + inclusion: { in: %w(created processing error success), message: "%{value} is not a valid status" }
29 31  
30   - before_save :default_values
  32 + before_validation :default_values
31 33  
32 34 default_scope { order('created_at DESC') }
33 35  
... ... @@ -35,6 +37,7 @@ class VLibras::Request &lt; ActiveRecord::Base
35 37 request = self.new
36 38  
37 39 request.service_type = params[:service]
  40 + request.video_filename = params[:video].original_filename
38 41 request.owner = user
39 42  
40 43 request.params = params[:params]
... ... @@ -42,10 +45,11 @@ class VLibras::Request &lt; ActiveRecord::Base
42 45 request
43 46 end
44 47  
45   - def perform_request
  48 + def perform_request(files)
46 49 logger.debug '[VLibras::Request] Starting request'
  50 + self.update!(status: 'processing')
47 51  
48   - ApiClient::Client.submit(self)
  52 + ApiClient::Client.submit(self, files)
49 53  
50 54 logger.debug '[VLibras::Request] Request done'
51 55 end
... ...
app/uploaders/file_uploader.rb 0 → 100644
... ... @@ -0,0 +1,42 @@
  1 +# encoding: utf-8
  2 +
  3 +class FileUploader < CarrierWave::Uploader::Base
  4 + storage :file
  5 +
  6 + def store_dir
  7 + "uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
  8 + end
  9 +
  10 + # Provide a default URL as a default if there hasn't been a file uploaded:
  11 + # def default_url
  12 + # # For Rails 3.1+ asset pipeline compatibility:
  13 + # # ActionController::Base.helpers.asset_path("fallback/" + [version_name, "default.png"].compact.join('_'))
  14 + #
  15 + # "/images/fallback/" + [version_name, "default.png"].compact.join('_')
  16 + # end
  17 +
  18 + # Process files as they are uploaded:
  19 + # process :scale => [200, 300]
  20 + #
  21 + # def scale(width, height)
  22 + # # do something
  23 + # end
  24 +
  25 + # Create different versions of your uploaded files:
  26 + # version :thumb do
  27 + # process :resize_to_fit => [50, 50]
  28 + # end
  29 +
  30 + # Add a white list of extensions which are allowed to be uploaded.
  31 + # For images you might use something like this:
  32 + # def extension_white_list
  33 + # %w(jpg jpeg gif png)
  34 + # end
  35 +
  36 + # Override the filename of the uploaded files:
  37 + # Avoid using model.id or version_name here, see uploader/store.rb for details.
  38 + # def filename
  39 + # "something.jpg" if original_filename
  40 + # end
  41 +
  42 +end
... ...
app/views/layouts/application.html.erb
... ... @@ -72,15 +72,13 @@
72 72 </div>
73 73  
74 74 <div class="container">
75   - <div class="body"></div>
76   -
77 75 <% if content_for?(:menu) %>
78 76 <div class="breadcrumb">
79 77 <%= yield :menu %>
80 78 </div>
81 79 <% end %>
82 80  
83   - <div class="container-fluid">
  81 +
84 82 <% flash.each do |type, message| %>
85 83 <div class="alert <%= bootstrap_class_for(type) %> fade in">
86 84 <button class="close" data-dismiss="alert">×</button>
... ... @@ -89,7 +87,7 @@
89 87 <% end %>
90 88  
91 89 <%= yield %>
92   - </div>
  90 +
93 91 <footer>
94 92 <p>GTAaaS - <%= t('shared.project') %> <a href="http://gtaaas.lavid.ufpb.br" target="_blank">LAVID</a> | &copy; <%= Time.now.year %>. <%= t('shared.copyright') %>.</p>
95 93 </footer>
... ...
app/views/v_libras/requests/rapid.haml
... ... @@ -4,7 +4,7 @@
4 4 %h2
5 5 = t('videos.new')
6 6  
7   - = form_tag v_libras_requests_path, method: :post do |f|
  7 + = form_tag v_libras_requests_path, method: :post, :multipart => true do |f|
8 8 - if @request.errors.any?
9 9 #error_explanation
10 10 %p/
... ... @@ -22,28 +22,27 @@
22 22 = radio_button_tag :service, 'video', false, :id => 'service-video'
23 23 Voz
24 24 %label.radio
25   - = radio_button_tag :service, 'video-subtitle', false, :id => 'service-video-subtitle'
  25 + = radio_button_tag :service, 'video-legenda', false, :id => 'service-video-subtitle'
26 26 Legenda (.SRT)
27 27  
28 28 #url.hide
29   - = label_tag :url, t('videos.url'), :class => "bold"
30   - = file_field_tag :url, :onchange => "return check_video(this)"
  29 + = label_tag :video, t('videos.url'), :class => "bold"
  30 + = file_field_tag :video, :onchange => "return check_video(this)"
31 31 #legend.hide
32   - = label_tag :legend, t('videos.subtitle'), :class => "bold"
33   - = file_field_tag :legend, :prompt => "LEGENDA", :onchange => "return check_subtitle(this)"
  32 + = label_tag :subtitle, t('videos.subtitle'), :class => "bold"
  33 + = file_field_tag :subtitle, :prompt => "LEGENDA", :onchange => "return check_subtitle(this)"
34 34 .field
35   - = label_tag 'params[:window_size]', t('videos.window_size'), :class => "bold"
36   - = select_tag 'params[:window_size]', options_for_select([['Pequena', 'pequeno'], ['Média', 'medio'], ['Grande', 'grande']])
  35 + = label_tag 'params[tamanho]', t('videos.window_size'), :class => "bold"
  36 + = select_tag 'params[tamanho]', options_for_select([['Pequena', 'pequeno'], ['Média', 'medio'], ['Grande', 'grande']])
37 37 .field
38 38 %p
39 39 %b
40   - = label_tag 'params[:window_position]', t('videos.window_position'), :class => "bold"
41   - = select_tag 'params[:window_position]', options_for_select([[t('videos.top_left'),
  40 + = label_tag 'params[posicao]', t('videos.window_position'), :class => "bold"
  41 + = select_tag 'params[posicao]', options_for_select([[t('videos.top_left'),
42 42 'superior-esquerdo'], [t('videos.top_right'), 'superior-direito'],
43 43 [t('videos.bottom_right'),'inferior-direito'], [t('videos.bottom_left'), 'inferior-esquerdo']])
44 44 .field
45   - = label_tag 'params[:transparency]', t('videos.transparency'), :class => "bold"
46   - = select_tag 'params[:transparency]', options_for_select([['Opaco', 'opaco'], ['Transparente', 'transparente']])
47   - = hidden_field_tag :user_id, :value => current_user.id
  45 + = label_tag 'params[transparencia]', t('videos.transparency'), :class => "bold"
  46 + = select_tag 'params[transparencia]', options_for_select([['Opaco', 'opaco'], ['Transparente', 'transparente']])
48 47 = submit_tag "Confirmar", :class => "btn btn-primary actions"
49 48  
... ...
app/views/v_libras/videos/index.haml
1 1 .breadcrumb
2 2 %h3= t('videos.list')
3 3  
4   -.row
  4 +.row.text-center
5 5 - @videos.each do |video|
6   - .span3
7   - = link_to image_tag("avatar.png"), video_path(video)
  6 + .span4
  7 + = link_to image_tag("avatar.png"), video.url
8 8 %p
9 9 = link_to t('videos.show'), video_path(video), class: "btn btn-success"
10 10 = link_to t('videos.delete'), video_path(video), confirm: t('shared.confirm_delete'), method: :delete, class: "btn btn-danger"
11 11  
12   -
13 12 .breadcrumb.requests
14 13 %h4= t('requests.list')
15 14  
16   -.row
17   - %table.table.table-hover.table-striped.table-requests.span6.offset3
  15 +.row-fluid
  16 + %table.table.table-hover.table-striped.table-requests.span8.offset2
18 17 %thead
19 18 %tr
20 19 %th Situação
... ... @@ -23,9 +22,9 @@
23 22  
24 23 - @requests.each do |request|
25 24 %tr
26   - %td.span1= request_status_label(request.status)
27   - %td.span2 Vídeo
28   - %td.span3= time_ago_in_words(request.created_at)
  25 + %td.span2= request_status_label(request.status)
  26 + %td.span5= request.video_filename
  27 + %td.span5= time_ago_in_words(request.created_at)
29 28  
30 29  
31 30  
... ...
config/initializers/active_admin.rb
... ... @@ -195,11 +195,11 @@ ActiveAdmin.setup do |config|
195 195 #
196 196 # If you wanted to add a static menu item to the default menu provided:
197 197 #
198   - # config.namespace :admin do |admin|
199   - # admin.build_menu :default do |menu|
200   - # menu.add label: "My Great Website", url: "http://www.mygreatwebsite.com", html_options: { target: :blank }
201   - # end
202   - # end
  198 + config.namespace :admin do |admin|
  199 + admin.build_menu :default do |menu|
  200 + menu.add label: 'Background Jobs Admin', url: 'delayed_job'
  201 + end
  202 + end
203 203  
204 204  
205 205 # == Download Links
... ...
config/initializers/can_access_delayed_job_web.rb 0 → 100644
... ... @@ -0,0 +1,7 @@
  1 +class CanAccessDelayedJobWeb
  2 + def self.matches?(request)
  3 + current_user = request.env['warden'].user
  4 + return false if current_user.blank?
  5 + Ability.new(current_user).can? :manage, DelayedJobWeb
  6 + end
  7 +end
0 8 \ No newline at end of file
... ...
config/locales/pt-BR.yml
... ... @@ -9,6 +9,10 @@ pt-BR:
9 9 error: 'Erro'
10 10 success: 'Sucesso'
11 11  
  12 + error:
  13 + api:
  14 + offline: 'O serviço de tradução de LIBRAS está fora do ar. Iremos notificar o administrador. Desculpe-nos o inconveniente.'
  15 +
12 16 shared:
13 17 main: "MENU"
14 18 about: "SOBRE O PROJETO"
... ...
config/routes.rb
1 1 Rails.application.routes.draw do
2 2 devise_for :users, ActiveAdmin::Devise.config
3 3  
  4 + constraints CanAccessDelayedJobWeb do
  5 + namespace :admin do
  6 + match "/delayed_job" => DelayedJobWeb, :anchor => false, via: [:get, :post]
  7 + end
  8 + end
  9 +
4 10 ActiveAdmin.routes(self)
5 11  
6 12 root 'static#home', as: :home
... ... @@ -8,9 +14,12 @@ Rails.application.routes.draw do
8 14 namespace :v_libras do
9 15 resources :requests, :only => [ :new, :create ] do
10 16 get 'rapid', on: :collection
  17 + post 'callback', on: :collection
11 18 end
12 19  
13 20 resources :videos, :only => [ :index ]
  21 +
  22 +
14 23 end
15 24  
16 25 end
... ...
db/migrate/20140523175644_add_video_filename_to_request.rb 0 → 100644
... ... @@ -0,0 +1,5 @@
  1 +class AddVideoFilenameToRequest < ActiveRecord::Migration
  2 + def change
  3 + add_column :v_libras_requests, :video_filename, :string
  4 + end
  5 +end
... ...
db/schema.rb
... ... @@ -11,7 +11,7 @@
11 11 #
12 12 # It's strongly recommended that you check this file into your version control system.
13 13  
14   -ActiveRecord::Schema.define(version: 20140522160613) do
  14 +ActiveRecord::Schema.define(version: 20140523175644) do
15 15  
16 16 create_table "delayed_jobs", force: true do |t|
17 17 t.integer "priority", default: 0, null: false
... ... @@ -74,6 +74,7 @@ ActiveRecord::Schema.define(version: 20140522160613) do
74 74 t.text "response"
75 75 t.datetime "created_at"
76 76 t.datetime "updated_at"
  77 + t.string "video_filename"
77 78 end
78 79  
79 80 create_table "v_libras_videos", force: true do |t|
... ...
lib/api_client/callback_processor.rb 0 → 100644
... ... @@ -0,0 +1,7 @@
  1 +class ApiClient::CallbackProcessor
  2 + def self.process(params)
  3 + request = VLibras::Request.find(params[:request_id])
  4 + request.update(:status => 'success')
  5 + request.create_video(:url => params['response'])
  6 + end
  7 +end
0 8 \ No newline at end of file
... ...
lib/api_client/client.rb
1 1 require 'httparty'
2 2  
3 3 module ApiClient::Client
4   - include HTTParty
  4 + include HTTMultiParty
5 5 default_timeout 10 * 60
6 6  
7   - def self.submit(request)
8   - request.update(status: 'processing')
  7 + def self.submit(request, files)
  8 + o = { query: request.params.clone }
  9 + o[:query].merge!({ :servico => request.service_type })
  10 + o[:query].merge!({ :callback => "http://150.165.205.192:3000/v_libras/requests/callback?request_id=#{request.id}" })
9 11  
10   - options = { query: request.params }
  12 + o[:query].merge!({ :video => files[:video].file.to_file })
11 13  
12   - Delayed::Worker.logger.debug "[VLibras::Request] Options: #{options}"
  14 + unless files[:subtitle].file.nil?
  15 + o[:query].merge!({ :legenda => files[:subtitle].file.to_file })
  16 + o[:query].merge!({ :linguagem => 'portugues' })
  17 + end
13 18  
14   - binding.pry
  19 + Delayed::Worker.logger.debug "[VLibras::Request] Options: #{o}"
15 20  
16   - response = self.post(url_with_service('texto'), { query: { texto: 'bola', transparencia: 'opaco' } })
  21 + response = self.post(ApiClient::API_URL, o)
17 22  
18 23 Delayed::Worker.logger.debug "[VLibras::Request] Status #{response.response.code}"
19 24  
20 25 if response.response.code == '200'
21   - request.create_video(:url => response.parsed_response['response'])
22   - request.update(:status => 'success')
  26 +
23 27 else
24   - request.update(:response => response.body, :status => 'error')
  28 + request.update!(:response => response.body, :status => 'error')
25 29 end
  30 + rescue
  31 +
26 32 end
27 33  
28 34 private
... ...