Skip to content

Commit

Permalink
Add "create user" admin API
Browse files Browse the repository at this point in the history
  • Loading branch information
gjtorikian committed Jul 30, 2015
1 parent 02685ee commit 97d2628
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 2 deletions.
13 changes: 13 additions & 0 deletions lib/octokit/enterprise_admin_client/users.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,19 @@ class EnterpriseAdminClient
#
# @see https://developer.github.com/v3/users/administration/
module Users
# Create a new user.
#
# @param login [String] The user's username.
# @param email [String] The user's email address.
# @see https://developer.github.com/v3/users/administration/#create-a-new-user
# @example
# @admin_client.promote('foobar', '[email protected]')
def create(login, email, options = {})
options[:login] = login
options[:email] = email
boolean_from_response :post, "admin/users", options
end

# Promote an ordinary user to a site administrator
#
# @param user [String] Username of the user to promote.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"http_interactions":[{"request":{"method":"post","uri":"<<ENTERPRISE_HOSTNAME>>admin/users","body":{"encoding":"UTF-8","base64_string":"eyJsb2dpbiI6ImZvb2JhciIsImVtYWlsIjoibm90cmVhbEBmb28uYmFyIn0=\n"},"headers":{"User-Agent":["Octokit Ruby Gem 4.0.1"],"Accept":["application/vnd.github.v3+json"],"Content-Type":["application/json"],"Authorization":["token <<ENTERPRISE_ACCESS_TOKEN>>"],"Accept-Encoding":["gzip;q=1.0,deflate;q=0.6,identity;q=0.3"]}},"response":{"status":{"code":201,"message":"Created"},"headers":{"Server":["GitHub.com"],"Date":["Thu, 30 Jul 2015 06:01:09 GMT"],"Content-Type":["application/json; charset=utf-8"],"Content-Length":["808"],"Status":["201 Created"],"Cache-Control":["private, max-age=60, s-maxage=60"],"Etag":["\"8a4e1d4aee9d9c47e99071922b80cd9c\""],"X-Oauth-Scopes":["admin:org, admin:org_hook, admin:public_key, admin:repo_hook, gist, repo, user"],"X-Accepted-Oauth-Scopes":[""],"Location":["<<ENTERPRISE_HOSTNAME>>users/foobar"],"Vary":["Accept, Authorization, Cookie, X-GitHub-OTP"],"X-Github-Media-Type":["github.v3; format=json"],"X-Xss-Protection":["1; mode=block"],"X-Frame-Options":["deny"],"Content-Security-Policy":["default-src 'none'"],"Access-Control-Allow-Credentials":["true"],"Access-Control-Expose-Headers":["ETag, Link, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval"],"Access-Control-Allow-Origin":["*"],"X-Github-Request-Id":["2c531614-0fbd-4d91-b027-fbb77b9cf2ef"],"Strict-Transport-Security":["max-age=31536000; includeSubdomains; preload"],"X-Content-Type-Options":["nosniff"]},"body":{"encoding":"UTF-8","base64_string":"eyJsb2dpbiI6ImZvb2JhciIsImlkIjo1MTQsImF2YXRhcl91cmwiOiJodHRw\nczovL2F2YXRhcnMuZ2hlLmlvL3UvNTE0PyIsImdyYXZhdGFyX2lkIjoiIiwi\ndXJsIjoiPDxFTlRFUlBSSVNFX0hPU1ROQU1FPj51c2Vycy9mb29iYXIiLCJo\ndG1sX3VybCI6Imh0dHBzOi8vZ2hlLmlvL2Zvb2JhciIsImZvbGxvd2Vyc191\ncmwiOiI8PEVOVEVSUFJJU0VfSE9TVE5BTUU+PnVzZXJzL2Zvb2Jhci9mb2xs\nb3dlcnMiLCJmb2xsb3dpbmdfdXJsIjoiPDxFTlRFUlBSSVNFX0hPU1ROQU1F\nPj51c2Vycy9mb29iYXIvZm9sbG93aW5ney9vdGhlcl91c2VyfSIsImdpc3Rz\nX3VybCI6Ijw8RU5URVJQUklTRV9IT1NUTkFNRT4+dXNlcnMvZm9vYmFyL2dp\nc3Rzey9naXN0X2lkfSIsInN0YXJyZWRfdXJsIjoiPDxFTlRFUlBSSVNFX0hP\nU1ROQU1FPj51c2Vycy9mb29iYXIvc3RhcnJlZHsvb3duZXJ9ey9yZXBvfSIs\nInN1YnNjcmlwdGlvbnNfdXJsIjoiPDxFTlRFUlBSSVNFX0hPU1ROQU1FPj51\nc2Vycy9mb29iYXIvc3Vic2NyaXB0aW9ucyIsIm9yZ2FuaXphdGlvbnNfdXJs\nIjoiPDxFTlRFUlBSSVNFX0hPU1ROQU1FPj51c2Vycy9mb29iYXIvb3JncyIs\nInJlcG9zX3VybCI6Ijw8RU5URVJQUklTRV9IT1NUTkFNRT4+dXNlcnMvZm9v\nYmFyL3JlcG9zIiwiZXZlbnRzX3VybCI6Ijw8RU5URVJQUklTRV9IT1NUTkFN\nRT4+dXNlcnMvZm9vYmFyL2V2ZW50c3svcHJpdmFjeX0iLCJyZWNlaXZlZF9l\ndmVudHNfdXJsIjoiPDxFTlRFUlBSSVNFX0hPU1ROQU1FPj51c2Vycy9mb29i\nYXIvcmVjZWl2ZWRfZXZlbnRzIiwidHlwZSI6IlVzZXIiLCJzaXRlX2FkbWlu\nIjpmYWxzZX0=\n"},"http_version":null},"recorded_at":"Thu, 30 Jul 2015 06:01:10 GMT"}],"recorded_with":"VCR 2.9.3"}
2 changes: 1 addition & 1 deletion spec/octokit/enterprise_admin_client/orgs_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@
expect(@admin_client.last_response.status).to eq(201)
assert_requested :post, github_enterprise_url("admin/organizations")
end
end # .license
end # .orgs
end
10 changes: 9 additions & 1 deletion spec/octokit/enterprise_admin_client/users_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,20 @@
@admin_client = enterprise_admin_client
end

describe ".create", :vcr do
it "creates a new user" do
@admin_client.create("foobar", "[email protected]")
expect(@admin_client.last_response.status).to eq(201)
assert_requested :post, github_enterprise_url("admin/users")
end
end # .create

describe ".promote", :vcr do
it "promotes an ordinary user to a site administrator" do
@admin_client.promote("pengwynn")
assert_requested :put, github_enterprise_url("users/pengwynn/site_admin")
end
end # .prmote
end # .promote

describe ".demote", :vcr do
it "demotes a site administrator to an ordinary user" do
Expand Down

0 comments on commit 97d2628

Please sign in to comment.