class Pdf4me::Client
Attributes
config[RW]
logger[R]
Public Class Methods
default()
click to toggle source
# File lib/pdf4me/client.rb, line 10 def self.default @@default ||= Client.new end
new(config = Configuration.default)
click to toggle source
# File lib/pdf4me/client.rb, line 6 def initialize(config = Configuration.default) @config = config end
Public Instance Methods
multipart_post(path, params) { |request| ... }
click to toggle source
# File lib/pdf4me/client.rb, line 22 def multipart_post(path, params) request = multipart_request(path, params) if block_given? yield request end request.run.tap do |response| validate_response!(response) end end
post(path, params)
click to toggle source
# File lib/pdf4me/client.rb, line 34 def post(path, params) request = Typhoeus::Request.new( request_url(path), method: :post, body: params, headers: { 'Accept': 'application/json', 'Content-Type': 'application/json', 'Authorization': "Basic #{config.token}", 'User-Agent': "Pdf4me/ruby/#{VERSION}" }, timeout: 0, ssl_verifypeer: true, ssl_verifyhost: 2, verbose: config.debugging ) request.run.tap do |response| validate_response!(response) end end
request_url(path)
click to toggle source
# File lib/pdf4me/client.rb, line 18 def request_url(path) URI.join(config.base_url, path) end
Private Instance Methods
multipart_request(path, params)
click to toggle source
# File lib/pdf4me/client.rb, line 58 def multipart_request(path, params) Typhoeus::Request.new( request_url(path), method: :post, body: params, headers: { 'Accept': 'application/octet-stream', 'Content-Type': 'multipart/form-data', 'Authorization': "Basic #{config.token}", 'User-Agent': "Pdf4me/ruby/#{VERSION}" }, timeout: 0, ssl_verifypeer: true, ssl_verifyhost: 2, verbose: config.debugging ) end
validate_response!(response)
click to toggle source
# File lib/pdf4me/client.rb, line 76 def validate_response!(response) unless response.success? if response.timed_out? fail ServerTimedOut.new('Server timed out') else fail ServerError.new(code: response.code, error: response.body) end end end