convert provider -> Provider
This commit is contained in:
parent
66d1e7fa79
commit
448c49ae79
5 changed files with 30 additions and 30 deletions
|
|
@ -1,7 +1,7 @@
|
|||
const std = @import("std");
|
||||
const httpz = @import("httpz");
|
||||
const Cache = @import("../cache/Cache.zig");
|
||||
const WeatherProvider = @import("../weather/provider.zig").WeatherProvider;
|
||||
const WeatherProvider = @import("../weather/Provider.zig");
|
||||
const Resolver = @import("../location/resolver.zig").Resolver;
|
||||
const Location = @import("../location/resolver.zig").Location;
|
||||
const QueryParams = @import("query.zig").QueryParams;
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
const std = @import("std");
|
||||
const weather_provider = @import("provider.zig");
|
||||
const WeatherProvider = @import("Provider.zig");
|
||||
const types = @import("types.zig");
|
||||
|
||||
const MetNo = @This();
|
||||
|
|
@ -12,7 +12,7 @@ pub fn init(allocator: std.mem.Allocator) !MetNo {
|
|||
};
|
||||
}
|
||||
|
||||
pub fn provider(self: *MetNo) weather_provider.WeatherProvider {
|
||||
pub fn provider(self: *MetNo) WeatherProvider {
|
||||
return .{
|
||||
.ptr = self,
|
||||
.vtable = &.{
|
||||
|
|
@ -107,11 +107,11 @@ fn parseMetNoResponse(allocator: std.mem.Allocator, location: []const u8, json:
|
|||
const instant = data.object.get("instant") orelse return error.InvalidResponse;
|
||||
const details = instant.object.get("details") orelse return error.InvalidResponse;
|
||||
|
||||
const temp_c = @as(f32, @floatCast(details.object.get("air_temperature").?.float));
|
||||
const humidity = @as(u8, @intFromFloat(details.object.get("relative_humidity").?.float));
|
||||
const temp_c: f32 = @floatCast(details.object.get("air_temperature").?.float);
|
||||
const humidity: u8 = @intFromFloat(details.object.get("relative_humidity").?.float);
|
||||
const wind_speed_ms = details.object.get("wind_speed").?.float;
|
||||
const wind_kph = @as(f32, @floatCast(wind_speed_ms * 3.6));
|
||||
const pressure_mb = @as(f32, @floatCast(details.object.get("air_pressure_at_sea_level").?.float));
|
||||
const wind_kph: f32 = @floatCast(wind_speed_ms * 3.6);
|
||||
const pressure_mb: f32 = @floatCast(details.object.get("air_pressure_at_sea_level").?.float);
|
||||
|
||||
// Get weather symbol
|
||||
const next_1h = data.object.get("next_1_hours");
|
||||
|
|
@ -173,7 +173,7 @@ fn symbolCodeToCondition(symbol: []const u8) []const u8 {
|
|||
|
||||
fn degreeToDirection(deg: f32) []const u8 {
|
||||
const normalized = @mod(deg + 22.5, 360.0);
|
||||
const idx = @as(usize, @intFromFloat(normalized / 45.0));
|
||||
const idx: usize = @intFromFloat(normalized / 45.0);
|
||||
const directions = [_][]const u8{ "N", "NE", "E", "SE", "S", "SW", "W", "NW" };
|
||||
return directions[@min(idx, 7)];
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
const std = @import("std");
|
||||
const weather_provider = @import("provider.zig");
|
||||
const WeatherProvider = @import("Provider.zig");
|
||||
const types = @import("types.zig");
|
||||
|
||||
const Mock = @This();
|
||||
|
|
@ -14,7 +14,7 @@ pub fn init(allocator: std.mem.Allocator) !Mock {
|
|||
};
|
||||
}
|
||||
|
||||
pub fn provider(self: *Mock) weather_provider.WeatherProvider {
|
||||
pub fn provider(self: *Mock) WeatherProvider {
|
||||
return .{
|
||||
.ptr = self,
|
||||
.vtable = &.{
|
||||
|
|
|
|||
20
src/weather/Provider.zig
Normal file
20
src/weather/Provider.zig
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
const std = @import("std");
|
||||
const types = @import("types.zig");
|
||||
|
||||
const WeatherProvider = @This();
|
||||
|
||||
ptr: *anyopaque,
|
||||
vtable: *const VTable,
|
||||
|
||||
pub const VTable = struct {
|
||||
fetch: *const fn (ptr: *anyopaque, allocator: std.mem.Allocator, location: []const u8) anyerror!types.WeatherData,
|
||||
deinit: *const fn (ptr: *anyopaque) void,
|
||||
};
|
||||
|
||||
pub fn fetch(self: WeatherProvider, allocator: std.mem.Allocator, location: []const u8) !types.WeatherData {
|
||||
return self.vtable.fetch(self.ptr, allocator, location);
|
||||
}
|
||||
|
||||
pub fn deinit(self: WeatherProvider) void {
|
||||
self.vtable.deinit(self.ptr);
|
||||
}
|
||||
|
|
@ -1,20 +0,0 @@
|
|||
const std = @import("std");
|
||||
const types = @import("types.zig");
|
||||
|
||||
pub const WeatherProvider = struct {
|
||||
ptr: *anyopaque,
|
||||
vtable: *const VTable,
|
||||
|
||||
pub const VTable = struct {
|
||||
fetch: *const fn (ptr: *anyopaque, allocator: std.mem.Allocator, location: []const u8) anyerror!types.WeatherData,
|
||||
deinit: *const fn (ptr: *anyopaque) void,
|
||||
};
|
||||
|
||||
pub fn fetch(self: WeatherProvider, allocator: std.mem.Allocator, location: []const u8) !types.WeatherData {
|
||||
return self.vtable.fetch(self.ptr, allocator, location);
|
||||
}
|
||||
|
||||
pub fn deinit(self: WeatherProvider) void {
|
||||
self.vtable.deinit(self.ptr);
|
||||
}
|
||||
};
|
||||
Loading…
Add table
Reference in a new issue