From 83eea50cf9bce925075b9e8c66906f9c2c3a249f Mon Sep 17 00:00:00 2001 From: James Date: Sun, 2 Feb 2020 15:09:10 +0000 Subject: [PATCH] update getTime functions to support upstream since/before args --- src/Client.php | 16 ++++++++++++++++ src/Repo.php | 24 ++++++++++++++++++++++-- 2 files changed, 38 insertions(+), 2 deletions(-) diff --git a/src/Client.php b/src/Client.php index 98fb403..bdadfc2 100644 --- a/src/Client.php +++ b/src/Client.php @@ -63,4 +63,20 @@ class Client{ $data=$this->request($url,'GET'); return $data->data[0]; } + + public function getCurrentUserTimes(\DateTime $since=null, \DateTime $before=null){ + $args=[]; + if($before){ + $args['before'] = $before->format('c'); + } + if($since){ + $args['since'] = $since->format('c'); + } + $url="{$this->url}user/times"; + if($args){ + $url.='?'.http_build_query($args); + } + $data=$this->request($url,'GET'); + return $data; + } } diff --git a/src/Repo.php b/src/Repo.php index 2474e33..4cfea37 100644 --- a/src/Repo.php +++ b/src/Repo.php @@ -122,13 +122,33 @@ class Repo{ return $data; } - public function getTimes(){ + public function getTimes(\DateTime $since=null, \DateTime $before=null){ + $args=[]; + if($before){ + $args['before'] = $before->format('c'); + } + if($since){ + $args['since'] = $since->format('c'); + } $url="repos/{$this->user}/{$this->repo}/times"; + if($args){ + $url.='?'.http_build_query($args); + } return $this->client->request($url,'GET'); } - public function getTimesByUsername($username){ + public function getTimesByUsername($username,\DateTime $since=null, \DateTime $before=null){ + $args=[]; + if($before){ + $args['before'] = $before->format('c'); + } + if($since){ + $args['since'] = $since->format('c'); + } $url="repos/{$this->user}/{$this->repo}/times/{$username}"; + if($args){ + $url.='?'.http_build_query($args); + } return $this->client->request($url,'GET'); }