public
Description: Automatic approximation of typical Photoshop actions
Homepage: http://rcrowley.org/2007/11/08/introducing-curvr/
Clone URL: git://github.com/rcrowley/curvr.git
curvr / curvrconf
100755 121 lines (103 sloc) 4.468 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
#!/usr/bin/perl
 
#
# curvr
# Richard Crowley <r@rcrowley.org>
#
 
# Gets a token by redirecting you to http://localhost:81/...
 
use strict;
 
# Flickr API goodness
my $FLICKR_API_KEY = '';
my $FLICKR_SECRET = '';
 
# Fire Bagel!
my $FIREEAGLE_CONSUMER_KEY = '';
my $FIREEAGLE_CONSUMER_SECRET = '';
 
 
 
#
# Flickr
# TODO: Change to desktop-style authentication without the callback
#
 
use Digest::MD5 'md5_hex';
use XML::Simple 'XMLin';
 
# Send the user to Flickr
my $api_sig = md5_hex("${FLICKR_SECRET}api_key${FLICKR_API_KEY}permswrite");
print "\nFlickr\n";
print "Give this to your browser, paste the URL you're bounced to below.\n";
print "http://flickr.com/services/auth/?api_key=${FLICKR_API_KEY}&perms=write&api_sig=${api_sig}\n";
print "Result: ";
my $flickr = <STDIN>;
 
# Get a token for the Flickr API
$flickr =~ m/^http:\/\/localhost:81\/\?frob=(.+)$/;
my $frob = $1;
$api_sig = md5_hex("${FLICKR_SECRET}api_key${FLICKR_API_KEY}frob${frob}methodflickr.auth.getToken");
my $raw = `wget -q -O - 'http://flickr.com/services/rest/?api_key=${FLICKR_API_KEY}&method=flickr.auth.getToken&frob=${frob}&api_sig=${api_sig}'`;
my $xml = XMLin($raw);
print "\nFlickr API token: ", $xml->{'auth'}->{'token'}, "\n";
 
 
 
#
# Fire Bagel!
# OAuth walkthrough - https://fireeagle.yahooapis.com/developer/code/perl
#
 
use Net::OAuth::Request;
use Net::OAuth::RequestTokenRequest;
use Net::OAuth::AccessTokenRequest;
use Net::OAuth::ProtectedResourceRequest;
use Data::Dumper;
use LWP;
use CGI;
 
my $REQUEST_TOKEN_URL = 'http://fireeagle.yahooapis.com/oauth/request_token';
my $AUTHORIZATION_URL = 'http://fireeagle.yahoo.net/oauth/authorize';
my $ACCESS_TOKEN_URL = 'http://fireeagle.yahooapis.com/oauth/access_token';
my $QUERY_API_URL = 'http://fireeagle.yahooapis.com/api/0.1/user';
my $UPDATE_API_URL = 'http://fireeagle.yahooapis.com/api/0.1/update';
 
print "\nFire Bagel!\n";
my $request_token_request = Net::OAuth::RequestTokenRequest->new(
consumer_key => $FIREEAGLE_CONSUMER_KEY,
consumer_secret => $FIREEAGLE_CONSUMER_SECRET,
request_url => $REQUEST_TOKEN_URL,
request_method => 'GET',
signature_method => 'HMAC-SHA1',
timestamp => time,
nonce => int(rand(2 ** 32)),
);
$request_token_request->sign;
die "COULDN'T VERIFY! Check OAuth parameters.\n" unless $request_token_request->verify;
my $request_token_request_url = $REQUEST_TOKEN_URL . '?' . $request_token_request->to_post_body;
my $browser = LWP::UserAgent->new;
my $request_token_response = $browser->get( $request_token_request_url );
die $request_token_response->status_line unless ($request_token_response->is_success);
my $request_token_response_query = new CGI($request_token_response->content);
my $oauth_token = $request_token_response_query->param('oauth_token');
my $oauth_token_secret = $request_token_response_query->param('oauth_token_secret');
if ( ! ( $oauth_token && $oauth_token_secret ) ) {
die "ERROR : FireEagle did not reply with an oauth_token and oauth_token_secret";
}
my $authorization_url = $AUTHORIZATION_URL . '?oauth_token=' . $oauth_token;
print "Give this to your browser, press <ENTER> after you're done there.\n";
print "$authorization_url\n";
my $enter = <STDIN>;
my $access_token_request = Net::OAuth::AccessTokenRequest->new(
consumer_key => $FIREEAGLE_CONSUMER_KEY,
consumer_secret => $FIREEAGLE_CONSUMER_SECRET,
request_url => $ACCESS_TOKEN_URL,
request_method => 'GET',
signature_method => 'HMAC-SHA1',
timestamp => time,
nonce => int(rand(2 ** 32)),
token => $oauth_token,
token_secret => $oauth_token_secret,
);
$access_token_request->sign;
die "COULDN'T VERIFY! Check OAuth parameters.\n" unless $access_token_request->verify;
my $access_token_request_url = $ACCESS_TOKEN_URL . '?' . $access_token_request->to_post_body;
my $access_token_response = $browser->get( $access_token_request_url );
if ( ! ($access_token_response->is_success) ) {
die $access_token_response->status_line;
}
my $access_token_response_query = new CGI($access_token_response->content);
my $oauth_access_token = $access_token_response_query->param('oauth_token');
my $oauth_access_token_secret = $access_token_response_query->param('oauth_token_secret');
if ( ! ( $oauth_token && $oauth_token_secret ) ) {
die "ERROR : FireEagle did not reply with an oauth_token and oauth_token_secret";
}
print "Request token: $oauth_token\n";
print "Request secret: $oauth_token_secret\n";
print "Access token: $oauth_access_token\n";
print "Access secret: $oauth_access_token_secret\n";