ruby-superparser 0.1.1 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 562838c888b03c5ee50200cfcdc414964b48357fa808987d1b621b5f414db8e0
4
- data.tar.gz: 9174a3c5e4598135047ba2ea1e6e2f9e5054e11c2502f88eb6056db9a4565774
3
+ metadata.gz: 966b314dde85d0109c5872422b83de9790afc0a737b72015e8d01f179591e65d
4
+ data.tar.gz: c895cf21e08a98032df020d8fdd0deb85c92bddf17583b2f757faf5802612106
5
5
  SHA512:
6
- metadata.gz: 4fba72973fc4195072b59d59e1d490a228dab41234d4e42e50f1a37d6baa2503645c65d67d944e66e9f141cb2811407ef8023880a0b0ddd24afb14983a9e23c2
7
- data.tar.gz: 8c74c7357eec6a85672d6adfcfca0f0c611630cbe0d9246c392dcb1a87e7581323190033dc829d3e0776f904621f4407bda2f72ce92c255bd96823cf632b719a
6
+ metadata.gz: 7b076db61b72dcf4727c02f2d8778c594f31770d41740a87fffd15c50df98ae314855bdb5deab74e169623b771e6d8e42e889d96d17fc8e139c00634edd1e863
7
+ data.tar.gz: f73d66dec856aeecb713a152577ec6f625114ec8b8408cb12bf0294eca7668d597b2c58b9105088ebbb05640f886eea9b8768cfa95b3966cfc6653b7ad717b4d
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- ruby-superparser (0.1.1)
4
+ ruby-superparser (0.1.3)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
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 ruby_superparser:install
38
+ rails generate superparser:install
39
39
  ```
40
40
 
41
- This will create a `config/initializers/ruby_superparser.rb` file, which initializes the `SUPERPARSER_CLIENT` constant.
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 'ruby_superparser'
55
+ require 'superparser'
56
56
 
57
57
  api_key = ENV['SUPERPARSER_API_KEY']
58
- client = RubySuperparser::Client.new(api_key)
59
- json_result = client.parse_resume('path/to/your/resume.pdf')
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/ruby_superparser/install_generator.rb
1
+ # lib/generators/superparser/install_generator.rb
2
2
 
3
3
  require 'rails/generators/base'
4
4
 
5
- module RubySuperparser
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/ruby_superparser.rb'
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/ruby_superparser/templates/initializer.rb
1
+ # lib/generators/superparser/templates/initializer.rb
2
2
 
3
- api_key = ENV['SUPERPARSER_API_KEY']
4
- SUPERPARSER_CLIENT = RubySuperparser::Client.new(api_key)
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
@@ -0,0 +1,8 @@
1
+ # lib/generators/superparser/templates/superparser_job.rb
2
+
3
+ class SuperparserJob < ApplicationJob
4
+ queue_as :default
5
+
6
+ def perform(document_id)
7
+ end
8
+ end
@@ -11,7 +11,7 @@ module RubySuperparser
11
11
  @api_key = api_key
12
12
  end
13
13
 
14
- def parse_resume(file_path)
14
+ def parse(file_path)
15
15
  uri = URI(API_URL)
16
16
 
17
17
  request = Net::HTTP::Post::Multipart.new(uri.path,
@@ -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,10 @@
1
+ module Superparser
2
+ class Configuration
3
+ attr_accessor :api_key, :async
4
+
5
+ def initialize
6
+ @api_key = nil
7
+ @async = nil
8
+ end
9
+ end
10
+ 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
+
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Superparser
4
+ VERSION = '0.1.3'
5
+ end
@@ -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
+
@@ -1,10 +1,10 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative "lib/ruby/superparser/version"
3
+ require_relative "lib/superparser/version"
4
4
 
5
5
  Gem::Specification.new do |spec|
6
6
  spec.name = "ruby-superparser"
7
- spec.version = Ruby::Superparser::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.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/ruby/superparser/version.rb
48
- - lib/ruby_superparser.rb
49
- - lib/ruby_superparser/superparser_integration.rb
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,7 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Ruby
4
- module Superparser
5
- VERSION = "0.1.1"
6
- end
7
- end
@@ -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
@@ -1,8 +0,0 @@
1
- # lib/ruby_superparser.rb
2
-
3
- require "ruby_superparser/version"
4
- require "ruby_superparser/client"
5
- require "ruby_superparser/superparser_integration"
6
-
7
- module RubySuperparser
8
- end