never_had_a_name
never_had_a_name

Reputation: 93166

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 someone show me how to do it with a Ruby gem like rest-client or octopussy?

Upvotes: 0

Views: 972

Answers (2)

nocache
nocache

Reputation: 1805

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

Upvotes: 0

BaroqueBobcat
BaroqueBobcat

Reputation: 10150

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

Upvotes: 3

Related Questions