开发者

Authenticate user through GitHub API using Ruby?

I have to authenticate a user through the GitHub API in Ruby to be able to create a private repository.

The GitHub manual shows how to do it with curl.

Could 开发者_JAVA百科someone show me how to do it with a Ruby gem like rest-client or octopussy?


Something like this?

client = Octokit::Client.new(:login => 'someguy', :token => 'sometoken123b1i3')
client.create(:name=>'foobar', :description=>'Foo Bar', :homepage=> 'http://example.com', :public=>false)

http://github.com/pengwynn/octokit/blob/master/lib/octokit/client.rb#L198


using RestClient, first you need to create a resource, then use that to post the JSON data defining the repo metadata:

my_resource = RestClient::Resource.new( "https://api.github.com", :user => "username", :password => "123456" )
my_resource["/user/repos"].post( { :name => "new-repo", :description => "this is a new repo", :public => true }.to_json )

See http://developer.github.com/v3/repos/ for details on the API

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜