nzbn 0.1.1

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: 8ac6e8983ce3a663bb3a50efaed76468fc11419d
4
+ data.tar.gz: 7c503bd4f5f3d3786ebd0441821c463db32cf524
5
+ SHA512:
6
+ metadata.gz: b5a816702782e3d35beb5997a972b86e07b1275725f2dbf23526bc18174ddf054084268aff374406f5307e8d0c230159c0761dbe913176795e39118ce6660994
7
+ data.tar.gz: 6bf182ab6c2302f8eb53bc85d00421e54fc8a7b0484c0d642630bb55002375921b75541c1476e911a5ad31a89b647741f011fa265e60801b4a526e2d1c828810
@@ -0,0 +1,10 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ /nzbn-0.1.0.gem
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in nzbn.gemspec
6
+ gemspec
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2017 T Pearse
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,78 @@
1
+ # NZBN Gem
2
+
3
+ Simple and fast authenticating API wrapper for the New Zealand Companies Office. Search by company and retrieve company details. Further functionality can easily be exposed.
4
+
5
+
6
+ ## About the Companies Office
7
+
8
+ The New Zealand Companies Office has an API which can be accessed through registration at: [https://api.business.govt.nz/api/](https://api.business.govt.nz/api/)
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 'nzbn'
18
+ ```
19
+
20
+ And then execute:
21
+
22
+ $ bundle
23
+
24
+ Or install it yourself as:
25
+
26
+ $ gem install nzbn
27
+
28
+ You will also need to set the following ENV variables, in order to access the API. These can be gound on the business.govt.nz website under your login.
29
+
30
+ $ NZBN_ID=
31
+
32
+ $ NZBN_SECRET=
33
+
34
+
35
+ ## Usage
36
+
37
+ Two functions have been exposed, as per below.
38
+
39
+ ### Company details by NZBN
40
+
41
+ $ NZBN.entity(nzbn)
42
+ * where nzbn is the entity nzbn
43
+
44
+ Full company details based on a unique 'Company Number' will be returned.
45
+
46
+ ### Search for a Company
47
+
48
+ $ NZBZN.entites(search_term, entity_status, page_length)
49
+ * entity_status = "registered" to filter the search for registered entities only (defaults to registered)*
50
+ * page_length = 50 to return the top 50 results only (max of 200, defaults to 50)*
51
+
52
+ All output is returned as parsed JSON. Within a rails view it can be quickly navigated with [Nokogiri](https://github.com/sparklemotion/nokogiri) or similar.
53
+
54
+
55
+ ## Pull requests welcome!
56
+
57
+ Pull requests welcome to build out further functionality including:
58
+ - Entity filings
59
+ - Subscriptions
60
+ - Users
61
+ - Authorities
62
+ - Organisations
63
+ - Documents
64
+
65
+
66
+ ## Queries
67
+
68
+ > NB: This Gem is not developed or maintained by the New Zealand Companies Office in anyway.
69
+
70
+ Please don't hesitate to get in touch if you have any queries and I'll try and point you in the right direction!
71
+
72
+ ## Contributing
73
+
74
+ Bug reports and pull requests are welcome on GitHub at https://github.com/tpearse/nzbn.
75
+
76
+ ## License
77
+
78
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+ task :default => :spec
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "nzbn"
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__)
@@ -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,49 @@
1
+ require "nzbn/version"
2
+
3
+ module NZBN
4
+ require 'rubygems'
5
+ require 'time'
6
+ require 'curb'
7
+ require 'base64'
8
+
9
+
10
+ def self.entities(search_term, entity_status, page_size)
11
+ entity_status = "registered" if entity_status.blank?
12
+ page_size = 50 if page_size.blank?
13
+ r = Curl::Easy.new("https://api.business.govt.nz/services/v3/nzbn/entities?search-term=#{search_term}&entity-status=#{entity_status}&page-size=#{page_size}") do |curl|
14
+ curl.headers['Authorization'] = 'Bearer ' + access_token
15
+ curl.http_auth_types = :basic
16
+ curl.verbose = true
17
+ end
18
+ r.perform
19
+ return JSON.parse(r.body_str)
20
+ end
21
+
22
+ def self.entity(nzbn)
23
+ r = Curl::Easy.new("https://api.business.govt.nz/services/v3/nzbn/entities/#{nzbn}") do |curl|
24
+ curl.headers['Authorization'] = 'Bearer ' + access_token
25
+ curl.http_auth_types = :basic
26
+ curl.verbose = true
27
+ end
28
+ r.perform
29
+ return JSON.parse(r.body_str)
30
+ end
31
+
32
+
33
+
34
+ private
35
+
36
+
37
+ def self.access_token
38
+ c = Curl::Easy.http_post("https://api.business.govt.nz/services/token", "grant_type=client_credentials") do |curl|
39
+ curl.headers['grant_type'] = 'client_credentials'
40
+ curl.headers['Authorization'] = 'Basic ' + Base64.strict_encode64(ENV["NZBN_ID"] + ":" + ENV["NZBN_SECRET"])
41
+ curl.http_auth_types = :basic
42
+ curl.verbose = true
43
+ end
44
+ c.perform
45
+ return JSON.parse(c.body_str)["access_token"]
46
+ end
47
+
48
+
49
+ end
@@ -0,0 +1,3 @@
1
+ module Nzbn
2
+ VERSION = "0.1.1"
3
+ end
@@ -0,0 +1,35 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "nzbn/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "nzbn"
8
+ spec.version = Nzbn::VERSION
9
+ spec.authors = ["T Pearse"]
10
+ spec.email = ["t.pearse@gmail.com"]
11
+
12
+ spec.summary = %q{Simple and fast authenticating ruby API wrapper for the NZBN API}
13
+ spec.description = %q{Search, update details and manage New Zealand companies through the NZBN register.}
14
+ spec.homepage = "https://github.com/t-pearse/nzbn"
15
+ spec.license = "MIT"
16
+
17
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
18
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
19
+ if spec.respond_to?(:metadata)
20
+ spec.metadata["allowed_push_host"] = "https://rubygems.org"
21
+ else
22
+ raise "RubyGems 2.0 or newer is required to protect against " \
23
+ "public gem pushes."
24
+ end
25
+
26
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
27
+ f.match(%r{^(test|spec|features)/})
28
+ end
29
+ spec.bindir = "exe"
30
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
31
+ spec.require_paths = ["lib"]
32
+
33
+ spec.add_development_dependency "bundler", "~> 1.15"
34
+ spec.add_development_dependency "rake", "~> 10.0"
35
+ end
metadata ADDED
@@ -0,0 +1,84 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: nzbn
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - T Pearse
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2017-09-16 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.15'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.15'
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
+ description: Search, update details and manage New Zealand companies through the NZBN
42
+ register.
43
+ email:
44
+ - t.pearse@gmail.com
45
+ executables: []
46
+ extensions: []
47
+ extra_rdoc_files: []
48
+ files:
49
+ - ".gitignore"
50
+ - Gemfile
51
+ - LICENSE.txt
52
+ - README.md
53
+ - Rakefile
54
+ - bin/console
55
+ - bin/setup
56
+ - lib/nzbn.rb
57
+ - lib/nzbn/version.rb
58
+ - nzbn.gemspec
59
+ homepage: https://github.com/t-pearse/nzbn
60
+ licenses:
61
+ - MIT
62
+ metadata:
63
+ allowed_push_host: https://rubygems.org
64
+ post_install_message:
65
+ rdoc_options: []
66
+ require_paths:
67
+ - lib
68
+ required_ruby_version: !ruby/object:Gem::Requirement
69
+ requirements:
70
+ - - ">="
71
+ - !ruby/object:Gem::Version
72
+ version: '0'
73
+ required_rubygems_version: !ruby/object:Gem::Requirement
74
+ requirements:
75
+ - - ">="
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ requirements: []
79
+ rubyforge_project:
80
+ rubygems_version: 2.4.6
81
+ signing_key:
82
+ specification_version: 4
83
+ summary: Simple and fast authenticating ruby API wrapper for the NZBN API
84
+ test_files: []