From b174b1dede0af9e5d24b24c7dff3c17c0181e2bf Mon Sep 17 00:00:00 2001 From: Fernando Brito Date: Fri, 23 May 2014 10:43:59 -0300 Subject: [PATCH] ApiClient --- lib/api_client.rb | 14 ++++++++++++++ lib/api_client/client.rb | 32 ++++++++++++++++++++++++++++++++ lib/api_client/service/video.rb | 3 +++ lib/api_client/service/video_subtitle.rb | 2 ++ 4 files changed, 51 insertions(+), 0 deletions(-) create mode 100644 lib/api_client.rb create mode 100644 lib/api_client/client.rb create mode 100644 lib/api_client/service/video.rb create mode 100644 lib/api_client/service/video_subtitle.rb diff --git a/lib/api_client.rb b/lib/api_client.rb new file mode 100644 index 0000000..d378e78 --- /dev/null +++ b/lib/api_client.rb @@ -0,0 +1,14 @@ +class ApiClient + API_URL = 'http://150.165.204.30:5000/api' + + def self.check_status + begin + ApiClient::Client.post(ApiClient::API_URL) + rescue + return false + end + + return true + end + +end diff --git a/lib/api_client/client.rb b/lib/api_client/client.rb new file mode 100644 index 0000000..699ba2b --- /dev/null +++ b/lib/api_client/client.rb @@ -0,0 +1,32 @@ +require 'httparty' + +module ApiClient::Client + include HTTParty + default_timeout 10 * 60 + + def self.submit(request) + request.update(status: 'processing') + + options = { query: request.params } + + Delayed::Worker.logger.debug "[VLibras::Request] Options: #{options}" + + binding.pry + + response = self.post(url_with_service('texto'), { query: { texto: 'bola', transparencia: 'opaco' } }) + + Delayed::Worker.logger.debug "[VLibras::Request] Status #{response.response.code}" + + if response.response.code == '200' + request.create_video(:url => response.parsed_response['response']) + request.update(:status => 'success') + else + request.update(:response => response.body, :status => 'error') + end + end + +private + def self.url_with_service(service) + URI.encode("#{ApiClient::API_URL}?servico=#{service}") + end +end \ No newline at end of file diff --git a/lib/api_client/service/video.rb b/lib/api_client/service/video.rb new file mode 100644 index 0000000..dbee337 --- /dev/null +++ b/lib/api_client/service/video.rb @@ -0,0 +1,3 @@ +module ApiClient::Service::Video + +end \ No newline at end of file diff --git a/lib/api_client/service/video_subtitle.rb b/lib/api_client/service/video_subtitle.rb new file mode 100644 index 0000000..c8f959a --- /dev/null +++ b/lib/api_client/service/video_subtitle.rb @@ -0,0 +1,2 @@ +class ApiClient::Service::VideoSubtitle +end \ No newline at end of file -- libgit2 0.21.2