mindee 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 5cdb0922b8ea540511c91a760d0b9d76dd5ba87f5e85b88b6008511077fe852b
4
+ data.tar.gz: 01a40229234d445a1838d71e945e7eacff7c8afdba2da09bb20fbf14670b21da
5
+ SHA512:
6
+ metadata.gz: cfecb4fc1da99567aa086e2af214544b294e6be7525984fab2775ff19877116203b0739bd1d8b9c66ef23205dbe8dcd277e89a149884cffd8bd10e133d3f8e46
7
+ data.tar.gz: f5f389e634f5c8ec8637b9d3a051f44248500f7553bad550da0dc0f3d8e49a2f68c2d0251868f89b37f2d465efce92b55a4bdd65422f64a36cedf8e3e0932667
data/.gitattributes ADDED
@@ -0,0 +1,14 @@
1
+ # Auto-detect text files, ensure they use LF.
2
+ * text=auto eol=lf
3
+
4
+ # These files are always considered text and should use LF.
5
+ # See core.whitespace @ https://git-scm.com/docs/git-config for whitespace flags.
6
+ *.rb text eol=lf whitespace=blank-at-eol,space-before-tab,tab-in-indent,tabwidth=2 diff=ruby
7
+ *.sh text eol=lf whitespace=blank-at-eol diff=bash
8
+ *.md text eol=lf whitespace=blank-at-eol diff=markdown
9
+
10
+ # Exclude non-essential files from dist
11
+ .gitattributes export-ignore
12
+ .gitignore export-ignore
13
+ tests/ export-ignore
14
+ .github export-ignore
data/.gitignore ADDED
@@ -0,0 +1,69 @@
1
+ # IDE
2
+ .vscode/
3
+ .idea
4
+
5
+ # Ruby
6
+ *.gem
7
+ *.rbc
8
+ /.config
9
+ /coverage/
10
+ /InstalledFiles
11
+ /pkg/
12
+ /spec/reports/
13
+ /spec/examples.txt
14
+ /test/tmp/
15
+ /test/version_tmp/
16
+ /tmp/
17
+ /mindee-*/
18
+
19
+ # Used by dotenv library to load environment variables.
20
+ .env
21
+
22
+ # Ignore Byebug command history file.
23
+ .byebug_history
24
+
25
+ ## Specific to RubyMotion:
26
+ .dat*
27
+ .repl_history
28
+ build/
29
+ *.bridgesupport
30
+ build-iPhoneOS/
31
+ build-iPhoneSimulator/
32
+
33
+ ## Specific to RubyMotion (use of CocoaPods):
34
+ #
35
+ # We recommend against adding the Pods directory to your .gitignore. However
36
+ # you should judge for yourself, the pros and cons are mentioned at:
37
+ # https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
38
+ #
39
+ # vendor/Pods/
40
+
41
+ ## Documentation cache and generated files:
42
+ /.yardoc/
43
+ /_yardoc/
44
+ /doc/
45
+ /rdoc/
46
+
47
+ ## Environment normalization:
48
+ /.bundle/
49
+ /vendor/bundle
50
+ /lib/bundler/man/
51
+
52
+ # for a library or gem, you might want to ignore these files since the code is
53
+ # intended to run in multiple environments; otherwise, check them in:
54
+ Gemfile.lock
55
+ .ruby-version
56
+ .ruby-gemset
57
+
58
+ # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
59
+ .rvmrc
60
+
61
+ # Used by RuboCop. Remote config files pulled in from inherit_from directive.
62
+ .rubocop-https?--*
63
+
64
+ # Mac OS
65
+ .DS_Store
66
+
67
+ # Temp files
68
+ *.swp
69
+ *-swp
data/.rubocop.yml ADDED
@@ -0,0 +1,41 @@
1
+ AllCops:
2
+ NewCops: enable
3
+ Exclude:
4
+ - 'vendor/**/*'
5
+ - 'spec/fixtures/**/*'
6
+ - 'tmp/**/*'
7
+ - '.git/**/*'
8
+ - 'bin/*'
9
+ TargetRubyVersion: 2.6
10
+ SuggestExtensions: false
11
+
12
+ Style/TrailingCommaInHashLiteral:
13
+ EnforcedStyleForMultiline: comma
14
+
15
+ Style/TrailingCommaInArrayLiteral:
16
+ EnforcedStyleForMultiline: comma
17
+
18
+ Style/WordArray:
19
+ EnforcedStyle: brackets
20
+
21
+ Metrics/BlockLength:
22
+ Exclude:
23
+ - 'Rakefile'
24
+ - '**/*.rake'
25
+ - 'spec/**/*.rb'
26
+ - '**/*.gemspec'
27
+
28
+ Metrics/MethodLength:
29
+ Max: 35
30
+
31
+ Metrics/ClassLength:
32
+ Max: 200
33
+
34
+ Metrics/ParameterLists:
35
+ Max: 7
36
+
37
+ Metrics/AbcSize:
38
+ Max: 50
39
+
40
+ Style/RegexpLiteral:
41
+ EnforcedStyle: percent_r
data/CHANGELOG.md ADDED
@@ -0,0 +1,4 @@
1
+ # Mindee Ruby API Library Changelog
2
+
3
+ ## v1.0.0 (2022-07-28)
4
+ * :tada: First release!
@@ -0,0 +1,129 @@
1
+
2
+ # Contributor Covenant Code of Conduct
3
+
4
+ ## Our Pledge
5
+
6
+ We as members, contributors, and leaders pledge to make participation in our
7
+ community a harassment-free experience for everyone, regardless of age, body
8
+ size, visible or invisible disability, ethnicity, sex characteristics, gender
9
+ identity and expression, level of experience, education, socio-economic status,
10
+ nationality, personal appearance, race, religion, or sexual identity
11
+ and orientation.
12
+
13
+ We pledge to act and interact in ways that contribute to an open, welcoming,
14
+ diverse, inclusive, and healthy community.
15
+
16
+ ## Our Standards
17
+
18
+ Examples of behavior that contributes to a positive environment for our
19
+ community include:
20
+
21
+ * Demonstrating empathy and kindness toward other people
22
+ * Being respectful of differing opinions, viewpoints, and experiences
23
+ * Giving and gracefully accepting constructive feedback
24
+ * Accepting responsibility and apologizing to those affected by our mistakes,
25
+ and learning from the experience
26
+ * Focusing on what is best not just for us as individuals, but for the
27
+ overall community
28
+
29
+ Examples of unacceptable behavior include:
30
+
31
+ * The use of sexualized language or imagery, and sexual attention or
32
+ advances of any kind
33
+ * Trolling, insulting or derogatory comments, and personal or political attacks
34
+ * Public or private harassment
35
+ * Publishing others' private information, such as a physical or email
36
+ address, without their explicit permission
37
+ * Other conduct which could reasonably be considered inappropriate in a
38
+ professional setting
39
+
40
+ ## Enforcement Responsibilities
41
+
42
+ Community leaders are responsible for clarifying and enforcing our standards of
43
+ acceptable behavior and will take appropriate and fair corrective action in
44
+ response to any behavior that they deem inappropriate, threatening, offensive,
45
+ or harmful.
46
+
47
+ Community leaders have the right and responsibility to remove, edit, or reject
48
+ comments, commits, code, wiki edits, issues, and other contributions that are
49
+ not aligned to this Code of Conduct, and will communicate reasons for moderation
50
+ decisions when appropriate.
51
+
52
+ ## Scope
53
+
54
+ This Code of Conduct applies within all community spaces, and also applies when
55
+ an individual is officially representing the community in public spaces.
56
+ Examples of representing our community include using an official e-mail address,
57
+ posting via an official social media account, or acting as an appointed
58
+ representative at an online or offline event.
59
+
60
+ ## Enforcement
61
+
62
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
63
+ reported to the community leaders responsible for enforcement at
64
+ [INSERT CONTACT METHOD].
65
+ All complaints will be reviewed and investigated promptly and fairly.
66
+
67
+ All community leaders are obligated to respect the privacy and security of the
68
+ reporter of any incident.
69
+
70
+ ## Enforcement Guidelines
71
+
72
+ Community leaders will follow these Community Impact Guidelines in determining
73
+ the consequences for any action they deem in violation of this Code of Conduct:
74
+
75
+ ### 1. Correction
76
+
77
+ **Community Impact**: Use of inappropriate language or other behavior deemed
78
+ unprofessional or unwelcome in the community.
79
+
80
+ **Consequence**: A private, written warning from community leaders, providing
81
+ clarity around the nature of the violation and an explanation of why the
82
+ behavior was inappropriate. A public apology may be requested.
83
+
84
+ ### 2. Warning
85
+
86
+ **Community Impact**: A violation through a single incident or series
87
+ of actions.
88
+
89
+ **Consequence**: A warning with consequences for continued behavior. No
90
+ interaction with the people involved, including unsolicited interaction with
91
+ those enforcing the Code of Conduct, for a specified period of time. This
92
+ includes avoiding interactions in community spaces as well as external channels
93
+ like social media. Violating these terms may lead to a temporary or
94
+ permanent ban.
95
+
96
+ ### 3. Temporary Ban
97
+
98
+ **Community Impact**: A serious violation of community standards, including
99
+ sustained inappropriate behavior.
100
+
101
+ **Consequence**: A temporary ban from any sort of interaction or public
102
+ communication with the community for a specified period of time. No public or
103
+ private interaction with the people involved, including unsolicited interaction
104
+ with those enforcing the Code of Conduct, is allowed during this period.
105
+ Violating these terms may lead to a permanent ban.
106
+
107
+ ### 4. Permanent Ban
108
+
109
+ **Community Impact**: Demonstrating a pattern of violation of community
110
+ standards, including sustained inappropriate behavior, harassment of an
111
+ individual, or aggression toward or disparagement of classes of individuals.
112
+
113
+ **Consequence**: A permanent ban from any sort of public interaction within
114
+ the community.
115
+
116
+ ## Attribution
117
+
118
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage],
119
+ version 2.0, available at
120
+ https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
121
+
122
+ Community Impact Guidelines were inspired by [Mozilla's code of conduct
123
+ enforcement ladder](https://github.com/mozilla/diversity).
124
+
125
+ [homepage]: https://www.contributor-covenant.org
126
+
127
+ For answers to common questions about this code of conduct, see the FAQ at
128
+ https://www.contributor-covenant.org/faq. Translations are available at
129
+ https://www.contributor-covenant.org/translations.
data/Gemfile ADDED
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ source 'https://rubygems.org'
4
+
5
+ # Specify your gem's dependencies in mindee.gemspec
6
+ gemspec
7
+
8
+ gem 'rake', '~> 12.0'
9
+ gem 'rubocop', require: false
10
+
11
+ group :test do
12
+ gem 'rspec', '~> 3.10'
13
+ end
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2022-Present Mindee
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,66 @@
1
+ # Mindee API Helper Library for Ruby
2
+ Quickly and easily connect to Mindee's API services using Ruby.
3
+
4
+ ## Quick Start
5
+ Here's the TL;DR of getting started.
6
+
7
+ First, get an [API Key](https://developers.mindee.com/docs/create-api-key)
8
+
9
+ Install by adding this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'mindee'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle install
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install mindee
22
+
23
+ Finally, Ruby away!
24
+
25
+ ### Off-the-Shelf Document
26
+ ```ruby
27
+ require 'mindee'
28
+
29
+ # Init a new client and configure the Invoice API
30
+ mindee_client = Mindee::Client.new(api_key: 'my-api-key').config_invoice
31
+
32
+ # Load a file from disk and parse it
33
+ api_response = mindee_client.doc_from_path("/path/to/the/invoice.pdf").parse("invoice")
34
+
35
+ # Print a brief summary of the parsed data
36
+ puts api_response.document
37
+ ```
38
+
39
+ ### Custom Document (API Builder)
40
+ ```ruby
41
+ require 'mindee'
42
+
43
+ # Init a new client and configure your custom document
44
+ mindee_client = Mindee::Client.new(api_key: 'my-api-key').config_custom_doc(
45
+ 'pokemon-card',
46
+ 'pikachu'
47
+ )
48
+
49
+ # Load a file from disk and parse it
50
+ api_response = mindee_client.doc_from_path("/path/to/the/card.jpg").parse("pokemon-card")
51
+
52
+ # Print a brief summary of the parsed data
53
+ puts api_response.document
54
+ ```
55
+
56
+ ## Further Reading
57
+ There's more to it than that for those that need more features, or want to
58
+ customize the experience.
59
+
60
+ All the juicy details are described in the
61
+ **[Official Documentation](https://developers.mindee.com/docs/ruby-getting-started)**.
62
+
63
+ ## License
64
+ Copyright © Mindee
65
+
66
+ Available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'bundler/gem_tasks'
4
+
5
+ task default: spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'bundler/setup'
4
+ require 'mindee'
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require 'irb'
14
+ IRB.start(__FILE__)
data/bin/mindee.rb ADDED
@@ -0,0 +1,137 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'bundler/setup'
4
+ require 'optparse'
5
+
6
+ require 'mindee'
7
+
8
+ DOCUMENTS = {
9
+ "invoice" => {
10
+ help: 'Invoice',
11
+ doc_type: Mindee::Client::DOC_TYPE_INVOICE,
12
+ },
13
+ "receipt" => {
14
+ help: "Expense Receipt",
15
+ doc_type: Mindee::Client::DOC_TYPE_RECEIPT,
16
+ },
17
+ "passport" => {
18
+ help: "Passport",
19
+ doc_type: Mindee::Client::DOC_TYPE_PASSPORT,
20
+ },
21
+ "financial" => {
22
+ help: "Financial Document (receipt or invoice)",
23
+ doc_type: Mindee::Client::DOC_TYPE_FINANCIAL,
24
+ },
25
+ "custom" => {
26
+ help: "Custom document type from API builder",
27
+ },
28
+ }
29
+
30
+ options = {}
31
+
32
+ def ots_subcommand(command, options)
33
+ OptionParser.new do |opt|
34
+ opt.banner = "Usage: #{command} [options] FILE"
35
+ opt.on('-k [KEY]', '--key [KEY]', 'API key for the endpoint') do |v|
36
+ options[:api_key] = v
37
+ end
38
+ opt.on('-w', '--with-words', 'Include words in response') do |v|
39
+ options[:include_words] = v
40
+ end
41
+ opt.on('-C', '--no-cut-pages', "Don't cut document pages") do |v|
42
+ options[:include_words] = v
43
+ end
44
+ end
45
+ end
46
+
47
+ def custom_subcommand(options)
48
+ OptionParser.new do |opt|
49
+ opt.banner = "Usage: custom [options] DOC_TYPE FILE"
50
+ opt.on('-w', '--with-words', 'Include words in response') do |v|
51
+ options[:include_words] = v
52
+ end
53
+ opt.on('-C', '--no-cut-pages', "Don't cut document pages") do |v|
54
+ options[:include_words] = v
55
+ end
56
+ opt.on('-k [KEY]', '--key [KEY]', 'API key for the endpoint') do |v|
57
+ options[:api_key] = v
58
+ end
59
+ opt.on('-v [VERSION]', '--version [VERSION]', 'Model version for the API') do |v|
60
+ options[:version] = v
61
+ end
62
+ opt.on('-u USER', '--user USER', 'API account name for the endpoint') do |v|
63
+ options[:user] = v
64
+ end
65
+ end
66
+ end
67
+
68
+ def new_ots_client(options, command)
69
+ raise_on_error = options[:no_raise_errors].nil? ? true : false
70
+ mindee_client = Mindee::Client.new(
71
+ api_key: options[:api_key], raise_on_error: raise_on_error
72
+ )
73
+ info = DOCUMENTS[command]
74
+ mindee_client.send("config_#{info[:doc_type]}")
75
+ end
76
+
77
+ def new_custom_client(options, doc_type)
78
+ raise_on_error = options[:no_raise_errors].nil? ? true : false
79
+ mindee_client = Mindee::Client.new(
80
+ api_key: options[:api_key], raise_on_error: raise_on_error
81
+ )
82
+ mindee_client.config_custom_doc(
83
+ doc_type,
84
+ options[:user],
85
+ version: options[:version] || '1'
86
+ )
87
+ end
88
+
89
+ global_parser = OptionParser.new do |opt|
90
+ opt.banner = "Usage: #{$PROGRAM_NAME} [options] subcommand [options] FILE"
91
+ opt.separator('')
92
+ opt.separator("subcommands: #{DOCUMENTS.keys.join(', ')}")
93
+ opt.separator('')
94
+ opt.on('-E', '--no-raise-errors', "raise errors behavior") do |v|
95
+ options[:no_raise_errors] = true
96
+ end
97
+ end
98
+
99
+ subcommands = {
100
+ 'invoice' => ots_subcommand('invoice', options),
101
+ 'receipt' => ots_subcommand('receipt', options),
102
+ 'passport' => ots_subcommand('passport', options),
103
+ 'financial' => ots_subcommand('financial', options),
104
+ 'custom' => custom_subcommand(options),
105
+ }
106
+
107
+
108
+ begin
109
+ global_parser.order!
110
+ command = ARGV.shift
111
+ subcommands[command].order!
112
+ rescue NoMethodError => e
113
+ $stderr.puts global_parser
114
+ exit(1)
115
+ end
116
+
117
+ if command == 'custom'
118
+ if ARGV.length != 2
119
+ $stderr.puts "The 'custom' command requires both DOC_TYPE and FILE arguments."
120
+ exit(1)
121
+ end
122
+ doc_type = ARGV[0]
123
+ file_path = ARGV[1]
124
+ mindee_client = new_custom_client(options, doc_type)
125
+ else
126
+ if ARGV.length != 1
127
+ $stderr.puts 'No file specified.'
128
+ exit(1)
129
+ end
130
+ mindee_client = new_ots_client(options, command)
131
+ doc_type = DOCUMENTS[command][:doc_type]
132
+ file_path = ARGV[0]
133
+ end
134
+
135
+ cut_pages = options[:no_cut_pages].nil? ? false : true
136
+ doc = mindee_client.doc_from_path(file_path, cut_pages: cut_pages)
137
+ puts doc.parse(doc_type).document