uktt 0.2.14

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 704cdbced174d1c9e81f21ad9f3719b76811c7d81771fddc25a70237df99b610
4
+ data.tar.gz: 4078426ef1e0491aade1ca67c6d5aeeff835ca509577022c78e91c459b5644a4
5
+ SHA512:
6
+ metadata.gz: e34e45e2fa8f46671ad010f16dec7522bfacecf2a6606a3e3b32a2e83cafbc2db00207d11f66adcdbd3f808a9d89f706abb69dbe9926b24e410a170d52c056a7
7
+ data.tar.gz: 7cbfb3c8bb72c7d3b65428b4b06419d6ab568e397ed57bb4d8ea7d68bb543e0f9beba6f6ddcf81ed1dc7e40aa45f701a9e914422055b864f52ea6369bc262a6a
@@ -0,0 +1,12 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
12
+ .idea/*
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
@@ -0,0 +1,21 @@
1
+ AllCops:
2
+ Exclude:
3
+ - 'db/**/*'
4
+ - 'config/**/*'
5
+ - 'script/**/*'
6
+ - 'bin/{rails,rake}'
7
+ - !ruby/regexp /old_and_unused\.rb$/
8
+ - 'lib/uktt/export_chapter_pdf.rb'
9
+ - 'vendor/**/*'
10
+ Metrics/ClassLength:
11
+ Enabled: false
12
+ Metrics/MethodLength:
13
+ Enabled: false
14
+ Metrics/BlockLength:
15
+ Enabled: false
16
+ Metrics/LineLength:
17
+ Enabled: false
18
+ Metrics/CyclomaticComplexity:
19
+ Max: 8
20
+ Metrics/ParameterLists:
21
+ Max: 6
@@ -0,0 +1,7 @@
1
+ ---
2
+ sudo: false
3
+ language: ruby
4
+ cache: bundler
5
+ rvm:
6
+ - 2.6.0
7
+ before_install: gem install bundler -v 2.0.1
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at mcu@mac.com. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in uktt.gemspec
4
+ gemspec
@@ -0,0 +1,54 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ uktt (0.2.14)
5
+ faraday
6
+ nokogiri
7
+ prawn
8
+ prawn-table
9
+ thor (~> 0.20)
10
+
11
+ GEM
12
+ remote: https://rubygems.org/
13
+ specs:
14
+ diff-lcs (1.3)
15
+ faraday (1.0.1)
16
+ multipart-post (>= 1.2, < 3)
17
+ mini_portile2 (2.4.0)
18
+ multipart-post (2.1.1)
19
+ nokogiri (1.10.10)
20
+ mini_portile2 (~> 2.4.0)
21
+ pdf-core (0.8.1)
22
+ prawn (2.3.0)
23
+ pdf-core (~> 0.8.1)
24
+ ttfunk (~> 1.6)
25
+ prawn-table (0.2.2)
26
+ prawn (>= 1.3.0, < 3.0.0)
27
+ rake (13.0.1)
28
+ rspec (3.8.0)
29
+ rspec-core (~> 3.8.0)
30
+ rspec-expectations (~> 3.8.0)
31
+ rspec-mocks (~> 3.8.0)
32
+ rspec-core (3.8.0)
33
+ rspec-support (~> 3.8.0)
34
+ rspec-expectations (3.8.2)
35
+ diff-lcs (>= 1.2.0, < 2.0)
36
+ rspec-support (~> 3.8.0)
37
+ rspec-mocks (3.8.0)
38
+ diff-lcs (>= 1.2.0, < 2.0)
39
+ rspec-support (~> 3.8.0)
40
+ rspec-support (3.8.0)
41
+ thor (0.20.3)
42
+ ttfunk (1.6.2.1)
43
+
44
+ PLATFORMS
45
+ ruby
46
+
47
+ DEPENDENCIES
48
+ bundler (~> 2.0)
49
+ rake (~> 13.0)
50
+ rspec (~> 3.0)
51
+ uktt!
52
+
53
+ BUNDLED WITH
54
+ 2.1.4
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2019 Christopher Unger
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,307 @@
1
+ # UKTT
2
+
3
+ Uktt provides a way to work with the UK Trade Tariff API, https://api.trade-tariff.service.gov.uk/#gov-uk-trade-tariff-api.
4
+
5
+ ### Features
6
+ - Fetches sections, chapters, headings, commodities, goods_nomenclatures, monetary exchange rates, and quota definitions from the Tariff API
7
+ - Covers both `v1` and `v2` of the API
8
+ - Tests local, production, and any other Frontend API servers using real (not mocked) API calls
9
+ - Produces printable Tariff PDF files for chapters
10
+ - Command-line interface
11
+
12
+ ## Installation
13
+
14
+ The repository is here: __https://gitlab.bitzesty.com/open-source/uktt__
15
+
16
+ Add to your Gemfile:
17
+
18
+ ```ruby
19
+ gem 'uktt', git: 'https://gitlab.bitzesty.com/open-source/uktt.git'
20
+ ```
21
+
22
+ ## Usage
23
+
24
+ ### Set options
25
+
26
+ Set library-wide options using a hash. Here are the current defaults:
27
+ ```ruby
28
+ opts = {
29
+ host: 'http://localhost:3002', # use a local frontend server
30
+ version: 'v1', # `v1` and `v2` are supported
31
+ debug: false, # dislays request and response info
32
+ return_json: false # returns OpenStruct by default
33
+ }
34
+ ```
35
+
36
+ Set options upon instantiation, and change them on the instance by passing-in a hash to overwrite existing or create new options:
37
+ ```ruby
38
+ # Instatiate an new object with options:
39
+
40
+ > s = Uktt::Section.new(opts.merge(section_id: '1'))
41
+
42
+ # or, set `section_id` with accessor. Only `*_id` options have accessors.
43
+
44
+ > s = Uktt::Section.new
45
+ > s.section_id = '1'
46
+
47
+ # => #<Uktt::Section @section_id="1", @config={:host=>"http://localhost:3002", :version=>"v1", :debug=>false, :return_json=>false}>
48
+
49
+ > s.config = {version: 'v2', return_json: true, section_id: '2'}
50
+ > s.inspect
51
+
52
+ # => #<Uktt::Section @section_id="2", @config={:host=>"http://localhost:3002", :version=>"v2", :debug=>false, :return_json=>true}>
53
+
54
+ # NOTE: `Uktt::Section` has accessors. Other objects also have *_id accessors.
55
+
56
+ > s.section_id
57
+
58
+ # => "2"
59
+
60
+ > s.section_id = '3'
61
+
62
+ # => #<Uktt::Section @section_id="3", @config={:host=>"http://localhost:3002", :version=>"v2", :debug=>false, :return_json=>true}>
63
+
64
+ ```
65
+
66
+ Options may be loaded from a YAML configuration file:
67
+
68
+ ```yaml
69
+ # uktt.yaml
70
+ ---
71
+ host: http://foo.bar:999
72
+ version: v2
73
+ debug: false
74
+ return_json: false
75
+ ```
76
+
77
+
78
+ Load options from file:
79
+
80
+ ```ruby
81
+ > Uktt.configure_with('./uktt.yaml')
82
+
83
+ # => {"host"=>"http://foo.bar:999", "version"=>"v2", "debug"=>false, "return_json"=>false}
84
+ ```
85
+
86
+ ### Retrieve one object
87
+
88
+ Retrieve an object as an OpenStruct, then retrieve it as JSON
89
+
90
+ ```ruby
91
+ > s.retrieve
92
+
93
+ # => #<OpenStruct data=#<OpenStruct id="3", type="section", attributes=#<OpenStruct ... >>>
94
+
95
+ > s.config = {return_json: true}
96
+ > s.retrieve
97
+
98
+ # => {"data":{"id":"3","type":"section","attributes":{"id": ... }}}
99
+
100
+ ```
101
+
102
+ ### Retrieve collections of objects
103
+
104
+ Retrieve all sections using `v2`, then switch to `v1`:
105
+
106
+ ```ruby
107
+ > s.retrieve_all
108
+
109
+ # => #<OpenStruct data=[#<OpenStruct id="1", type="section", attributes=#<OpenStruct ... >>]>
110
+
111
+ > s.config = {version: 'v1'}
112
+ > s.retrieve_all
113
+
114
+ # => [#<OpenStruct id=1, position=1, title="Live animals; animal products", numeral="I", ...>]
115
+ ```
116
+
117
+ ### Quota search
118
+
119
+ Retrieve quota definitions, optionally filtered by various criteria. The search criteria are passed-in with a hash:
120
+
121
+ ```ruby
122
+ > criteria = {
123
+ goods_nomenclature_item_id: '0805102200',
124
+ year: '2018',
125
+ geographical_area_id: 'EG',
126
+ order_number: '091784',
127
+ status: 'not blocked',
128
+ critical: 'N'
129
+ }
130
+ > quotas = Uktt::Quota.new(version: 'v2') # must use `v2`
131
+ > quotas.search(criteria)
132
+
133
+ # => #<OpenStruct data=[#<OpenStruct id="12202", type="definition", attributes=#<OpenStruct quota_definition_sid=12202, quota_order_number_id="091784" ... >>]>
134
+ ```
135
+ ### Goods nomenclatures
136
+
137
+ Retrieves goods nomenclatures by heading, chapter, or section.
138
+
139
+ E.g., use a heading object to retrieve all associated goods nomenclatures:
140
+
141
+ ```ruby
142
+ > h = Uktt::Heading.new(heading_id: '0101')
143
+ > h.goods_nomenclatures
144
+
145
+ # => #<OpenStruct data=[#<OpenStruct id="27624", type="goods_nomenclature", attributes=#<OpenStruct goods_nomenclature_item_id="0101000000", ... >>]>
146
+ ```
147
+
148
+ ### API Testing
149
+
150
+ The Uktt gem may be used to test the Trade Tariff API. The specs _do not_ use mocks-- and will make real API requests against a Trade Tariff frontend server, e.g., local, dev, staging, or production.
151
+
152
+ Run tests using default server (localhost:3002) and default API version `v1`:
153
+
154
+ ```bash
155
+ $ rake spec
156
+ ```
157
+
158
+ To run tests using API version `v2`, set the `VER` environment variable:
159
+
160
+ ```bash
161
+ $ VER=v2 rake spec
162
+ ```
163
+
164
+ To run tests against any Trade Tariff Frontend server, set the `HOST` variable, or use a shortcut `PROD=true` to set the host to the production server:
165
+
166
+ ```bash
167
+ $ HOST=https://dev.trade-tariff.service.gov.uk rake spec
168
+
169
+ # or using a shortcut for production:
170
+
171
+ $ PROD=true rake spec
172
+
173
+ # envorinment variables may be combined:
174
+
175
+ $ HOST=https://localhost:3002 VER=v2 rake spec
176
+ ```
177
+
178
+ ### PDF
179
+
180
+ The Uktt gem can produce PDF files for individual chapters of the Tariff.
181
+
182
+ Set `chapter_id` and optional `filepath` with a hash.
183
+
184
+ ```ruby
185
+ > p = Uktt::Pdf.new
186
+ > p.config = {chapter_id: '01', filepath: './Chapter-01.pdf'}
187
+ > p.make_chapter
188
+ ```
189
+
190
+ #### Currencies in PDF
191
+
192
+ The default currency for PDFs is the Euro. The PDF may be produced in certain other supported currencies. if one or more supported currencies is specified, all currency amounts in the PDF will be converted from EUR (the "parent" currency) into the specified child currency.
193
+
194
+ The exchange rates for each supported currency must be specified in one of the following ways:
195
+ 1. For any supported currency, set a `MX_RATE_EUR_***` environment variable, where `***` is the three-letter currency code
196
+ 2. For GBP, the gem will attempt to look up the EUR-GBP exchange rate using the Tariff API
197
+ 3. EUR is the default currency if no currency is specified
198
+
199
+ The Tariff PDF will be produced in any supported currency specified in the options:
200
+ ```ruby
201
+ > Uktt::Pdf.new(chapter_id: '01', filepath: './Chapter-01-GBP.pdf', host:'https://www.trade-tariff.service.gov.uk/api', currency:'GBP').make_chapter
202
+ ```
203
+
204
+ ** In the backend (where we run the PDF gem), the exchange rate is fetched from the db and then set as an ENV variable before the chapters are produced:
205
+ ```ruby
206
+ ENV["MX_RATE_EUR_#{currency}"] ||= MonetaryExchangeRate.latest(currency).to_s
207
+ ```
208
+
209
+ The supported currencies are:
210
+ ```ruby
211
+ SUPPORTED_CURRENCIES = {
212
+ 'BGN' => 'лв',
213
+ 'CZK' => 'Kč',
214
+ 'DKK' => 'kr.',
215
+ 'EUR' => '€',
216
+ 'GBP' => '£',
217
+ 'HRK' => 'kn',
218
+ 'HUF' => 'Ft',
219
+ 'PLN' => 'zł',
220
+ 'RON' => 'lei',
221
+ 'SEK' => 'kr'
222
+ }
223
+ ```
224
+
225
+ ## Command line interface
226
+
227
+ This gem provides a command-line interface (CLI).
228
+
229
+ ```bash
230
+ $ uktt
231
+
232
+ Commands:
233
+ uktt chapter # Retrieves a chapter
234
+ uktt chapters # Retrieves all chapters
235
+ uktt commodity # Retrieves a commodity
236
+ uktt heading # Retrieves a heading
237
+ uktt help [COMMAND] # Describe available commands or one specific command
238
+ uktt info # Prints help for `uktt`
239
+ uktt monetary_exchange_rates # Retrieves monetary exchange rates
240
+ uktt pdf # Makes a PDF of a chapter
241
+ uktt section # Retrieves a section
242
+ uktt sections # Retrieves all sections
243
+ uktt test # Runs API specs
244
+
245
+ Options:
246
+ -h, --host, [--host=http://localhost:3002] # Use specified API host, otherwise `http://localhost:3002`
247
+ -a, --api-version, [--version=v1] # Request a specific API version, otherwise `v1`
248
+ -d, --debug, [--debug=true], [--no-debug] # Show request and response headers, otherwise not shown
249
+ -j, --json, [--return-json=true], [--no-return-json] # Request JSON response, otherwise OpenStruct
250
+ -p, --production, [--prod=true] # Use production API host, otherwise `http://localhost:3002`
251
+ -g, --goods, [--goods=GOODS] # Retrieve goods nomenclatures in this object
252
+ -n, --note, [--note=NOTE] # Retrieve a note for this object
253
+ -c, --changes, [--changes=CHANGES] # Retrieve changes for this object
254
+ ```
255
+
256
+ Here are some examples of the CLI:
257
+
258
+ ```bash
259
+ # basic usage
260
+ $ uktt sections # get all sections
261
+ $ uktt section 1 # get one section
262
+ $ uktt section 1 -j # get JSON
263
+ $ uktt section 1 -jp # get JSON, from prod.
264
+ $ uktt section 1 -jp -a v2 # get JSON, from prod., use `v2`
265
+ $ uktt monetary_exchange_rates # get a collection
266
+
267
+ # get an object
268
+ $ uktt chapter 01
269
+ $ uktt heading 0101
270
+ $ uktt commodity 0101210000
271
+
272
+ # make a PDF
273
+ $ uktt pdf 01 # specify a chapter_id
274
+ $ uktt pdf 'test' # use the magic filename 'test' for a PDF smoketest
275
+ # which _doesn't_ hit the API
276
+
277
+ # 'goods nomenclatures' resources are only availab=le on `v2` of the API
278
+ $ uktt heading 0101 -g -a v2
279
+ $ uktt chapter 01 -g -a v2
280
+ $ uktt section 1 --goods --api-version v2 # using long format options
281
+ ```
282
+
283
+ ## Development
284
+
285
+ While developing the gem, and for use outside of a Rails app, I found it useful to have a console:
286
+
287
+ ```bash
288
+ $ bundle console
289
+ ```
290
+
291
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` (or `bundle console` outside of a rails app) for an interactive prompt that will allow you to experiment.
292
+
293
+ ## Contributing
294
+
295
+ Pull requests: https://gitlab.bitzesty.com/open-source/uktt/merge_requests.
296
+
297
+ Issues list: https://gitlab.bitzesty.com/open-source/uktt/issues.
298
+
299
+ This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
300
+
301
+ ## License
302
+
303
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
304
+
305
+ ## Code of Conduct
306
+
307
+ Everyone interacting in the `uktt` project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://gitlab.bitzesty.com/open-source/uktt/blob/master/CODE_OF_CONDUCT.md).