File Coverage

blib/lib/WebService/VigLink.pm
Criterion Covered Total %
statement 11 21 52.3
branch 1 4 25.0
condition 0 2 0.0
subroutine 4 5 80.0
pod 2 2 100.0
total 18 34 52.9


line stmt bran cond sub pod time code
1             package WebService::VigLink;
2              
3 1     1   19475 use strict;
  1         1  
  1         30  
4 1     1   3 use warnings;
  1         2  
  1         35  
5              
6             =head1 NAME
7              
8             WebService::VigLink - Interface to the VigLink web API
9              
10             =cut
11              
12             our $VERSION = 0.06;
13              
14 1     1   851 use Any::URI::Escape;
  1         2847  
  1         237  
15              
16             =head1 METHODS
17              
18             =over 4
19              
20             =item new()
21              
22             $VigLink = WebService::VigLink->new({ key => $apikey })
23              
24             See http://www.viglink.com/corp/api for the low level details and where
25             to obtain an API key.
26              
27             =cut
28              
29             sub new {
30 1     1 1 13 my ($class, $args) = @_;
31            
32 1 50       16 die "You need an api key to access the VigLink API, args "
33             unless (defined $args->{key});
34              
35 0           my %self; # old school OO
36              
37 0           $self{key} = $args->{key};
38 0   0       $self{format} = $args->{format} || 'go'; # default to 301
39              
40 0           bless \%self, $class;
41              
42 0           return \%self;
43             }
44              
45             =item make_url()
46              
47             $api_url = $VigLink->make_url({ out => $click_destination,
48             cuid => $anonymous_user_id,
49             txt => $text_of_link,
50             loc => $current_webpage,
51             title => $current_page_title,
52             referrer => $referring_page, });
53              
54             Returns a VigLink href. Dies on missing args.
55              
56             =cut
57              
58              
59             sub make_url {
60 0     0 1   my ($self, $args) = @_;
61              
62 0           foreach my $param ( qw( out cuid txt loc title referrer ) ) {
63 0 0         die "missing param $param" unless defined $args->{$param};
64             }
65              
66 0           my $url = sprintf("http://api.viglink.com/api/click?title=%s&key=%s&out=%s&format=%s&cuid=%s&loc=%s&txt=%s&ref=%s",
67             uri_escape($args->{'title'}),
68             $self->{'key'},
69             uri_escape($args->{'out'}),
70             $self->{'format'},
71             $args->{'cuid'},
72             uri_escape($args->{'loc'}),
73             uri_escape($args->{'txt'}),
74             uri_escape($args->{'referrer'}),);
75              
76 0           return $url;
77             }
78              
79             1;
80              
81              
82             =back
83              
84             =head1 SYNOPSIS
85              
86             use WebService::VigLink;
87             $VigLink = WebService::VigLink->new({ key => $api_key });
88             $affiliate_url = $VigLink->make_url({ ... });
89              
90             =head1 DESCRIPTION
91              
92             Simple encapsulation of the VigLink API.
93              
94             =head1 AUTHOR
95              
96             "Fred Moyer", Efred@slwifi.comE
97              
98             =head1 COPYRIGHT AND LICENSE
99              
100             Copyright (C) 2010 by Silver Lining Networks
101              
102             This library is free software; you can redistribute it and/or modify
103             it under the same terms as Perl itself, either Perl version 5.10.1 or,
104             at your option, any later version of Perl 5 you may have available.
105              
106              
107             =cut