Conditions | 2 |
Paths | 2 |
Total Lines | 24 |
Code Lines | 15 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
1 | <?php |
||
50 | public static function withUsernameAndPassword(string $username, string $password, Client $client): Authentication |
||
51 | { |
||
52 | $response = $client->get( |
||
53 | self::URL_AUTHENTICATE, |
||
54 | array( |
||
55 | 'query' => array( |
||
56 | 'country' => 'GB', |
||
57 | 'action' => 'pair', |
||
58 | 'deviceId' => Uuid::uuid5(Uuid::NAMESPACE_DNS, gethostname())->toString(), |
||
59 | 'email' => $username, |
||
60 | 'password' => $password, |
||
61 | ) |
||
62 | ) |
||
63 | ); |
||
64 | |||
65 | $responseBody = $response->getBody()->getContents(); |
||
66 | $response = parse_ini_string($responseBody); |
||
67 | |||
68 | if (array_key_exists('authToken', $response)) { |
||
69 | return new static($response['authToken']); |
||
70 | } |
||
71 | |||
72 | throw new InvalidCredentialsException('Authentication on Endomondo failed.'); |
||
73 | } |
||
74 | |||
80 |