Skip to content

Commit

Permalink
Modify all calls to encode_json() to make them compatible with JSON < 4
Browse files Browse the repository at this point in the history
  • Loading branch information
stevieb9 committed Apr 11, 2022
1 parent cc78110 commit b625bab
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
3 changes: 3 additions & 0 deletions Changes
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ Revision history for Tesla-API
- Remove WWW::Mechanize timeout (it defaults to 180 secs in LWP::UserAgent)
- Add API_TIMEOUT_RETRIES; If a Tesla API call times out, try it again this
many times
- Accept PR #9 (fix compatibility with JSON < 4) and apply that change to
all instances of encode_json()
-

0.09 2022-03-22
- In CI script, manually install File::ShareDir::Install, as it doesn't get
Expand Down
17 changes: 14 additions & 3 deletions lib/Tesla/API.pm
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,12 @@ sub _access_token_generate {
redirect_uri => "https://auth.tesla.com/void/callback",
};

my $request = HTTP::Request->new('POST', $url, $header, encode_json($request_data));
my $request = HTTP::Request->new(
'POST',
$url,
$header,
JSON->new->allow_nonref->encode($request_data)
);

my $response = $self->mech->request($request);

Expand Down Expand Up @@ -428,7 +433,12 @@ sub _access_token_refresh {
client_id => 'ownerapi',
};

my $request = HTTP::Request->new('POST', $url, $header, encode_json($request_data));
my $request = HTTP::Request->new(
'POST',
$url,
$header,
JSON->new->allow_nonref->encode($request_data)
);

my $response = $self->mech->request($request);

Expand Down Expand Up @@ -460,7 +470,8 @@ sub _access_token_update {
$self->_access_token_data($token_data);

open my $fh, '>', CACHE_FILE or die $!;
print $fh encode_json($token_data);

print $fh JSON->new->allow_nonref->encode($token_data);
}
sub _authentication_code {
# If an access token is unavailable, prompt the user with a URL to
Expand Down

0 comments on commit b625bab

Please sign in to comment.