forked from github/platform-samples
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request github#31 from github/resource-discovery
Add samples re: discovering resources for the authenticated user
- Loading branch information
Showing
4 changed files
with
56 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
source "http://rubygems.org" | ||
|
||
gem "octokit", "~> 3.0" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
GEM | ||
remote: http://rubygems.org/ | ||
specs: | ||
addressable (2.3.6) | ||
faraday (0.9.0) | ||
multipart-post (>= 1.2, < 3) | ||
multipart-post (2.0.0) | ||
octokit (3.7.0) | ||
sawyer (~> 0.6.0, >= 0.5.3) | ||
sawyer (0.6.0) | ||
addressable (~> 2.3.5) | ||
faraday (~> 0.8, < 0.10) | ||
|
||
PLATFORMS | ||
ruby | ||
|
||
DEPENDENCIES | ||
octokit (~> 3.0) |
13 changes: 13 additions & 0 deletions
13
api/ruby/discovering-resources-for-a-user/discovering_organizations.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
require 'octokit' | ||
|
||
Octokit.auto_paginate = true | ||
|
||
Octokit.default_media_type = "application/vnd.github.moondragon+json" | ||
|
||
# !!! DO NOT EVER USE HARD-CODED VALUES IN A REAL APP !!! | ||
# Instead, set and test environment variables, like below. | ||
client = Octokit::Client.new :access_token => ENV["OAUTH_ACCESS_TOKEN"] | ||
|
||
client.organizations.each do |organization| | ||
puts "User belongs to the #{organization[:login]} organization." | ||
end |
22 changes: 22 additions & 0 deletions
22
api/ruby/discovering-resources-for-a-user/discovering_repositories.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
require 'octokit' | ||
|
||
Octokit.auto_paginate = true | ||
|
||
Octokit.default_media_type = "application/vnd.github.moondragon+json" | ||
|
||
# !!! DO NOT EVER USE HARD-CODED VALUES IN A REAL APP !!! | ||
# Instead, set and test environment variables, like below. | ||
client = Octokit::Client.new :access_token => ENV["OAUTH_ACCESS_TOKEN"] | ||
|
||
client.repositories.each do |repository| | ||
full_name = repository[:full_name] | ||
has_push_access = repository[:permissions][:push] | ||
|
||
access_type = if has_push_access | ||
"write" | ||
else | ||
"read-only" | ||
end | ||
|
||
puts "User has #{access_type} access to #{full_name}." | ||
end |