summary refs log tree commit diff
path: root/eg
diff options
context:
space:
mode:
Diffstat (limited to 'eg')
-rw-r--r--eg/github.pl43
-rw-r--r--eg/twitter.pl44
2 files changed, 87 insertions, 0 deletions
diff --git a/eg/github.pl b/eg/github.pl
new file mode 100644
index 0000000..4053d67
--- /dev/null
+++ b/eg/github.pl
@@ -0,0 +1,43 @@
+use strict;
+use warnings;
+
+use Net::HTTP::Spore;
+use Getopt::Long;
+
+use Config::GitLike::Git;
+use Git::Repository;
+
+GetOptions(
+    'spec=s' => \my $specification,
+    'name=s' => \my $name,
+    'desc=s' => \my $desc,
+);
+
+print ">> creating repository $name on github\n";
+
+my $c = Config::GitLike::Git->new();
+$c->load;
+
+my $login = $c->get(key => 'github.user');
+my $token = $c->get(key => 'github.token');
+
+my $github = Net::HTTP::Spore->new_from_spec($specification);
+$github->enable('Format::JSON');
+$github->enable(
+    'Auth::Basic',
+    username => $login . '/token',
+    password => $token,
+);
+
+my $remote = "git\@github.com:" . $login . "/" . $name . ".git";
+
+my $res = $github->create_repo(format => 'json', payload => {name => $name, description => $desc});
+
+print ">> repository $remote created\n";
+
+my $r = Git::Repository->create(init => $name);
+my @cmd = ('remote', 'add', 'origin', $remote);
+$r->run(@cmd);
+
+print ">> repository cloned to $name\n";
+print ">> done!\n";
diff --git a/eg/twitter.pl b/eg/twitter.pl
new file mode 100644
index 0000000..965e5c8
--- /dev/null
+++ b/eg/twitter.pl
@@ -0,0 +1,44 @@
+use strict;
+use warnings;
+use Net::HTTP::Spore;
+
+use Encode;
+use Getopt::Long;
+
+GetOptions(
+    'spec=s'            => \my $specification,
+    'consumer_key=s'    => \my $consumer_key,
+    'consumer_secret=s' => \my $consumer_secret,
+    'token=s'           => \my $token,
+    'token_secret=s'    => \my $token_secret,
+);
+
+my $client = Net::HTTP::Spore->new_from_spec($specification);
+
+$client->enable('Format::JSON');
+$client->enable(
+    'Auth::OAuth',
+    consumer_key    => $consumer_key,
+    consumer_secret => $consumer_secret,
+    token           => $token,
+    token_secret    => $token_secret,
+);
+
+my $timeline = $client->public_timeline( format => 'json' );
+if ( $timeline->status == 200 ) {
+    my $tweets = $timeline->body;
+    print ">> Timeline\n";
+    foreach my $tweet (@$tweets) {
+        print $tweet->{user}->{screen_name} . " says " . encode_utf8($tweet->{text}) . "\n";
+    }
+    print "\n\n";
+}
+
+my $friends_timeline = $client->friends_timeline(format => 'json', include_rts => 1);
+if  ($friends_timeline->code == 200) {
+    my $tweets = $friends_timeline->body;
+    print ">> Friend timeline\n";
+    foreach my $tweet (@$tweets) {
+        print $tweet->{user}->{screen_name} . " says " . encode_utf8($tweet->{text}) . "\n";
+    }
+}