valabn 0.1.0 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +9 -9
- data/.rspec +2 -2
- data/.travis.yml +4 -4
- data/CODE_OF_CONDUCT.md +48 -48
- data/Gemfile +4 -4
- data/LICENSE.txt +21 -21
- data/README.md +74 -73
- data/Rakefile +6 -6
- data/bin/console +14 -14
- data/bin/setup +8 -8
- data/lib/valabn.rb +20 -18
- data/lib/valabn/lookup.rb +63 -63
- data/lib/valabn/utils.rb +21 -21
- data/lib/valabn/version.rb +3 -3
- data/valabn.gemspec +29 -29
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 64f49b1db9f21a7603bbdfc3f8a6f1170bd3cae7
|
4
|
+
data.tar.gz: 3ffc23de9b5aa5f5f95137aa6c90fada99f705d8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d63677d2451eb8150cbdece37d5387e8d43fbfd4dbe784a29bf74ba91c1a2e801a5f5678b7b1a8f44c7d4d2db1b7103d5822fb986025ec9315d695acefa7b5bb
|
7
|
+
data.tar.gz: 36a15e7b5ff6a546009a501b3fc573628d76a03d962a7e703309a00606894e0874ba39861d9fb7910d8d4470cb8af90dac39fdee7e795d1628a6fe476688afdd
|
data/.gitignore
CHANGED
@@ -1,10 +1,10 @@
|
|
1
|
-
/.bundle/
|
2
|
-
/.yardoc
|
3
|
-
/Gemfile.lock
|
4
|
-
/_yardoc/
|
5
|
-
/coverage/
|
6
|
-
/doc/
|
7
|
-
/pkg/
|
8
|
-
/spec/reports/
|
9
|
-
/tmp/
|
1
|
+
/.bundle/
|
2
|
+
/.yardoc
|
3
|
+
/Gemfile.lock
|
4
|
+
/_yardoc/
|
5
|
+
/coverage/
|
6
|
+
/doc/
|
7
|
+
/pkg/
|
8
|
+
/spec/reports/
|
9
|
+
/tmp/
|
10
10
|
*.gem
|
data/.rspec
CHANGED
@@ -1,2 +1,2 @@
|
|
1
|
-
--format documentation
|
2
|
-
--color
|
1
|
+
--format documentation
|
2
|
+
--color
|
data/.travis.yml
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
language: ruby
|
2
|
-
rvm:
|
3
|
-
- 2.1.1
|
4
|
-
before_install: gem install bundler -v 1.11.2
|
1
|
+
language: ruby
|
2
|
+
rvm:
|
3
|
+
- 2.1.1
|
4
|
+
before_install: gem install bundler -v 1.11.2
|
data/CODE_OF_CONDUCT.md
CHANGED
@@ -1,49 +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 vidadelaempresa@gmail.com. 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
|
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 vidadelaempresa@gmail.com. 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
49
|
[version]: http://contributor-covenant.org/version/1/3/0/
|
data/Gemfile
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
source 'https://rubygems.org'
|
2
|
-
|
3
|
-
# Specify your gem's dependencies in valabn.gemspec
|
4
|
-
gemspec
|
1
|
+
source 'https://rubygems.org'
|
2
|
+
|
3
|
+
# Specify your gem's dependencies in valabn.gemspec
|
4
|
+
gemspec
|
data/LICENSE.txt
CHANGED
@@ -1,21 +1,21 @@
|
|
1
|
-
The MIT License (MIT)
|
2
|
-
|
3
|
-
Copyright (c) 2017 xxswingxx
|
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.
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2017 xxswingxx
|
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.
|
data/README.md
CHANGED
@@ -1,73 +1,74 @@
|
|
1
|
-
# Valabn
|
2
|
-
|
3
|
-
Valabn (read *valaban*) is a simple Australian Business Number (ABN) validator.
|
4
|
-
|
5
|
-
## Installation
|
6
|
-
|
7
|
-
Add this line to your application's Gemfile:
|
8
|
-
|
9
|
-
```ruby
|
10
|
-
gem 'valabn'
|
11
|
-
```
|
12
|
-
|
13
|
-
And then execute:
|
14
|
-
|
15
|
-
$ bundle
|
16
|
-
|
17
|
-
Or install it yourself as:
|
18
|
-
|
19
|
-
$ gem install valabn
|
20
|
-
|
21
|
-
## Usage
|
22
|
-
|
23
|
-
If you just need to check the format of the ABN, just use:
|
24
|
-
|
25
|
-
```ruby
|
26
|
-
Valabn::Utils.validate_format(number) #=> Boolean
|
27
|
-
```
|
28
|
-
|
29
|
-
In order to lookup real ABN, you'll need to get a GUID (`https://abr.business.gov.au/RegisterAgreement.aspx`). Once you've got one initialize the gem like this:
|
30
|
-
|
31
|
-
```ruby
|
32
|
-
require 'valabn'
|
33
|
-
|
34
|
-
Valabn::Lookup.configure do |config|
|
35
|
-
config.guid = APP_GUID # Your assigned GUID
|
36
|
-
config.cache_host = 'localhost' # (optional) The host of the redis server
|
37
|
-
config.cache_port = '6379' # (optional) The port of the redis server
|
38
|
-
end
|
39
|
-
|
40
|
-
```
|
41
|
-
|
42
|
-
`cache_host` and `cache_port` are optional configuration attributes in order to keep a cache on a redis database. The current cache configuration lives up to two hours.
|
43
|
-
|
44
|
-
After that, you invoke
|
45
|
-
|
46
|
-
```ruby
|
47
|
-
Valabn::Lookup.validate(abn) #=> Hash
|
48
|
-
|
49
|
-
number = Valabn.new(abn)
|
50
|
-
number.exists? #=> Boolean
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
*
|
57
|
-
*
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
1
|
+
# Valabn
|
2
|
+
|
3
|
+
Valabn (read *valaban*) is a simple Australian Business Number (ABN) validator.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'valabn'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install valabn
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
If you just need to check the format of the ABN, just use:
|
24
|
+
|
25
|
+
```ruby
|
26
|
+
Valabn::Utils.validate_format(number) #=> Boolean
|
27
|
+
```
|
28
|
+
|
29
|
+
In order to lookup real ABN, you'll need to get a GUID (`https://abr.business.gov.au/RegisterAgreement.aspx`). Once you've got one initialize the gem like this:
|
30
|
+
|
31
|
+
```ruby
|
32
|
+
require 'valabn'
|
33
|
+
|
34
|
+
Valabn::Lookup.configure do |config|
|
35
|
+
config.guid = APP_GUID # Your assigned GUID
|
36
|
+
config.cache_host = 'localhost' # (optional) The host of the redis server
|
37
|
+
config.cache_port = '6379' # (optional) The port of the redis server
|
38
|
+
end
|
39
|
+
|
40
|
+
```
|
41
|
+
|
42
|
+
`cache_host` and `cache_port` are optional configuration attributes in order to keep a cache on a redis database. The current cache configuration lives up to two hours.
|
43
|
+
|
44
|
+
After that, you invoke
|
45
|
+
|
46
|
+
```ruby
|
47
|
+
Valabn::Lookup.validate(abn) #=> Hash
|
48
|
+
|
49
|
+
number = Valabn.new(abn)
|
50
|
+
number.exists? #=> Boolean
|
51
|
+
number.exists?(details: true) #=> Hash or false
|
52
|
+
```
|
53
|
+
|
54
|
+
## TODO:
|
55
|
+
|
56
|
+
* Allow custom expiration time on the cache.
|
57
|
+
* Integrate with `Activerecord`/`ActiveModel` as validator.
|
58
|
+
* Add specs
|
59
|
+
|
60
|
+
## Development
|
61
|
+
|
62
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
63
|
+
|
64
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
65
|
+
|
66
|
+
## Contributing
|
67
|
+
|
68
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/valabn. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
69
|
+
|
70
|
+
|
71
|
+
## License
|
72
|
+
|
73
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
74
|
+
|
data/Rakefile
CHANGED
@@ -1,6 +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
|
1
|
+
require "bundler/gem_tasks"
|
2
|
+
require "rspec/core/rake_task"
|
3
|
+
|
4
|
+
RSpec::Core::RakeTask.new(:spec)
|
5
|
+
|
6
|
+
task :default => :spec
|
data/bin/console
CHANGED
@@ -1,14 +1,14 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
|
3
|
-
require "bundler/setup"
|
4
|
-
require "valabn"
|
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
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "valabn"
|
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
|
data/bin/setup
CHANGED
@@ -1,8 +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
|
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
|
data/lib/valabn.rb
CHANGED
@@ -1,18 +1,20 @@
|
|
1
|
-
require 'valabn/lookup'
|
2
|
-
|
3
|
-
class Valabn
|
4
|
-
# Instance methods
|
5
|
-
def initialize(number)
|
6
|
-
@number = number.to_s.gsub(/\W/, '')
|
7
|
-
end
|
8
|
-
|
9
|
-
def exists?(options = {})
|
10
|
-
res = Valabn::Lookup.validate(@number, options)
|
11
|
-
|
12
|
-
if res.any?
|
13
|
-
|
14
|
-
|
15
|
-
false
|
16
|
-
|
17
|
-
|
18
|
-
end
|
1
|
+
require 'valabn/lookup'
|
2
|
+
|
3
|
+
class Valabn
|
4
|
+
# Instance methods
|
5
|
+
def initialize(number)
|
6
|
+
@number = number.to_s.gsub(/\W/, '')
|
7
|
+
end
|
8
|
+
|
9
|
+
def exists?(options = {})
|
10
|
+
res = Valabn::Lookup.validate(@number, options)
|
11
|
+
|
12
|
+
if res.any? && res[:search_by_ab_nv201408_response][:abr_payload_search_results][:response].keys.include?(:business_entity201408)
|
13
|
+
options[:detail] == true ? res : true
|
14
|
+
elsif !res.nil?
|
15
|
+
options[:detail] == true ? res : false
|
16
|
+
else
|
17
|
+
nil
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
data/lib/valabn/lookup.rb
CHANGED
@@ -1,64 +1,64 @@
|
|
1
|
-
require 'savon'
|
2
|
-
require 'json'
|
3
|
-
require 'redis-namespace'
|
4
|
-
require_relative 'utils'
|
5
|
-
|
6
|
-
class Valabn
|
7
|
-
class Lookup
|
8
|
-
|
9
|
-
WSDL = 'http://www.abn.business.gov.au/abrxmlsearch/ABRXMLSearch.asmx?WSDL'
|
10
|
-
@@cache_host = nil
|
11
|
-
@@cache_port = nil
|
12
|
-
@@guid = nil
|
13
|
-
|
14
|
-
def self.guid=(value)
|
15
|
-
@@guid = value
|
16
|
-
end
|
17
|
-
|
18
|
-
def self.cache_host=(value)
|
19
|
-
@@cache_host = value
|
20
|
-
end
|
21
|
-
|
22
|
-
def self.cache_port=(value)
|
23
|
-
@@cache_port = value
|
24
|
-
end
|
25
|
-
|
26
|
-
def self.configure
|
27
|
-
yield self
|
28
|
-
end
|
29
|
-
|
30
|
-
def self.validate(number, options = {})
|
31
|
-
number = number.to_s.gsub(/\W/, '')
|
32
|
-
|
33
|
-
if Valabn::Utils.valid_format?(number)
|
34
|
-
cache = if @@cache_port && @@cache_host
|
35
|
-
redis_client = Redis.new(host: @@cache_host, port: @@cache_port, db: 15)
|
36
|
-
namespaced_redis = Redis::Namespace.new(:valabn_cache, redis: redis_client)
|
37
|
-
|
38
|
-
JSON.parse(namespaced_redis.get(number) || '{}', symbolize_names: true)
|
39
|
-
else
|
40
|
-
{}
|
41
|
-
end
|
42
|
-
|
43
|
-
if cache.any? && Time.at(cache[:expires_at]) > Time.now
|
44
|
-
cache
|
45
|
-
else
|
46
|
-
options[:includeHistoricalDetails] ||= 'n'
|
47
|
-
options[:searchString] = number
|
48
|
-
options[:authenticationGuid] = options[:guid] || @@guid
|
49
|
-
|
50
|
-
client = Savon.client(wsdl: WSDL)
|
51
|
-
|
52
|
-
response = JSON.parse(client.call(:search_by_ab_nv201408, message: options).body.to_json, symbolize_names: true)
|
53
|
-
response[:expires_at] = (Time.now + 7200).to_i
|
54
|
-
|
55
|
-
namespaced_redis.set(number, response.to_json) if @@cache_port && @@cache_host
|
56
|
-
|
57
|
-
response
|
58
|
-
end
|
59
|
-
else
|
60
|
-
{}
|
61
|
-
end
|
62
|
-
end
|
63
|
-
end
|
1
|
+
require 'savon'
|
2
|
+
require 'json'
|
3
|
+
require 'redis-namespace'
|
4
|
+
require_relative 'utils'
|
5
|
+
|
6
|
+
class Valabn
|
7
|
+
class Lookup
|
8
|
+
|
9
|
+
WSDL = 'http://www.abn.business.gov.au/abrxmlsearch/ABRXMLSearch.asmx?WSDL'
|
10
|
+
@@cache_host = nil
|
11
|
+
@@cache_port = nil
|
12
|
+
@@guid = nil
|
13
|
+
|
14
|
+
def self.guid=(value)
|
15
|
+
@@guid = value
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.cache_host=(value)
|
19
|
+
@@cache_host = value
|
20
|
+
end
|
21
|
+
|
22
|
+
def self.cache_port=(value)
|
23
|
+
@@cache_port = value
|
24
|
+
end
|
25
|
+
|
26
|
+
def self.configure
|
27
|
+
yield self
|
28
|
+
end
|
29
|
+
|
30
|
+
def self.validate(number, options = {})
|
31
|
+
number = number.to_s.gsub(/\W/, '')
|
32
|
+
|
33
|
+
if Valabn::Utils.valid_format?(number)
|
34
|
+
cache = if @@cache_port && @@cache_host
|
35
|
+
redis_client = Redis.new(host: @@cache_host, port: @@cache_port, db: 15)
|
36
|
+
namespaced_redis = Redis::Namespace.new(:valabn_cache, redis: redis_client)
|
37
|
+
|
38
|
+
JSON.parse(namespaced_redis.get(number) || '{}', symbolize_names: true)
|
39
|
+
else
|
40
|
+
{}
|
41
|
+
end
|
42
|
+
|
43
|
+
if cache.any? && Time.at(cache[:expires_at]) > Time.now
|
44
|
+
cache
|
45
|
+
else
|
46
|
+
options[:includeHistoricalDetails] ||= 'n'
|
47
|
+
options[:searchString] = number
|
48
|
+
options[:authenticationGuid] = options[:guid] || @@guid
|
49
|
+
|
50
|
+
client = Savon.client(wsdl: WSDL)
|
51
|
+
|
52
|
+
response = JSON.parse(client.call(:search_by_ab_nv201408, message: options).body.to_json, symbolize_names: true)
|
53
|
+
response[:expires_at] = (Time.now + 7200).to_i
|
54
|
+
|
55
|
+
namespaced_redis.set(number, response.to_json) if @@cache_port && @@cache_host
|
56
|
+
|
57
|
+
response
|
58
|
+
end
|
59
|
+
else
|
60
|
+
{}
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
64
|
end
|
data/lib/valabn/utils.rb
CHANGED
@@ -1,22 +1,22 @@
|
|
1
|
-
class Valabn
|
2
|
-
class Utils
|
3
|
-
def self.valid_format?(number)
|
4
|
-
number = number.to_s.gsub(/\W/, '')
|
5
|
-
|
6
|
-
if !!( number =~ /\A
|
7
|
-
weights = [10, 1, 3, 5, 7, 9, 11, 13, 15, 17, 19]
|
8
|
-
sum = 0
|
9
|
-
|
10
|
-
numbers = number.split('').map(&:to_i)
|
11
|
-
numbers[0] = numbers[0] - 1
|
12
|
-
|
13
|
-
numbers = numbers.zip(weights).map { |x, y| x * y }
|
14
|
-
sum = numbers.inject(0, :+)
|
15
|
-
|
16
|
-
(sum % 89).zero?
|
17
|
-
else
|
18
|
-
false
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
1
|
+
class Valabn
|
2
|
+
class Utils
|
3
|
+
def self.valid_format?(number)
|
4
|
+
number = number.to_s.gsub(/\W/, '')
|
5
|
+
|
6
|
+
if !!( number =~ /\A[0-9]{11}\z/)
|
7
|
+
weights = [10, 1, 3, 5, 7, 9, 11, 13, 15, 17, 19]
|
8
|
+
sum = 0
|
9
|
+
|
10
|
+
numbers = number.split('').map(&:to_i)
|
11
|
+
numbers[0] = numbers[0] - 1
|
12
|
+
|
13
|
+
numbers = numbers.zip(weights).map { |x, y| x * y }
|
14
|
+
sum = numbers.inject(0, :+)
|
15
|
+
|
16
|
+
(sum % 89).zero?
|
17
|
+
else
|
18
|
+
false
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
22
|
end
|
data/lib/valabn/version.rb
CHANGED
@@ -1,3 +1,3 @@
|
|
1
|
-
class Valabn
|
2
|
-
VERSION = "0.1.
|
3
|
-
end
|
1
|
+
class Valabn
|
2
|
+
VERSION = "0.1.2"
|
3
|
+
end
|
data/valabn.gemspec
CHANGED
@@ -1,29 +1,29 @@
|
|
1
|
-
# coding: utf-8
|
2
|
-
lib = File.expand_path('../lib', __FILE__)
|
3
|
-
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
-
require 'valabn/version'
|
5
|
-
|
6
|
-
Gem::Specification.new do |spec|
|
7
|
-
spec.name = "valabn"
|
8
|
-
spec.version = Valabn::VERSION
|
9
|
-
spec.authors = ["xxswingxx"]
|
10
|
-
spec.email = ["vidadelaempresa@gmail.com"]
|
11
|
-
|
12
|
-
spec.summary = %q{A wrapper for validating ABN.}
|
13
|
-
spec.description = %q{Validate the format and lookup ABN by using the ABN web services.}
|
14
|
-
spec.homepage = "https://github.com/xxswingxx/valabn"
|
15
|
-
spec.license =
|
16
|
-
"MIT"
|
17
|
-
|
18
|
-
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
19
|
-
spec.bindir = "exe"
|
20
|
-
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
21
|
-
spec.require_paths = ["lib"]
|
22
|
-
|
23
|
-
spec.add_development_dependency "savon"
|
24
|
-
spec.add_development_dependency "redis"
|
25
|
-
spec.add_development_dependency "redis-namespace"
|
26
|
-
spec.add_development_dependency "bundler", "~> 1.11"
|
27
|
-
spec.add_development_dependency "rake", "~> 10.0"
|
28
|
-
spec.add_development_dependency "rspec", "~> 3.0"
|
29
|
-
end
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'valabn/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "valabn"
|
8
|
+
spec.version = Valabn::VERSION
|
9
|
+
spec.authors = ["xxswingxx"]
|
10
|
+
spec.email = ["vidadelaempresa@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{A wrapper for validating ABN.}
|
13
|
+
spec.description = %q{Validate the format and lookup ABN by using the ABN web services.}
|
14
|
+
spec.homepage = "https://github.com/xxswingxx/valabn"
|
15
|
+
spec.license =
|
16
|
+
"MIT"
|
17
|
+
|
18
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
19
|
+
spec.bindir = "exe"
|
20
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
21
|
+
spec.require_paths = ["lib"]
|
22
|
+
|
23
|
+
spec.add_development_dependency "savon"
|
24
|
+
spec.add_development_dependency "redis"
|
25
|
+
spec.add_development_dependency "redis-namespace"
|
26
|
+
spec.add_development_dependency "bundler", "~> 1.11"
|
27
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
28
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
29
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: valabn
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- xxswingxx
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2018-02-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: savon
|