sprint_client 0.0.9 → 0.0.10
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/sprint_client.rb +41 -12
- metadata +18 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4cd904fb03773aa281e55de6e10dfc0e6be2b24a198fa95ffe1a82372264e926
|
4
|
+
data.tar.gz: 51a498b4afb2c6889fa4d9aa9f713eb42f1fb7f44bafa64730d6114c83b4892b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d0e3bd5b194bf9154388352c89e4ced28449da45fa72b0d6670d2ee6d9d974e0f2f718abea0ba6b89f2d4e07dc7fd124ad2ecb821f5b9aa2ee1270f4f3d258e5
|
7
|
+
data.tar.gz: bad2bbc3b52516b56aabda4feb8b60764e6a31f5217504536f6367c839e127a16c4ec67e1183a0dee9cc4b84bee2e052d0eb068a2166ef384ac94f4b57603e66
|
data/lib/sprint_client.rb
CHANGED
@@ -1,10 +1,13 @@
|
|
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
12
|
# label_template_name - a string to identify which label template to be used in the print request
|
10
13
|
# merge_fields_list - a list of hashes, each containing the field values for a particular label
|
@@ -17,14 +20,12 @@ class SprintClient
|
|
17
20
|
}
|
18
21
|
}"
|
19
22
|
|
20
|
-
# locate the required label template
|
21
|
-
path =
|
22
|
-
template =
|
23
|
+
# locate the required label template
|
24
|
+
path = get_label_template_path(label_template_name)
|
25
|
+
template = get_template(path)
|
23
26
|
|
24
27
|
# parse the template for each label
|
25
|
-
layouts = merge_fields_list
|
26
|
-
YAML.load template.result binding
|
27
|
-
end
|
28
|
+
layouts = set_layouts(merge_fields_list, template)
|
28
29
|
|
29
30
|
# build the body of the print request
|
30
31
|
body = {
|
@@ -37,10 +38,38 @@ class SprintClient
|
|
37
38
|
}
|
38
39
|
}
|
39
40
|
|
41
|
+
send_post(body)
|
42
|
+
|
43
|
+
end
|
44
|
+
|
45
|
+
def self.sprint_uri=(sprint_uri)
|
46
|
+
@@sprint_uri = sprint_uri
|
47
|
+
end
|
48
|
+
|
49
|
+
def self.send_post(body)
|
40
50
|
# send POST request to SPrint url and return response
|
41
|
-
Net::HTTP.post URI(
|
42
|
-
|
43
|
-
|
51
|
+
Net::HTTP.post URI(@@sprint_uri),
|
52
|
+
body.to_json,
|
53
|
+
'Content-Type' => 'application/json'
|
54
|
+
end
|
44
55
|
|
56
|
+
def self.get_template(path)
|
57
|
+
ERB.new File.read(path)
|
45
58
|
end
|
59
|
+
|
60
|
+
def self.set_layouts(merge_fields_list, template)
|
61
|
+
layouts = []
|
62
|
+
merge_fields_list.each do |merge_fields|
|
63
|
+
template_array = YAML.load template.result binding
|
64
|
+
template_array.each { |ar| layouts << ar }
|
65
|
+
end
|
66
|
+
layouts
|
67
|
+
end
|
68
|
+
|
69
|
+
private
|
70
|
+
|
71
|
+
def self.get_label_template_path(label_template_name)
|
72
|
+
File.join('config', 'sprint', 'label_templates', label_template_name)
|
73
|
+
end
|
74
|
+
|
46
75
|
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.0.10
|
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-
|
13
|
-
dependencies:
|
12
|
+
date: 2020-11-05 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: []
|
@@ -37,7 +51,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
37
51
|
- !ruby/object:Gem::Version
|
38
52
|
version: '0'
|
39
53
|
requirements: []
|
40
|
-
rubygems_version: 3.
|
54
|
+
rubygems_version: 3.1.2
|
41
55
|
signing_key:
|
42
56
|
specification_version: 4
|
43
57
|
summary: A client gem for SPrint
|