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
|
package WWW::Unfuddle;
use Moose;
use LWP::UserAgent;
use JSON;
has username => (
is => 'ro',
isa => 'Str',
required => 1,
);
has password => (
is => 'ro',
isa => 'Str',
required => 1,
);
has subdomain => (
is => 'ro',
isa => 'Str',
required => 1,
);
has ua => (
is => 'ro',
isa => 'LWP::UserAgent',
lazy => 1,
default => sub {
my $self = shift;
my $ua = LWP::UserAgent->new;
$ua->credentials($self->_domain . ':80', 'Unfuddle API',
$self->username, $self->password);
return $ua;
},
);
sub _domain {
my $self = shift;
return $self->subdomain . '.unfuddle.com';
}
sub _api_url {
my $self = shift;
my @path = @_;
return 'http://' . $self->_domain . '/api/v1/' . join('/', @path) . '.json';
}
sub list_projects {
my $self = shift;
my $request = HTTP::Request->new(GET => $self->_api_url('projects'));
$request->header(Accept => 'application/json');
my $response = $self->ua->request($request);
my $projects = from_json($response->content);
for my $project (@$projects) {
print $project->{short_name}, "\n";
}
}
__PACKAGE__->meta->make_immutable;
no Moose;
1;
|