| 1 | #!/usr/local/bin/perl |
|---|
| 2 | # $Id$ |
|---|
| 3 | # This program is free software; you can redistribute it and/or # modify it under the same terms as Perl itself |
|---|
| 4 | use strict; |
|---|
| 5 | use warnings; |
|---|
| 6 | |
|---|
| 7 | Flickr2Twitter->run(YAML::LoadFile('/home/mayuki/.flickr2twitter.yaml')); |
|---|
| 8 | |
|---|
| 9 | |
|---|
| 10 | package Flickr2Twitter; |
|---|
| 11 | use YAML; |
|---|
| 12 | use XMLRPC::Transport::HTTP; |
|---|
| 13 | |
|---|
| 14 | use base qw/Class::Data::Inheritable/; |
|---|
| 15 | |
|---|
| 16 | sub authenticate { |
|---|
| 17 | my ($class, $username, $password) = @_; |
|---|
| 18 | |
|---|
| 19 | $username eq $class->config->{FromFlickr}->{Username} && $password eq $class->config->{FromFlickr}->{Password}; |
|---|
| 20 | } |
|---|
| 21 | |
|---|
| 22 | sub run { |
|---|
| 23 | my ($class, $config) = @_; |
|---|
| 24 | |
|---|
| 25 | $class->mk_classdata('config'); |
|---|
| 26 | $class->config($config); |
|---|
| 27 | |
|---|
| 28 | my $server = XMLRPC::Transport::HTTP::CGI |
|---|
| 29 | -> dispatch_to('blogger', 'metaWeblog') |
|---|
| 30 | -> handle; |
|---|
| 31 | |
|---|
| 32 | } |
|---|
| 33 | |
|---|
| 34 | |
|---|
| 35 | package blogger; |
|---|
| 36 | sub getUsersBlogs { |
|---|
| 37 | my ($class, $appkey, $username, $password) = @_; |
|---|
| 38 | |
|---|
| 39 | return undef unless Flickr2Twitter->authenticate($username, $password); |
|---|
| 40 | |
|---|
| 41 | [{ |
|---|
| 42 | url => 'http://twitter.com/'.Flickr2Twitter->config->{Twitter}->{Username}, |
|---|
| 43 | blogid => '1', |
|---|
| 44 | blogName => 'Twitter - '.Flickr2Twitter->config->{Twitter}->{Username} |
|---|
| 45 | }] |
|---|
| 46 | } |
|---|
| 47 | |
|---|
| 48 | |
|---|
| 49 | package metaWeblog; |
|---|
| 50 | use Encode; |
|---|
| 51 | use Net::Twitter; |
|---|
| 52 | |
|---|
| 53 | sub newPost { |
|---|
| 54 | my ($class, $blogid, $username, $password, $params, $publish) = @_; |
|---|
| 55 | |
|---|
| 56 | return undef unless Flickr2Twitter->authenticate($username, $password); |
|---|
| 57 | |
|---|
| 58 | my $twit = Net::Twitter->new(username => Flickr2Twitter->config->{Twitter}->{Username}, |
|---|
| 59 | password => Flickr2Twitter->config->{Twitter}->{Password}); |
|---|
| 60 | |
|---|
| 61 | $twit->update(Encode::encode('utf8', $params->{'description'})); |
|---|
| 62 | |
|---|
| 63 | 1; |
|---|
| 64 | } |
|---|