taggun 0.4.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: d9deac5b17f94465ce0b5060e0d547c2ebcacafdf0a2c367c31d8fa9a989dadf
4
+ data.tar.gz: 2ed516231a7833549f90b0c29a053b30065cb0a4434c3b225ef78628f88397ba
5
+ SHA512:
6
+ metadata.gz: 1441dde576a9c23737f555c8b08c7e47e735a5d276b174441448038cf00692017d458880d5fbdd66bbbb9bbd0488256f8d476a48174c66f864fe5400828fe8b4
7
+ data.tar.gz: fff179cc0515758753104ce86374a5ca8cf3faaed324f64e750ffc7f999dac00e85b4b3b2981b249d8eee78adcfb91eb3737e571d289ef9aa458fe3f93392663
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2019 Sebastian Menhofer
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,58 @@
1
+ # Taggun
2
+ This is a ruby gem for the [Taggun](https://www.taggun.io) receipt OCR-Engine.
3
+
4
+ Currently we support the following scan types:
5
+
6
+ - [x] URL
7
+ - [ ] encoded
8
+ - [ ] file
9
+ - [ ] storage
10
+
11
+ ## Installation
12
+ Add this line to your application's Gemfile:
13
+
14
+ ```ruby
15
+ gem 'taggun'
16
+ ```
17
+
18
+ And then execute:
19
+ ```bash
20
+ $ bundle
21
+ ```
22
+
23
+ Or install it yourself as:
24
+ ```bash
25
+ $ gem install taggun
26
+ ```
27
+
28
+ ## Usage
29
+ First you have to set your API key provided by Taggun.
30
+
31
+ Create an initializer `taggun.rb` with
32
+ ```ruby
33
+ Taggun.configure do |config|
34
+ config.api_key = 'your_api_key'
35
+ end
36
+ ```
37
+
38
+ Then you can just call the Parser with
39
+ ```ruby
40
+ taggun = Taggun::Parser.new
41
+
42
+ taggun.from_url(Taggun::SIMPLE, 'url_to_image')
43
+ ```
44
+
45
+ The `form_xxx` methods return the Taggun responses. See https://api.taggun.io for details.
46
+
47
+ ## TODOs
48
+ - Implement more scan types
49
+ - Documentation
50
+ - Add tests
51
+ - Publish to RubyGems
52
+
53
+
54
+ ## Contributing
55
+ TODO
56
+
57
+ ## License
58
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,27 @@
1
+ begin
2
+ require 'bundler/setup'
3
+ rescue LoadError
4
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
5
+ end
6
+
7
+ require 'rdoc/task'
8
+
9
+ RDoc::Task.new(:rdoc) do |rdoc|
10
+ rdoc.rdoc_dir = 'rdoc'
11
+ rdoc.title = 'Taggun'
12
+ rdoc.options << '--line-numbers'
13
+ rdoc.rdoc_files.include('README.md')
14
+ rdoc.rdoc_files.include('lib/**/*.rb')
15
+ end
16
+
17
+ require 'bundler/gem_tasks'
18
+
19
+ require 'rake/testtask'
20
+
21
+ Rake::TestTask.new(:test) do |t|
22
+ t.libs << 'test'
23
+ t.pattern = 'test/**/*_test.rb'
24
+ t.verbose = false
25
+ end
26
+
27
+ task default: :test
@@ -0,0 +1,8 @@
1
+ Description:
2
+ Creates an initializer file for taggun.
3
+
4
+ Example:
5
+ rails generate taggun valid_api_key
6
+
7
+ This will create:
8
+ config/initializers/taggun.rb
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ class TaggunGenerator < Rails::Generators::Base
4
+ source_root File.expand_path('templates', __dir__)
5
+
6
+ argument :api_key, required: false
7
+
8
+ desc 'Configures Taggun with your api_key'
9
+ def generate_layout
10
+ template 'initializer.rb.erb', 'config/initializers/taggun.rb'
11
+ end
12
+ end
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Configure Taggun here.
4
+ # This file is filled with defaults.
5
+ Taggun.configure do |config|
6
+ # Your Api-Key is required.
7
+ # You can get one from taggun.io
8
+ <% if api_key %>
9
+ config.api_key = '<%= api_key %>'
10
+ <% else %>
11
+ config.api_key = 'your_api_key'
12
+ <% end %>
13
+ # Set true to avoid saving the receipt in storage.
14
+ # config.incognito = true
15
+
16
+ # Set true to force re-process image transcription if the receipt is already in storage
17
+ # config.refresh = false
18
+ end
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Taggun
4
+ module ActsAsTaggun
5
+ extend ActiveSupport::Concern
6
+
7
+ included do
8
+ def parse_receipt_by_url(receipt_url)
9
+ Taggun::Parser.new.parse(SIMPLE, receipt_url)
10
+ end
11
+ end
12
+
13
+ class_methods do
14
+ def acts_as_taggun(options = {})
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Taggun
4
+ class Configuration
5
+ attr_accessor :api_key, :incognito, :refresh
6
+
7
+ def initialize
8
+ @api_key = nil
9
+ @incognito = true
10
+ @refresh = false
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,62 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Taggun
4
+ # Basic parser class
5
+ class Parser
6
+ def initialize
7
+ raise(ArgumentError, 'Initializer missing. See README for details') if Taggun.configuration.nil?
8
+ raise(ArgumentError, 'Api Key not set. See README for details.') if Taggun.configuration.api_key.nil?
9
+ end
10
+
11
+ # Parse the receipt from url
12
+ #
13
+ # === Arguments
14
+ #
15
+ # * +url+ - The URL to parse from as +String+
16
+ #
17
+ # * +method+ - The method to get. Valid values are +Taggun::Simple+
18
+ # and +Taggun::Verbose+. Default is +Taggun::Simple+
19
+ #
20
+ # Returns a +JSON+ with the result from Taggun.io
21
+ def from_url(url, method = Taggun::SIMPLE)
22
+ uri = URI.parse("#{BASE_URL}/#{RECEIPT_URL}/#{API_VERSION}/#{method}/#{URL}")
23
+
24
+ body = {
25
+ url: url,
26
+ incognito: Taggun.configuration.incognito,
27
+ refresh: Taggun.configuration.refresh
28
+ }
29
+
30
+ parse(uri, body)
31
+ end
32
+
33
+ def from_file(method, file)
34
+ # TODO
35
+ end
36
+
37
+ def from_encoded(method, encoded)
38
+ # TODO
39
+ end
40
+
41
+ def from_storage(method, md5)
42
+ # TODO
43
+ end
44
+
45
+ def parse(uri, body)
46
+ http = ::Net::HTTP.new(uri.host, uri.port)
47
+ http.use_ssl = true
48
+
49
+ request = ::Net::HTTP::Post.new(
50
+ uri.request_uri,
51
+ 'Content-Type': 'application/json'
52
+ )
53
+ request['apikey'] = Taggun.configuration.api_key
54
+
55
+ request.body = body.to_json
56
+
57
+ response = http.request(request)
58
+
59
+ JSON.parse(response.body)
60
+ end
61
+ end
62
+ end
@@ -0,0 +1,4 @@
1
+ module Taggun
2
+ class Railtie < ::Rails::Railtie
3
+ end
4
+ end
@@ -0,0 +1,3 @@
1
+ module Taggun
2
+ VERSION = '0.4.0'
3
+ end
data/lib/taggun.rb ADDED
@@ -0,0 +1,51 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "taggun/railtie"
4
+ require 'taggun/acts_as_taggun'
5
+ require 'taggun/configuration'
6
+ require 'taggun/parser'
7
+ require 'net/http'
8
+
9
+ module Taggun
10
+
11
+ # The base taggun api URL
12
+ BASE_URL = 'https://api.taggun.io/api'.freeze
13
+
14
+ # The Api version to use
15
+ API_VERSION = 'v1'.freeze
16
+
17
+ # URL for receipt actions
18
+ RECEIPT_URL = 'receipt'.freeze
19
+
20
+ # URL for account actions
21
+ ACCOUNT_URL = 'account'.freeze
22
+
23
+ # API endpoint to use file parsing
24
+ FILE = 'file'.freeze
25
+
26
+ # API endpoint to use encoded parsing
27
+ ENCODED = 'encoded'.freeze
28
+
29
+ # API endpoint to use storage parsing
30
+ STORAGE = 'storage'.freeze
31
+
32
+ # API endpoint to use URL parsing
33
+ URL = 'url'.freeze
34
+
35
+ # API endpoint to get simple response
36
+ SIMPLE = 'simple'.freeze
37
+
38
+ # API endpoint to get detailed response
39
+ VERBOSE = 'verbose'.freeze
40
+
41
+ class << self
42
+ attr_accessor :configuration
43
+ end
44
+
45
+ def self.configure
46
+ self.configuration ||= Configuration.new
47
+ yield(configuration)
48
+ end
49
+
50
+ require 'taggun/railtie' if defined?(Rails)
51
+ end
@@ -0,0 +1,4 @@
1
+ # desc "Explaining what the task does"
2
+ # task :taggun do
3
+ # # Task goes here
4
+ # end
metadata ADDED
@@ -0,0 +1,91 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: taggun
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.4.0
5
+ platform: ruby
6
+ authors:
7
+ - Sebastian Menhofer
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2019-04-03 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rails
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 5.2.2
20
+ - - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: 5.2.2.1
23
+ type: :development
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - "~>"
28
+ - !ruby/object:Gem::Version
29
+ version: 5.2.2
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: 5.2.2.1
33
+ - !ruby/object:Gem::Dependency
34
+ name: pg
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ">="
38
+ - !ruby/object:Gem::Version
39
+ version: '0'
40
+ type: :development
41
+ prerelease: false
42
+ version_requirements: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ version: '0'
47
+ description: Ruby gem for the Taggun receipt OCR-Engine
48
+ email:
49
+ - sebastian.menhofer@gmail.com
50
+ executables: []
51
+ extensions: []
52
+ extra_rdoc_files: []
53
+ files:
54
+ - MIT-LICENSE
55
+ - README.md
56
+ - Rakefile
57
+ - lib/generators/taggun/USAGE
58
+ - lib/generators/taggun/taggun_generator.rb
59
+ - lib/generators/taggun/templates/initializer.rb.erb
60
+ - lib/taggun.rb
61
+ - lib/taggun/acts_as_taggun.rb
62
+ - lib/taggun/configuration.rb
63
+ - lib/taggun/parser.rb
64
+ - lib/taggun/railtie.rb
65
+ - lib/taggun/version.rb
66
+ - lib/tasks/taggun_tasks.rake
67
+ homepage: https://github.com/pabse/taggun-rb
68
+ licenses:
69
+ - MIT
70
+ metadata:
71
+ allowed_push_host: https://rubygems.org
72
+ post_install_message:
73
+ rdoc_options: []
74
+ require_paths:
75
+ - lib
76
+ required_ruby_version: !ruby/object:Gem::Requirement
77
+ requirements:
78
+ - - ">="
79
+ - !ruby/object:Gem::Version
80
+ version: '0'
81
+ required_rubygems_version: !ruby/object:Gem::Requirement
82
+ requirements:
83
+ - - ">="
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ requirements: []
87
+ rubygems_version: 3.0.1
88
+ signing_key:
89
+ specification_version: 4
90
+ summary: Ruby gem for the Taggun receipt OCR-Engine
91
+ test_files: []