veterejo

Unnamed repository; edit this file 'description' to name the repository.
git clone git://git.swab.dev/veterejo.git
Log | Files | Refs | README | LICENSE

commit 9fba5b4d2a1589a82883d00bf9956f1977825ce5
parent acd7c2a1f1fffd2de14fe9240c7ae873f2b7e358
Author: Jaron Swab <jrswab@gmail.com>
Date:   Sun,  8 Mar 2020 21:16:26 -0400

Added wind speed and cloud coverage

windspeed is a float
cloud coverage is an integer

Diffstat:
MREADME.md | 3++-
Mtests/veterejo_test.go | 55+++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mveterejo.go | 12+++++++++++-
3 files changed, 68 insertions(+), 2 deletions(-)

diff --git a/README.md b/README.md @@ -11,7 +11,8 @@ By replacing the **o** of a noun with **ejo** the word discribes a place of that 3. Create a new `WeatherData` struct: `w := new(veterejo.WeatherData)` 4. Parse the URL: `url, err := veterejo.MakeURL(yourCityID, unitsOfMeasure, yourApiId)` - `yourApiId` is required - - The rest may be omitted if desired. + - The rest may be omitted by passing an empty string. + - This package defaults the units of mesaure to metric. 5. Call the data: `w.getData(url)` 6. Use the appropriate method to get the most recent data needed from OpenWeatherMap. diff --git a/tests/veterejo_test.go b/tests/veterejo_test.go @@ -277,3 +277,58 @@ func TestGetCoords(t *testing.T) { }) } } + +func TestGetWindSpeed(t *testing.T) { + tests := []struct { + name string + data *v.WeatherData + want float32 + }{ + // TODO: Add test cases. + { + name: "return float on a correct call to the api (imperial)", + data: RunTestServer("imperial"), + want: 3.42, + }, + { + name: "return float on a correct call to the api (metric)", + data: RunTestServer("metric"), + want: 1.5, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + got := tt.data.GetWindSpeed() + if got != tt.want { + t.Errorf("GetMinTemp() = %v, want %v", got, tt.want) + } + }) + } +} +func TestGetCloudCoverage(t *testing.T) { + tests := []struct { + name string + data *v.WeatherData + want int + }{ + // TODO: Add test cases. + { + name: "GetCloudCoverage returns integer on a correct call to the api (imperial)", + data: RunTestServer("imperial"), + want: 1, + }, + { + name: "GetCloudCoverage returns integer on a correct call to the api (metric)", + data: RunTestServer("metric"), + want: 1, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + got := tt.data.GetCloudCoverage() + if got != tt.want { + t.Errorf("GetMaxTemp() = %v, want %v", got, tt.want) + } + }) + } +} diff --git a/veterejo.go b/veterejo.go @@ -60,7 +60,7 @@ func MakeURL(cityID, units, apiID string) (string, error) { } if units == "" { - return fmt.Sprintf("https://api.openweathermap.org/data/2.5/weather/?id=%s&appid=%s", cityID, apiID), nil + return fmt.Sprintf("https://api.openweathermap.org/data/2.5/weather/?id=%s&units=metrics&appid=%s", cityID, apiID), nil } return fmt.Sprintf("https://api.openweathermap.org/data/2.5/weather/?id=%s&units=%s&appid=%s", cityID, units, apiID), nil @@ -120,3 +120,13 @@ func (w *WeatherData) GetCoords() string { func (w *WeatherData) GetVisibility() int { return w.Visibility } + +// GetWindSpeed returns the current windspeed of the city. +func (w *WeatherData) GetWindSpeed() float32 { + return w.Wind.Speed +} + +// GetCloudCoverage returns an int as a percentage of cloud coverage +func (w *WeatherData) GetCloudCoverage() int { + return w.Clouds.All +}