ruby-superparser 0.1.2 → 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: 27e79dbede1bacc8d5e082dd9e2eb06ce21d8f898d74e73a051e5cc507d3cfb4
4
- data.tar.gz: 7acc5017d71d14d3112db73a19948a34e87871ccb78b2e577581b74601ebb829
3
+ metadata.gz: 966b314dde85d0109c5872422b83de9790afc0a737b72015e8d01f179591e65d
4
+ data.tar.gz: c895cf21e08a98032df020d8fdd0deb85c92bddf17583b2f757faf5802612106
5
5
  SHA512:
6
- metadata.gz: 12d019e44100ef67b924fc176ca3a644b126c536e52be08ddee240b49d665f6e7591abd63ccc5e58c12290760c1051a5750310a521e20fd37881e7fc89223dcc
7
- data.tar.gz: 10ee3ccdb9b5990fe046c854430da080bf408f0756ca424118250e6306998dd4620102b6d868799daada7a17b6b82a717d4f3f32ccfbf4b1a22d8a418475949d
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.2)
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,6 +1,6 @@
1
- # lib/generators/ruby_superparser/templates/initializer.rb
1
+ # lib/generators/superparser/templates/initializer.rb
2
2
 
3
- RubySuperparser.init do |config|
3
+ Superparser.init do |config|
4
4
  config.api_key = ENV['SUPERPARSER_API_KEY']
5
5
 
6
6
  config.async = lambda { |document_id|
@@ -1,10 +1,8 @@
1
- # lib/generators/ruby_superparser/templates/superparser_job.rb
1
+ # lib/generators/superparser/templates/superparser_job.rb
2
2
 
3
3
  class SuperparserJob < ApplicationJob
4
4
  queue_as :default
5
5
 
6
6
  def perform(document_id)
7
- document = ExternalDocument.find(document_id)
8
- RubySuperparser.config.async.call(document)
9
7
  end
10
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
@@ -1,4 +1,4 @@
1
- module RubySuperparser
1
+ module Superparser
2
2
  class Configuration
3
3
  attr_accessor :api_key, :async
4
4
 
@@ -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 = RubySuperparser::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.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - JP Silvashy
@@ -44,11 +44,12 @@ files:
44
44
  - lib/generators/ruby_superparser/install_generator.rb
45
45
  - lib/generators/ruby_superparser/templates/initializer.rb
46
46
  - lib/generators/ruby_superparser/templates/superparser_job.rb
47
- - lib/ruby/superparser/version.rb
48
- - lib/ruby_superparser.rb
49
- - lib/ruby_superparser/client.rb
50
- - lib/ruby_superparser/configuration.rb
51
- - lib/ruby_superparser/superparser_integration.rb
47
+ - lib/ruby/superparser.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
52
53
  - ruby-superparser.gemspec
53
54
  - sig/ruby/superparser.rbs
54
55
  homepage: https://github.com/jpsilvashy/ruby-superparser
@@ -1,5 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module RubySuperparser
4
- VERSION = '0.1.2'
5
- end
@@ -1,29 +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.config.async.call(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
- @superparser_client ||= RubySuperparser::Client.new(RubySuperparser.config)
25
- end
26
-
27
- end
28
- end
29
-
@@ -1,16 +0,0 @@
1
- # lib/ruby_superparser.rb
2
-
3
- require_relative 'ruby/superparser/version'
4
- require_relative 'ruby_superparser/client'
5
- require_relative 'ruby_superparser/configuration'
6
- require_relative 'ruby_superparser/superparser_integration'
7
-
8
- module RubySuperparser
9
- def self.config
10
- @config ||= Configuration.new
11
- end
12
-
13
- def self.init
14
- yield config if block_given?
15
- end
16
- end