Class: Superparser::Client
- Inherits:
-
Object
- Object
- Superparser::Client
- Defined in:
- lib/superparser/client.rb
Constant Summary collapse
- API_URL =
'https://api.superparser.com/parse'.freeze
Instance Method Summary collapse
-
#initialize(config) ⇒ Client
constructor
A new instance of Client.
- #parse(data_resource) ⇒ Object
Constructor Details
#initialize(config) ⇒ Client
Returns a new instance of Client.
10 11 12 |
# File 'lib/superparser/client.rb', line 10 def initialize(config) @api_key = config.api_key end |
Instance Method Details
#parse(data_resource) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/superparser/client.rb', line 14 def parse(data_resource) uri = URI(API_URL) if data_resource.is_a?(ActiveStorage::Blob) file_data = StringIO.new(data_resource.download) file_name = 'resume.pdf' else file_data = StringIO.new(data_resource) file_name = 'resume.pdf' end request = Net::HTTP::Post::Multipart.new(uri.path, 'file_name' => UploadIO.new(file_data, 'application/pdf', file_name) ) request['X-API-Key'] = @api_key http = Net::HTTP.new(uri.host, uri.port) http.use_ssl = true response = http.request(request) if response.is_a?(Net::HTTPSuccess) puts 'Successfully parsed the document' return response.body else puts 'Failed to parse the document' return nil end end |