0

我目前正在尝试检索 Github 存储库返回的状态代码。我曾尝试使用#response_status doc,但文档对如何创建 Octokit:: Error 类的实例不是很清楚。而且,我似乎无法调用该方法来检索状态代码。

      #create an instance of the class  
      @git_client_error = Octokit::Error.new
      ....
      # sample usage
      @git_client_error.response_status

任何使用 ruby​​ 中的 response_status 实现的例子都将不胜感激。

4

1 回答 1

1

如果我们假设您按照github repo 自述文件中的说明进行操作,您应该有一个客户端对象。从那里,您向客户端发出请求。要检查状态代码,您可以检查响应。每个客户端请求都会发出一个 http 请求。

client = Octokit::Client.new(:login => 'somebody', :password => 'something!')
# now make any request
user = client.user
# client.user should return a user object instance of Sawyer::Resource class
response = client.last_response
response.status
=> 200
于 2019-05-31T17:15:29.133 回答