Class: DynamicPDFApi::ImageInfo
- Defined in:
- lib/ruby_client/ImageInfo.rb
Overview
Represents an image information endpoint.
Instance Attribute Summary
Attributes inherited from Endpoint
#_endpoint_name, #api_key, #base_url
Instance Method Summary collapse
-
#initialize(resource) ⇒ ImageInfo
constructor
Initializes a new instance of the ImageInfo class.
-
#process ⇒ Object
Process the image resource to get image’s information.
Methods inherited from Endpoint
Constructor Details
#initialize(resource) ⇒ ImageInfo
Initializes a new instance of the ImageInfo class.
ImageResource resource The image resource of type ImageResource.
14 15 16 17 18 |
# File 'lib/ruby_client/ImageInfo.rb', line 14 def initialize(resource) @_endpoint_name = 'image-info' super() @resource = resource end |
Instance Method Details
#process ⇒ Object
Process the image resource to get image’s information.
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/ruby_client/ImageInfo.rb', line 25 def process header = { 'Authorization': "Bearer #{@api_key}", 'Content-Length': @resource.data.length.to_s, 'Expect': '100-continue', 'Content-Type': "image/#{@resource._file_extension[1, @resource._file_extension.length - 1]}" } uri = URI.parse("#{@base_url}/v1.0/#{@_endpoint_name}") request = Net::HTTP::Post.new(uri.request_uri, header) = { use_ssl: uri.scheme == 'https', verify_mode: OpenSSL::SSL::VERIFY_NONE } request.content_type = "image/#{@resource._file_extension[1, @resource._file_extension.length - 1]}" request.body = @resource.data response = Net::HTTP.start(uri.hostname, uri.port, ) do |http| http.request(request) end out_data = response.body ret_object = ImageResponse.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 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 |