alpr_ruby 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 1b031fd67ab51bd7f10c949eefe67c40397fdf5b
4
+ data.tar.gz: 6574be8152079036844d4088f408b8a9531f726c
5
+ SHA512:
6
+ metadata.gz: 3088c41d85362dba221dc39e71848ca1bc521940bc9f50896c65fef3c5e6a02f969a73b786042062970ac6126e297676bb5ebc85c3ed348000d06fcd1ecd3475
7
+ data.tar.gz: bb996065090ca5023c4fe38ce0aff287c663016fff0f09a362ffedfc84fd379b091bf3e9367bdbe9e7c81bfb4732c0ad27536409a1cd7a206d9ef6471330b155
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.3.0
4
+ before_install: gem install bundler -v 1.11.2
@@ -0,0 +1,49 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, and in the interest of
4
+ fostering an open and welcoming community, we pledge to respect all people who
5
+ contribute through reporting issues, posting feature requests, updating
6
+ documentation, submitting pull requests or patches, and other activities.
7
+
8
+ We are committed to making participation in this project a harassment-free
9
+ experience for everyone, regardless of level of experience, gender, gender
10
+ identity and expression, sexual orientation, disability, personal appearance,
11
+ body size, race, ethnicity, age, religion, or nationality.
12
+
13
+ Examples of unacceptable behavior by participants include:
14
+
15
+ * The use of sexualized language or imagery
16
+ * Personal attacks
17
+ * Trolling or insulting/derogatory comments
18
+ * Public or private harassment
19
+ * Publishing other's private information, such as physical or electronic
20
+ addresses, without explicit permission
21
+ * Other unethical or unprofessional conduct
22
+
23
+ Project maintainers have the right and responsibility to remove, edit, or
24
+ reject comments, commits, code, wiki edits, issues, and other contributions
25
+ that are not aligned to this Code of Conduct, or to ban temporarily or
26
+ permanently any contributor for other behaviors that they deem inappropriate,
27
+ threatening, offensive, or harmful.
28
+
29
+ By adopting this Code of Conduct, project maintainers commit themselves to
30
+ fairly and consistently applying these principles to every aspect of managing
31
+ this project. Project maintainers who do not follow or enforce the Code of
32
+ Conduct may be permanently removed from the project team.
33
+
34
+ This code of conduct applies both within project spaces and in public spaces
35
+ when an individual is representing the project or its community.
36
+
37
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
38
+ reported by contacting a project maintainer at mateuszurbanski@yahoo.pl. All
39
+ complaints will be reviewed and investigated and will result in a response that
40
+ is deemed necessary and appropriate to the circumstances. Maintainers are
41
+ obligated to maintain confidentiality with regard to the reporter of an
42
+ incident.
43
+
44
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage],
45
+ version 1.3.0, available at
46
+ [http://contributor-covenant.org/version/1/3/0/][version]
47
+
48
+ [homepage]: http://contributor-covenant.org
49
+ [version]: http://contributor-covenant.org/version/1/3/0/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in alpr_ruby.gemspec
4
+ gemspec
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Mateusz Urbański
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
13
+ all 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
21
+ THE SOFTWARE.
@@ -0,0 +1,43 @@
1
+ [![Build Status](https://travis-ci.org/MatUrbanski/alpr_ruby.svg?branch=master)](https://travis-ci.org/MatUrbanski/alpr_ruby)
2
+
3
+ # AlprRuby
4
+
5
+ Ruby wrapper for OpenALPR REST API
6
+ [API Documents/Play Ground](http://doc.openalpr.com/api/cloudapi.html#!/default/post_recognize)
7
+
8
+ ## Installation
9
+
10
+ Add this line to your application's Gemfile:
11
+
12
+ ```ruby
13
+ gem 'alpr_ruby'
14
+ ```
15
+
16
+ And then execute:
17
+
18
+ $ bundle
19
+
20
+ Or install it yourself as:
21
+
22
+ $ gem install alpr_ruby
23
+
24
+ ## Usage
25
+
26
+ ### Initialize client
27
+
28
+ ```ruby
29
+ AlprRuby::Client.new(secret: 'your_secret_here')
30
+ ```
31
+
32
+ ### Send data to OpenALPR API
33
+
34
+ ```ruby
35
+ params = {
36
+ image_url: 'http://www.motofilm.pl/wp-content/uploads/2010/04/audi_a8_prezentacja_270410_03_glo.jpg',
37
+ tasks: 'plate',
38
+ topn: 1,
39
+ country: 'eu'
40
+ }
41
+
42
+ client.recognize(params: params)
43
+ ```
@@ -0,0 +1,6 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task default: :spec
@@ -0,0 +1,31 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'alpr_ruby/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'alpr_ruby'
8
+ spec.version = AlprRuby::VERSION
9
+ spec.authors = ["Mateusz Urbański"]
10
+ spec.email = ['mateuszurbanski@yahoo.pl']
11
+
12
+ spec.summary = 'Ruby wrapper for OpenALPR Cloud API.'
13
+ spec.description = 'Ruby wrapper for OpenALPR Cloud API. See
14
+ https://http://doc.openalpr.com/bindings.html#cloud-api-commercial
15
+ for more details'
16
+ spec.homepage = 'https://github.com/MatUrbanski/alpr_ruby'
17
+ spec.license = 'MIT'
18
+
19
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
20
+ spec.bindir = 'exe'
21
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
22
+ spec.require_paths = ['lib']
23
+
24
+ spec.add_dependency 'typhoeus'
25
+ spec.add_dependency 'virtus'
26
+
27
+ spec.add_development_dependency 'bundler', '~> 1.11'
28
+ spec.add_development_dependency 'rake', '~> 10.0'
29
+ spec.add_development_dependency 'rspec', '~> 3.0'
30
+ spec.add_development_dependency 'vcr', '~> 3.0'
31
+ end
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'bundler/setup'
4
+ require 'alpr_ruby'
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
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,18 @@
1
+ require 'typhoeus'
2
+ require 'virtus'
3
+
4
+ require 'alpr_ruby/version'
5
+ require 'alpr_ruby/error'
6
+ require 'alpr_ruby/connection'
7
+ require 'alpr_ruby/client'
8
+ require 'alpr_ruby/candidate'
9
+ require 'alpr_ruby/coordinate'
10
+ require 'alpr_ruby/result'
11
+ require 'alpr_ruby/plate'
12
+ require 'alpr_ruby/color'
13
+ require 'alpr_ruby/make'
14
+ require 'alpr_ruby/model'
15
+ require 'alpr_ruby/recognition'
16
+
17
+ module AlprRuby
18
+ end
@@ -0,0 +1,9 @@
1
+ module AlprRuby
2
+ class Candidate
3
+ include Virtus.model
4
+
5
+ attribute :matches_template, Integer
6
+ attribute :plate, String
7
+ attribute :confidence, Float
8
+ end
9
+ end
@@ -0,0 +1,17 @@
1
+ module AlprRuby
2
+ class Client
3
+ def initialize(secret:)
4
+ @api = AlprRuby::Connection.new(secret: secret)
5
+ end
6
+
7
+ def recognize(params: {})
8
+ response = @api.call(
9
+ endpoint: 'recognize',
10
+ method: :post,
11
+ params: params
12
+ )
13
+
14
+ AlprRuby::Recognition.new(response)
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,8 @@
1
+ module AlprRuby
2
+ class Color
3
+ include Virtus.model
4
+
5
+ attribute :confidence, Float
6
+ attribute :value, String
7
+ end
8
+ end
@@ -0,0 +1,25 @@
1
+ require 'json'
2
+
3
+ module AlprRuby
4
+ class Connection
5
+ BASE_URL = 'https://api.openalpr.com/v1'.freeze
6
+
7
+ def initialize(secret:)
8
+ @secret = secret
9
+ end
10
+
11
+ def call(endpoint:, method:, params: {})
12
+ response = Typhoeus::Request.new(
13
+ "#{BASE_URL}/#{endpoint}",
14
+ method: method,
15
+ params: { secret_key: @secret }.merge!(params),
16
+ ).run
17
+
18
+ if response.response_code != 200
19
+ AlprRuby::Error.new(code: response.response_code).render
20
+ end
21
+
22
+ JSON.parse(response.response_body)
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,8 @@
1
+ module AlprRuby
2
+ class Coordinate
3
+ include Virtus.model
4
+
5
+ attribute :y, Integer
6
+ attribute :x, Integer
7
+ end
8
+ end
@@ -0,0 +1,23 @@
1
+ module AlprRuby
2
+ class InvalidParametersError < StandardError; end
3
+ class UnauthorizedError < StandardError; end
4
+ class LimitUsageExceededError < StandardError; end
5
+ class TemporaryLimitExceeded < StandardError; end
6
+
7
+ class Error
8
+ ERROR_TYPES = {
9
+ 400 => InvalidParametersError,
10
+ 401 => UnauthorizedError,
11
+ 402 => LimitUsageExceededError,
12
+ 403 => TemporaryLimitExceeded,
13
+ }
14
+
15
+ def initialize(code:)
16
+ @code = code
17
+ end
18
+
19
+ def render
20
+ fail ERROR_TYPES[@code]
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,8 @@
1
+ module AlprRuby
2
+ class Make
3
+ include Virtus.model
4
+
5
+ attribute :confidence, Float
6
+ attribute :value, String
7
+ end
8
+ end
@@ -0,0 +1,8 @@
1
+ module AlprRuby
2
+ class Model
3
+ include Virtus.model
4
+
5
+ attribute :confidence, Float
6
+ attribute :value, String
7
+ end
8
+ end
@@ -0,0 +1,11 @@
1
+ module AlprRuby
2
+ class Plate
3
+ include Virtus.model
4
+
5
+ attribute :img_height, Integer
6
+ attribute :img_width, Integer
7
+ attribute :results, Array[Result]
8
+ attribute :version, Integer
9
+ attribute :processing_time_ms, Float
10
+ end
11
+ end
@@ -0,0 +1,18 @@
1
+ module AlprRuby
2
+ class Recognition
3
+ include Virtus.model
4
+
5
+ attribute :plate, Plate
6
+ attribute :image_bytes, String
7
+ attribute :color, Array[Color]
8
+ attribute :make, Array[Make]
9
+ attribute :img_width, Integer
10
+ attribute :img_height, Integer
11
+ attribute :credits_monthly_used, Integer
12
+ attribute :makemodel, Array[Model]
13
+ attribute :total_processing_time, Float
14
+ attribute :credits_monthly_total, Integer
15
+ attribute :image_bytes_prefix, String
16
+ attribute :credit_cost, Integer
17
+ end
18
+ end
@@ -0,0 +1,15 @@
1
+ module AlprRuby
2
+ class Result
3
+ include Virtus.model
4
+
5
+ attribute :plate, String
6
+ attribute :confidence, Float
7
+ attribute :region_confidence, Integer
8
+ attribute :plate_index, Integer
9
+ attribute :processing_time_ms, Float
10
+ attribute :candidates, Array[Candidate]
11
+ attribute :coordinates, Array[Coordinate]
12
+ attribute :matches_template, Integer
13
+ attribute :requested_topn, Integer
14
+ end
15
+ end
@@ -0,0 +1,3 @@
1
+ module AlprRuby
2
+ VERSION = '0.2.0'.freeze
3
+ end
metadata ADDED
@@ -0,0 +1,155 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: alpr_ruby
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.0
5
+ platform: ruby
6
+ authors:
7
+ - Mateusz Urbański
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-03-20 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: typhoeus
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: virtus
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.11'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.11'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '10.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '10.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '3.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '3.0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: vcr
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '3.0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '3.0'
97
+ description: |-
98
+ Ruby wrapper for OpenALPR Cloud API. See
99
+ https://http://doc.openalpr.com/bindings.html#cloud-api-commercial
100
+ for more details
101
+ email:
102
+ - mateuszurbanski@yahoo.pl
103
+ executables: []
104
+ extensions: []
105
+ extra_rdoc_files: []
106
+ files:
107
+ - ".gitignore"
108
+ - ".rspec"
109
+ - ".travis.yml"
110
+ - CODE_OF_CONDUCT.md
111
+ - Gemfile
112
+ - LICENSE.txt
113
+ - README.md
114
+ - Rakefile
115
+ - alpr_ruby.gemspec
116
+ - bin/console
117
+ - bin/setup
118
+ - lib/alpr_ruby.rb
119
+ - lib/alpr_ruby/candidate.rb
120
+ - lib/alpr_ruby/client.rb
121
+ - lib/alpr_ruby/color.rb
122
+ - lib/alpr_ruby/connection.rb
123
+ - lib/alpr_ruby/coordinate.rb
124
+ - lib/alpr_ruby/error.rb
125
+ - lib/alpr_ruby/make.rb
126
+ - lib/alpr_ruby/model.rb
127
+ - lib/alpr_ruby/plate.rb
128
+ - lib/alpr_ruby/recognition.rb
129
+ - lib/alpr_ruby/result.rb
130
+ - lib/alpr_ruby/version.rb
131
+ homepage: https://github.com/MatUrbanski/alpr_ruby
132
+ licenses:
133
+ - MIT
134
+ metadata: {}
135
+ post_install_message:
136
+ rdoc_options: []
137
+ require_paths:
138
+ - lib
139
+ required_ruby_version: !ruby/object:Gem::Requirement
140
+ requirements:
141
+ - - ">="
142
+ - !ruby/object:Gem::Version
143
+ version: '0'
144
+ required_rubygems_version: !ruby/object:Gem::Requirement
145
+ requirements:
146
+ - - ">="
147
+ - !ruby/object:Gem::Version
148
+ version: '0'
149
+ requirements: []
150
+ rubyforge_project:
151
+ rubygems_version: 2.5.1
152
+ signing_key:
153
+ specification_version: 4
154
+ summary: Ruby wrapper for OpenALPR Cloud API.
155
+ test_files: []