nzbn 0.1.2 → 0.1.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +5 -5
- data/.gitignore +1 -0
- data/lib/nzbn/version.rb +1 -1
- data/lib/nzbn.rb +41 -41
- data/nzbn.gemspec +3 -3
- metadata +12 -11
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: fb52da02245857cd4a78cb20994cb4ad8be45c0f95680faa6b44e8f7137e23ea
|
4
|
+
data.tar.gz: ca14b0d78da8415a56b3de8c76917ab0b08a982e0eeded420b6e4fee3979bd24
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 03afc942f4e01aab0cbb2cbca4728d4d614c2f75a97f001f46c79b3a94affd3b7d3bf8552b4543b27136a33b6fb04929dae0f12ebc561d452943ff2bbe65fec2
|
7
|
+
data.tar.gz: 65e277beb72c4641dafa2a1e2c58e91f0b55c12d91144d21a81445246037dc5c1ea40136eb32a1f4f39ec817a88c964826a6888bd073d409828896b44d3009ee
|
data/.gitignore
CHANGED
data/lib/nzbn/version.rb
CHANGED
data/lib/nzbn.rb
CHANGED
@@ -3,57 +3,57 @@ require "nzbn/version"
|
|
3
3
|
module NZBN
|
4
4
|
require 'rubygems'
|
5
5
|
require 'time'
|
6
|
-
require '
|
6
|
+
require 'rest-client'
|
7
7
|
require 'base64'
|
8
8
|
|
9
|
+
NZBN_API_VERSION="v4"
|
9
10
|
|
10
|
-
|
11
|
-
|
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
|
11
|
+
class DataError < StandardError; end
|
12
|
+
class AuthError < StandardError; end
|
21
13
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
14
|
+
def self.entities(search_term, entity_status, page_size)
|
15
|
+
entity_status = "registered" if entity_status.blank?
|
16
|
+
page_size = 50 if page_size.blank?
|
17
|
+
response = RestClient.get("https://api.business.govt.nz/services/#{NZBN_API_VERSION}/nzbn/entities?search-term=#{search_term}&entity-status=#{entity_status}&page-size=#{page_size}",
|
18
|
+
{ authorization: "Bearer #{access_token}", accept: 'application/json' })
|
19
|
+
begin
|
20
|
+
JSON.parse(response.body).with_indifferent_access
|
21
|
+
rescue JSON::ParserError
|
22
|
+
raise NZBN::DataError, "NZBN API returned bad data"
|
30
23
|
end
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
24
|
+
end
|
25
|
+
|
26
|
+
def self.entity(nzbn)
|
27
|
+
response = RestClient.get("https://api.business.govt.nz/services/#{NZBN_API_VERSION}/nzbn/entities/#{nzbn}",
|
28
|
+
{ authorization: "Bearer #{access_token}", accept: 'application/json' })
|
29
|
+
begin
|
30
|
+
JSON.parse(response.body).with_indifferent_access
|
31
|
+
rescue JSON::ParserError
|
32
|
+
raise NZBN::DataError, "NZBN API returned bad data"
|
40
33
|
end
|
41
|
-
|
42
|
-
|
34
|
+
end
|
35
|
+
|
36
|
+
def self.filings(nzbn)
|
37
|
+
response = RestClient.get("https://api.business.govt.nz/services/#{NZBN_API_VERSION}/nzbn/entities/#{nzbn}/filings",
|
38
|
+
{ authorization: "Bearer #{access_token}", accept: 'application/json' })
|
39
|
+
begin
|
40
|
+
JSON.parse(response.body).with_indifferent_access
|
41
|
+
rescue JSON::ParserError
|
42
|
+
raise NZBN::DataError, "NZBN API returned bad data"
|
43
|
+
end
|
44
|
+
end
|
43
45
|
|
44
46
|
private
|
45
47
|
|
48
|
+
def self.access_token
|
49
|
+
begin
|
50
|
+
response = RestClient.post("https://api.business.govt.nz/services/token", { grant_type: "client_credentials" },
|
51
|
+
{ grant_type: "client_credentials", authorization: "Basic #{Base64.strict_encode64(ENV["NZBN_ID"] + ":" + ENV["NZBN_SECRET"])}" })
|
46
52
|
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
curl.headers['Authorization'] = 'Basic ' + Base64.strict_encode64(ENV["NZBN_ID"] + ":" + ENV["NZBN_SECRET"])
|
51
|
-
curl.http_auth_types = :basic
|
52
|
-
curl.verbose = true
|
53
|
-
end
|
54
|
-
c.perform
|
55
|
-
return JSON.parse(c.body_str)["access_token"]
|
53
|
+
JSON.parse(response.body)["access_token"]
|
54
|
+
rescue JSON::ParserError, NoMethodError
|
55
|
+
raise NZBN::AuthError, "Authentication failed! Are you missing NZBN_ID or NZBN_SECRET?"
|
56
56
|
end
|
57
57
|
|
58
|
-
|
58
|
+
end
|
59
59
|
end
|
data/nzbn.gemspec
CHANGED
@@ -6,8 +6,8 @@ require "nzbn/version"
|
|
6
6
|
Gem::Specification.new do |spec|
|
7
7
|
spec.name = "nzbn"
|
8
8
|
spec.version = Nzbn::VERSION
|
9
|
-
spec.authors = ["T Pearse"]
|
10
|
-
spec.email = ["t.pearse@gmail.com"]
|
9
|
+
spec.authors = ["T Pearse", "Theo Morra"]
|
10
|
+
spec.email = ["t.pearse@gmail.com", "git@theom.nz"]
|
11
11
|
|
12
12
|
spec.summary = %q{Simple and fast authenticating ruby API wrapper for the NZBN API}
|
13
13
|
spec.description = %q{Search, update details and manage New Zealand companies through the NZBN register.}
|
@@ -32,6 +32,6 @@ Gem::Specification.new do |spec|
|
|
32
32
|
|
33
33
|
spec.add_development_dependency "bundler", "~> 1.15"
|
34
34
|
spec.add_development_dependency "rake", "~> 10.0"
|
35
|
-
spec.
|
35
|
+
spec.add_runtime_dependency "rest-client", "~> 2.1.0"
|
36
36
|
|
37
37
|
end
|
metadata
CHANGED
@@ -1,14 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: nzbn
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- T Pearse
|
8
|
-
|
8
|
+
- Theo Morra
|
9
|
+
autorequire:
|
9
10
|
bindir: exe
|
10
11
|
cert_chain: []
|
11
|
-
date:
|
12
|
+
date: 2022-06-19 00:00:00.000000000 Z
|
12
13
|
dependencies:
|
13
14
|
- !ruby/object:Gem::Dependency
|
14
15
|
name: bundler
|
@@ -39,23 +40,24 @@ dependencies:
|
|
39
40
|
- !ruby/object:Gem::Version
|
40
41
|
version: '10.0'
|
41
42
|
- !ruby/object:Gem::Dependency
|
42
|
-
name:
|
43
|
+
name: rest-client
|
43
44
|
requirement: !ruby/object:Gem::Requirement
|
44
45
|
requirements:
|
45
46
|
- - "~>"
|
46
47
|
- !ruby/object:Gem::Version
|
47
|
-
version:
|
48
|
-
type: :
|
48
|
+
version: 2.1.0
|
49
|
+
type: :runtime
|
49
50
|
prerelease: false
|
50
51
|
version_requirements: !ruby/object:Gem::Requirement
|
51
52
|
requirements:
|
52
53
|
- - "~>"
|
53
54
|
- !ruby/object:Gem::Version
|
54
|
-
version:
|
55
|
+
version: 2.1.0
|
55
56
|
description: Search, update details and manage New Zealand companies through the NZBN
|
56
57
|
register.
|
57
58
|
email:
|
58
59
|
- t.pearse@gmail.com
|
60
|
+
- git@theom.nz
|
59
61
|
executables: []
|
60
62
|
extensions: []
|
61
63
|
extra_rdoc_files: []
|
@@ -75,7 +77,7 @@ licenses:
|
|
75
77
|
- MIT
|
76
78
|
metadata:
|
77
79
|
allowed_push_host: https://rubygems.org
|
78
|
-
post_install_message:
|
80
|
+
post_install_message:
|
79
81
|
rdoc_options: []
|
80
82
|
require_paths:
|
81
83
|
- lib
|
@@ -90,9 +92,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
90
92
|
- !ruby/object:Gem::Version
|
91
93
|
version: '0'
|
92
94
|
requirements: []
|
93
|
-
|
94
|
-
|
95
|
-
signing_key:
|
95
|
+
rubygems_version: 3.1.6
|
96
|
+
signing_key:
|
96
97
|
specification_version: 4
|
97
98
|
summary: Simple and fast authenticating ruby API wrapper for the NZBN API
|
98
99
|
test_files: []
|