Skip to content

Commit

Permalink
Merge pull request #130 from ker0x/hotfix/user-response
Browse files Browse the repository at this point in the history
[n/a] remove methods isPaymentEnabled and getLastAdReferral from User…
  • Loading branch information
ker0x authored Oct 30, 2018
2 parents f4c77fc + 1f1d14e commit 3f5b4e1
Show file tree
Hide file tree
Showing 25 changed files with 32 additions and 80 deletions.
1 change: 0 additions & 1 deletion .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,3 @@
/phpunit.xml.dist export-ignore
/.scrutinizer.yml export-ignore
/tests export-ignore
/docs export-ignore
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,14 @@ The Messenger library follows [SemVer](http://semver.org/).

## 3.x

**Changelog** (since [`3.0.0`](https://github.com/ker0x/messenger/compare/3.0.0...3.1.0))

- 3.1.0 (2018-10)
- Update API version to `v3.2`.
- Fix type for properties *AppId in `\Kerox\Messenger\Model\Callback\PassThreadControl::class`, `\Kerox\Messenger\Model\Callback\RequestThreadControl::class` and `\Kerox\Messenger\Model\Callback\TakeThreadControl::class`. (Thanks to @dbknet)
- Change method visibility from `public` to `protected` in `\Kerox\Messenger\Helper\ValidatorTrait::class`
- Remove methods `isPaymentEnabled` and `getLastAdReferral` from `\Kerox\Messenger\Response\UserResponse::class` as there are been removed from the API (see [CHANGELOG](https://developers.facebook.com/docs/graph-api/changelog/version3.1#messenger-platform))

**Changelog** (since [`2.1.1`](https://github.com/ker0x/messenger/compare/2.1.1...3.0.0))

Version `3.0.0` of the Messenger library is an enhancement of version `2.1.1` with major break changes.
Expand Down
1 change: 0 additions & 1 deletion src/Api/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ private function getAllowedFields(): array
self::LOCALE,
self::TIMEZONE,
self::GENDER,
self::IS_PAYMENT_ENABLED,
];
}
}
8 changes: 4 additions & 4 deletions src/Helper/ValidatorTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ protected function isValidTag(string $tag, Message $message = null): void
/**
* @return array
*/
public function getAllowedSenderAction(): array
protected function getAllowedSenderAction(): array
{
return [
SendInterface::SENDER_ACTION_TYPING_ON,
Expand All @@ -286,7 +286,7 @@ public function getAllowedSenderAction(): array
/**
* @return array
*/
public function getAllowedNotificationType(): array
protected function getAllowedNotificationType(): array
{
return [
SendInterface::NOTIFICATION_TYPE_REGULAR,
Expand All @@ -298,7 +298,7 @@ public function getAllowedNotificationType(): array
/**
* @return array
*/
public function getAllowedTag(): array
protected function getAllowedTag(): array
{
return [
SendInterface::TAG_BUSINESS_PRODUCTIVITY,
Expand All @@ -324,7 +324,7 @@ public function getAllowedTag(): array
/**
* @return array
*/
public function getAllowedCurrency(): array
protected function getAllowedCurrency(): array
{
return [
'SGD',
Expand Down
2 changes: 1 addition & 1 deletion src/Messenger.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
class Messenger
{
public const API_URL = 'https://graph.facebook.com/';
public const API_VERSION = 'v3.1';
public const API_VERSION = 'v3.2';

/**
* @var string
Expand Down
2 changes: 1 addition & 1 deletion src/Model/Callback/RequestThreadControl.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
class RequestThreadControl
{
/**
* @var string
* @var int
*/
protected $requestedOwnerAppId;

Expand Down
40 changes: 0 additions & 40 deletions src/Response/UserResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

namespace Kerox\Messenger\Response;

use Kerox\Messenger\Model\Referral;
use Kerox\Messenger\UserInterface;

class UserResponse extends AbstractResponse implements UserInterface
Expand Down Expand Up @@ -39,16 +38,6 @@ class UserResponse extends AbstractResponse implements UserInterface
*/
protected $gender;

/**
* @var null|bool
*/
protected $paymentEnabled;

/**
* @var null|\Kerox\Messenger\Model\Referral
*/
protected $lastAdReferral;

/**
* @param array $response
*/
Expand All @@ -60,9 +49,6 @@ protected function parseResponse(array $response): void
$this->locale = $response[UserInterface::LOCALE] ?? null;
$this->timezone = $response[UserInterface::TIMEZONE] ?? null;
$this->gender = $response[UserInterface::GENDER] ?? null;
$this->paymentEnabled = $response[UserInterface::IS_PAYMENT_ENABLED] ?? null;

$this->setLastAdReferral($response);
}

/**
Expand Down Expand Up @@ -112,30 +98,4 @@ public function getGender(): ?string
{
return $this->gender;
}

/**
* @return null|bool
*/
public function isPaymentEnabled(): ?bool
{
return $this->paymentEnabled;
}

/**
* @return null|\Kerox\Messenger\Model\Referral
*/
public function getLastAdReferral(): ?Referral
{
return $this->lastAdReferral;
}

/**
* @param array $response
*/
private function setLastAdReferral(array $response): void
{
if (isset($response[UserInterface::LAST_AD_REFERRAL])) {
$this->lastAdReferral = Referral::create($response[UserInterface::LAST_AD_REFERRAL]);
}
}
}
2 changes: 0 additions & 2 deletions src/UserInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,4 @@ interface UserInterface
public const LOCALE = 'locale';
public const TIMEZONE = 'timezone';
public const GENDER = 'gender';
public const IS_PAYMENT_ENABLED = 'is_payment_enabled';
public const LAST_AD_REFERRAL = 'last_ad_referral';
}
2 changes: 1 addition & 1 deletion tests/Mocks/Response/Broadcast/broadcast_messages.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"broadcast_id": "0123456789"
}
}
2 changes: 1 addition & 1 deletion tests/Mocks/Response/Broadcast/message_creatives.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"message_creative_id": "0123456789"
}
}
2 changes: 1 addition & 1 deletion tests/Mocks/Response/Code/code.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"uri": "https://scontent.xx.fbcdn.net/v/t39.8917-6/16685555_1672240442792330_5569294125766803456_n.png?oh=eb8cf65a7a7a5808b24e55527b366dd0&oe=592BBFCC"
}
}
2 changes: 1 addition & 1 deletion tests/Mocks/Response/Insights/insights.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,4 @@
"id": "1234567/insights/page_messages_active_threads_unique/day"
}
]
}
}
2 changes: 1 addition & 1 deletion tests/Mocks/Response/Nlp/success.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"success": true
}
}
1 change: 1 addition & 0 deletions tests/Mocks/Response/Persona/add.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{
"id": "<PERSONA_ID>"
}

2 changes: 1 addition & 1 deletion tests/Mocks/Response/Persona/delete.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"success": true
}
}
2 changes: 1 addition & 1 deletion tests/Mocks/Response/Profile/add.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"result": "success"
}
}
2 changes: 1 addition & 1 deletion tests/Mocks/Response/Send/attachment.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"attachment_id":"1854626884821032"
}
}
2 changes: 1 addition & 1 deletion tests/Mocks/Response/Send/attachment_to_user.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
"recipient_id": "1008372609250235",
"message_id": "mid.1456970487936:c34767dfe57ee6e339",
"attachment_id": "1745504518999123"
}
}
2 changes: 1 addition & 1 deletion tests/Mocks/Response/Send/basic.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"recipient_id": "1008372609250235",
"message_id": "mid.1456970487936:c34767dfe57ee6e339"
}
}
2 changes: 1 addition & 1 deletion tests/Mocks/Response/Send/error.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@
"error_subcode": 1234567,
"fbtrace_id": "BLBz/WZt8dN"
}
}
}
2 changes: 1 addition & 1 deletion tests/Mocks/Response/Tag/tag.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,4 @@
"description": "The ticket_update tag may only be used to provide updates pertaining to an event for which a person already has a ticket. For example, when there is a change in time, a location update or a cancellation (such as when a concert is canceled, the venue has changed or a refund opportunity is available). This tag cannot be used for use cases beyond those listed above or for promotional content (ex: daily deals, coupons and discounts, or sale announcements)."
}
]
}
}
2 changes: 1 addition & 1 deletion tests/Mocks/Response/Thread/success.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"success": true
}
}
11 changes: 2 additions & 9 deletions tests/Mocks/Response/User/user.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,5 @@
"profile_pic": "https://fbcdn-profile-a.akamaihd.net/hprofile-ak-xpf1/v/t1.0-1/p200x200/13055603_10105219398495383_8237637584159975445_n.jpg?oh=1d241d4b6d4dac50eaf9bb73288ea192&oe=57AF5C03&__gda__=1470213755_ab17c8c8e3a0a447fed3f272fa2179ce",
"locale": "en_US",
"timezone": -7,
"gender": "male",
"is_payment_enabled": true,
"last_ad_referral": {
"source": "ADS",
"type": "OPEN_THREAD",
"ad_id": "6045246247433",
"ref": "myparam"
}
}
"gender": "male"
}
2 changes: 1 addition & 1 deletion tests/Mocks/Response/Webhook/success.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"success": true
}
}
8 changes: 1 addition & 7 deletions tests/TestCase/Api/UserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,18 +45,12 @@ public function testGetProfile(): void
$this->assertSame('en_US', $response->getLocale());
$this->assertSame(-7., $response->getTimezone());
$this->assertSame('male', $response->getGender());
$this->assertTrue($response->isPaymentEnabled());
$this->assertInstanceOf(Referral::class, $response->getLastAdReferral());
$this->assertSame('ADS', $response->getLastAdReferral()->getSource());
$this->assertSame('OPEN_THREAD', $response->getLastAdReferral()->getType());
$this->assertSame('6045246247433', $response->getLastAdReferral()->getAdId());
$this->assertSame('myparam', $response->getLastAdReferral()->getRef());
}

public function testGetProfileWithBadField(): void
{
$this->expectException(MessengerException::class);
$this->expectExceptionMessage('username is not a valid value. fields must only contain "first_name, last_name, profile_pic, locale, timezone, gender, is_payment_enabled".');
$this->expectExceptionMessage('username is not a valid value. fields must only contain "first_name, last_name, profile_pic, locale, timezone, gender".');
$response = $this->userApi->profile('1234abcd', ['username']);
}
}

0 comments on commit 3f5b4e1

Please sign in to comment.