sprint_client 0.0.6

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.
Files changed (3) hide show
  1. checksums.yaml +7 -0
  2. data/lib/sprint_client.rb +49 -0
  3. metadata +44 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 170e6b6ee33cd8f973be154337d2d1ad1e034ce912c5f869bdbe9d7c0c3dd3e7
4
+ data.tar.gz: 35f5a95ed99fd93be81382601412225b533228e638041989cbc71df88ed216b6
5
+ SHA512:
6
+ metadata.gz: abdb40499b6fdc6eb269b66e442b195f6b3f4223c14499e2e278e38135ea9cfbc9e5032600e18fc9205f9ee9db7acd707eb8e574efea47163a39b01e2a6d6db5
7
+ data.tar.gz: 61a1a012eddd76546cb4c47cdfd2a9fb37a2d2065e4292b0ab1ca64cecb654b68cb423a2ff94693e9e82496cceed120fab6523c61291ae135d5cf920d5a9ec5e
@@ -0,0 +1,49 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Interfaces with SPrint service: https://github.com/sanger/sprint
4
+ class SprintClient
5
+ require 'uri'
6
+ require 'erb'
7
+
8
+ # printer_name - a string showing which printer to send the request to
9
+ # label_template_name - a string to identify which label template to be used in the print request
10
+ # merge_fields_list - a list of hashes, each containing the field values for a particular label
11
+ # e.g [{ barcode: "DN111111", date: "1-APR-2020" }, { barcode: "DN222222", date: "2-APR-2020" }] would print two labels
12
+ def self.send_print_request(printer_name, label_template_name, merge_fields_list)
13
+ # define GraphQL print mutation
14
+ query = "mutation Print($printRequest: PrintRequest!, $printer: String!) {
15
+ print(printRequest: $printRequest, printer: $printer) {
16
+ jobId
17
+ }
18
+ }"
19
+
20
+ # locate the required label template
21
+ path = File.join('config', 'sprint', label_template_name)
22
+ template = ERB.new File.read(path)
23
+
24
+ # parse the template for each label
25
+ layouts = merge_fields_list.map do |merge_fields|
26
+ YAML.load template.result binding
27
+ end
28
+
29
+ # build the body of the print request
30
+ body = {
31
+ "query": query,
32
+ "variables": {
33
+ "printer": printer_name,
34
+ "printRequest": {
35
+ "layouts": layouts
36
+ }
37
+ }
38
+ }
39
+
40
+ # send POST request to SPrint url
41
+ reponse = Net::HTTP.post URI(configatron.sprint_url),
42
+ body.to_json,
43
+ 'Content-Type' => 'application/json'
44
+
45
+ # return response of POST request
46
+ puts response
47
+ reponse
48
+ end
49
+ end
metadata ADDED
@@ -0,0 +1,44 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: sprint_client
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.6
5
+ platform: ruby
6
+ authors:
7
+ - Harriet Craven
8
+ - Katy Taylor
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2020-10-27 00:00:00.000000000 Z
13
+ dependencies: []
14
+ description: ''
15
+ email: seq-help@sanger.ac.uk
16
+ executables: []
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - lib/sprint_client.rb
21
+ homepage: https://rubygems.org/gems/sprint_client
22
+ licenses:
23
+ - MIT
24
+ metadata: {}
25
+ post_install_message:
26
+ rdoc_options: []
27
+ require_paths:
28
+ - lib
29
+ required_ruby_version: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ required_rubygems_version: !ruby/object:Gem::Requirement
35
+ requirements:
36
+ - - ">="
37
+ - !ruby/object:Gem::Version
38
+ version: '0'
39
+ requirements: []
40
+ rubygems_version: 3.0.8
41
+ signing_key:
42
+ specification_version: 4
43
+ summary: A client gem for SPrint
44
+ test_files: []