Skip to content
This repository has been archived by the owner on Jul 26, 2022. It is now read-only.

Commit

Permalink
fix 400 bad request when empty 'extra' params are passed
Browse files Browse the repository at this point in the history
  • Loading branch information
matthewgoslett committed Jun 29, 2017
1 parent 9eb5736 commit 7490de7
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 2 deletions.
4 changes: 4 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## 1.0.1 - 2017-06-29

* Fix 400 bad request when empty 'extra' params are passed

## 1.0.0 - 2017-05-30

* Initial release
5 changes: 4 additions & 1 deletion src/Messages/AndroidMessageBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,6 @@ public function build()
$params = [
'alert' => $this->alert,
'title' => $this->title,
'extra' => $this->extra,
'message_variation_id' => $this->messageVariationId,
'priority' => $this->priority,
'collapse_key' => $this->collapseKey,
Expand All @@ -341,6 +340,10 @@ public function build()
'accent_color' => $this->accentColour,
];

if (!empty($this->extra)) {
$params['extra'] = $this->extra;
}

return array_filter($params, function ($param) {
return $param !== null;
});
Expand Down
5 changes: 4 additions & 1 deletion src/Messages/AppleMessageBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,6 @@ public function build()
'badge' => $this->badge,
'alert' => $this->alert,
'sound' => $this->sound,
'extra' => $this->extra,
'category' => $this->category,
'expiry' => $this->expiryDate ? $this->expiryDate->format('c') : null,
'custom_uri' => $this->uri,
Expand All @@ -250,6 +249,10 @@ public function build()
'asset_file_type' => $this->assetFileType,
];

if (!empty($this->extra)) {
$params['extra'] = $this->extra;
}

return array_filter($params, function ($param) {
return $param !== null;
});
Expand Down
4 changes: 4 additions & 0 deletions tests/AndroidMessageBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ public function testWithExtraAttributes()
$params = $builder->build();
$this->assertArrayHasKey('extra', $params);
$this->assertEquals(['version' => 'abc'], $params['extra']);

$builder->withExtraAttributes([]);
$params = $builder->build();
$this->assertArrayNotHasKey('extra', $params);
}

public function testAddExtraAttribute()
Expand Down
4 changes: 4 additions & 0 deletions tests/AppleMessageBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ public function testWithExtraAttributes()
$params = $builder->build();
$this->assertArrayHasKey('extra', $params);
$this->assertEquals(['version' => 'abc'], $params['extra']);

$builder->withExtraAttributes([]);
$params = $builder->build();
$this->assertArrayNotHasKey('extra', $params);
}

public function testAddExtraAttribute()
Expand Down

0 comments on commit 7490de7

Please sign in to comment.