sprint_client 0.0.6 → 0.1.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/lib/sprint_client.rb +62 -18
- metadata +17 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c21d3dac4bda250212579d1b8d3b593e0208d365354d9aae1e1085ecb6711bef
|
4
|
+
data.tar.gz: a029637cc6ff98f21409ec28f050dd7058dae5f539437115806e3e93601a4b00
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f50f3845d341a9f1f6a2484ee17a18b99b4e925894377a04da186a30eab3d7da953fb274c62d328a9ef6e5d4b94e9aa8b58c63c61db1549caa7563efd7796e54
|
7
|
+
data.tar.gz: f4297e1d3e2040622a4b5990f3561b86d1f11d364d1c7be3e8b7c1838eec0c68017f5a708e9d83d7f4100b3097312c3dd4cfa5fdb17c39be30e0927b7fd3448b
|
data/lib/sprint_client.rb
CHANGED
@@ -1,14 +1,22 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
# Interfaces with SPrint service: https://github.com/sanger/sprint
|
4
|
-
class
|
3
|
+
# Interfaces with SPrint service: https://github.com/sanger/sprint
|
4
|
+
class SPrintClient
|
5
5
|
require 'uri'
|
6
6
|
require 'erb'
|
7
|
-
|
7
|
+
require 'yaml'
|
8
|
+
require 'net/http'
|
9
|
+
require 'json'
|
10
|
+
|
8
11
|
# 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
|
12
|
+
# label_template_name - a string to identify which label template to be used in the print request e.g plate_384.yml.erb
|
10
13
|
# merge_fields_list - a list of hashes, each containing the field values for a particular label
|
11
|
-
# e.g
|
14
|
+
# e.g
|
15
|
+
# [
|
16
|
+
# {"right_text"=>"DN9000003B", "left_text"=>"DN9000003B", "barcode"=>"DN9000003B", "extra_right_text"=>"DN9000003B LTHR-384 RT", "extra_left_text"=>"10-NOV-2020"},
|
17
|
+
# {"right_text"=>"DN9000003B", "left_text"=>"DN9000003B", "barcode"=>"DN9000003B", "extra_right_text"=>"DN9000003B LTHR-384 RT", "extra_left_text"=>"10-NOV-2020"}
|
18
|
+
# ]
|
19
|
+
# would print two labels
|
12
20
|
def self.send_print_request(printer_name, label_template_name, merge_fields_list)
|
13
21
|
# define GraphQL print mutation
|
14
22
|
query = "mutation Print($printRequest: PrintRequest!, $printer: String!) {
|
@@ -17,14 +25,27 @@ class SprintClient
|
|
17
25
|
}
|
18
26
|
}"
|
19
27
|
|
20
|
-
# locate the required label template
|
21
|
-
path =
|
22
|
-
|
28
|
+
# locate the required label template
|
29
|
+
path = get_label_template_path(label_template_name)
|
30
|
+
begin
|
31
|
+
template = get_template(path)
|
32
|
+
rescue StandardError => e
|
33
|
+
return Net::HTTPResponse.new('1.1', '422', "Could not find label template with name #{label_template_name}")
|
34
|
+
end
|
23
35
|
|
24
36
|
# parse the template for each label
|
25
|
-
layouts = merge_fields_list
|
26
|
-
|
27
|
-
|
37
|
+
layouts = set_layouts(merge_fields_list, template)
|
38
|
+
# layouts: [
|
39
|
+
# {
|
40
|
+
# "labelSize"=>{"width"=>68, "height"=>6, "displacement"=>13},
|
41
|
+
# "barcodeFields"=>[{"x"=>21, "y"=>0, "cellWidth"=>0.2, "barcodeType"=>"code39", "value"=>"DN9000003B", "height"=>5}],
|
42
|
+
# "textFields"=>[{"x"=>1, "y"=>4, "value"=>"DN9000003B", "font"=>"proportional", "fontSize"=>1.7}, {"x"=>47, "y"=>4, "value"=>"DN9000003B", "font"=>"proportional", "fontSize"=>1.7}]
|
43
|
+
# },
|
44
|
+
# {
|
45
|
+
# "labelSize"=>{"width"=>68, "height"=>6, "displacement"=>13},
|
46
|
+
# "textFields"=>[{"x"=>1, "y"=>3, "value"=>"10-NOV-2020", "font"=>"proportional", "fontSize"=>1.7}, {"x"=>15, "y"=>3, "value"=>"DN9000003B LTHR-384 RT", "font"=>"proportional", "fontSize"=>1.7}]
|
47
|
+
# }
|
48
|
+
# ]
|
28
49
|
|
29
50
|
# build the body of the print request
|
30
51
|
body = {
|
@@ -37,13 +58,36 @@ class SprintClient
|
|
37
58
|
}
|
38
59
|
}
|
39
60
|
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
61
|
+
send_post(body)
|
62
|
+
end
|
63
|
+
|
64
|
+
def self.sprint_uri=(sprint_uri)
|
65
|
+
@@sprint_uri = sprint_uri
|
66
|
+
end
|
67
|
+
|
68
|
+
def self.send_post(body)
|
69
|
+
# send POST request to SPrint url and return response
|
70
|
+
Net::HTTP.post URI(@@sprint_uri),
|
71
|
+
body.to_json,
|
72
|
+
'Content-Type' => 'application/json'
|
73
|
+
rescue StandardError => e
|
74
|
+
Net::HTTPResponse.new('1.1', '422', "Failed to send post to #{@@sprint_uri}")
|
75
|
+
end
|
76
|
+
|
77
|
+
def self.get_template(path)
|
78
|
+
ERB.new File.read(path)
|
79
|
+
end
|
80
|
+
|
81
|
+
def self.set_layouts(merge_fields_list, template)
|
82
|
+
layouts = []
|
83
|
+
merge_fields_list.each do |merge_fields|
|
84
|
+
template_array = YAML.load template.result binding
|
85
|
+
template_array.each { |ar| layouts << ar }
|
86
|
+
end
|
87
|
+
layouts
|
88
|
+
end
|
44
89
|
|
45
|
-
|
46
|
-
|
47
|
-
reponse
|
90
|
+
def self.get_label_template_path(label_template_name)
|
91
|
+
File.join('config', 'sprint', 'label_templates', label_template_name)
|
48
92
|
end
|
49
93
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sprint_client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Harriet Craven
|
@@ -9,8 +9,22 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2020-10
|
13
|
-
dependencies:
|
12
|
+
date: 2020-11-10 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rspec
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
requirements:
|
18
|
+
- - "~>"
|
19
|
+
- !ruby/object:Gem::Version
|
20
|
+
version: 3.9.0
|
21
|
+
type: :development
|
22
|
+
prerelease: false
|
23
|
+
version_requirements: !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - "~>"
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
version: 3.9.0
|
14
28
|
description: ''
|
15
29
|
email: seq-help@sanger.ac.uk
|
16
30
|
executables: []
|