docmago_client 0.5.0 → 0.5.1
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/docmago_client.rb +4 -6
- data/lib/docmago_client/railtie.rb +8 -7
- data/lib/docmago_client/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a9536ecd03665d2dde981f55a9f8fcdbc11c21e6
|
4
|
+
data.tar.gz: 8ee2f7771d3f421ceba8d29a21c78ea445a345a4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 49f5cbdf4eeb7065ef615c7748d8005f6fa2f7329b6fa650ace1aba10da6816ccd4fcb3101a1e81dc0dee87df3452b55821768e638cbeb3552f1c4a5463942fd
|
7
|
+
data.tar.gz: 7c3010309e42866505406ba8104a07eaee8817ea5e010546955dedabf8d71c89ff085c48f4958fed5f1120866853535005f99891a4e6a63ed2bf8b3c84f51237
|
data/lib/docmago_client.rb
CHANGED
@@ -42,9 +42,7 @@ module DocmagoClient
|
|
42
42
|
|
43
43
|
default_options = {
|
44
44
|
name: 'default',
|
45
|
-
type: 'pdf'
|
46
|
-
test_mode: false,
|
47
|
-
raise_exception_on_failure: false
|
45
|
+
type: 'pdf'
|
48
46
|
}
|
49
47
|
|
50
48
|
options = default_options.merge(options)
|
@@ -58,7 +56,7 @@ module DocmagoClient
|
|
58
56
|
|
59
57
|
response = Typhoeus.post "#{base_uri}/documents", body: {
|
60
58
|
auth_token: api_key,
|
61
|
-
document:
|
59
|
+
document: options.slice(:content, :name, :type, :test_mode)
|
62
60
|
}
|
63
61
|
ensure
|
64
62
|
FileUtils.remove_entry_secure tmp_dir
|
@@ -66,7 +64,7 @@ module DocmagoClient
|
|
66
64
|
else
|
67
65
|
response = Typhoeus.post "#{base_uri}/documents", body: {
|
68
66
|
auth_token: api_key,
|
69
|
-
document: options
|
67
|
+
document: options.slice(:content, :name, :type, :test_mode)
|
70
68
|
}
|
71
69
|
end
|
72
70
|
|
@@ -74,7 +72,7 @@ module DocmagoClient
|
|
74
72
|
ret_val = nil
|
75
73
|
Tempfile.open('docmago') do |f|
|
76
74
|
f.sync = true
|
77
|
-
f.write(response.body)
|
75
|
+
f.write(response.body.force_encoding('utf-8'))
|
78
76
|
f.rewind
|
79
77
|
|
80
78
|
ret_val = yield f, response
|
@@ -21,7 +21,7 @@ module DocmagoClient
|
|
21
21
|
|
22
22
|
default_options = {
|
23
23
|
name: filename || controller_name,
|
24
|
-
test_mode: Rails.env.development
|
24
|
+
test_mode: Rails.env.development?.to_s,
|
25
25
|
base_uri: url_for(only_path: false),
|
26
26
|
resource_path: Rails.root.join('public').to_s,
|
27
27
|
assets: Rails.application.assets,
|
@@ -31,13 +31,14 @@ module DocmagoClient
|
|
31
31
|
options = default_options.merge(options)
|
32
32
|
options[:content] ||= render_to_string(options)
|
33
33
|
|
34
|
-
|
35
|
-
|
34
|
+
DocmagoClient.create(options) do |file, res|
|
35
|
+
logger.info "Docmago response - status: #{res.code}; size: #{res.body.size}"
|
36
36
|
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
37
|
+
if res.code == 200
|
38
|
+
send_file file, filename: "#{options[:name]}.pdf", type: 'application/pdf', disposition: 'attachment'
|
39
|
+
else
|
40
|
+
render inline: res.body, status: res.code
|
41
|
+
end
|
41
42
|
end
|
42
43
|
end
|
43
44
|
end
|