root/lang/perl/Flickr2Twitter/xmlrpc.cgi @ 33632

Revision 6108, 1.6 kB (checked in by mayuki, 6 years ago)

lang/perl: import Flickr2Twitter

Line 
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
4use strict;
5use warnings;
6
7Flickr2Twitter->run(YAML::LoadFile('/home/mayuki/.flickr2twitter.yaml'));
8
9
10package Flickr2Twitter;
11use YAML;
12use XMLRPC::Transport::HTTP;
13
14use base qw/Class::Data::Inheritable/;
15
16sub authenticate {
17    my ($class, $username, $password) = @_;
18
19    $username eq $class->config->{FromFlickr}->{Username} && $password eq $class->config->{FromFlickr}->{Password};
20}
21
22sub 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
35package blogger;
36sub 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
49package metaWeblog;
50use Encode;
51use Net::Twitter;
52
53sub 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}
Note: See TracBrowser for help on using the browser.