File Coverage

blib/lib/API/Basecamp.pm
Criterion Covered Total %
statement 9 24 37.5
branch 0 2 0.0
condition n/a
subroutine 3 5 60.0
pod 0 2 0.0
total 12 33 36.3


line stmt bran cond sub pod time code
1             # ABSTRACT: Basecamp.com API Client
2             package API::Basecamp;
3              
4 1     1   1459 use Data::Object::Class;
  1         24640  
  1         9  
5 1     1   2347 use Data::Object::Signatures;
  1         264634  
  1         11  
6              
7 1         5 use Data::Object::Library qw(
8             Str
9 1     1   8880 );
  1         2  
10              
11             extends 'API::Client';
12              
13             our $VERSION = '0.06'; # VERSION
14              
15             our $DEFAULT_URL = "https://basecamp.com";
16              
17             # ATTRIBUTES
18              
19             has account => (
20             is => 'rw',
21             isa => Str,
22             required => 1,
23             );
24              
25             has password => (
26             is => 'rw',
27             isa => Str,
28             required => 1,
29             );
30              
31             has username => (
32             is => 'rw',
33             isa => Str,
34             required => 1,
35             );
36              
37             # DEFAULTS
38              
39             has '+identifier' => (
40             default => 'API::Basecamp (Perl)',
41             required => 0,
42             );
43              
44             has '+url' => (
45             default => $DEFAULT_URL,
46             required => 0,
47             );
48              
49             has '+version' => (
50             default => 1,
51             required => 0,
52             );
53              
54             # CONSTRUCTION
55              
56             after BUILD => method {
57              
58             my $username = $self->username;
59             my $password = $self->password;
60             my $account = $self->account;
61             my $version = $self->version;
62              
63             my $userinfo = "$username:$password";
64             my $url = $self->url;
65              
66             $url->path("/$account/api/v$version");
67             $url->userinfo($userinfo);
68              
69             return $self;
70              
71             };
72              
73             # METHODS
74              
75 0     0 0   method PREPARE ($ua, $tx, %args) {
  0            
  0            
76              
77 0           my $headers = $tx->req->headers;
78 0           my $url = $tx->req->url;
79              
80             # default headers
81 0           $headers->header('Content-Type' => 'application/json');
82              
83             # append path suffix
84 0 0         $url->path("@{[$url->path]}.json") if $url->path !~ /\.json$/;
  0            
85              
86             }
87              
88 0     0 0   method resource (@segments) {
  0            
  0            
89              
90             # build new resource instance
91 0           my $instance = __PACKAGE__->new(
92             debug => $self->debug,
93             fatal => $self->fatal,
94             retries => $self->retries,
95             timeout => $self->timeout,
96             user_agent => $self->user_agent,
97             account => $self->account,
98             identifier => $self->identifier,
99             username => $self->username,
100             password => $self->password,
101             version => $self->version,
102             );
103              
104             # resource locator
105 0           my $url = $instance->url;
106              
107             # modify resource locator if possible
108 0           $url->path(join '/', $self->url->path, @segments);
109              
110             # return resource instance
111 0           return $instance;
112              
113             }
114              
115             1;
116              
117             __END__