File Coverage

blib/lib/WWW/Jawbone/Up/Mock.pm
Criterion Covered Total %
statement 36 41 87.8
branch 16 22 72.7
condition n/a
subroutine 9 12 75.0
pod 0 3 0.0
total 61 78 78.2


line stmt bran cond sub pod time code
1             package WWW::Jawbone::Up::Mock;
2              
3 6     6   394424 use 5.010;
  6         26  
  6         286  
4 6     6   35 use strict;
  6         12  
  6         213  
5 6     6   33 use warnings;
  6         14  
  6         331  
6              
7 6     6   31 use base 'WWW::Jawbone::Up';
  6         11  
  6         5605  
8              
9 6     6   81 use Carp;
  6         12  
  6         470  
10              
11 6     6   35 use constant URI_BASE => 'https://jawbone.com';
  6         12  
  6         520  
12 6     6   33 use constant URI_API => URI_BASE . '/nudge/api/v.1.32';
  6         12  
  6         4952  
13              
14             sub bad_request {
15 0     0 0 0 croak '400 BAD REQUEST';
16             }
17              
18             sub unauthorized {
19 0     0 0 0 croak '401 UNAUTHORIZED';
20             }
21              
22             sub not_found {
23 0     0 0 0 croak '404 NOT FOUND';
24             }
25              
26             our %_RESPONSE = (
27             profile => {
28             data => {
29             last => 'Berndt',
30             name => 'Alan Berndt',
31             short_name => 'Alan',
32             image => 'user/image/i/photo.png',
33             first => 'Alan',
34             user_is_friend => 1,
35             },
36             },
37             feed => {
38             data => {
39             feed => [ {
40             time_updated => 1366008300,
41             title => '9,885 steps',
42             image => '/nudge/api/v.1.32/moves/xid/image/time',
43             reached_goal => undef,
44             time_created => 1366008300,
45             tz => 'America/Phoenix',
46             type => 'move',
47             user => {
48             last => 'Berndt',
49             name => 'Alan Berndt',
50             short_name => 'Alan',
51             image => 'user/image/i/photo.png',
52             first => 'Alan',
53             },
54             }, {
55             time_updated => 1365960060,
56             title => 'for 8h 17m',
57             image => '/nudge/api/v.1.32/sleeps/xid/image/time',
58             reached_goal => 1,
59             time_created => 1365960060,
60             tz => 'America/Phoenix',
61             type => 'sleep',
62             user => {
63             last => 'Berndt',
64             name => 'Alan Berndt',
65             short_name => 'Alan',
66             image => 'user/image/i/photo.png',
67             first => 'Alan',
68             },
69             },
70             ],
71             },
72             },
73             score => {
74             data => {
75             move => {
76             distance => 7.553,
77             longest_idle => 9000,
78             calories => 608.235829421,
79             bg_steps => 9885,
80             longest_active => 932,
81             bmr_calories => 2201.52221491,
82             active_time => 5135,
83             },
84             sleep => {
85             awakenings => 2,
86             light => 10243,
87             time_to_sleep => 693,
88             goals => {
89             bedtime => [ 10, undef ],
90             deep => [ 15190, undef ],
91             },
92             awake => 2091,
93             },
94             },
95             },
96             band => {
97             data => {
98             ticks => [ {
99             value => {
100             distance => 25,
101             active_time => 15,
102             aerobic => undef,
103             calories => 1.54764223099,
104             steps => 31,
105             time => 1365980040,
106             speed => 1,
107             },
108             },
109             ],
110             },
111             },
112             workouts => {
113             data => {
114             items => [ {
115             time_completed => 1364827020,
116             title => 'Workout',
117             is_complete => 1,
118             time_updated => 1364828785,
119             details => {
120             intensity => undef,
121             tz => 'America/Phoenix',
122             calories => 236.39623734,
123             km => 2.156,
124             steps => 3221,
125             time => 1781,
126             },
127             time_created => 1364825239,
128             },
129             ],
130             },
131             },
132             auth_failure => {
133             error => {
134             msg => 'Email or Password cannot be validated',
135             },
136             },
137             auth_success => {
138             token => '123abc',
139             },
140             );
141              
142             sub _get {
143 5     5   16 my ($self, $uri, $data) = @_;
144              
145 5 50       21 unauthorized unless $self->{token};
146              
147 5 100       41 if ($uri eq URI_API . '/users/@me') {
    100          
    100          
    100          
    50          
148 1         4 return $_RESPONSE{profile};
149             } elsif ($uri eq URI_API . '/users/@me/social') {
150 1         5 return $_RESPONSE{feed};
151             } elsif ($uri eq URI_API . '/users/@me/score') {
152 1         4 return $_RESPONSE{score};
153             } elsif ($uri eq URI_API . '/users/@me/band') {
154 1         3 return $_RESPONSE{band};
155             } elsif ($uri eq URI_API . '/users/@me/workouts') {
156 1         4 return $_RESPONSE{workouts};
157             } else {
158 0         0 not_found;
159             }
160             }
161              
162             sub _post {
163 7     7   21 my ($self, $uri, $data) = @_;
164              
165 7 50       32 if ($uri eq URI_BASE . '/user/signin/login') {
166 7 50       31 bad_request unless $data->{service};
167 7 50       215 bad_request unless $data->{email};
168 7 50       35 bad_request unless $data->{pwd};
169              
170 7 100       34 return $_RESPONSE{auth_failure} unless $data->{pwd} eq 's3kr3t';
171 6         30 return $_RESPONSE{auth_success};
172             } else {
173 0           not_found;
174             }
175             }
176              
177             1;