diff options
author | Jesse Luehrs <doy@tozt.net> | 2009-06-16 18:45:19 -0500 |
---|---|---|
committer | Jesse Luehrs <doy@tozt.net> | 2009-06-16 18:45:19 -0500 |
commit | 15086113f27d6ba6eb1837f54e80a8f267902174 (patch) | |
tree | 2ffc63a2882a6ee1696188d524ffcdb04018afa2 | |
download | www-unfuddle-15086113f27d6ba6eb1837f54e80a8f267902174.tar.gz www-unfuddle-15086113f27d6ba6eb1837f54e80a8f267902174.zip |
basic skeleton
-rw-r--r-- | lib/WWW/Unfuddle.pm | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/lib/WWW/Unfuddle.pm b/lib/WWW/Unfuddle.pm new file mode 100644 index 0000000..26d3717 --- /dev/null +++ b/lib/WWW/Unfuddle.pm @@ -0,0 +1,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; |