printnode 1.0.5 → 1.0.7
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/printnode/client.rb +3 -3
- data/lib/printnode/printjob.rb +32 -15
- metadata +3 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d695182e835ba0775915de715ca18878b1634199
|
4
|
+
data.tar.gz: c9dd27039dbb57a324ff180dbea704b7c85e50e2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5f67ec8fcb1c0f825334d4733221fc424eb19319ed611f0c212b29a2c438c0af74154014a9aaa5a4002d0031d525f51988715487e536cb654487b5f00b1c0835
|
7
|
+
data.tar.gz: 45563ed39f6cbd49ff40f13fb420da3dccea2415534620e96caf583b6d09809e26e89627354751ce9ef5dfd85bfa99c1a4d8eee9a061062e46a44eb4ef2713da
|
data/lib/printnode/client.rb
CHANGED
@@ -2,7 +2,6 @@ require 'net/https'
|
|
2
2
|
require 'uri'
|
3
3
|
require 'json'
|
4
4
|
require 'ostruct'
|
5
|
-
require 'base64'
|
6
5
|
require 'cgi'
|
7
6
|
|
8
7
|
module PrintNode
|
@@ -11,6 +10,8 @@ module PrintNode
|
|
11
10
|
# @author PrintNode
|
12
11
|
class Client
|
13
12
|
|
13
|
+
attr_reader :headers
|
14
|
+
|
14
15
|
# If an argument is not a string, map it to a string so it can be escaped
|
15
16
|
# and put into a URL.
|
16
17
|
#
|
@@ -23,7 +24,6 @@ module PrintNode
|
|
23
24
|
CGI.escape(obj)
|
24
25
|
end
|
25
26
|
|
26
|
-
attr_reader :headers
|
27
27
|
# Initializes auth object, api url and headers.
|
28
28
|
#
|
29
29
|
# @param auth [PrintNode::Auth] auth object with credentials.
|
@@ -100,7 +100,7 @@ module PrintNode
|
|
100
100
|
def start_response(request, uri)
|
101
101
|
response = Net::HTTP.start(uri.hostname,
|
102
102
|
uri.port,
|
103
|
-
use_ssl: uri.scheme
|
103
|
+
use_ssl: uri.scheme == 'https') do |http|
|
104
104
|
http.request(request)
|
105
105
|
end
|
106
106
|
http_error_handler(response)
|
data/lib/printnode/printjob.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'base64'
|
2
|
+
|
2
3
|
module PrintNode
|
3
4
|
# An object for printjob creation.
|
4
5
|
# @author Jake Torrance
|
@@ -10,21 +11,6 @@ module PrintNode
|
|
10
11
|
attr_accessor :content
|
11
12
|
attr_accessor :source
|
12
13
|
|
13
|
-
# Maps the object into a hash ready for JSON Encoding.
|
14
|
-
def to_hash
|
15
|
-
hash = {}
|
16
|
-
hash['printerId'] = @printer_id
|
17
|
-
hash['title'] = @title
|
18
|
-
hash['contentType'] = @content_type
|
19
|
-
if @content_type.match('base64$')
|
20
|
-
hash ['content'] = Base64.encode64(IO.read(@content))
|
21
|
-
else
|
22
|
-
hash ['content'] = @content
|
23
|
-
end
|
24
|
-
hash['source'] = @source
|
25
|
-
hash
|
26
|
-
end
|
27
|
-
|
28
14
|
# Initializes the object with the variables required.
|
29
15
|
def initialize(printer_id, title, content_type, content, source)
|
30
16
|
@printer_id = printer_id
|
@@ -33,5 +19,36 @@ module PrintNode
|
|
33
19
|
@content = content
|
34
20
|
@source = source
|
35
21
|
end
|
22
|
+
|
23
|
+
# Maps the object into a hash ready for JSON Encoding.
|
24
|
+
def to_hash
|
25
|
+
{
|
26
|
+
'printerId' => @printer_id,
|
27
|
+
'title' => @title,
|
28
|
+
'contentType' => @content_type,
|
29
|
+
'content' => load_content,
|
30
|
+
'source' => @source
|
31
|
+
}
|
32
|
+
end
|
33
|
+
|
34
|
+
def load_content
|
35
|
+
# Used to be, we only supported file names for Base64, but it's actually better
|
36
|
+
# to allow the user to send us a data string if they desire. Testing the
|
37
|
+
# content to see if it's a path allows for backwards compatibility
|
38
|
+
if @content_type.match('base64$') && content_is_existing_file?
|
39
|
+
Base64.encode64(IO.read(@content))
|
40
|
+
else
|
41
|
+
@content
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def content_is_existing_file?
|
46
|
+
begin
|
47
|
+
File.exist?(@content)
|
48
|
+
rescue
|
49
|
+
false
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
36
53
|
end
|
37
54
|
end
|
metadata
CHANGED
@@ -1,15 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: printnode
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- PrintNode
|
8
|
-
- Jake Torrance
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date:
|
11
|
+
date: 2018-06-18 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
14
|
name: json
|
@@ -72,9 +71,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
72
71
|
version: '0'
|
73
72
|
requirements: []
|
74
73
|
rubyforge_project:
|
75
|
-
rubygems_version: 2.
|
74
|
+
rubygems_version: 2.5.2
|
76
75
|
signing_key:
|
77
76
|
specification_version: 4
|
78
77
|
summary: PrintNode-Ruby
|
79
78
|
test_files: []
|
80
|
-
has_rdoc:
|