开发者

Authenticate user through GitHub API using Ruby?

开发者 https://www.devze.com 2023-01-15 12:05 出处:网络
I have to authenticate a user through the GitHub API in Ruby to be able to create a private repository.

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

精彩评论

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