-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6 from loloop/mc/category-list-command
Adds a command to the telegram bot to list all available categories
- Loading branch information
Showing
18 changed files
with
333 additions
and
256 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
84 changes: 0 additions & 84 deletions
84
telegram/.swiftpm/xcode/xcshareddata/xcschemes/LandinhoBot.xcscheme
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
// | ||
// APIClient.swift | ||
// | ||
// | ||
// Created by Mauricio Cardozo on 09/11/23. | ||
// | ||
|
||
import Foundation | ||
#if os(Linux) | ||
import FoundationNetworking | ||
#endif | ||
|
||
struct APIClientError: LocalizedError { | ||
let message: String | ||
|
||
var errorDescription: String? { | ||
message | ||
} | ||
} | ||
|
||
struct APIClient<T: Decodable> { | ||
|
||
init(endpoint: String) { | ||
self.endpoint = endpoint | ||
} | ||
|
||
let endpoint: String | ||
|
||
func fetch(arguments: [String: String] = [:]) async throws -> T { | ||
guard let url = buildURL(path: endpoint, args: arguments) else { | ||
throw APIClientError(message: "Couldn't build URL") | ||
} | ||
|
||
let data = try await URLSession.shared.data(from: url) | ||
let decoder = JSONDecoder() | ||
decoder.dateDecodingStrategy = .iso8601 | ||
|
||
do { | ||
let response = try decoder.decode(T.self, from: data.0) | ||
return response | ||
} catch (let error) { | ||
let result = String(data: data.0, encoding: .utf8) ?? "Couldn't decode JSON" | ||
throw APIClientError(message: """ | ||
\(error) | ||
–––– | ||
\(result) | ||
""") | ||
} | ||
} | ||
|
||
func buildURL(path: String, args: [String: String]) -> URL? { | ||
var components = URLComponents() | ||
components.scheme = "http" | ||
components.host = "localhost" | ||
components.path = "/\(path)" | ||
components.port = 8080 | ||
components.queryItems = args.map { URLQueryItem(name: $0.key, value: $0.value) } | ||
return components.url | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
// | ||
// Bot.swift | ||
// | ||
// | ||
// Created by Mauricio Cardozo on 09/11/23. | ||
// | ||
|
||
import Foundation | ||
|
||
public protocol Bot { | ||
func reply(_ update: ChatUpdate, text: String) async throws | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.