Class: Spout::Helpers::SendFile
- Inherits:
-
Object
- Object
- Spout::Helpers::SendFile
- Defined in:
- lib/spout/helpers/send_file.rb
Instance Attribute Summary collapse
-
#url ⇒ Object
readonly
Returns the value of attribute url.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(url, filename, version, token, slug, folder) ⇒ SendFile
constructor
A new instance of SendFile.
- #post ⇒ Object
Constructor Details
#initialize(url, filename, version, token, slug, folder) ⇒ SendFile
Returns a new instance of SendFile.
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/spout/helpers/send_file.rb', line 18 def initialize(url, filename, version, token, slug, folder) @params = {} @params["version"] = version @params["auth_token"] = token if token @params["dataset"] = slug if slug @params["folder"] = folder if folder begin file = File.open(filename, "rb") @params["file"] = file mp = Multipart::MultipartPost.new @query, @headers = mp.prepare_query(@params) ensure file.close if file end begin @url = URI.parse(url) @http = Net::HTTP.new(@url.host, @url.port) if @url.scheme == "https" @http.use_ssl = true @http.verify_mode = OpenSSL::SSL::VERIFY_NONE end rescue end end |
Instance Attribute Details
#url ⇒ Object (readonly)
Returns the value of attribute url.
16 17 18 |
# File 'lib/spout/helpers/send_file.rb', line 16 def url @url end |
Class Method Details
.post(*args) ⇒ Object
11 12 13 |
# File 'lib/spout/helpers/send_file.rb', line 11 def post(*args) new(*args).post end |
Instance Method Details
#post ⇒ Object
46 47 48 49 50 51 52 53 |
# File 'lib/spout/helpers/send_file.rb', line 46 def post response = @http.start do |http| http.post(@url.path, @query, @headers) end JSON.parse(response.body) rescue nil end |