Class: DynamicPDFApi::PdfText
- Defined in:
- lib/ruby_client/PdfText.rb
Overview
Represents the pdf text endpoint.
Instance Attribute Summary collapse
-
#page_count ⇒ Object
Gets or sets the page count.
-
#start_page ⇒ Object
Gets or sets the start page.
-
#text_order ⇒ Object
Gets or sets the text extraction order.
Attributes inherited from Endpoint
#_endpoint_name, #api_key, #base_url
Instance Method Summary collapse
-
#initialize(resource, start_page = 1, page_count = 0, text_order = TextOrder::STREAM) ⇒ PdfText
constructor
Initializes a new instance of the PdfText class.
-
#process ⇒ Object
Process the pdf resource to get pdf’s text.
Methods inherited from Endpoint
Constructor Details
#initialize(resource, start_page = 1, page_count = 0, text_order = TextOrder::STREAM) ⇒ PdfText
Initializes a new instance of the PdfText class.
18 19 20 21 22 23 24 25 |
# File 'lib/ruby_client/PdfText.rb', line 18 def initialize(resource, start_page = 1, page_count = 0, text_order = TextOrder::STREAM) @_endpoint_name = 'pdf-text' super() @resource = resource @start_page = start_page @page_count = page_count @text_order = text_order end |
Instance Attribute Details
#page_count ⇒ Object
Gets or sets the page count.
35 36 37 |
# File 'lib/ruby_client/PdfText.rb', line 35 def page_count @page_count end |
#start_page ⇒ Object
Gets or sets the start page.
30 31 32 |
# File 'lib/ruby_client/PdfText.rb', line 30 def start_page @start_page end |
#text_order ⇒ Object
Gets or sets the text extraction order.
40 41 42 |
# File 'lib/ruby_client/PdfText.rb', line 40 def text_order @text_order end |
Instance Method Details
#process ⇒ Object
Process the pdf resource to get pdf’s text.
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/ruby_client/PdfText.rb', line 46 def process header = { 'Authorization': "Bearer #{@api_key}", 'Content-Length': @resource.data.length.to_s, 'Expect': '100-continue', 'Content-Type': 'application/pdf' } uri = URI.parse("#{@base_url}/v1.0/#{@_endpoint_name}") params = { 'startPage' => @start_page, 'pageCount' => @page_count, 'textOrder' => @text_order } uri.query = URI.encode_www_form(params) request = Net::HTTP::Post.new(uri.request_uri, header) request.set_form_data(params) = { use_ssl: uri.scheme == 'https', verify_mode: OpenSSL::SSL::VERIFY_NONE } request.content_type = 'application/pdf' request.body = @resource.data response = Net::HTTP.start(uri.hostname, uri.port, ) do |http| http.request(request) end out_data = response.body ret_object = PdfTextResponse.new(out_data) ret_object.is_successful = false ret_object.status_code = response.code if ret_object.status_code == '200' ret_object.is_successful = true else if ret_object.status_code == '401' raise "Invalid api key specified." end out_data_json = JSON.parse(out_data) ret_object.error_json = out_data ret_object. = if !out_data_json['message'].nil? out_data_json['message'] else "status_code : #{Net::HTTPResponse::CODE_TO_OBJ[ret_object.status_code]}" end ret_object.error_id = out_data_json['id'] end ret_object end |