pad_utils 1.12.0 → 1.13.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/pad_utils/pad_http.rb +32 -0
- data/lib/pad_utils/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: 666d446c66e74463183e738bd50dad4d366a0be4
|
4
|
+
data.tar.gz: 64d015b46bfe342bb7c135057b4e72f1b394184a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d923ff1197164a19d94d6fe140bf9bf5bb7d75777cbc7b83a1e356d9de981f83c2de4b6f2fe8d3e71c371339ef78d35e9d4575a4310e9a8c3d9cd0b774c9c242
|
7
|
+
data.tar.gz: 82423a6dbe5a1d04002900fdb7d22f8299aa12dbadef6ea48e7593d0ffc37101dc8c956ba143089bf5d77b9f20e4501b7952195faba077f4da177d3ff3f6a473
|
data/lib/pad_utils/pad_http.rb
CHANGED
@@ -82,4 +82,36 @@ module PadUtils
|
|
82
82
|
reply_hash = {error: e.message}
|
83
83
|
end
|
84
84
|
|
85
|
+
# Downloads a file API-frienldy.
|
86
|
+
#
|
87
|
+
# @note **Warning:** If the server answers with an error message, no error will
|
88
|
+
# be raised and the `target` file be created with the content of the error message.
|
89
|
+
#
|
90
|
+
# @param url [String]
|
91
|
+
# @param target [String] the local target file path and name
|
92
|
+
# @param headers [Hash] the hash containing the header key/value pair
|
93
|
+
# @return [String] the target path and name or the error message
|
94
|
+
# @example
|
95
|
+
# PadUtils.http_get_file("http:/example.com/v1/get_file", "image.jpg") # => "image.jpg"
|
96
|
+
def self.http_get_file(url, target, headers: {'User-Agent' => 'Padstone'})
|
97
|
+
File.open(target, "wb") do |f|
|
98
|
+
f.binmode
|
99
|
+
f.write HTTParty.get(url).parsed_response
|
100
|
+
end
|
101
|
+
|
102
|
+
if File.size(target) < 1
|
103
|
+
PadUtils.delete_file(target)
|
104
|
+
"File not found"
|
105
|
+
else
|
106
|
+
target
|
107
|
+
end
|
108
|
+
|
109
|
+
rescue Errno::ECONNREFUSED => e
|
110
|
+
PadUtils.delete_file(target)
|
111
|
+
"Server unreachable"
|
112
|
+
rescue Exception => e
|
113
|
+
PadUtils.delete_file(target)
|
114
|
+
e.message
|
115
|
+
end
|
116
|
+
|
85
117
|
end
|
data/lib/pad_utils/version.rb
CHANGED