diff --git a/lib/WWW/Fitbit/API.pm b/lib/WWW/Fitbit/API.pm old mode 100755 new mode 100644 index ce27a82..05b079b --- a/lib/WWW/Fitbit/API.pm +++ b/lib/WWW/Fitbit/API.pm @@ -203,6 +203,24 @@ sub get_step_log { } +################################################################# +# Title : get_weight_log (public) +# Usage : $self->get_weight_log($date) +# Purpose : Displays weight in 1d intervals +# Parameters : date = YYYY-MM-DD (optional; default = today) +# Returns : Hash ref; keys = time, value +# values = YYYY-MM-DD HH:MM[A|P]M, decimal + +sub get_weight_log { + + my $self = shift; + + my ($date) = @_; + + return $self->_parse_graph_xml( "weight_historical", $date ); + +} + ################################################################# # Title : get_sleep_log (public) # Usage : $self->get_sleep_log($date) @@ -400,7 +418,8 @@ sub _request_graph_xml { 'distance_historical' => 'distanceFromSteps', 'steps_historical' => 'stepsTaken', 'sleep_time_historical' => 'timeAsleep', - 'wakeup_historical' => 'timesWokenUp' + 'wakeup_historical' => 'timesWokenUp', + 'weight_historical' => 'weight' }; if ( !defined $type_map->{$graph_type} ) { @@ -457,7 +476,7 @@ sub _parse_graph_xml { defined $date ? $self->_check_date_format($date) : $date = $self->_get_date(); - $self->{_logger}->info("Getting calories burned for date $date"); + $self->{_logger}->info("Getting $graph_type for date $date"); my $xml = $self->_request_graph_xml( $graph_type, $date ); my $graph_data; @@ -550,6 +569,14 @@ sub _parse_graph_xml { push( @entries, $total_wakes ); } + if ( $graph_type eq "weight_historical" ) { + # Sample description: "80.5 kg on Mon, Jan 1" + my @v = split / /, + $graph_data->{data}{chart}{graphs}{graph}[0]{value}[1]{description}; + my $weight = $v[0]; + $self->{_logger}->debug("weight = $weight"); + push( @entries, $weight ); + } if ( $graph_type eq "steps_historical" ) { # Sample description: "11,232 steps on Sat, May 1" @@ -702,4 +729,3 @@ as Perl itself. =cut - diff --git a/script/test_client.pl b/script/test_client.pl old mode 100755 new mode 100644 index 23c9b18..fb63dd5 --- a/script/test_client.pl +++ b/script/test_client.pl @@ -31,3 +31,6 @@ my $st = $fb->total_sleep_time("2010-05-01"); print "sleep = hours[$st->{hours_asleep}], wakes[$st->{wakes}]\n"; + +my @weight = $fb->get_weight_log("2011-01-11"); +print "weight = $weight[0]\n";