Created
December 28, 2011 04:12
-
-
Save avdi/1526209 to your computer and use it in GitHub Desktop.
Leadlight sneak peek
This file contains hidden or 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
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'] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
It occurs to me that this snippet doesn't really illustrate why I'm so happy. Oh well. All will become clear in time.