Welcome to the documentation page for the OpenWeatherFreeClient library. This library is designed to provide a simple way to access data from the OpenWeatherMap API. Whether you are a beginner or an experienced developer, this documentation will guide you through the installation process, usage instructions, and provide examples to help you integrate the library into your projects.
Table of Contents:
Installation
To get started with the OpenWeatherFreeClient library, follow the steps below:
- Download the library files from the GitHub repository.
- Extract the downloaded files to your project directory.
- Include the library in your project by adding the following line to your PHP code:
require_once 'path/to/OpenWeatherFreeClient.php';
Usage
Configuration
Before making API requests, you need to set up your API key in the configuration file:
- Open the
config.php
file in the library directory. - Locate the
API_KEY
constant and replace the value with your OpenWeatherMap API key.
Current Weather
To retrieve the current weather data, use the following code:
$weather = new OpenWeatherFreeClient();
$currentWeather = $weather->getCurrentWeather('city-name');
Note: Replace 'city-name'
with the name of the city for which you want to get weather information.
Forecast
To obtain a weather forecast, utilize the following code:
$weather = new OpenWeatherFreeClient();
$forecast = $weather->getForecast('city-name');
Note: Replace 'city-name'
with the name of the city for which you want to retrieve the forecast.
Search
If you need to search for a specific city, you can use the following code snippet:
$weather = new OpenWeatherFreeClient();
$searchResults = $weather->search('query');
Note: Replace 'query'
with the search term or city name to obtain the search results.
Examples
Below are a few examples demonstrating the usage of OpenWeatherFreeClient library in different scenarios:
$weather = new OpenWeatherFreeClient();
$temperature = $weather->getCurrentWeather('paris')->main->temp;
echo "Temperature in Paris: ".$temperature."°C";
$weather = new OpenWeatherFreeClient();
$forecastData = $weather->getForecast('london')->list[0];
echo "Time: ".$forecastData->dt_txt;
echo "Weather: ".$forecastData->weather[0]->description;
Contribution
We welcome contributions from the community to improve and enhance this library. If you have any suggestions, bug reports, or feature requests, please feel free to contribute on GitHub.
Support
If you encounter any issues while using the OpenWeatherFreeClient library, you can find help and support by reaching out to the community on the official GitHub repository.