summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2009-06-16 21:10:03 -0500
committerJesse Luehrs <doy@tozt.net>2009-06-16 21:23:30 -0500
commitafcde73887075e3befd4bf35815ee0f757b093b6 (patch)
tree8f16b7dd08ae9314f1817cfec0d882c49cf68a67 /lib
parent27117318b1bddcaa16e795041e5d26fb7bfcd8d9 (diff)
downloadwww-unfuddle-afcde73887075e3befd4bf35815ee0f757b093b6.tar.gz
www-unfuddle-afcde73887075e3befd4bf35815ee0f757b093b6.zip
start making the main interface sane
Diffstat (limited to 'lib')
-rw-r--r--lib/WWW/Unfuddle.pm28
1 files changed, 21 insertions, 7 deletions
diff --git a/lib/WWW/Unfuddle.pm b/lib/WWW/Unfuddle.pm
index 26d3717..93dcb15 100644
--- a/lib/WWW/Unfuddle.pm
+++ b/lib/WWW/Unfuddle.pm
@@ -3,6 +3,8 @@ use Moose;
use LWP::UserAgent;
use JSON;
+use WWW::Unfuddle::Project;
+
has username => (
is => 'ro',
isa => 'Str',
@@ -45,15 +47,27 @@ sub _api_url {
return 'http://' . $self->_domain . '/api/v1/' . join('/', @path) . '.json';
}
-sub list_projects {
+sub request {
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";
+ my ($method, @path) = @_;
+ my $req = HTTP::Request->new($method => $self->_api_url(@path));
+ $req->header(Accept => 'application/json');
+ my $resp = $self->ua->request($req);
+ if ($resp->code != 200) {
+ confess sprintf 'Error (%d): %s', $resp->code, $resp->content;
}
+ return from_json($resp->content);
+}
+
+sub get {
+ my $self = shift;
+ $self->request(GET => @_);
+}
+
+sub projects {
+ my $self = shift;
+ return map { WWW::Unfuddle::Project->new($_) } @{ $self->get('projects') };
+
}
__PACKAGE__->meta->make_immutable;