Class: Pdfcrowd::ConnectionHelper

Inherits:
Object
  • Object
show all
Defined in:
lib/pdfcrowd.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(user_name, api_key) ⇒ ConnectionHelper

Returns a new instance of ConnectionHelper.



564
565
566
567
568
569
570
571
572
573
574
575
576
# File 'lib/pdfcrowd.rb', line 564

def initialize(user_name, api_key)
    @user_name = user_name
    @api_key = api_key

    reset_response_data()

    setProxy(nil, nil, nil, nil)
    setUseHttp(false)
    setUserAgent('pdfcrowd_ruby_client/6.5.4 (https://pdfcrowd.com)')

    @retry_count = 1
    @converter_version = '24.04'
end

Class Method Details

.add_file_field(name, file_name, data, body) ⇒ Object



657
658
659
660
661
662
663
# File 'lib/pdfcrowd.rb', line 657

def self.add_file_field(name, file_name, data, body)
    body << '--' + MULTIPART_BOUNDARY
    body << 'Content-Disposition: form-data; name="%s"; filename="%s"' % [name, file_name]
    body << 'Content-Type: application/octet-stream'
    body << ''
    body << data.force_encoding('UTF-8')
end

.encode_multipart_post_data(fields, files, raw_data) ⇒ Object



665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
# File 'lib/pdfcrowd.rb', line 665

def self.encode_multipart_post_data(fields, files, raw_data)
    body = []
    for field, value in fields
        body << '--' + MULTIPART_BOUNDARY << 'Content-Disposition: form-data; name="%s"' % field << '' << value.to_s if value
    end
    for name, file_name in files
        File.open(file_name, 'rb') do |f|
            ConnectionHelper.add_file_field(name, file_name, f.read, body)
        end
    end
    for name, data in raw_data
        ConnectionHelper.add_file_field(name, name, data, body)
    end
    # finalize
    body << '--' + MULTIPART_BOUNDARY + '--'
    body << ''
    body.join("\r\n")
end

Instance Method Details

#getConsumedCreditCountObject



616
617
618
# File 'lib/pdfcrowd.rb', line 616

def getConsumedCreditCount()
    @consumed_credits
end

#getConverterVersionObject



636
637
638
# File 'lib/pdfcrowd.rb', line 636

def getConverterVersion()
    @converter_version
end

#getDebugLogUrlObject



608
609
610
# File 'lib/pdfcrowd.rb', line 608

def getDebugLogUrl()
    @debug_log_url
end

#getJobIdObject



620
621
622
# File 'lib/pdfcrowd.rb', line 620

def getJobId()
    @job_id
end

#getOutputSizeObject



632
633
634
# File 'lib/pdfcrowd.rb', line 632

def getOutputSize()
    @output_size
end

#getPageCountObject



624
625
626
# File 'lib/pdfcrowd.rb', line 624

def getPageCount()
    @page_count
end

#getRemainingCreditCountObject



612
613
614
# File 'lib/pdfcrowd.rb', line 612

def getRemainingCreditCount()
    @credits
end

#getTotalPageCountObject



628
629
630
# File 'lib/pdfcrowd.rb', line 628

def getTotalPageCount()
    @total_page_count
end

#post(fields, files, raw_data, out_stream = nil) ⇒ Object



578
579
580
581
582
583
# File 'lib/pdfcrowd.rb', line 578

def post(fields, files, raw_data, out_stream = nil)
    request = create_request()
    request.body = ConnectionHelper.encode_multipart_post_data(fields, files, raw_data)
    request.content_type = 'multipart/form-data; boundary=' + MULTIPART_BOUNDARY
    do_post(request, out_stream)
end

#setConverterVersion(converter_version) ⇒ Object



597
598
599
# File 'lib/pdfcrowd.rb', line 597

def setConverterVersion(converter_version)
    @converter_version = converter_version
end

#setProxy(host, port, user_name, password) ⇒ Object



601
602
603
604
605
606
# File 'lib/pdfcrowd.rb', line 601

def setProxy(host, port, user_name, password)
    @proxy_host = host
    @proxy_port = port
    @proxy_user_name = user_name
    @proxy_password = password
end

#setRetryCount(retry_count) ⇒ Object



593
594
595
# File 'lib/pdfcrowd.rb', line 593

def setRetryCount(retry_count)
    @retry_count = retry_count
end

#setUseHttp(use_http) ⇒ Object



585
586
587
# File 'lib/pdfcrowd.rb', line 585

def setUseHttp(use_http)
    @use_http = use_http
end

#setUserAgent(user_agent) ⇒ Object



589
590
591
# File 'lib/pdfcrowd.rb', line 589

def setUserAgent(user_agent)
    @user_agent = user_agent
end