Skip to content

Commit

Permalink
Merge pull request github#31 from github/resource-discovery
Browse files Browse the repository at this point in the history
Add samples re: discovering resources for the authenticated user
  • Loading branch information
jasonrudolph committed Jan 8, 2015
2 parents bbc568a + 6bc8209 commit b3348e3
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 0 deletions.
3 changes: 3 additions & 0 deletions api/ruby/discovering-resources-for-a-user/Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
source "http://rubygems.org"

gem "octokit", "~> 3.0"
18 changes: 18 additions & 0 deletions api/ruby/discovering-resources-for-a-user/Gemfile.lock
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)
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
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

0 comments on commit b3348e3

Please sign in to comment.