0

我保留错误“ /usr/local/bin/git_flow_tools.rb:55:in `set_issue': uninitialized constant Net::HTTP::Patch (NameError)

我需要这个:

require 'rubygems'
require 'net/http'
require 'net/https'
require 'uri'
require 'timeout'
require 'json'
require 'pp'

此功能失败:

def self.set_issue(user, repo, number, data)
  uri              = URI.parse('https://api.github.com')
  http             = Net::HTTP.new(uri.host, uri.port)
  http.use_ssl     = true if uri.scheme == 'https'
  http.verify_mode = OpenSSL::SSL::VERIFY_NONE

  path                 = URI.escape("/repos/#{user}/#{repo}/issues/#{number}")
  req                  = Net::HTTP::Patch.new(path)
  req['Content-Type']  = 'application/json'
  req['Accept']        = 'application/json'
  req['Authorization'] = 'token OAUTH-TOKEN'
  req.body             = data

  begin
    Timeout::timeout(30) { JSON.parse http.request(req).body }
  rescue Exception => e
    puts "Failed to contact github #{e}"
  end
end

其他方法,如GetPutPost工作正常。

有任何想法吗?

4

1 回答 1

4

尝试在要求之后添加

class Net::HTTP::Patch < Net::HTTPRequest
  METHOD = 'PATCH'
  REQUEST_HAS_BODY = true
  RESPONSE_HAS_BODY = true
end
于 2013-10-27T19:47:33.007 回答