我基本上是在尝试使用 octokit github api ruby 工具包获取我的存储库的名称。我查看了文档和他们的代码文件:
# Get a single repository
#
# @see https://developer.github.com/v3/repos/#get
# @see https://developer.github.com/v3/licenses/#get-a-repositorys-license
# @param repo [Integer, String, Hash, Repository] A GitHub repository
# @return [Sawyer::Resource] Repository information
def repository(repo, options = {})
get Repository.path(repo), options
end
alias :repo :repository
# Edit a repository
#
# @see https://developer.github.com/v3/repos/#edit
# @param repo [String, Hash, Repository] A GitHub repository
# @param options [Hash] Repository information to update
# @option options [String] :name Name of the repo
# @option options [String] :description Description of the repo
# @option options [String] :homepage Home page of the repo
# @option options [String] :private `true` makes the repository private, and `false` makes it public.
# @option options [String] :has_issues `true` enables issues for this repo, `false` disables issues.
# @option options [String] :has_wiki `true` enables wiki for this repo, `false` disables wiki.
# @option options [String] :has_downloads `true` enables downloads for this repo, `false` disables downloads.
# @option options [String] :default_branch Update the default branch for this repository.
# @return [Sawyer::Resource] Repository information
我知道 options 参数是一个哈希,但我仍然对如何指定参数来获取存储库名称感到困惑。这是我的代码:
require 'octokit'
require 'netrc'
class Base
# attr_accessor :un, :pw
# un = username
# pw = password
def initialize
@client = Octokit::Client.new(:access_token =>
'<access_token>')
print "Username you want to search?\t"
@username = gets.chomp.to_s
@user = @client.user(@username)
puts "#{@username} email is:\t\t#{@user.email}"
puts @user.repository('converse', :options => name)
end
end
start = Base.new
使用我的 acess_token,我可以获得自己或其他人的 github 名称、电子邮件、组织等,但是当我使用方法时……它们总是有选项参数,我很难为此指定正确的参数。