nzcoapi 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +87 -0
- data/Rakefile +2 -0
- data/bin/console +14 -0
- data/bin/setup +7 -0
- data/lib/nzcoapi.rb +69 -0
- data/lib/nzcoapi/version.rb +3 -0
- data/nzcoapi.gemspec +32 -0
- metadata +126 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: bc4888d9c8fde256801d0c996ddf0925db98d649
|
4
|
+
data.tar.gz: 5c30f6142e6aa958174cb3c0ba3a049fff3075a9
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: bf78125b4086a2c5d70bc17446b94b38d1fe84a24d226ae5f1e14972e32178740c0b5e39742cf331d194f86ca09e0e5e12e3bfaf3567e17a9979c392750b8985
|
7
|
+
data.tar.gz: 6d2841aa57a8c8e80bc2338dfeca4a38b560bdfe8d20175372ce1c950ae8c556985a3f0ec1e3c5043fe0e964a0679a583f8d24985a704ea04b6065d12c4ce473
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2015 TODO: Write your name
|
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
ADDED
@@ -0,0 +1,87 @@
|
|
1
|
+
# New Zealand Companies Office API Gem
|
2
|
+
|
3
|
+
Simple and fast authenticating API wrapper for the New Zealand Companies Office. Full functionality to search by company name, company number and director. Further functionality can be easily exposed inline with API documentation.
|
4
|
+
|
5
|
+
|
6
|
+
## About the Companies Office
|
7
|
+
|
8
|
+
The New Zealand Companies Office has an API which can be accessed through registration at: [http://www.business.govt.nz/businessdata](http://www.business.govt.nz/businessdata)
|
9
|
+
|
10
|
+
Registration is required in order to obtain unique access keys to use the API.
|
11
|
+
|
12
|
+
## Installation
|
13
|
+
|
14
|
+
Add this line to your application's Gemfile:
|
15
|
+
|
16
|
+
```ruby
|
17
|
+
gem 'nzcoapi'
|
18
|
+
```
|
19
|
+
|
20
|
+
And then execute:
|
21
|
+
|
22
|
+
$ bundle
|
23
|
+
|
24
|
+
Or install it yourself as:
|
25
|
+
|
26
|
+
$ gem install nzcoapi
|
27
|
+
|
28
|
+
## Configuration
|
29
|
+
|
30
|
+
[Figaro](https://github.com/laserlemon/figaro) is a dependency required to securely store your Companies Office access and secret keys.
|
31
|
+
|
32
|
+
Execute the following to setup application.yml to store your Companies Office keys with Figaro.
|
33
|
+
|
34
|
+
$ rails generate nzcoapi:install
|
35
|
+
|
36
|
+
Alternatively you can manually add your Companies Office keys:
|
37
|
+
|
38
|
+
# config/application.yml
|
39
|
+
$ nzcoapi_access_key: "J5zFrdbg2iw"
|
40
|
+
$ nzcoapi_secret_key: "fin39USzsZGWgL2yUDQ1C0n6NBtv2"
|
41
|
+
|
42
|
+
|
43
|
+
## Usage
|
44
|
+
|
45
|
+
Three functions have been exposed, as per below.
|
46
|
+
|
47
|
+
### Find by Company Number
|
48
|
+
|
49
|
+
$ NZcoapi.find_company(123566)
|
50
|
+
|
51
|
+
Full company details based on a unique 'Company Number' will be returned.
|
52
|
+
|
53
|
+
### Find Director
|
54
|
+
|
55
|
+
$ NZcoapi.find_director("Jones, Bob")
|
56
|
+
|
57
|
+
All company directorships (active and inactive) of this individual will be returned.
|
58
|
+
|
59
|
+
### Search for a Company
|
60
|
+
|
61
|
+
$ NZcoapi.search_for_company("TradeMe")
|
62
|
+
|
63
|
+
Search results for this company name will be returned.
|
64
|
+
|
65
|
+
|
66
|
+
All output is returned as parsed XML. Within a rails view it can be quickly navigated with [Nokogiri](https://github.com/sparklemotion/nokogiri), for example:
|
67
|
+
|
68
|
+
# In View
|
69
|
+
<%= NZcoapi.find_company(973228).css('companyName').text %>
|
70
|
+
|
71
|
+
# Returns
|
72
|
+
Trade Me Limited
|
73
|
+
|
74
|
+
## Queries
|
75
|
+
|
76
|
+
> NB: This Gem is not developed or maintained by the New Zealand Companies Office in anyway.
|
77
|
+
|
78
|
+
Please don't hesitate to get in touch if you have any queries and I'll try and point you in the right direction!
|
79
|
+
|
80
|
+
|
81
|
+
## Contributing
|
82
|
+
|
83
|
+
1. Fork it ( https://github.com/[my-github-username]/nzcoapi/fork )
|
84
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
85
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
86
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
87
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "nzcoapi"
|
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
ADDED
data/lib/nzcoapi.rb
ADDED
@@ -0,0 +1,69 @@
|
|
1
|
+
# Set Version
|
2
|
+
VERSION = "0.1.0"
|
3
|
+
|
4
|
+
|
5
|
+
require 'httparty'
|
6
|
+
require 'base64'
|
7
|
+
require 'time'
|
8
|
+
require 'nokogiri'
|
9
|
+
|
10
|
+
module Nzcoapi
|
11
|
+
include HTTParty
|
12
|
+
include Nokogiri
|
13
|
+
base_uri "http://www.businessdata.govt.nz"
|
14
|
+
format :xml
|
15
|
+
|
16
|
+
@@access_key = "J5zFrdfHu5Bbg2iw"
|
17
|
+
@@secret_key = "fin39USzsZGHSJGVUwzkUJWgL2yUDQ1C0n6NBtv2"
|
18
|
+
@@timestamp = Time.now.rfc2822 + " GMT"
|
19
|
+
headers "Timestamp" => Time.now.rfc2822 + " GMT"
|
20
|
+
headers "Access" => @@access_key
|
21
|
+
headers 'Accept' => "application/xml"
|
22
|
+
|
23
|
+
|
24
|
+
def self.search_for_company(string)
|
25
|
+
headers "Timestamp" => Time.now.rfc2822 + " GMT"
|
26
|
+
@@timestamp = Time.now.rfc2822 + " GMT"
|
27
|
+
|
28
|
+
stringtosign = "GET" + "\n" + "www.businessdata.govt.nz" + "\n" + "/data/app/ws/rest/companies/entity/search/v2.0/#{string}" + "\n" + @@timestamp + "\n" + @@access_key + "\n" + "application/xml" + "\n"
|
29
|
+
|
30
|
+
headers "Authorization" => @@access_key + ":" + Base64.strict_encode64(OpenSSL::HMAC.digest('sha256', @@secret_key, stringtosign))
|
31
|
+
headers "Timestamp" => Time.now.rfc2822 + " GMT"
|
32
|
+
|
33
|
+
Nokogiri::XML((get("/data/app/ws/rest/companies/entity/search/v2.0/#{string}").body), 'UTF-8')
|
34
|
+
end
|
35
|
+
|
36
|
+
def self.find_director(string)
|
37
|
+
headers "Timestamp" => Time.now.rfc2822 + " GMT"
|
38
|
+
@@timestamp = Time.now.rfc2822 + " GMT"
|
39
|
+
|
40
|
+
stringtosign = "GET" + "\n" + "www.businessdata.govt.nz" + "\n" + "/data/app/ws/rest/companies/role/search/v1.0/size/200/type/DIR/#{string}" + "\n" + @@timestamp + "\n" + @@access_key + "\n" + "application/xml" + "\n"
|
41
|
+
|
42
|
+
headers "Authorization" => @@access_key + ":" + Base64.strict_encode64(OpenSSL::HMAC.digest('sha256', @@secret_key, stringtosign))
|
43
|
+
|
44
|
+
Nokogiri::XML((get("/data/app/ws/rest/companies/role/search/v1.0/size/200/type/DIR/#{string}").body), 'UTF-8')
|
45
|
+
|
46
|
+
end
|
47
|
+
|
48
|
+
def self.find_company(id)
|
49
|
+
headers "Timestamp" => Time.now.rfc2822 + " GMT"
|
50
|
+
@@timestamp = Time.now.rfc2822 + " GMT"
|
51
|
+
|
52
|
+
stringtosign = "GET" + "\n" + "www.businessdata.govt.nz" + "\n" + "/data/app/ws/rest/companies/entity/v2.0/#{id}" + "\n" + @@timestamp + "\n" + @@access_key + "\n" + "application/xml" + "\n"
|
53
|
+
|
54
|
+
headers "Authorization" => @@access_key + ":" + Base64.strict_encode64(OpenSSL::HMAC.digest('sha256', @@secret_key, stringtosign))
|
55
|
+
|
56
|
+
Nokogiri::XML((get("/data/app/ws/rest/companies/entity/v2.0/#{id}").body), 'UTF-8')
|
57
|
+
|
58
|
+
end
|
59
|
+
|
60
|
+
|
61
|
+
|
62
|
+
def self.tagged(tag)
|
63
|
+
retrieve_url get("/#{tag}.json")
|
64
|
+
end
|
65
|
+
|
66
|
+
|
67
|
+
|
68
|
+
end
|
69
|
+
|
data/nzcoapi.gemspec
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'nzcoapi/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "nzcoapi"
|
8
|
+
spec.version = Nzcoapi::VERSION
|
9
|
+
spec.authors = ["T Pearse"]
|
10
|
+
spec.email = ["t.pearse@gmail.com"]
|
11
|
+
|
12
|
+
if spec.respond_to?(:metadata)
|
13
|
+
spec.metadata['allowed_push_host'] = "https://rubygems.org"
|
14
|
+
end
|
15
|
+
|
16
|
+
spec.summary = %q{Simple and fast authenticating API wrapper for the New Zealand Companies Office}
|
17
|
+
spec.description = %q{Full functionality to search by company name, company number and director. }
|
18
|
+
spec.homepage = "https://github.com/t-pearse/nzcoapi"
|
19
|
+
spec.license = "MIT"
|
20
|
+
|
21
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
22
|
+
spec.bindir = "exe"
|
23
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
24
|
+
spec.require_paths = ["lib"]
|
25
|
+
|
26
|
+
spec.add_development_dependency "bundler", "~> 1.8"
|
27
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
28
|
+
|
29
|
+
spec.add_dependency "httparty"
|
30
|
+
spec.add_dependency "nokogiri"
|
31
|
+
spec.add_dependency "figaro"
|
32
|
+
end
|
metadata
ADDED
@@ -0,0 +1,126 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: nzcoapi
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- T Pearse
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-03-01 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.8'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.8'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: httparty
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: nokogiri
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: figaro
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
description: 'Full functionality to search by company name, company number and director. '
|
84
|
+
email:
|
85
|
+
- t.pearse@gmail.com
|
86
|
+
executables: []
|
87
|
+
extensions: []
|
88
|
+
extra_rdoc_files: []
|
89
|
+
files:
|
90
|
+
- ".gitignore"
|
91
|
+
- Gemfile
|
92
|
+
- LICENSE.txt
|
93
|
+
- README.md
|
94
|
+
- Rakefile
|
95
|
+
- bin/console
|
96
|
+
- bin/setup
|
97
|
+
- lib/nzcoapi.rb
|
98
|
+
- lib/nzcoapi/version.rb
|
99
|
+
- nzcoapi.gemspec
|
100
|
+
homepage: https://github.com/t-pearse/nzcoapi
|
101
|
+
licenses:
|
102
|
+
- MIT
|
103
|
+
metadata:
|
104
|
+
allowed_push_host: https://rubygems.org
|
105
|
+
post_install_message:
|
106
|
+
rdoc_options: []
|
107
|
+
require_paths:
|
108
|
+
- lib
|
109
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
110
|
+
requirements:
|
111
|
+
- - ">="
|
112
|
+
- !ruby/object:Gem::Version
|
113
|
+
version: '0'
|
114
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
115
|
+
requirements:
|
116
|
+
- - ">="
|
117
|
+
- !ruby/object:Gem::Version
|
118
|
+
version: '0'
|
119
|
+
requirements: []
|
120
|
+
rubyforge_project:
|
121
|
+
rubygems_version: 2.4.6
|
122
|
+
signing_key:
|
123
|
+
specification_version: 4
|
124
|
+
summary: Simple and fast authenticating API wrapper for the New Zealand Companies
|
125
|
+
Office
|
126
|
+
test_files: []
|