class PandaGo::Converter
Constants
- BOUNDARY
Attributes
config[R]
read_format[R]
source_io[R]
write_format[R]
Public Class Methods
new(source_io, read_format, write_format, config)
click to toggle source
# File lib/pandago/converter.rb, line 10 def initialize(source_io, read_format, write_format, config) @source_io, @read_format, @write_format = source_io, read_format, write_format @config = config end
Public Instance Methods
body()
click to toggle source
# File lib/pandago/converter.rb, line 44 def body source_io.rewind <<~BODY --#{ BOUNDARY } Content-Disposition: form-data; name="from" #{ read_format } --#{ BOUNDARY } Content-Disposition: form-data; name="to" #{ write_format } --#{ BOUNDARY } Content-Disposition: form-data; name="payload"; filename="payload" Content-Type: #{ ContentTypes[read_format] } #{ source_io.read } --#{ BOUNDARY }-- BODY end
convert()
click to toggle source
# File lib/pandago/converter.rb, line 15 def convert if response.code == "200" StringIO.new(response.body) else raise RequestError, response end end
header()
click to toggle source
# File lib/pandago/converter.rb, line 40 def header { "content-type" => "multipart/form-data; charset=utf-8; boundary=#{ BOUNDARY }" } end
request()
click to toggle source
# File lib/pandago/converter.rb, line 23 def request return @request if defined? @request @request = Net::HTTP::Post.new("/convert", header) @request.body = body @request end
response()
click to toggle source
# File lib/pandago/converter.rb, line 30 def response return @response if defined? @response raise UrlNotSetError if config.url.nil? http = Net::HTTP.new(config.host, config.port) http.read_timeout = config.timeout @response = http.request(request) rescue Net::ReadTimeout raise TimeoutError end