Skip to content

Update to use cmfcmf/openweathermap-php-api ^3 #3

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@

`composer require coliving/laravel-owm`

You will also need a PSR-17 compatible HTTP factory implementation and a PSR-18 compatible HTTP client implementation. Laravel already requires guzzle as a http client, but you may need to add a http-factory package. Choose any [from this list](https://packagist.org/providers/psr/http-factory-implementation) or use the suggested package below:

```
composer require "http-interop/http-factory-guzzle:^1.0"
```

#### 2. Add this line to your conf/app.php file

For Laravel == 5.0.*
Expand Down
7 changes: 5 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,12 @@
"keywords": ["weather","clima","open weather map","laravel"],
"require": {
"php": ">=7.2.0",
"cmfcmf/openweathermap-php-api": "^2.1"
"cmfcmf/openweathermap-php-api": "^3.0",
"php-http/discovery": "^1.13"
},
"require-dev": {
"php-http/mock-client": "1.4.x-dev"
},

"license": "MIT",

"authors": [
Expand Down
23 changes: 21 additions & 2 deletions src/LaravelOWM.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
namespace Gmopx\LaravelOWM;

use Cmfcmf\OpenWeatherMap;
use Http\Discovery\Psr17FactoryDiscovery;
use Http\Discovery\Psr18ClientDiscovery;
use Psr\Http\Client\ClientInterface;
use Psr\Http\Message\RequestFactoryInterface;

class LaravelOWM
{
Expand All @@ -15,6 +19,18 @@ class LaravelOWM
*/
protected $api_key;

/**
* Psr18 http client
* @var ClientInterface
*/
protected $httpClient;

/**
* Psr17 http Factory
* @var RequestFactoryInterface
*/
protected $httpRequestFactory;

public function __construct()
{
$this->config = config('laravel-owm');
Expand All @@ -28,6 +44,9 @@ public function __construct()
}

$this->api_key = $this->config['api_key'];

$this->httpClient = Psr18ClientDiscovery::find();
$this->httpRequestFactory = Psr17FactoryDiscovery::findRequestFactory();
}

/**
Expand Down Expand Up @@ -55,11 +74,11 @@ public function getCurrentWeather($query, $lang = 'en', $units = 'metric', $cach
$units = $units ?: 'metric';

if ($cache) {
$owm = new OpenWeatherMap($this->api_key, null, new Cache(), $time);
$owm = new OpenWeatherMap($this->api_key, $this->httpClient, $this->httpRequestFactory, new Cache(), $time);
return $owm->getWeather($query, $units, $lang);
}

$owm = new OpenWeatherMap($this->api_key);
$owm = new OpenWeatherMap($this->api_key, $this->httpClient, $this->httpRequestFactory);
return $owm->getWeather($query, $units, $lang);
}

Expand Down