From 4b8a9a5189a625bf99fedec7fd31f6e146410a14 Mon Sep 17 00:00:00 2001 From: emkael Date: Thu, 26 Apr 2018 01:00:12 +0200 Subject: Update FB API library --- .../src/Facebook/GraphNodes/Birthday.php | 85 ++++++++++++++++++++++ .../src/Facebook/GraphNodes/Collection.php | 4 +- .../src/Facebook/GraphNodes/GraphAchievement.php | 5 +- .../src/Facebook/GraphNodes/GraphAlbum.php | 2 +- .../src/Facebook/GraphNodes/GraphApplication.php | 2 +- .../src/Facebook/GraphNodes/GraphCoverPhoto.php | 2 +- .../src/Facebook/GraphNodes/GraphEdge.php | 44 +++++------ .../src/Facebook/GraphNodes/GraphEvent.php | 2 +- .../src/Facebook/GraphNodes/GraphGroup.php | 3 +- .../src/Facebook/GraphNodes/GraphList.php | 2 +- .../src/Facebook/GraphNodes/GraphLocation.php | 2 +- .../src/Facebook/GraphNodes/GraphNode.php | 18 ++++- .../src/Facebook/GraphNodes/GraphNodeFactory.php | 4 +- .../src/Facebook/GraphNodes/GraphObject.php | 2 +- .../src/Facebook/GraphNodes/GraphObjectFactory.php | 8 +- .../src/Facebook/GraphNodes/GraphPage.php | 24 +++++- .../src/Facebook/GraphNodes/GraphPicture.php | 2 +- .../src/Facebook/GraphNodes/GraphSessionInfo.php | 2 +- .../src/Facebook/GraphNodes/GraphUser.php | 14 +++- 19 files changed, 174 insertions(+), 53 deletions(-) create mode 100644 lib/facebook-graph-sdk/src/Facebook/GraphNodes/Birthday.php (limited to 'lib/facebook-graph-sdk/src/Facebook/GraphNodes') diff --git a/lib/facebook-graph-sdk/src/Facebook/GraphNodes/Birthday.php b/lib/facebook-graph-sdk/src/Facebook/GraphNodes/Birthday.php new file mode 100644 index 0000000..4338b65 --- /dev/null +++ b/lib/facebook-graph-sdk/src/Facebook/GraphNodes/Birthday.php @@ -0,0 +1,85 @@ +hasYear = count($parts) === 3 || count($parts) === 1; + $this->hasDate = count($parts) === 3 || count($parts) === 2; + + parent::__construct($date); + } + + /** + * Returns whether date object contains birth day and month + * + * @return bool + */ + public function hasDate() + { + return $this->hasDate; + } + + /** + * Returns whether date object contains birth year + * + * @return bool + */ + public function hasYear() + { + return $this->hasYear; + } +} diff --git a/lib/facebook-graph-sdk/src/Facebook/GraphNodes/Collection.php b/lib/facebook-graph-sdk/src/Facebook/GraphNodes/Collection.php index cac010b..424b7cf 100644 --- a/lib/facebook-graph-sdk/src/Facebook/GraphNodes/Collection.php +++ b/lib/facebook-graph-sdk/src/Facebook/GraphNodes/Collection.php @@ -1,6 +1,6 @@ items[$name]; } - return $default ?: null; + return $default; } /** diff --git a/lib/facebook-graph-sdk/src/Facebook/GraphNodes/GraphAchievement.php b/lib/facebook-graph-sdk/src/Facebook/GraphNodes/GraphAchievement.php index 3fba815..31508ee 100644 --- a/lib/facebook-graph-sdk/src/Facebook/GraphNodes/GraphAchievement.php +++ b/lib/facebook-graph-sdk/src/Facebook/GraphNodes/GraphAchievement.php @@ -1,6 +1,6 @@ validateForPagination(); // Do we have a paging URL? - if (isset($this->metaData['paging'][$direction])) { - // Graph returns the full URL with all the original params. - // We just want the endpoint though. - $pageUrl = $this->metaData['paging'][$direction]; - - return FacebookUrlManipulator::baseGraphUrlEndpoint($pageUrl); - } - - // Do we have a cursor to work with? - $cursorDirection = $direction === 'next' ? 'after' : 'before'; - $cursor = $this->getCursor($cursorDirection); - if (!$cursor) { - return null; - } - - // If we don't know the ID of the parent node, this ain't gonna work. - if (!$this->parentEdgeEndpoint) { + if (!isset($this->metaData['paging'][$direction])) { return null; } - // We have the parent node ID, paging cursor & original request. - // These were the ingredients chosen to create the perfect little URL. - $pageUrl = $this->parentEdgeEndpoint . '?' . $cursorDirection . '=' . urlencode($cursor); + $pageUrl = $this->metaData['paging'][$direction]; - // Pull in the original params - $originalUrl = $this->request->getUrl(); - $pageUrl = FacebookUrlManipulator::mergeUrlParams($originalUrl, $pageUrl); - - return FacebookUrlManipulator::forceSlashPrefix($pageUrl); + return FacebookUrlManipulator::baseGraphUrlEndpoint($pageUrl); } /** @@ -257,4 +235,18 @@ class GraphEdge extends Collection return null; } + + /** + * @inheritDoc + */ + public function map(\Closure $callback) + { + return new static( + $this->request, + array_map($callback, $this->items, array_keys($this->items)), + $this->metaData, + $this->parentEdgeEndpoint, + $this->subclassName + ); + } } diff --git a/lib/facebook-graph-sdk/src/Facebook/GraphNodes/GraphEvent.php b/lib/facebook-graph-sdk/src/Facebook/GraphNodes/GraphEvent.php index 19ff2fb..a470d89 100644 --- a/lib/facebook-graph-sdk/src/Facebook/GraphNodes/GraphEvent.php +++ b/lib/facebook-graph-sdk/src/Facebook/GraphNodes/GraphEvent.php @@ -1,6 +1,6 @@ getField('venue'); } - } diff --git a/lib/facebook-graph-sdk/src/Facebook/GraphNodes/GraphList.php b/lib/facebook-graph-sdk/src/Facebook/GraphNodes/GraphList.php index a60a07a..3dfbd49 100644 --- a/lib/facebook-graph-sdk/src/Facebook/GraphNodes/GraphList.php +++ b/lib/facebook-graph-sdk/src/Facebook/GraphNodes/GraphList.php @@ -1,6 +1,6 @@ $v) { if ($this->shouldCastAsDateTime($k) && (is_numeric($v) - || $k === 'birthday' || $this->isIso8601DateString($v)) ) { $items[$k] = $this->castToDateTime($v); + } elseif ($k === 'birthday') { + $items[$k] = $this->castToBirthday($v); } else { $items[$k] = $v; } @@ -149,7 +150,6 @@ class GraphNode extends Collection 'backdated_time', 'issued_at', 'expires_at', - 'birthday', 'publish_time' ], true); } @@ -173,6 +173,18 @@ class GraphNode extends Collection return $dt; } + /** + * Casts a birthday value from Graph to Birthday + * + * @param string $value + * + * @return Birthday + */ + public function castToBirthday($value) + { + return new Birthday($value); + } + /** * Getter for $graphObjectMap. * diff --git a/lib/facebook-graph-sdk/src/Facebook/GraphNodes/GraphNodeFactory.php b/lib/facebook-graph-sdk/src/Facebook/GraphNodes/GraphNodeFactory.php index e1bedd9..6a37091 100644 --- a/lib/facebook-graph-sdk/src/Facebook/GraphNodes/GraphNodeFactory.php +++ b/lib/facebook-graph-sdk/src/Facebook/GraphNodes/GraphNodeFactory.php @@ -1,6 +1,6 @@ safelyMakeGraphNode($graphNode, $subclassName, $parentKey, $parentNodeId); + $dataList[] = $this->safelyMakeGraphNode($graphNode, $subclassName); } $metaData = $this->getMetaData($data); diff --git a/lib/facebook-graph-sdk/src/Facebook/GraphNodes/GraphObject.php b/lib/facebook-graph-sdk/src/Facebook/GraphNodes/GraphObject.php index bb8f8e4..0633c40 100644 --- a/lib/facebook-graph-sdk/src/Facebook/GraphNodes/GraphObject.php +++ b/lib/facebook-graph-sdk/src/Facebook/GraphNodes/GraphObject.php @@ -1,6 +1,6 @@ makeGraphNode($subclassName); } - + /** * Convenience method for creating a GraphEvent collection. * @@ -66,7 +68,7 @@ class GraphObjectFactory extends GraphNodeFactory */ public function makeGraphEvent() { - return $this->makeGraphObject(static::BASE_GRAPH_OBJECT_PREFIX . 'GraphEvent'); + return $this->makeGraphNode(static::BASE_GRAPH_OBJECT_PREFIX . 'GraphEvent'); } /** diff --git a/lib/facebook-graph-sdk/src/Facebook/GraphNodes/GraphPage.php b/lib/facebook-graph-sdk/src/Facebook/GraphNodes/GraphPage.php index ab8e31a..3dfb0e0 100644 --- a/lib/facebook-graph-sdk/src/Facebook/GraphNodes/GraphPage.php +++ b/lib/facebook-graph-sdk/src/Facebook/GraphNodes/GraphPage.php @@ -1,6 +1,6 @@ '\Facebook\GraphNodes\GraphPage', 'global_brand_parent_page' => '\Facebook\GraphNodes\GraphPage', 'location' => '\Facebook\GraphNodes\GraphLocation', + 'cover' => '\Facebook\GraphNodes\GraphCoverPhoto', + 'picture' => '\Facebook\GraphNodes\GraphPicture', ]; /** @@ -99,6 +101,26 @@ class GraphPage extends GraphNode return $this->getField('location'); } + /** + * Returns CoverPhoto of the Page. + * + * @return GraphCoverPhoto|null + */ + public function getCover() + { + return $this->getField('cover'); + } + + /** + * Returns Picture of the Page. + * + * @return GraphPicture|null + */ + public function getPicture() + { + return $this->getField('picture'); + } + /** * Returns the page access token for the admin user. * diff --git a/lib/facebook-graph-sdk/src/Facebook/GraphNodes/GraphPicture.php b/lib/facebook-graph-sdk/src/Facebook/GraphNodes/GraphPicture.php index bfd37fa..10274ec 100644 --- a/lib/facebook-graph-sdk/src/Facebook/GraphNodes/GraphPicture.php +++ b/lib/facebook-graph-sdk/src/Facebook/GraphNodes/GraphPicture.php @@ -1,6 +1,6 @@ getField('last_name'); } + /** + * Returns the email for the user as a string if present. + * + * @return string|null + */ + public function getEmail() + { + return $this->getField('email'); + } + /** * Returns the gender for the user as a string if present. * @@ -113,7 +123,7 @@ class GraphUser extends GraphNode /** * Returns the users birthday, if available. * - * @return \DateTime|null + * @return Birthday|null */ public function getBirthday() { -- cgit v1.2.3