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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: dc28d59b4a7c4dc9c77238af7eeb51ec1410fe25
4
- data.tar.gz: 7a33e4e396c173ebce722c3923bbcebb1e2741db
2
+ SHA256:
3
+ metadata.gz: fb52da02245857cd4a78cb20994cb4ad8be45c0f95680faa6b44e8f7137e23ea
4
+ data.tar.gz: ca14b0d78da8415a56b3de8c76917ab0b08a982e0eeded420b6e4fee3979bd24
5
5
  SHA512:
6
- metadata.gz: a1d9c5dcd0497c1ba0d3d2265fe9457873d56d290ae7769d1dab2912a5cf6c80dc0ced76719a1981db69bcd1b6820c1d41c99c1110a224da63caf20f19d87bd9
7
- data.tar.gz: ecb9322f9810a64c86a02c6353fa5d8c1eb30b08627800a4bd3cee81b2bcfbc0f14b6f14b268e8ff58fe40865813e822be2d59e672f1e923083e853338f431c3
6
+ metadata.gz: 03afc942f4e01aab0cbb2cbca4728d4d614c2f75a97f001f46c79b3a94affd3b7d3bf8552b4543b27136a33b6fb04929dae0f12ebc561d452943ff2bbe65fec2
7
+ data.tar.gz: 65e277beb72c4641dafa2a1e2c58e91f0b55c12d91144d21a81445246037dc5c1ea40136eb32a1f4f39ec817a88c964826a6888bd073d409828896b44d3009ee
data/.gitignore CHANGED
@@ -8,3 +8,4 @@
8
8
  /spec/reports/
9
9
  /tmp/
10
10
  /nzbn-0.1.0.gem
11
+ /.idea/
data/lib/nzbn/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Nzbn
2
- VERSION = "0.1.2"
2
+ VERSION = "0.1.4"
3
3
  end
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 'curb'
6
+ require 'rest-client'
7
7
  require 'base64'
8
8
 
9
+ NZBN_API_VERSION="v4"
9
10
 
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
11
+ class DataError < StandardError; end
12
+ class AuthError < StandardError; end
21
13
 
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)
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
- def self.filings(nzbn)
33
- r = Curl::Easy.new("https://api.business.govt.nz/services/v3/nzbn/entities/#{nzbn}/filings") do |curl|
34
- curl.headers['Authorization'] = 'Bearer ' + access_token
35
- curl.http_auth_types = :basic
36
- curl.verbose = true
37
- end
38
- r.perform
39
- return JSON.parse(r.body_str)
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
- def self.access_token
48
- c = Curl::Easy.http_post("https://api.business.govt.nz/services/token", "grant_type=client_credentials") do |curl|
49
- curl.headers['grant_type'] = 'client_credentials'
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.add_development_dependency "curb", "~> 0.96"
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.2
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - T Pearse
8
- autorequire:
8
+ - Theo Morra
9
+ autorequire:
9
10
  bindir: exe
10
11
  cert_chain: []
11
- date: 2018-07-30 00:00:00.000000000 Z
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: curb
43
+ name: rest-client
43
44
  requirement: !ruby/object:Gem::Requirement
44
45
  requirements:
45
46
  - - "~>"
46
47
  - !ruby/object:Gem::Version
47
- version: '0.96'
48
- type: :development
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: '0.96'
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
- rubyforge_project:
94
- rubygems_version: 2.6.12
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: []