lib/roku_builder/util.rb in roku_builder-3.3.3 vs lib/roku_builder/util.rb in roku_builder-3.3.4
- old
+ new
@@ -25,7 +25,46 @@
# Second initializer to be overwriten
def init
#Override in subclass
end
+
+ # Generates a simpe Faraday connection with digest credentials
+ # @return [Faraday] The faraday connection
+ def simple_connection
+ Faraday.new(url: @url) do |f|
+ f.request :digest, @dev_username, @dev_password
+ f.adapter Faraday.default_adapter
+ end
+ end
+
+ # Generates a multipart Faraday connection with digest credentials
+ # @param port [Integer] optional port to connect to
+ # @return [Faraday] The faraday connection
+ def multipart_connection(port: nil)
+ url = @url
+ url = "#{url}:#{port}" if port
+ Faraday.new(url: url) do |f|
+ f.headers['Content-Type'] = Faraday::Request::Multipart.mime_type
+ f.request :digest, @dev_username, @dev_password
+ f.request :multipart
+ f.request :url_encoded
+ f.adapter Faraday.default_adapter
+ end
+ end
+
+ # Parses a string into and options hash
+ # @param options [String] string of options in the format "a:b, c:d"
+ # @return [Hash] Options hash generated
+ def self.options_parse(options:)
+ parsed = {}
+ opts = options.split(/,\s*/)
+ opts.each do |opt|
+ opt = opt.split(":")
+ key = opt.shift.to_sym
+ value = opt.join(":")
+ parsed[key] = value
+ end
+ parsed
+ end
end
end