diff --git a/src/main.zig b/src/main.zig index b2c1a30..d4942f7 100644 --- a/src/main.zig +++ b/src/main.zig @@ -55,7 +55,9 @@ fn authenticate(allocator: std.mem.Allocator, username: []const u8, password: [] var client = http.Client{ .allocator = allocator }; defer client.deinit(); - const body = try std.fmt.allocPrint(allocator, "{{\"AuthFlow\":\"USER_PASSWORD_AUTH\",\"ClientId\":\"{s}\",\"AuthParameters\":{{\"USERNAME\":\"{s}\",\"PASSWORD\":\"{s}\"}}}}", .{ client_id, username, password }); + const body = try std.fmt.allocPrint(allocator, + \\{{"AuthFlow":"USER_PASSWORD_AUTH","ClientId":"{s}","AuthParameters":{{"USERNAME":"{s}","PASSWORD":"{s}"}}}} + , .{ client_id, username, password }); defer allocator.free(body); const uri = try std.Uri.parse(cognito_url); @@ -107,9 +109,32 @@ fn getDevices(allocator: std.mem.Allocator, id_token: []const u8, username: []co var client = http.Client{ .allocator = allocator }; defer client.deinit(); - const query = "query GetUserByEmail($email: String!) { getUserByEmail(email: $email) { items { id email devices { items { id thing_name device_name dsn model info { serial_id } } } } } }"; + const query = + \\query GetUserByEmail($email: String!) { + \\ getUserByEmail(email: $email) { + \\ items { + \\ id + \\ email + \\ devices { + \\ items { + \\ id + \\ thing_name + \\ device_name + \\ dsn + \\ model + \\ info { + \\ serial_id + \\ } + \\ } + \\ } + \\ } + \\ } + \\} + ; - const body = try std.fmt.allocPrint(allocator, "{{\"query\":\"{s}\",\"variables\":{{\"email\":\"{s}\"}}}}", .{ query, username }); + const body = try std.fmt.allocPrint(allocator, + \\{{"query":"{s}","variables":{{"email":"{s}"}}}} + , .{ query, username }); defer allocator.free(body); const uri = try std.Uri.parse(appsync_url); @@ -137,14 +162,20 @@ fn startRecirculation(allocator: std.mem.Allocator, id_token: []const u8, serial var client = http.Client{ .allocator = allocator }; defer client.deinit(); - const url = try std.fmt.allocPrint(allocator, "{s}/{s}/shadow", .{ shadow_api_url, serial_number }); + const url = try std.fmt.allocPrint(allocator, + \\{s}/{s}/shadow + , .{ shadow_api_url, serial_number }); defer allocator.free(url); - const body = try std.fmt.allocPrint(allocator, "{{\"recirculation_duration\":{d},\"set_recirculation_enabled\":true}}", .{duration_minutes}); + const body = try std.fmt.allocPrint(allocator, + \\{{"recirculation_duration":{d},"set_recirculation_enabled":true}} + , .{duration_minutes}); defer allocator.free(body); const uri = try std.Uri.parse(url); - const auth_header = try std.fmt.allocPrint(allocator, "Bearer {s}", .{id_token}); + const auth_header = try std.fmt.allocPrint(allocator, + \\Bearer {s} + , .{id_token}); defer allocator.free(auth_header); const result = try client.fetch(.{ @@ -165,9 +196,22 @@ fn getRecirculationStatus(allocator: std.mem.Allocator, id_token: []const u8, se var client = http.Client{ .allocator = allocator }; defer client.deinit(); - const query = "query GetDeviceShadow($heater_serial_number: ID!) { getDeviceShadow(heater_serial_number: $heater_serial_number) { heater_serial_number set_recirculation_enabled recirculation_enabled recirculation_duration set_domestic_temperature operation_enabled } }"; + const query = + \\query GetDeviceShadow($heater_serial_number: ID!) { + \\ getDeviceShadow(heater_serial_number: $heater_serial_number) { + \\ heater_serial_number + \\ set_recirculation_enabled + \\ recirculation_enabled + \\ recirculation_duration + \\ set_domestic_temperature + \\ operation_enabled + \\ } + \\} + ; - const body = try std.fmt.allocPrint(allocator, "{{\"query\":\"{s}\",\"variables\":{{\"heater_serial_number\":\"{s}\"}}}}", .{ query, serial_number }); + const body = try std.fmt.allocPrint(allocator, + \\{{"query":"{s}","variables":{{"heater_serial_number":"{s}"}}}} + , .{ query, serial_number }); defer allocator.free(body); const uri = try std.Uri.parse(appsync_url);