Foursquare.pm untested

filter: Statementstmt 0.0% 0 / 41 Branchbran 0.0% 0 / 2 Conditioncond 0.0% 0 / 4 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 0.0% 0 / 8 Podpod 0.0% 0 / 3 totaltotal 0.0% 0 / 60 CC 2 SCAR 10.6
CC
2
Cov
0%
setup
6.0
component
2.0
services
2.0
CRAP 2.9
1 package Exobrain::Foursquare;
2 use Moose;
3 use Exobrain::Config;
4 use JSON::Any;
5 use Try::Tiny;
6 use feature qw(say);
7  
8 # ABSTRACT: Foursquare components for Exobrain
9 our $VERSION = '0.01'; # VERSION
10  
11 with 'Exobrain::Component';
12  
13 my $FOURSQUARE_API = 'https://api.foursquare.com/v2';
14  
15 sub component { "foursquare" };
16  
17 sub services {
18 return (
19 source => 'Foursquare::Source',
20 );
21 }
22  
23 sub setup {
24  
25 # Load module and die swiftly on failure
26 eval 'use WWW::Mechanize; 1;' or die $@;
27  
28 say "Welcome to the Exobrain::Foursquare setup process.";
29 say "To complete setup, we'll need a valid FourSquare auth token";
30 say "You can yoink this out of the API explorer at";
31 say 'https://developer.foursquare.com/docs/explore';
32  
33 print "Auth token: ";
34 chomp( my $token = <STDIN> );
35  
36 # Check to see if we auth okay.
37  
38 my $mech = WWW::Mechanize->new( autocheck => 1 );
39 my $json = JSON::Any->new;
40  
41 $mech->get("$FOURSQUARE_API/checkins/recent?oauth_token=$token&v=20130425");
42  
43 my $status = $json->decode($mech->content);
44  
45 if ($status->{meta}{code} != 200) {
46 my $reason = $status->{meta}{errorDetail} || "Unknown error, sorry!";
47 die "Auth failed! $reason\n";
48 }
49
50 say "\nThanks! Writing configuration...";
51  
52 my $config =
53 "[Components]\n" .
54 "Foursquare=$VERSION\n\n" .
55  
56 "[Foursquare]\n" .
57 "auth_token = $token\n"
58 ;
59  
60 my $filename = Exobrain::Config->write_config('Foursquare.ini', $config);
61  
62 say "\nConfig written to $filename. Have a nice day!";
63  
64 return;
65 }
66  
67 1;
68  
69 __END__