lib/nightcrawler_swift/commands/upload.rb in nightcrawler_swift-0.11.1 vs lib/nightcrawler_swift/commands/upload.rb in nightcrawler_swift-1.0.0

- old
+ new

@@ -1,9 +1,13 @@ module NightcrawlerSwift class Upload < Command def execute path, file, opts = {} + if path.nil? or path.empty? + raise Exceptions::ValidationError.new "Upload command requires a path parameter" + end + body = file.read headers = {etag: etag(body), content_type: content_type(file)} max_age = opts[:max_age] || options.max_age headers.merge!(cache_control: "public, max-age=#{max_age}") if max_age @@ -16,10 +20,10 @@ custom_headers = opts[:custom_headers] headers.merge!(custom_headers) if custom_headers response = put "#{connection.upload_url}/#{path}", body: body, headers: headers - [200, 201].include?(response.code) + response.code >= 200 && response.code < 300 end private def content_type file