uk-hs_code 0.1.2 → 0.2.0
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 +4 -4
- data/.rubocop.yml +21 -4
- data/CONTRIBUTING.md +19 -0
- data/Gemfile.lock +20 -2
- data/README.md +14 -16
- data/lib/uk/hs_code/api_request.rb +0 -1
- data/lib/uk/hs_code/client.rb +48 -0
- data/lib/uk/hs_code/parsers/search_response_parser.rb +100 -0
- data/lib/uk/hs_code/record.rb +74 -1
- data/lib/uk/hs_code/services/search_service.rb +39 -0
- data/lib/uk/hs_code/version.rb +1 -1
- data/lib/uk/hs_code.rb +8 -8
- data/uk-hs_code.gemspec +5 -9
- metadata +52 -9
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 85e09b189b4a286a2766142d0b38f27be4bca6b5441ed8d6b3c274d1e3109036
|
|
4
|
+
data.tar.gz: 1e76d26889a40ebdd5ebd1b70f3634cce6fb92a6518e7d046d109020e84053ab
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: ea095185027cfd389a2cbe225db95313de464046f60a97d53d0df943a551667c873afd33d7059804041721cb5832639c2e7c974b82eefd6bf0ffe5e277556d86
|
|
7
|
+
data.tar.gz: a65cf16cfba32f7dcfb611acf1af51b0e721cd7e24326913a8279ed38c6971f708be76a09c1ebe622ec7c40fc64bb34d58520abe7f83504e8e50008e40e62427
|
data/.rubocop.yml
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
AllCops:
|
|
2
|
-
TargetRubyVersion:
|
|
2
|
+
TargetRubyVersion: 3.0
|
|
3
|
+
NewCops: enable
|
|
4
|
+
SuggestExtensions: false
|
|
3
5
|
|
|
4
6
|
Style/StringLiterals:
|
|
5
7
|
Enabled: true
|
|
@@ -12,9 +14,6 @@ Style/StringLiteralsInInterpolation:
|
|
|
12
14
|
Style/Documentation:
|
|
13
15
|
Enabled: false
|
|
14
16
|
|
|
15
|
-
Layout/LineLength:
|
|
16
|
-
Max: 120
|
|
17
|
-
|
|
18
17
|
Layout/LineLength:
|
|
19
18
|
Enabled: false
|
|
20
19
|
|
|
@@ -23,3 +22,21 @@ Metrics/AbcSize:
|
|
|
23
22
|
|
|
24
23
|
Metrics/BlockLength:
|
|
25
24
|
Enabled: false
|
|
25
|
+
|
|
26
|
+
Metrics/MethodLength:
|
|
27
|
+
Enabled: false
|
|
28
|
+
|
|
29
|
+
Metrics/CyclomaticComplexity:
|
|
30
|
+
Enabled: false
|
|
31
|
+
|
|
32
|
+
Metrics/PerceivedComplexity:
|
|
33
|
+
Enabled: false
|
|
34
|
+
|
|
35
|
+
Metrics/ParameterLists:
|
|
36
|
+
Enabled: false
|
|
37
|
+
|
|
38
|
+
Gemspec/DevelopmentDependencies:
|
|
39
|
+
Enabled: false
|
|
40
|
+
|
|
41
|
+
Gemspec/RequireMFA:
|
|
42
|
+
Enabled: false
|
data/CONTRIBUTING.md
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
# UK/Hs_code Contributing Guidelines
|
|
2
|
+
|
|
3
|
+
Thank you for your interest in contributing to our open source project! We appreciate your effort and to ensure that your contributions align with the goals of this project and are integrated smoothly, we ask that you follow these guidelines.
|
|
4
|
+
|
|
5
|
+
1. **Commit Small, Commit Regularly:** Regular and smaller commits are preferred over large, infrequent commits. This makes the changes easier to review and troubleshoot.
|
|
6
|
+
|
|
7
|
+
2. **Use Imperative Commands:** Your commit titles should succinctly describe the changes you've made. Prefix your commit titles with imperative commands such as: fix, refactor, add, and remove. This is because you should be able to suffix a commit message to the phrase: "If applied, this code will...".
|
|
8
|
+
|
|
9
|
+
A good practice is to structure your commit title like this: "[GitHub issue number] Add fields to hs record".
|
|
10
|
+
|
|
11
|
+
Keep It Brief - You're not writing a monologue, so keep it brief. As a general rule, a commit message should not exceed 50 characters.
|
|
12
|
+
|
|
13
|
+
3. **Use Draft PRs for Ongoing Work:** If your pull request is not ready for review, please mark it as a draft. This indicates to the team that the changes are still in progress.
|
|
14
|
+
|
|
15
|
+
4. **Request Reviews Before Merging:** When your pull request is ready, request a review from your team members. Reviews ensure that your changes are validated by others.
|
|
16
|
+
|
|
17
|
+
5. **Address Review Feedback:** If a reviewer asks for changes or provides feedback, please respond promptly and incorporate necessary changes.
|
|
18
|
+
|
|
19
|
+
6. **Merge Cautiously:** Once your pull request is reviewed and approved, ensure that it's merging into the correct branch and that it's up-to-date with the latest changes in that branch before merging.
|
data/Gemfile.lock
CHANGED
|
@@ -1,14 +1,22 @@
|
|
|
1
1
|
PATH
|
|
2
2
|
remote: .
|
|
3
3
|
specs:
|
|
4
|
-
uk-hs_code (0.
|
|
4
|
+
uk-hs_code (0.2.0)
|
|
5
5
|
|
|
6
6
|
GEM
|
|
7
7
|
remote: https://rubygems.org/
|
|
8
8
|
specs:
|
|
9
|
+
addressable (2.9.0)
|
|
10
|
+
public_suffix (>= 2.0.2, < 8.0)
|
|
9
11
|
ast (2.4.2)
|
|
12
|
+
base64 (0.3.0)
|
|
13
|
+
bigdecimal (4.1.3)
|
|
10
14
|
coderay (1.1.3)
|
|
15
|
+
crack (1.0.1)
|
|
16
|
+
bigdecimal
|
|
17
|
+
rexml
|
|
11
18
|
diff-lcs (1.5.0)
|
|
19
|
+
hashdiff (1.2.1)
|
|
12
20
|
json (2.6.3)
|
|
13
21
|
method_source (1.0.0)
|
|
14
22
|
parallel (1.22.1)
|
|
@@ -17,10 +25,12 @@ GEM
|
|
|
17
25
|
pry (0.14.2)
|
|
18
26
|
coderay (~> 1.1)
|
|
19
27
|
method_source (~> 1.0)
|
|
28
|
+
public_suffix (7.0.5)
|
|
29
|
+
racc (1.8.1)
|
|
20
30
|
rainbow (3.1.1)
|
|
21
31
|
rake (13.0.6)
|
|
22
32
|
regexp_parser (2.7.0)
|
|
23
|
-
rexml (3.
|
|
33
|
+
rexml (3.4.1)
|
|
24
34
|
rspec (3.12.0)
|
|
25
35
|
rspec-core (~> 3.12.0)
|
|
26
36
|
rspec-expectations (~> 3.12.0)
|
|
@@ -48,16 +58,24 @@ GEM
|
|
|
48
58
|
parser (>= 3.1.1.0)
|
|
49
59
|
ruby-progressbar (1.11.0)
|
|
50
60
|
unicode-display_width (2.4.2)
|
|
61
|
+
webmock (3.34.0)
|
|
62
|
+
addressable (>= 2.8.0)
|
|
63
|
+
crack (>= 0.3.2)
|
|
64
|
+
hashdiff (>= 0.4.0, < 2.0.0)
|
|
51
65
|
|
|
52
66
|
PLATFORMS
|
|
67
|
+
arm64-darwin-23
|
|
53
68
|
x86_64-linux
|
|
54
69
|
|
|
55
70
|
DEPENDENCIES
|
|
71
|
+
base64
|
|
56
72
|
pry
|
|
73
|
+
racc (~> 1.8)
|
|
57
74
|
rake (~> 13.0)
|
|
58
75
|
rspec (~> 3.0)
|
|
59
76
|
rubocop
|
|
60
77
|
uk-hs_code!
|
|
78
|
+
webmock (~> 3.0)
|
|
61
79
|
|
|
62
80
|
BUNDLED WITH
|
|
63
81
|
2.4.5
|
data/README.md
CHANGED
|
@@ -18,28 +18,26 @@ And:
|
|
|
18
18
|
## Usage
|
|
19
19
|
|
|
20
20
|
```ruby
|
|
21
|
-
#
|
|
21
|
+
# Search HS codes matching free-text commodity description
|
|
22
|
+
commodities = Uk::HsCode.search('cotton t-shirt')
|
|
22
23
|
|
|
23
|
-
|
|
24
|
+
commodities.first.code
|
|
25
|
+
# => "6109100010"
|
|
24
26
|
|
|
25
|
-
|
|
27
|
+
commodities.first.title
|
|
28
|
+
# => "T-shirts"
|
|
26
29
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
#<Uk::HsCode::Record id="11205", type="search_reference", attributes=#<Uk::HsCode::Record title="tablecloths, knitted or crocheted", referenced_id="6302", referenced_class="Heading", goods_nomenclature_item_id="6302000000", productline_suffix="80", goods_nomenclature_sid=43645>>,
|
|
30
|
-
#<Uk::HsCode::Record id="7289", type="search_reference", attributes=#<Uk::HsCode::Record title="tablecloths, of paper", referenced_id="4818300000-80", referenced_class="Commodity", goods_nomenclature_item_id="4818300000", productline_suffix="80", goods_nomenclature_sid=40686>>,
|
|
31
|
-
#<Uk::HsCode::Record id="11206", type="search_reference", attributes=#<Uk::HsCode::Record title="table cloths, other than knitted or crocheted", referenced_id="6302510000-10", referenced_class="Subheading", goods_nomenclature_item_id="6302510000", productline_suffix="10", goods_nomenclature_sid=43679>>
|
|
30
|
+
commodities.first.declarable
|
|
31
|
+
# => true
|
|
32
32
|
|
|
33
|
-
# Get only HS codes with their titles
|
|
33
|
+
# Get only HS codes with their titles
|
|
34
|
+
records = Uk::HsCode.search_hs_codes('carpet')
|
|
34
35
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
> refs.inspect
|
|
38
|
-
|
|
39
|
-
# => [#<Uk::HsCode::Record code="8451808000", title="carpet cleaning machines liquid injection">,
|
|
40
|
-
#<Uk::HsCode::Record code="4008000000", title="carpet underlay, rubber">,
|
|
41
|
-
#<Uk::HsCode::Record code="5402000000", title="carpet yarn, of man-made filaments">]
|
|
36
|
+
records.first.code
|
|
37
|
+
# => "8451808000"
|
|
42
38
|
|
|
39
|
+
records.first.title
|
|
40
|
+
# => "carpet cleaning machines liquid injection"
|
|
43
41
|
```
|
|
44
42
|
|
|
45
43
|
## Development
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "net/http"
|
|
4
|
+
require "uri"
|
|
5
|
+
require "json"
|
|
6
|
+
|
|
7
|
+
module Uk
|
|
8
|
+
module HsCode
|
|
9
|
+
class Client
|
|
10
|
+
BASE_URL = "https://www.trade-tariff.service.gov.uk/api/v2"
|
|
11
|
+
|
|
12
|
+
def initialize(base_url: BASE_URL)
|
|
13
|
+
@base_url = base_url
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def get(path, params = {})
|
|
17
|
+
uri = build_uri(path, params)
|
|
18
|
+
request = Net::HTTP::Get.new(uri)
|
|
19
|
+
request["User-Agent"] = "UK HS Code gem/#{Uk::HsCode::VERSION}"
|
|
20
|
+
request["Accept"] = "application/json"
|
|
21
|
+
|
|
22
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
|
23
|
+
http.use_ssl = true if uri.scheme == "https"
|
|
24
|
+
|
|
25
|
+
response = http.request(request)
|
|
26
|
+
handle_response(response)
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
private
|
|
30
|
+
|
|
31
|
+
def build_uri(path, params)
|
|
32
|
+
full_url = "#{@base_url}#{path}"
|
|
33
|
+
uri = URI.parse(full_url)
|
|
34
|
+
if params && !params.empty?
|
|
35
|
+
query_str = URI.encode_www_form(params)
|
|
36
|
+
uri.query = uri.query ? "#{uri.query}&#{query_str}" : query_str
|
|
37
|
+
end
|
|
38
|
+
uri
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
def handle_response(response)
|
|
42
|
+
raise Uk::HsCode::Error, "Request failed with status: #{response.code} - #{response.message}" unless response.is_a?(Net::HTTPSuccess)
|
|
43
|
+
|
|
44
|
+
JSON.parse(response.body)
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
end
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Uk
|
|
4
|
+
module HsCode
|
|
5
|
+
module Parsers
|
|
6
|
+
class SearchResponseParser
|
|
7
|
+
def self.call(response_hash)
|
|
8
|
+
new(response_hash).call
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def initialize(response_hash)
|
|
12
|
+
@response_hash = response_hash || {}
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def call
|
|
16
|
+
data = @response_hash["data"] || @response_hash[:data]
|
|
17
|
+
return [] unless data
|
|
18
|
+
|
|
19
|
+
type = data["type"] || data[:type]
|
|
20
|
+
attributes = data["attributes"] || data[:attributes] || {}
|
|
21
|
+
|
|
22
|
+
case type
|
|
23
|
+
when "exact_search"
|
|
24
|
+
parse_exact_search(attributes)
|
|
25
|
+
when "fuzzy_search"
|
|
26
|
+
parse_fuzzy_search(attributes)
|
|
27
|
+
else
|
|
28
|
+
[]
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
private
|
|
33
|
+
|
|
34
|
+
def parse_exact_search(attributes)
|
|
35
|
+
entry = attributes["entry"] || attributes[:entry] || {}
|
|
36
|
+
code = entry["id"] || entry[:id]
|
|
37
|
+
return [] unless code
|
|
38
|
+
|
|
39
|
+
[
|
|
40
|
+
Record.new(
|
|
41
|
+
code: code,
|
|
42
|
+
title: "Exact match for #{code}",
|
|
43
|
+
declarable: true,
|
|
44
|
+
type: "exact"
|
|
45
|
+
)
|
|
46
|
+
]
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
def parse_fuzzy_search(attributes)
|
|
50
|
+
records = []
|
|
51
|
+
seen_codes = {}
|
|
52
|
+
|
|
53
|
+
extract_commodities(attributes, records, seen_codes)
|
|
54
|
+
extract_references(attributes, records, seen_codes)
|
|
55
|
+
|
|
56
|
+
records
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
def extract_commodities(attributes, records, seen_codes)
|
|
60
|
+
gn_commodities = attributes.dig("goods_nomenclature_match", "commodities") || []
|
|
61
|
+
gn_commodities.each do |hit|
|
|
62
|
+
source = hit["_source"] || {}
|
|
63
|
+
code = source["goods_nomenclature_item_id"]
|
|
64
|
+
next if code.nil? || seen_codes[code]
|
|
65
|
+
|
|
66
|
+
seen_codes[code] = true
|
|
67
|
+
records << Record.new(
|
|
68
|
+
code: code,
|
|
69
|
+
title: source["description"],
|
|
70
|
+
description: source["description"],
|
|
71
|
+
score: hit["_score"],
|
|
72
|
+
declarable: source["declarable"],
|
|
73
|
+
type: "commodity"
|
|
74
|
+
)
|
|
75
|
+
end
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
def extract_references(attributes, records, seen_codes)
|
|
79
|
+
ref_commodities = attributes.dig("reference_match", "commodities") || []
|
|
80
|
+
ref_commodities.each do |hit|
|
|
81
|
+
source = hit["_source"] || {}
|
|
82
|
+
ref_data = source["reference"] || {}
|
|
83
|
+
code = ref_data["goods_nomenclature_item_id"]
|
|
84
|
+
next if code.nil? || seen_codes[code]
|
|
85
|
+
|
|
86
|
+
seen_codes[code] = true
|
|
87
|
+
records << Record.new(
|
|
88
|
+
code: code,
|
|
89
|
+
title: source["title"],
|
|
90
|
+
description: ref_data["description"] || source["title"],
|
|
91
|
+
score: hit["_score"],
|
|
92
|
+
declarable: ref_data["declarable"],
|
|
93
|
+
type: "reference"
|
|
94
|
+
)
|
|
95
|
+
end
|
|
96
|
+
end
|
|
97
|
+
end
|
|
98
|
+
end
|
|
99
|
+
end
|
|
100
|
+
end
|
data/lib/uk/hs_code/record.rb
CHANGED
|
@@ -2,6 +2,79 @@
|
|
|
2
2
|
|
|
3
3
|
module Uk
|
|
4
4
|
module HsCode
|
|
5
|
-
class Record
|
|
5
|
+
class Record
|
|
6
|
+
attr_reader :score, :declarable, :type
|
|
7
|
+
|
|
8
|
+
def initialize(code: nil, title: nil, description: nil, score: nil, declarable: nil, type: nil, **extra)
|
|
9
|
+
@extra = extra || {}
|
|
10
|
+
@code = code || @extra[:goods_nomenclature_item_id] || @extra["goods_nomenclature_item_id"]
|
|
11
|
+
@title = title || description || @extra[:negated_title] || @extra["negated_title"]
|
|
12
|
+
@description = description || title
|
|
13
|
+
@score = score
|
|
14
|
+
@declarable = declarable
|
|
15
|
+
@type = type
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def code
|
|
19
|
+
@code || self["code"] || self["goods_nomenclature_item_id"]
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def title
|
|
23
|
+
@title || self["title"] || self["description"]
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def description
|
|
27
|
+
@description || self["description"] || self["title"]
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def goods_nomenclature_item_id
|
|
31
|
+
code
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def attributes
|
|
35
|
+
self["attributes"] || self
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
def [](key)
|
|
39
|
+
instance_variable_get("@#{key}") || @extra[key.to_s] || @extra[key.to_sym]
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
def []=(key, val)
|
|
43
|
+
instance_variable_set("@#{key}", val)
|
|
44
|
+
@extra[key.to_s] = val
|
|
45
|
+
@extra[key.to_sym] = val
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
def method_missing(method_name, *args, &block)
|
|
49
|
+
str_key = method_name.to_s
|
|
50
|
+
if str_key.end_with?("=")
|
|
51
|
+
self[str_key.chop] = args.first
|
|
52
|
+
elsif @extra.key?(str_key) || @extra.key?(method_name)
|
|
53
|
+
self[method_name]
|
|
54
|
+
else
|
|
55
|
+
super
|
|
56
|
+
end
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
def respond_to_missing?(method_name, include_private = false)
|
|
60
|
+
str_key = method_name.to_s.chomp("=")
|
|
61
|
+
@extra.key?(str_key) || @extra.key?(str_key.to_sym) || super
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
def to_h
|
|
65
|
+
{
|
|
66
|
+
code: code,
|
|
67
|
+
title: title,
|
|
68
|
+
description: description,
|
|
69
|
+
score: score,
|
|
70
|
+
declarable: declarable,
|
|
71
|
+
type: type
|
|
72
|
+
}
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
def ==(other)
|
|
76
|
+
other.is_a?(Record) && code == other.code && title == other.title
|
|
77
|
+
end
|
|
78
|
+
end
|
|
6
79
|
end
|
|
7
80
|
end
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Uk
|
|
4
|
+
module HsCode
|
|
5
|
+
module Services
|
|
6
|
+
class SearchService
|
|
7
|
+
def self.call(...)
|
|
8
|
+
new(...).call
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def initialize(params = {}, client: Client.new, **keyword_params)
|
|
12
|
+
merged_params = keyword_params.empty? ? params : keyword_params
|
|
13
|
+
@params = merged_params.is_a?(Hash) ? merged_params : { query: merged_params }
|
|
14
|
+
@client = client
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def call
|
|
18
|
+
validate_prerequisites!
|
|
19
|
+
execute_workflow
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
private
|
|
23
|
+
|
|
24
|
+
def validate_prerequisites!
|
|
25
|
+
raise ArgumentError, "Missing required query" if query.empty?
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def execute_workflow
|
|
29
|
+
raw_response = @client.get("/search", { q: query })
|
|
30
|
+
Parsers::SearchResponseParser.call(raw_response)
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def query
|
|
34
|
+
(@params[:query] || @params["query"] || @params[:q] || @params["q"]).to_s.strip
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
end
|
data/lib/uk/hs_code/version.rb
CHANGED
data/lib/uk/hs_code.rb
CHANGED
|
@@ -1,29 +1,29 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
require_relative "hs_code/version"
|
|
4
|
-
require_relative "hs_code/api_request"
|
|
5
4
|
require_relative "hs_code/record"
|
|
5
|
+
require_relative "hs_code/client"
|
|
6
|
+
require_relative "hs_code/parsers/search_response_parser"
|
|
7
|
+
require_relative "hs_code/services/search_service"
|
|
8
|
+
require_relative "hs_code/api_request"
|
|
6
9
|
|
|
7
10
|
module Uk
|
|
8
11
|
module HsCode
|
|
9
|
-
API_ENDPOINT = "https://www.trade-tariff.service.gov.uk/api"
|
|
12
|
+
API_ENDPOINT = "https://www.trade-tariff.service.gov.uk/api/v2"
|
|
10
13
|
|
|
11
14
|
class Error < StandardError; end
|
|
12
15
|
|
|
13
16
|
class << self
|
|
14
17
|
def search(query)
|
|
15
|
-
|
|
18
|
+
Services::SearchService.call(query: query)
|
|
16
19
|
end
|
|
17
20
|
|
|
18
21
|
def search_hs_codes(query)
|
|
19
|
-
|
|
20
|
-
result.map { |a| Record.new(code: a.attributes.goods_nomenclature_item_id, title: a.attributes.title) }
|
|
22
|
+
search(query)
|
|
21
23
|
end
|
|
22
24
|
|
|
23
|
-
private
|
|
24
|
-
|
|
25
25
|
def search_references(query)
|
|
26
|
-
ApiRequest.new("#{API_ENDPOINT}/
|
|
26
|
+
ApiRequest.new("#{API_ENDPOINT}/search_references.json", { query: { letter: query } }).get
|
|
27
27
|
end
|
|
28
28
|
end
|
|
29
29
|
end
|
data/uk-hs_code.gemspec
CHANGED
|
@@ -12,7 +12,7 @@ Gem::Specification.new do |spec|
|
|
|
12
12
|
spec.description = "Trade Tariff Public API V2 communicator."
|
|
13
13
|
spec.homepage = "https://github.com/enigmatt-pl/uk-hs_code.git"
|
|
14
14
|
spec.license = "MIT"
|
|
15
|
-
spec.required_ruby_version = ">=
|
|
15
|
+
spec.required_ruby_version = ">= 3.0.0"
|
|
16
16
|
|
|
17
17
|
spec.metadata["homepage_uri"] = spec.homepage
|
|
18
18
|
spec.metadata["source_code_uri"] = spec.homepage
|
|
@@ -29,15 +29,11 @@ Gem::Specification.new do |spec|
|
|
|
29
29
|
spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
|
|
30
30
|
spec.require_paths = ["lib"]
|
|
31
31
|
|
|
32
|
+
spec.add_development_dependency "base64"
|
|
32
33
|
spec.add_development_dependency "pry"
|
|
33
|
-
spec.add_development_dependency "
|
|
34
|
-
|
|
34
|
+
spec.add_development_dependency "racc", "~> 1.8"
|
|
35
35
|
spec.add_development_dependency "rake", "~> 13.0"
|
|
36
36
|
spec.add_development_dependency "rspec", "~> 3.0"
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
# spec.add_dependency "example-gem", "~> 1.0"
|
|
40
|
-
|
|
41
|
-
# For more information and examples about making a new gem, check out our
|
|
42
|
-
# guide at: https://bundler.io/guides/creating_gem.html
|
|
37
|
+
spec.add_development_dependency "rubocop"
|
|
38
|
+
spec.add_development_dependency "webmock", "~> 3.0"
|
|
43
39
|
end
|
metadata
CHANGED
|
@@ -1,17 +1,16 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: uk-hs_code
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.2.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Mateusz Michalski
|
|
8
|
-
autorequire:
|
|
9
8
|
bindir: exe
|
|
10
9
|
cert_chain: []
|
|
11
|
-
date:
|
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
|
12
11
|
dependencies:
|
|
13
12
|
- !ruby/object:Gem::Dependency
|
|
14
|
-
name:
|
|
13
|
+
name: base64
|
|
15
14
|
requirement: !ruby/object:Gem::Requirement
|
|
16
15
|
requirements:
|
|
17
16
|
- - ">="
|
|
@@ -25,7 +24,7 @@ dependencies:
|
|
|
25
24
|
- !ruby/object:Gem::Version
|
|
26
25
|
version: '0'
|
|
27
26
|
- !ruby/object:Gem::Dependency
|
|
28
|
-
name:
|
|
27
|
+
name: pry
|
|
29
28
|
requirement: !ruby/object:Gem::Requirement
|
|
30
29
|
requirements:
|
|
31
30
|
- - ">="
|
|
@@ -38,6 +37,20 @@ dependencies:
|
|
|
38
37
|
- - ">="
|
|
39
38
|
- !ruby/object:Gem::Version
|
|
40
39
|
version: '0'
|
|
40
|
+
- !ruby/object:Gem::Dependency
|
|
41
|
+
name: racc
|
|
42
|
+
requirement: !ruby/object:Gem::Requirement
|
|
43
|
+
requirements:
|
|
44
|
+
- - "~>"
|
|
45
|
+
- !ruby/object:Gem::Version
|
|
46
|
+
version: '1.8'
|
|
47
|
+
type: :development
|
|
48
|
+
prerelease: false
|
|
49
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
50
|
+
requirements:
|
|
51
|
+
- - "~>"
|
|
52
|
+
- !ruby/object:Gem::Version
|
|
53
|
+
version: '1.8'
|
|
41
54
|
- !ruby/object:Gem::Dependency
|
|
42
55
|
name: rake
|
|
43
56
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -66,6 +79,34 @@ dependencies:
|
|
|
66
79
|
- - "~>"
|
|
67
80
|
- !ruby/object:Gem::Version
|
|
68
81
|
version: '3.0'
|
|
82
|
+
- !ruby/object:Gem::Dependency
|
|
83
|
+
name: rubocop
|
|
84
|
+
requirement: !ruby/object:Gem::Requirement
|
|
85
|
+
requirements:
|
|
86
|
+
- - ">="
|
|
87
|
+
- !ruby/object:Gem::Version
|
|
88
|
+
version: '0'
|
|
89
|
+
type: :development
|
|
90
|
+
prerelease: false
|
|
91
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
92
|
+
requirements:
|
|
93
|
+
- - ">="
|
|
94
|
+
- !ruby/object:Gem::Version
|
|
95
|
+
version: '0'
|
|
96
|
+
- !ruby/object:Gem::Dependency
|
|
97
|
+
name: webmock
|
|
98
|
+
requirement: !ruby/object:Gem::Requirement
|
|
99
|
+
requirements:
|
|
100
|
+
- - "~>"
|
|
101
|
+
- !ruby/object:Gem::Version
|
|
102
|
+
version: '3.0'
|
|
103
|
+
type: :development
|
|
104
|
+
prerelease: false
|
|
105
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
106
|
+
requirements:
|
|
107
|
+
- - "~>"
|
|
108
|
+
- !ruby/object:Gem::Version
|
|
109
|
+
version: '3.0'
|
|
69
110
|
description: Trade Tariff Public API V2 communicator.
|
|
70
111
|
email:
|
|
71
112
|
- enigmatt.priv@gmail.com
|
|
@@ -75,6 +116,7 @@ extra_rdoc_files: []
|
|
|
75
116
|
files:
|
|
76
117
|
- ".rspec"
|
|
77
118
|
- ".rubocop.yml"
|
|
119
|
+
- CONTRIBUTING.md
|
|
78
120
|
- Gemfile
|
|
79
121
|
- Gemfile.lock
|
|
80
122
|
- LICENSE.txt
|
|
@@ -82,7 +124,10 @@ files:
|
|
|
82
124
|
- Rakefile
|
|
83
125
|
- lib/uk/hs_code.rb
|
|
84
126
|
- lib/uk/hs_code/api_request.rb
|
|
127
|
+
- lib/uk/hs_code/client.rb
|
|
128
|
+
- lib/uk/hs_code/parsers/search_response_parser.rb
|
|
85
129
|
- lib/uk/hs_code/record.rb
|
|
130
|
+
- lib/uk/hs_code/services/search_service.rb
|
|
86
131
|
- lib/uk/hs_code/version.rb
|
|
87
132
|
- sig/uk/hs_code.rbs
|
|
88
133
|
- uk-hs_code.gemspec
|
|
@@ -93,7 +138,6 @@ metadata:
|
|
|
93
138
|
homepage_uri: https://github.com/enigmatt-pl/uk-hs_code.git
|
|
94
139
|
source_code_uri: https://github.com/enigmatt-pl/uk-hs_code.git
|
|
95
140
|
changelog_uri: https://github.com/enigmatt-pl/uk-hs_code.git
|
|
96
|
-
post_install_message:
|
|
97
141
|
rdoc_options: []
|
|
98
142
|
require_paths:
|
|
99
143
|
- lib
|
|
@@ -101,15 +145,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
101
145
|
requirements:
|
|
102
146
|
- - ">="
|
|
103
147
|
- !ruby/object:Gem::Version
|
|
104
|
-
version:
|
|
148
|
+
version: 3.0.0
|
|
105
149
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
106
150
|
requirements:
|
|
107
151
|
- - ">="
|
|
108
152
|
- !ruby/object:Gem::Version
|
|
109
153
|
version: '0'
|
|
110
154
|
requirements: []
|
|
111
|
-
rubygems_version: 3.
|
|
112
|
-
signing_key:
|
|
155
|
+
rubygems_version: 3.6.7
|
|
113
156
|
specification_version: 4
|
|
114
157
|
summary: Enables communication with Trade Tariff Public API V2.
|
|
115
158
|
test_files: []
|