ruby-superparser 0.1.1 → 0.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/README.md +5 -5
- data/lib/generators/ruby_superparser/install_generator.rb +3 -3
- data/lib/generators/ruby_superparser/templates/initializer.rb +8 -3
- data/lib/generators/ruby_superparser/templates/superparser_job.rb +8 -0
- data/lib/ruby/superparser.rb +1 -1
- data/lib/superparser/client.rb +45 -0
- data/lib/superparser/configuration.rb +10 -0
- data/lib/superparser/superparser_integration.rb +30 -0
- data/lib/superparser/version.rb +5 -0
- data/lib/superparser.rb +25 -0
- data/ruby-superparser.gemspec +2 -2
- metadata +7 -4
- data/lib/ruby/superparser/version.rb +0 -7
- data/lib/ruby_superparser/superparser_integration.rb +0 -28
- data/lib/ruby_superparser.rb +0 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 966b314dde85d0109c5872422b83de9790afc0a737b72015e8d01f179591e65d
|
4
|
+
data.tar.gz: c895cf21e08a98032df020d8fdd0deb85c92bddf17583b2f757faf5802612106
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7b076db61b72dcf4727c02f2d8778c594f31770d41740a87fffd15c50df98ae314855bdb5deab74e169623b771e6d8e42e889d96d17fc8e139c00634edd1e863
|
7
|
+
data.tar.gz: f73d66dec856aeecb713a152577ec6f625114ec8b8408cb12bf0294eca7668d597b2c58b9105088ebbb05640f886eea9b8768cfa95b3966cfc6653b7ad717b4d
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -35,10 +35,10 @@ export SUPERPARSER_API_KEY=your_api_key_here
|
|
35
35
|
To use this gem in a Rails application, run the generator to create an initializer:
|
36
36
|
|
37
37
|
```sh
|
38
|
-
rails generate
|
38
|
+
rails generate superparser:install
|
39
39
|
```
|
40
40
|
|
41
|
-
This will create a `config/initializers/
|
41
|
+
This will create a `config/initializers/superparser.rb` file, which initializes the `SUPERPARSER_CLIENT` constant.
|
42
42
|
|
43
43
|
Now you can use the gem throughout your Rails application:
|
44
44
|
|
@@ -52,11 +52,11 @@ puts json_result
|
|
52
52
|
In other Ruby applications, create a `Client` instance and use it to parse resumes:
|
53
53
|
|
54
54
|
```ruby
|
55
|
-
require '
|
55
|
+
require 'superparser'
|
56
56
|
|
57
57
|
api_key = ENV['SUPERPARSER_API_KEY']
|
58
|
-
client =
|
59
|
-
json_result = client.
|
58
|
+
client = Superparser::Client.new(api_key)
|
59
|
+
json_result = client.parse('path/to/your/resume.pdf')
|
60
60
|
puts json_result
|
61
61
|
```
|
62
62
|
|
@@ -1,13 +1,13 @@
|
|
1
|
-
# lib/generators/
|
1
|
+
# lib/generators/superparser/install_generator.rb
|
2
2
|
|
3
3
|
require 'rails/generators/base'
|
4
4
|
|
5
|
-
module
|
5
|
+
module Superparser
|
6
6
|
class InstallGenerator < Rails::Generators::Base
|
7
7
|
source_root File.expand_path('templates', __dir__)
|
8
8
|
|
9
9
|
def create_initializer_file
|
10
|
-
copy_file 'initializer.rb', 'config/initializers/
|
10
|
+
copy_file 'initializer.rb', 'config/initializers/superparser.rb'
|
11
11
|
end
|
12
12
|
end
|
13
13
|
end
|
@@ -1,4 +1,9 @@
|
|
1
|
-
# lib/generators/
|
1
|
+
# lib/generators/superparser/templates/initializer.rb
|
2
2
|
|
3
|
-
|
4
|
-
|
3
|
+
Superparser.init do |config|
|
4
|
+
config.api_key = ENV['SUPERPARSER_API_KEY']
|
5
|
+
|
6
|
+
config.async = lambda { |document_id|
|
7
|
+
SuperparserJob.perform_later(document_id)
|
8
|
+
}
|
9
|
+
end
|
data/lib/ruby/superparser.rb
CHANGED
@@ -0,0 +1,45 @@
|
|
1
|
+
# lib/superparser.rb
|
2
|
+
|
3
|
+
require 'net/http'
|
4
|
+
require 'net/http/post/multipart'
|
5
|
+
|
6
|
+
module Superparser
|
7
|
+
class Client
|
8
|
+
API_URL = 'https://api.superparser.com/parse'.freeze
|
9
|
+
|
10
|
+
def initialize(config)
|
11
|
+
@api_key = config.api_key
|
12
|
+
end
|
13
|
+
|
14
|
+
def parse(data_resource)
|
15
|
+
uri = URI(API_URL)
|
16
|
+
|
17
|
+
if data_resource.is_a?(ActiveStorage::Blob)
|
18
|
+
file_data = StringIO.new(data_resource.download)
|
19
|
+
file_name = 'resume.pdf'
|
20
|
+
else
|
21
|
+
file_data = StringIO.new(data_resource)
|
22
|
+
file_name = 'resume.pdf'
|
23
|
+
end
|
24
|
+
|
25
|
+
request = Net::HTTP::Post::Multipart.new(uri.path,
|
26
|
+
'file_name' => UploadIO.new(file_data, 'application/pdf', file_name)
|
27
|
+
)
|
28
|
+
|
29
|
+
request['X-API-Key'] = @api_key
|
30
|
+
|
31
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
32
|
+
http.use_ssl = true
|
33
|
+
|
34
|
+
response = http.request(request)
|
35
|
+
|
36
|
+
if response.is_a?(Net::HTTPSuccess)
|
37
|
+
puts 'Successfully parsed the document'
|
38
|
+
return response.body
|
39
|
+
else
|
40
|
+
puts 'Failed to parse the document'
|
41
|
+
return nil
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
# lib/superparser/superparser_integration.rb
|
2
|
+
|
3
|
+
module Superparser
|
4
|
+
module SuperparserIntegration
|
5
|
+
extend ActiveSupport::Concern
|
6
|
+
|
7
|
+
class_methods do
|
8
|
+
def superparser_for_attached(attached_attribute, options = {})
|
9
|
+
@attached_attribute = attached_attribute
|
10
|
+
after_save :process_document_with_superparser, if: -> { saved_change_to_attribute?(@attached_attribute) }
|
11
|
+
|
12
|
+
define_method :process_document_with_superparser do
|
13
|
+
if options[:async]
|
14
|
+
Superparser.config.async.call(id)
|
15
|
+
else
|
16
|
+
superparser_client.parse(send(attached_attribute))
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
private
|
23
|
+
|
24
|
+
def superparser_client
|
25
|
+
@superparser_client ||= Superparser::Client.new(Superparser.config)
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
data/lib/superparser.rb
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
# lib/superparser.rb
|
2
|
+
|
3
|
+
require "superparser/version"
|
4
|
+
require "superparser/configuration"
|
5
|
+
require "superparser/client"
|
6
|
+
# require "superparser/superparser_integration"
|
7
|
+
|
8
|
+
module Superparser
|
9
|
+
class Error < StandardError; end
|
10
|
+
|
11
|
+
def self.init
|
12
|
+
@config = Configuration.new
|
13
|
+
yield @config if block_given?
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.config
|
17
|
+
@config
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
# Include the SuperparserIntegration module in ActiveRecord::Base
|
22
|
+
# ActiveSupport.on_load(:active_record) do
|
23
|
+
# include Superparser::SuperparserIntegration
|
24
|
+
# end
|
25
|
+
|
data/ruby-superparser.gemspec
CHANGED
@@ -1,10 +1,10 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require_relative "lib/
|
3
|
+
require_relative "lib/superparser/version"
|
4
4
|
|
5
5
|
Gem::Specification.new do |spec|
|
6
6
|
spec.name = "ruby-superparser"
|
7
|
-
spec.version =
|
7
|
+
spec.version = Superparser::VERSION
|
8
8
|
spec.authors = ["JP Silvashy"]
|
9
9
|
spec.email = ["jpsilvashy@gmail.com"]
|
10
10
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ruby-superparser
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- JP Silvashy
|
@@ -43,10 +43,13 @@ files:
|
|
43
43
|
- bin/setup
|
44
44
|
- lib/generators/ruby_superparser/install_generator.rb
|
45
45
|
- lib/generators/ruby_superparser/templates/initializer.rb
|
46
|
+
- lib/generators/ruby_superparser/templates/superparser_job.rb
|
46
47
|
- lib/ruby/superparser.rb
|
47
|
-
- lib/
|
48
|
-
- lib/
|
49
|
-
- lib/
|
48
|
+
- lib/superparser.rb
|
49
|
+
- lib/superparser/client.rb
|
50
|
+
- lib/superparser/configuration.rb
|
51
|
+
- lib/superparser/superparser_integration.rb
|
52
|
+
- lib/superparser/version.rb
|
50
53
|
- ruby-superparser.gemspec
|
51
54
|
- sig/ruby/superparser.rbs
|
52
55
|
homepage: https://github.com/jpsilvashy/ruby-superparser
|
@@ -1,28 +0,0 @@
|
|
1
|
-
# lib/ruby_superparser/superparser_integration.rb
|
2
|
-
|
3
|
-
module RubySuperparser
|
4
|
-
module SuperparserIntegration
|
5
|
-
extend ActiveSupport::Concern
|
6
|
-
|
7
|
-
class_methods do
|
8
|
-
def superparser_for_attached(attached_attribute, options = {})
|
9
|
-
after_save :process_document_with_superparser, if: "saved_change_to_attribute?(:#{attached_attribute})"
|
10
|
-
|
11
|
-
define_method :process_document_with_superparser do
|
12
|
-
if options[:async]
|
13
|
-
RubySuperparser::DocumentProcessorWorker.perform_async(id)
|
14
|
-
else
|
15
|
-
superparser_client.parse_resume(send(attached_attribute))
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
private
|
22
|
-
|
23
|
-
def superparser_client
|
24
|
-
api_key = ENV['SUPERPARSER_API_KEY']
|
25
|
-
@superparser_client ||= RubySuperparser::Client.new(api_key)
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|