-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#28 Fix error for sending InlineKeyboardMarkup and MaskPosition in a …
…multipart message
- Loading branch information
Showing
3 changed files
with
30 additions
and
2 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
28 changes: 28 additions & 0 deletions
28
Sources/Telegrammer/Helpers/MultipartPartConvertible+Helper.swift
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,28 @@ | ||
// | ||
// MultipartPartConvertible+Helper.swift | ||
// Telegrammer | ||
// | ||
// Created by Givi on 11/03/2019. | ||
// | ||
|
||
import Foundation | ||
import Multipart | ||
|
||
public protocol MultipartPartNestedConvertible: MultipartPartConvertible {} | ||
|
||
public extension MultipartPartNestedConvertible where Self: Codable { | ||
func convertToMultipartPart() throws -> MultipartPart { | ||
return try MultipartPart(data: JSONEncoder().encode(self)) | ||
} | ||
|
||
static func convertFromMultipartPart(_ part: MultipartPart) throws -> Self { | ||
do { | ||
return try JSONDecoder().decode(self.self, from: part.data) | ||
} catch { | ||
throw MultipartError( | ||
identifier: "\(self.self)", | ||
reason: "Failed to setup instance from json decoder - \(error)" | ||
) | ||
} | ||
} | ||
} |
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