File Coverage

blib/lib/API/Basecamp.pm
Criterion Covered Total %
statement 18 33 54.5
branch 0 2 0.0
condition n/a
subroutine 6 8 75.0
pod 0 2 0.0
total 24 45 53.3


line stmt bran cond sub pod time code
1             # ABSTRACT: Basecamp.com API Client
2             package API::Basecamp;
3              
4 1     1   1948 use namespace::autoclean -except => 'has';
  1         107152  
  1         6  
5              
6 1     1   872 use Data::Object::Class;
  1         86538  
  1         17  
7 1     1   3782 use Data::Object::Class::Syntax;
  1         7104  
  1         4  
8 1     1   1007 use Data::Object::Signatures;
  1         381774  
  1         15  
9              
10 1     1   8408 use Data::Object qw(load);
  1         3  
  1         91  
11 1     1   5 use Data::Object::Library qw(Str);
  1         2  
  1         4  
12              
13             extends 'API::Client';
14              
15             our $VERSION = '0.04'; # VERSION
16              
17             our $DEFAULT_URL = "https://basecamp.com";
18              
19             # ATTRIBUTES
20              
21             has account => rw;
22             has password => rw;
23             has username => rw;
24              
25             # CONSTRAINTS
26              
27             req account => Str;
28             req password => Str;
29             req username => Str;
30              
31             # DEFAULTS
32              
33             def identifier => 'API::Basecamp (Perl)';
34             def url => method { load('Mojo::URL')->new($DEFAULT_URL) };
35             def version => 1;
36              
37             # CONSTRUCTION
38              
39             after BUILD => method {
40             my $username = $self->username;
41             my $password = $self->password;
42             my $account = $self->account;
43             my $version = $self->version;
44              
45             my $userinfo = "$username:$password";
46             my $url = $self->url;
47              
48             $url->path("/$account/api/v$version");
49             $url->userinfo($userinfo);
50              
51             return $self;
52             };
53              
54             # METHODS
55              
56 0     0 0   method PREPARE ($ua, $tx, %args) {
  0            
  0            
57 0           my $headers = $tx->req->headers;
58 0           my $url = $tx->req->url;
59              
60             # default headers
61 0           $headers->header('Content-Type' => 'application/json');
62              
63             # append path suffix
64 0 0         $url->path("@{[$url->path]}.json") if $url->path !~ /\.json$/;
  0            
65             }
66              
67 0     0 0   method resource (@segments) {
  0            
  0            
68             # build new resource instance
69 0           my $instance = __PACKAGE__->new(
70             debug => $self->debug,
71             fatal => $self->fatal,
72             retries => $self->retries,
73             timeout => $self->timeout,
74             user_agent => $self->user_agent,
75             account => $self->account,
76             identifier => $self->identifier,
77             username => $self->username,
78             password => $self->password,
79             version => $self->version,
80             );
81              
82             # resource locator
83 0           my $url = $instance->url;
84              
85             # modify resource locator if possible
86 0           $url->path(join '/', $self->url->path, @segments);
87              
88             # return resource instance
89 0           return $instance;
90             }
91              
92             1;
93              
94             __END__