sprint_client 0.0.10 → 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 +25 -7
- metadata +3 -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
@@ -9,9 +9,14 @@ class SPrintClient
|
|
9
9
|
require 'json'
|
10
10
|
|
11
11
|
# printer_name - a string showing which printer to send the request to
|
12
|
-
# 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
|
13
13
|
# merge_fields_list - a list of hashes, each containing the field values for a particular label
|
14
|
-
# 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
|
15
20
|
def self.send_print_request(printer_name, label_template_name, merge_fields_list)
|
16
21
|
# define GraphQL print mutation
|
17
22
|
query = "mutation Print($printRequest: PrintRequest!, $printer: String!) {
|
@@ -22,10 +27,25 @@ class SPrintClient
|
|
22
27
|
|
23
28
|
# locate the required label template
|
24
29
|
path = get_label_template_path(label_template_name)
|
25
|
-
|
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
|
26
35
|
|
27
36
|
# parse the template for each label
|
28
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
|
+
# ]
|
29
49
|
|
30
50
|
# build the body of the print request
|
31
51
|
body = {
|
@@ -39,7 +59,6 @@ class SPrintClient
|
|
39
59
|
}
|
40
60
|
|
41
61
|
send_post(body)
|
42
|
-
|
43
62
|
end
|
44
63
|
|
45
64
|
def self.sprint_uri=(sprint_uri)
|
@@ -51,6 +70,8 @@ class SPrintClient
|
|
51
70
|
Net::HTTP.post URI(@@sprint_uri),
|
52
71
|
body.to_json,
|
53
72
|
'Content-Type' => 'application/json'
|
73
|
+
rescue StandardError => e
|
74
|
+
Net::HTTPResponse.new('1.1', '422', "Failed to send post to #{@@sprint_uri}")
|
54
75
|
end
|
55
76
|
|
56
77
|
def self.get_template(path)
|
@@ -66,10 +87,7 @@ class SPrintClient
|
|
66
87
|
layouts
|
67
88
|
end
|
68
89
|
|
69
|
-
private
|
70
|
-
|
71
90
|
def self.get_label_template_path(label_template_name)
|
72
91
|
File.join('config', 'sprint', 'label_templates', label_template_name)
|
73
92
|
end
|
74
|
-
|
75
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,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2020-11-
|
12
|
+
date: 2020-11-10 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rspec
|
@@ -51,7 +51,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
51
51
|
- !ruby/object:Gem::Version
|
52
52
|
version: '0'
|
53
53
|
requirements: []
|
54
|
-
rubygems_version: 3.
|
54
|
+
rubygems_version: 3.0.8
|
55
55
|
signing_key:
|
56
56
|
specification_version: 4
|
57
57
|
summary: A client gem for SPrint
|