Skip to content

Instantly share code, notes, and snippets.

@avdi
Created December 28, 2011 04:12
Show Gist options
  • Save avdi/1526209 to your computer and use it in GitHub Desktop.
Save avdi/1526209 to your computer and use it in GitHub Desktop.
Leadlight sneak peek
class GithubService
Leadlight.build_service(self) do
url 'https://api.github.com'
build_connection do |c|
c.adapter :typhoeus
end
tint 'root' do
match_path('/')
add_link_template '/users/{login}', 'user', 'Find user by login'
end
tint 'auth_scopes' do
extend do
def oauth_scopes
__response__.headers['X-OAuth-Scopes'].to_s.strip.split(/\W+/)
end
end
end
end
def prepare_request(request)
request.headers['Authorization'] = "Bearer #{options[:oauth2_token]}"
end
end
user = GithubService.session(oauth2_token: "...").root.user('avdi') # => {'type' => 'User', 'name' => 'Avdi Grimm', ...}
user.oauth_scopes # => ['repo']
@avdi
Copy link
Author

avdi commented Dec 28, 2011

It occurs to me that this snippet doesn't really illustrate why I'm so happy. Oh well. All will become clear in time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment