From 7719013771c2da0b466b86acf586fd2d10850f6a Mon Sep 17 00:00:00 2001 From: Renato Martins Date: Sun, 10 Sep 2017 17:08:01 +0100 Subject: [PATCH 1/5] Add files via upload MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Entrega do desafio relativo ao calculo da idade de uma pessoa, passando o seu ano de nascimento como parâmetro. --- src/MinhaCalculadora.php | 61 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 src/MinhaCalculadora.php diff --git a/src/MinhaCalculadora.php b/src/MinhaCalculadora.php new file mode 100644 index 0000000..187eff7 --- /dev/null +++ b/src/MinhaCalculadora.php @@ -0,0 +1,61 @@ + Date: Wed, 13 Sep 2017 21:54:38 +0100 Subject: [PATCH 2/5] Desafio relativo a api do GitHub, Renato Martins --- src/GitHubAngola.php | 67 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 src/GitHubAngola.php diff --git a/src/GitHubAngola.php b/src/GitHubAngola.php new file mode 100644 index 0000000..4a5412a --- /dev/null +++ b/src/GitHubAngola.php @@ -0,0 +1,67 @@ + Date: Wed, 13 Sep 2017 22:24:18 +0100 Subject: [PATCH 3/5] AgeCalculator --- src/AgeCalculator.php | 63 +++++++++++++++++++++++++++ tests/testAgeCalculator.php | 86 +++++++++++++++++++++++++++++++++++++ 2 files changed, 149 insertions(+) create mode 100644 src/AgeCalculator.php create mode 100644 tests/testAgeCalculator.php diff --git a/src/AgeCalculator.php b/src/AgeCalculator.php new file mode 100644 index 0000000..bf866d3 --- /dev/null +++ b/src/AgeCalculator.php @@ -0,0 +1,63 @@ + + + + + + + Coding Dojo Angola + + + + + + + + +
+ +

Calculo da idade

+ +
+ +

Insira o seu ano de nascimento

+ +

+ +

+
+ + + getAge($userAge) . " ano(s) de idade"); + + } + + + ?> +
+ + + \ No newline at end of file From 1d709e7167a605b536c83d70755487a5e44e9355 Mon Sep 17 00:00:00 2001 From: guimar86 Date: Fri, 15 Sep 2017 07:52:22 +0100 Subject: [PATCH 4/5] Test wit curl features --- src/GitHubAngola.php | 13 ++++++ tests/testAgeCalculator.php | 86 ------------------------------------- 2 files changed, 13 insertions(+), 86 deletions(-) delete mode 100644 tests/testAgeCalculator.php diff --git a/src/GitHubAngola.php b/src/GitHubAngola.php index 4a5412a..6e75cc6 100644 --- a/src/GitHubAngola.php +++ b/src/GitHubAngola.php @@ -9,6 +9,18 @@ class GitHubAngola { + + function getCurlVal(){ + + $curl_init=curl_init(); + $url="curl -u guimar86:540bdd5a9a1d676d7e4ca4b082aaf62d12fcc8ee https://api.github.com/search/users?q=location:Luanda/Angola"; + curl_setopt($curl_init,CURLOPT_URL,$url); + curl_setopt($curl_init,CURLOPT_RETURNTRANSFER,$url); + + $result=curl_exec($curl_init); + + + } /** * Função usada para ler o endpoint do gitHub * e obter todos utilizadores em Angola @@ -19,6 +31,7 @@ function getGitHubAngolanUsers() { $toReturn = array(); + //$github_url=curl -u guimar86:540bdd5a9a1d676d7e4ca4b082aaf62d12fcc8ee https://api.github.com/search/users?q=location:Luanda/Angola $github_url = 'https://api.github.com/search/users?q=location:Luanda/Angola'; $github_json = file_get_contents($github_url); $github_array = json_decode($github_json, true); diff --git a/tests/testAgeCalculator.php b/tests/testAgeCalculator.php deleted file mode 100644 index e16be71..0000000 --- a/tests/testAgeCalculator.php +++ /dev/null @@ -1,86 +0,0 @@ - - - - - - Coding Dojo Angola - - - - - - - - -
- -

Calculo da idade

- -
- -

Insira o seu ano de nascimento

- -

- -

-
- - - getAge($userAge) . " ano(s) de idade"); - - } - - - ?> -
- - - \ No newline at end of file From 824a1c25d058fc82f2bf748817ce7bcf1b0f15cb Mon Sep 17 00:00:00 2001 From: guimar86 Date: Sun, 17 Sep 2017 02:05:32 +0100 Subject: [PATCH 5/5] Challenge partially completed. Need phpUnit Test --- src/GitHubAngola.php | 75 +++++++++++++------------------------------- 1 file changed, 22 insertions(+), 53 deletions(-) diff --git a/src/GitHubAngola.php b/src/GitHubAngola.php index 6e75cc6..3c2b23a 100644 --- a/src/GitHubAngola.php +++ b/src/GitHubAngola.php @@ -2,79 +2,48 @@ /** * User: Renato Martins - * Date: 12/09/2017 - * Time: 21:13 + * Date: 16/09/2017 + * Time: 20:13 */ class GitHubAngola { - - function getCurlVal(){ - - $curl_init=curl_init(); - $url="curl -u guimar86:540bdd5a9a1d676d7e4ca4b082aaf62d12fcc8ee https://api.github.com/search/users?q=location:Luanda/Angola"; - curl_setopt($curl_init,CURLOPT_URL,$url); - curl_setopt($curl_init,CURLOPT_RETURNTRANSFER,$url); - - $result=curl_exec($curl_init); - - - } /** - * Função usada para ler o endpoint do gitHub - * e obter todos utilizadores em Angola - * =====AUTENTICACAO EM FALTA==== - * @return array + * Metodo usado para retornar a lista de utilizadores pela + * localizacao indicada + * @return mixed */ - function getGitHubAngolanUsers() + function getGitHubUsersByLocation($location) { - $toReturn = array(); - //$github_url=curl -u guimar86:540bdd5a9a1d676d7e4ca4b082aaf62d12fcc8ee https://api.github.com/search/users?q=location:Luanda/Angola - $github_url = 'https://api.github.com/search/users?q=location:Luanda/Angola'; - $github_json = file_get_contents($github_url); - $github_array = json_decode($github_json, true); - - - if (!empty($github_array)) { - - foreach ($github_array['data'] as $names) { - - array_push($toReturn, ['total_count']['incomplete_results']['items']['login']); - } + if (!isset($location)) { + trigger_error("Falta o parametro localizacao", E_USER_ERROR); } - return $toReturn; - } + $userAgent = $_SERVER['HTTP_USER_AGENT']; - /** - * Função usada para ler o endpoint do rest api do github - * e devolver a lista de utilizadores na localizcao solicitada. - * ==== AUTENTICACAO EM FALTA ==== - * @param $location - * @return array - */ - function getGitHubUserByLocation($location) - { + $ch = curl_init(); + $url = "https://api.github.com/search/users?q=location:" . $location; + curl_setopt($ch, CURLOPT_URL, $url); + curl_setopt($ch, CURLOPT_USERAGENT, $userAgent); + curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); - $toReturn = array(); - $github_url = 'https://api.github.com/search/users?q=location:' . $location; - $github_json = file_get_contents($github_url); - $github_array = json_decode($github_json, true); + $result = curl_exec($ch); - if (!empty($github_array)) { + curl_close($ch); - foreach ($github_array['data'] as $names) { + $gitReturn = json_decode($result, true); - array_push($toReturn, ['total_count']['incomplete_results']['items']['login']); - } + //var_dump($gitReturn); - } + return $gitReturn; - return $toReturn; } + + } \ No newline at end of file