Skip to content

Instantly share code, notes, and snippets.

@sukria
Created October 20, 2010 09:01
Show Gist options
  • Save sukria/636063 to your computer and use it in GitHub Desktop.
Save sukria/636063 to your computer and use it in GitHub Desktop.
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
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
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