Skip to content

Commit

Permalink
Merge branch 'fix_multipart_data'
Browse files Browse the repository at this point in the history
  • Loading branch information
givip committed Mar 11, 2019
2 parents a70316e + 7735fb7 commit 22b6f86
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Sources/Telegrammer/Bot/Models/MaskPosition.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
SeeAlso Telegram Bot API Reference:
[MaskPosition](https://core.telegram.org/bots/api#maskposition)
*/
public final class MaskPosition: Codable {
public final class MaskPosition: Codable, MultipartPartNestedConvertible {

/// Custom keys for coding/decoding `MaskPosition` struct
enum CodingKeys: String, CodingKey {
Expand Down
28 changes: 28 additions & 0 deletions Sources/Telegrammer/Helpers/MultipartPartConvertible+Helper.swift
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)"
)
}
}
}
2 changes: 1 addition & 1 deletion Sources/Telegrammer/Types/ReplyMarkup.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
SeeAlso Telegram Bot API Reference:
[Reply Markups](https://core.telegram.org/bots/2-0-intro#new-inline-keyboards)
*/
public enum ReplyMarkup: Codable {
public enum ReplyMarkup: Codable, MultipartPartNestedConvertible {
case inlineKeyboardMarkup(InlineKeyboardMarkup)
case replyKeyboardMarkup(ReplyKeyboardMarkup)
case replyKeyboardRemove(ReplyKeyboardRemove)
Expand Down

0 comments on commit 22b6f86

Please sign in to comment.