Skip to content

Instantly share code, notes, and snippets.

View semifor's full-sized avatar

Marc Mims semifor

  • Spokane Valley, WA
View GitHub Profile
@semifor
semifor / gist:1165621
Created August 23, 2011 16:03
Eliminating @raw_lists
# just want the user's basic info?
sub trim_user { trim_hash(shift, [qw/id name screen_name/]) }
sub trim_list { trim_hash(shift, [qw/name slug id mode description/]) }
sub trim_hash {
my ( $hash, $keys ) = @_;
{ map { $_ => $hash->{$_} } @$keys }
}
sub for_each_result {
@semifor
semifor / dm-access.pl
Created August 10, 2011 20:59
Simple OAuth test for DM access
#!/usr/bin/env perl
use Modern::Perl;
use Net::Twitter;
my $nt = Net::Twitter->new(
traits => [qw/OAuth API::REST RetryOnError/],
consumer_key => 'MkkW2yJ2H1WTWhOIWlw',
consumer_secret => '0oWd3jArJrEFOHUZu6b6NAsJShZoDiDtaLJCmrzdu8',
);
#!perl
use warnings;
use strict;
use DBICx::TestDatabase;
use Test::More tests => 3;
use Path::Class qw/file/;
use File::Find;
use lib qw(t/lib);
my $schema = DBICx::TestDatabase->new('My::TestSchema');
#!/usr/bin/perl
use Net::Twitter;
my $nt = Net::Twitter->new(traits => [
qw/API::REST API::Search InflateObjects RetryOnError AutoCursor/,
AutoCursor => { max_calls => 4, methods => [qw/followers friends/] },
]);
print ref $nt, "\n";
# Net::Twitter::with__API_REST__API_Search__AutoCursor__AutoCursor_1__InflateObjects__RetryOnError
#!/usr/bin/env perl
use warnings;
use strict;
use Net::Twitter;
use Data::Dumper;
my $nt = Net::Twitter->new(traits => [qw/API::REST/]);
# uncomment the following line to simulate a failure
#$nt->ua->add_handler(request_send => sub { HTTP::Response->new(503) });
@semifor
semifor / jrn
Created November 12, 2010 21:29
Create/edit a journal entry for the current date
#!/bin/sh
#
# Edit a "journal file" in YYYY-MM-DD.txt format for the current date in
# ~/writings/journal or the specified directory (use '.' for the current
# directory).
EXT="txt"
BASE=$(date +%Y-%m-%d)
DIR=${1:-~/writings/journal}
#!perl
# Dumping a Twitter request/response
my $nt = Net::Twitter->new(%options);
my $res;
$nt->ua->add_handler(response_done => sub { $res = shift });
print "Request:\n",
$res->request->as_string,
#!/usr/bin/env perl
use warnings;
use strict;
use Net::Twitter;
use utf8;
use Net::Netrc;
my ($key, $key_secret) = Net::Netrc->lookup('semifor_test-scripts.oauth.twitter')->lpa;
my ($token, $token_secret) = Net::Netrc->lookup('semifor_test.semifor_test-scripts.oauth.twitter')->lpa;
use Net::Twitter::Lite;
my $nt = Net::Twitter::Lite->new(
consumer_key => $YOUR_CONSUMER_KEY,
consumer_secret => $YOUR_CONSUMER_SECRET,
access_token => $YOUR_ACCESS_TOKEN,
access_token_secret => $YOUR_ACCESS_SECRET,
);
$nt->update("Bob's your uncle!");
package Net::Twitter::Error;
use Moose;
use Try::Tiny;
use Devel::StackTrace;
use overload '""' => \&error,
'fallback' => 1;
has twitter_error => ( is => 'rw', predicate => 'has_twitter_error' );
has http_response => ( isa => 'HTTP::Response', is => 'rw', required => 1, handles => [qw/code message/] );