def upload(cookbook, extended_metadata = false)
      # Artifactory doesn't prevent uploading over an existing release in
      # some cases so let's check for that. Seriously never do this, go delete
      # and then re-upload if you have to.
      response = request(:get, "api/v1/cookbooks/#{cookbook.name}/versions/#{cookbook.version}")
      # Artifactory's version of the cookbook_version endpoint returns an
      # empty 200 on an unknown version.
      unless response.code == '404' || (response.code == '200' && response.body.to_s == '')
        raise Error::CookbookAlreadyExists.new(cookbook: cookbook)
      end

      # Run the upload.
      response = request(:post, "api/v1/cookbooks/#{cookbook.name}.tgz") do |req|
        req.body_stream = cookbook.tarball(extended_metadata)
        req.content_length = req.body_stream.size
        req['Content-Type'] = 'application/x-binary'
      end
      response.error! unless response.code == '201'
    end
def upload(cookbook, extended_metadata = false)
      # Artifactory doesn't prevent uploading over an existing release in
      # some cases so let's check for that. Seriously never do this, go delete
      # and then re-upload if you have to.
      response = request(:get, "api/v1/cookbooks/#{cookbook.name}/versions/#{cookbook.version}")
      # Artifactory's version of the cookbook_version endpoint returns an
      # empty 200 on an unknown version.
      unless response.code == '404' || (response.code == '200' && response.body.to_s == '')
        raise Error::CookbookAlreadyExists.new(cookbook: cookbook)
      end

      # Run the upload.
      response = request(:post, "api/v1/cookbooks/#{cookbook.name}.tgz") do |req|
        req.body_stream = cookbook.tarball(extended_metadata)
        req.content_length = req.body_stream.size
        req['Content-Type'] = 'application/x-binary'
      end
      response.error! unless response.code == '201'
    end
Upload a cookbook to an Artifactory server.

 @param [Cookbook] cookbook
   the cookbook to upload