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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a57ad969adf349766fdd182d7584def31151f923
4
- data.tar.gz: 7573d40a4b00a0840b4570f28feb8056c4392ce3
3
+ metadata.gz: 666d446c66e74463183e738bd50dad4d366a0be4
4
+ data.tar.gz: 64d015b46bfe342bb7c135057b4e72f1b394184a
5
5
  SHA512:
6
- metadata.gz: ced60c55e799ddef2dc513d65dcfbae361294b06b612428b35d9903b7c8aa5b5b81d69fa1aafbd2b31af2ecff1df8ae622f4ea12f014fc2392f370f06b837a4a
7
- data.tar.gz: 17a2ca11e5a148e33c0303433070a806e5030e9da97a2a76f2001d117ce474b424696b0386b59c904a57b68544b9cae6bb8aef7e52c54963dae3c3de428cd7c6
6
+ metadata.gz: d923ff1197164a19d94d6fe140bf9bf5bb7d75777cbc7b83a1e356d9de981f83c2de4b6f2fe8d3e71c371339ef78d35e9d4575a4310e9a8c3d9cd0b774c9c242
7
+ data.tar.gz: 82423a6dbe5a1d04002900fdb7d22f8299aa12dbadef6ea48e7593d0ffc37101dc8c956ba143089bf5d77b9f20e4501b7952195faba077f4da177d3ff3f6a473
@@ -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
@@ -1,4 +1,4 @@
1
1
  module PadUtils
2
2
  # PadUtils version number
3
- VERSION = "1.12.0"
3
+ VERSION = "1.13.0"
4
4
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pad_utils
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.12.0
4
+ version: 1.13.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nico Schuele