class Pdftable::Connection

Attributes

configuration[R]

Public Class Methods

new() click to toggle source
# File lib/pdftable/connection.rb, line 6
def initialize
        @configuration = Pdftable::Configuration.instance
end

Public Instance Methods

get(path) click to toggle source
# File lib/pdftable/connection.rb, line 10
def get (path)
        opt = { key: configuration.key }
        res = RestClient.get url(path, opt)
        parse_response(res)
end
post(path, file:, format:) click to toggle source
# File lib/pdftable/connection.rb, line 16
def post (path, file:, format:)
        opt = {  key: configuration.key, format: format }
        res = RestClient.post url(path, opt), file: File.new(file, 'rb')
        parse_response(res)
        #req = RestClient::Request.new method: :post, url:  uri, payload: { multipart: true, file: File.new("pdf_table.pdf", 'rb')}, headers: {params: {key: 'abcde', format: "xml"}}
        #response = req.execute
end

Private Instance Methods

parse_response(res) click to toggle source
# File lib/pdftable/connection.rb, line 30
def parse_response(res)
        res.body
end
url(path, opt) click to toggle source
# File lib/pdftable/connection.rb, line 26
def url(path, opt)
        URI::HTTPS.build(host: configuration.host, path: path, query: URI.encode_www_form(opt)).to_s
end