Created
October 20, 2010 09:01
-
-
Save sukria/636063 to your computer and use it in GitHub Desktop.
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
require 'Spore' | |
local github = Spore.new_from_spec 'github.json' | |
github:enable 'Format.JSON' | |
github:enable 'Runtime' | |
local r = github:user_information{format = 'json', username = 'schacon'} | |
print(r.status) --> 200 | |
print(r.headers['x-runtime']) --> 126ms | |
print(r.body.user.name) --> Scott Chacon |
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
use Net::HTTP::Spore; | |
my $gh = Net::HTTP::Spore->new_from_spec('github.json'); | |
$gh->enable('Format::JSON'); | |
$gh->enable('Runtime'); | |
my $r= $gh->user_information( format => 'json', username => 'schacon' ); | |
say "HTTP status => ".$r->status; # 200 | |
say "Runtime => ".$r->header('X-Spore-Runtime'); # 128ms | |
say "username => ".$r->body->{user}->{name}; # Scott Chacon |
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
require 'spore' | |
gh = Spore.new(File.join(File.dirname(__FILE__), 'github.json')) | |
gh.enable(Spore::Middleware::Runtime) # will add a header with runtime | |
gh.enable(Spore::Middleware::Format::JSON) # will deserialize JSON responses | |
# API call | |
r = gh.user_information( :format => 'json', :username => 'schacon' ) | |
puts "HTTP status => ".r.code # 200 | |
puts "Runtime => ".r.header('X-Spore-Runtime') # 128ms | |
puts "username => ".r.body['user']['name'] # Scott Chacon |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment