Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
givip committed Mar 11, 2019
2 parents 22b6f86 + 03d4cce commit 9ee8624
Show file tree
Hide file tree
Showing 91 changed files with 337 additions and 189 deletions.
16 changes: 11 additions & 5 deletions API/generate_wrappers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ def generate_model_file(f, node)

current_node.search('tr').each { |node|
td = node.search('td')
next unless td[0].text != 'Field' && td[0].text != 'Parameters'
next unless !(td[0].nil? || td[0] == 0) && (td[0].text != 'Field' && td[0].text != 'Parameters')

var_name = td[0].text
var_type = td[1].text
Expand Down Expand Up @@ -310,7 +310,13 @@ def generate_model_file(f, node)
out.write " SeeAlso Telegram Bot API Reference:\n"
out.write " [#{type_name}](https://core.telegram.org/bots/api\##{type_name.downcase})\n"
out.write " */\n"

var_protocol = "Codable"

if type_name == "MaskPosition" then
var_protocol += ", MultipartPartNestedConvertible"
end

if type_name.start_with?('InputMedia') then
var_protocol = "Encodable"
end
Expand Down Expand Up @@ -371,7 +377,7 @@ def generate_method(f, node)

current_node.search('tr').each { |node|
td = node.search('td')
next unless td[0].text != 'Parameters'
next unless !(td[0].nil? || td[0] == 0) && (td[0].text != 'Parameters')

var_name = td[0].text
var_type = td[1].text
Expand Down Expand Up @@ -440,7 +446,7 @@ def generate_method(f, node)
params_block = "(params: #{method_name_capitalized}? = nil)"
out.write method_description
out.write "#{ONE}@discardableResult\n"
out.write "#{ONE}public func #{method_name}() throws -> Future<#{result_type}> {\n"
out.write "#{ONE}func #{method_name}() throws -> Future<#{result_type}> {\n"
else

encodable_type = "JSONEncodable"
Expand All @@ -449,7 +455,7 @@ def generate_method(f, node)
encodable_type = "MultipartEncodable"
end
out.write "#{ONE}/// Parameters container struct for `#{method_name}` method\n"
out.write "#{ONE}public struct #{method_name_capitalized}: #{encodable_type} {\n\n"
out.write "#{ONE}struct #{method_name_capitalized}: #{encodable_type} {\n\n"
out.write "#{all_params}"
out.write "#{TWO}/// Custom keys for coding/decoding `#{method_name_capitalized}` struct\n"
out.write "#{TWO}enum CodingKeys: String, CodingKey {\n"
Expand All @@ -469,7 +475,7 @@ def generate_method(f, node)

out.write method_description
out.write "#{ONE}@discardableResult\n"
out.write "#{ONE}public func #{method_name}#{params_block} throws -> Future<#{result_type}> {\n"
out.write "#{ONE}func #{method_name}#{params_block} throws -> Future<#{result_type}> {\n"

out.write "#{TWO}let body = try httpBody(for: params)\n"
out.write "#{TWO}let headers = httpHeaders(for: params)\n"
Expand Down
4 changes: 2 additions & 2 deletions Sources/Telegrammer/Bot/Methods/Bot+addStickerToSet.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import HTTP
public extension Bot {

/// Parameters container struct for `addStickerToSet` method
public struct AddStickerToSetParams: MultipartEncodable {
struct AddStickerToSetParams: MultipartEncodable {

/// User identifier of sticker set owner
var userId: Int64
Expand Down Expand Up @@ -54,7 +54,7 @@ public extension Bot {
- Returns: Future of `Bool` type
*/
@discardableResult
public func addStickerToSet(params: AddStickerToSetParams) throws -> Future<Bool> {
func addStickerToSet(params: AddStickerToSetParams) throws -> Future<Bool> {
let body = try httpBody(for: params)
let headers = httpHeaders(for: params)
let response: Future<TelegramContainer<Bool>>
Expand Down
4 changes: 2 additions & 2 deletions Sources/Telegrammer/Bot/Methods/Bot+answerCallbackQuery.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import HTTP
public extension Bot {

/// Parameters container struct for `answerCallbackQuery` method
public struct AnswerCallbackQueryParams: JSONEncodable {
struct AnswerCallbackQueryParams: JSONEncodable {

/// Unique identifier for the query to be answered
var callbackQueryId: String
Expand Down Expand Up @@ -57,7 +57,7 @@ public extension Bot {
- Returns: Future of `Bool` type
*/
@discardableResult
public func answerCallbackQuery(params: AnswerCallbackQueryParams) throws -> Future<Bool> {
func answerCallbackQuery(params: AnswerCallbackQueryParams) throws -> Future<Bool> {
let body = try httpBody(for: params)
let headers = httpHeaders(for: params)
let response: Future<TelegramContainer<Bool>>
Expand Down
4 changes: 2 additions & 2 deletions Sources/Telegrammer/Bot/Methods/Bot+answerInlineQuery.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import HTTP
public extension Bot {

/// Parameters container struct for `answerInlineQuery` method
public struct AnswerInlineQueryParams: JSONEncodable {
struct AnswerInlineQueryParams: JSONEncodable {

/// Unique identifier for the answered query
var inlineQueryId: String
Expand Down Expand Up @@ -67,7 +67,7 @@ public extension Bot {
- Returns: Future of `Bool` type
*/
@discardableResult
public func answerInlineQuery(params: AnswerInlineQueryParams) throws -> Future<Bool> {
func answerInlineQuery(params: AnswerInlineQueryParams) throws -> Future<Bool> {
let body = try httpBody(for: params)
let headers = httpHeaders(for: params)
let response: Future<TelegramContainer<Bool>>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import HTTP
public extension Bot {

/// Parameters container struct for `answerPreCheckoutQuery` method
public struct AnswerPreCheckoutQueryParams: JSONEncodable {
struct AnswerPreCheckoutQueryParams: JSONEncodable {

/// Unique identifier for the query to be answered
var preCheckoutQueryId: String
Expand Down Expand Up @@ -44,7 +44,7 @@ public extension Bot {
- Returns: Future of `Bool` type
*/
@discardableResult
public func answerPreCheckoutQuery(params: AnswerPreCheckoutQueryParams) throws -> Future<Bool> {
func answerPreCheckoutQuery(params: AnswerPreCheckoutQueryParams) throws -> Future<Bool> {
let body = try httpBody(for: params)
let headers = httpHeaders(for: params)
let response: Future<TelegramContainer<Bool>>
Expand Down
4 changes: 2 additions & 2 deletions Sources/Telegrammer/Bot/Methods/Bot+answerShippingQuery.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import HTTP
public extension Bot {

/// Parameters container struct for `answerShippingQuery` method
public struct AnswerShippingQueryParams: JSONEncodable {
struct AnswerShippingQueryParams: JSONEncodable {

/// Unique identifier for the query to be answered
var shippingQueryId: String
Expand Down Expand Up @@ -49,7 +49,7 @@ public extension Bot {
- Returns: Future of `Bool` type
*/
@discardableResult
public func answerShippingQuery(params: AnswerShippingQueryParams) throws -> Future<Bool> {
func answerShippingQuery(params: AnswerShippingQueryParams) throws -> Future<Bool> {
let body = try httpBody(for: params)
let headers = httpHeaders(for: params)
let response: Future<TelegramContainer<Bool>>
Expand Down
4 changes: 2 additions & 2 deletions Sources/Telegrammer/Bot/Methods/Bot+createNewStickerSet.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import HTTP
public extension Bot {

/// Parameters container struct for `createNewStickerSet` method
public struct CreateNewStickerSetParams: MultipartEncodable {
struct CreateNewStickerSetParams: MultipartEncodable {

/// User identifier of created sticker set owner
var userId: Int64
Expand Down Expand Up @@ -64,7 +64,7 @@ public extension Bot {
- Returns: Future of `Bool` type
*/
@discardableResult
public func createNewStickerSet(params: CreateNewStickerSetParams) throws -> Future<Bool> {
func createNewStickerSet(params: CreateNewStickerSetParams) throws -> Future<Bool> {
let body = try httpBody(for: params)
let headers = httpHeaders(for: params)
let response: Future<TelegramContainer<Bool>>
Expand Down
4 changes: 2 additions & 2 deletions Sources/Telegrammer/Bot/Methods/Bot+deleteChatPhoto.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import HTTP
public extension Bot {

/// Parameters container struct for `deleteChatPhoto` method
public struct DeleteChatPhotoParams: JSONEncodable {
struct DeleteChatPhotoParams: JSONEncodable {

/// Unique identifier for the target chat or username of the target channel (in the format @channelusername)
var chatId: ChatId
Expand Down Expand Up @@ -35,7 +35,7 @@ public extension Bot {
- Returns: Future of `Bool` type
*/
@discardableResult
public func deleteChatPhoto(params: DeleteChatPhotoParams) throws -> Future<Bool> {
func deleteChatPhoto(params: DeleteChatPhotoParams) throws -> Future<Bool> {
let body = try httpBody(for: params)
let headers = httpHeaders(for: params)
let response: Future<TelegramContainer<Bool>>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import HTTP
public extension Bot {

/// Parameters container struct for `deleteChatStickerSet` method
public struct DeleteChatStickerSetParams: JSONEncodable {
struct DeleteChatStickerSetParams: JSONEncodable {

/// Unique identifier for the target chat or username of the target supergroup (in the format @supergroupusername)
var chatId: ChatId
Expand All @@ -34,7 +34,7 @@ public extension Bot {
- Returns: Future of `Bool` type
*/
@discardableResult
public func deleteChatStickerSet(params: DeleteChatStickerSetParams) throws -> Future<Bool> {
func deleteChatStickerSet(params: DeleteChatStickerSetParams) throws -> Future<Bool> {
let body = try httpBody(for: params)
let headers = httpHeaders(for: params)
let response: Future<TelegramContainer<Bool>>
Expand Down
6 changes: 3 additions & 3 deletions Sources/Telegrammer/Bot/Methods/Bot+deleteMessage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import HTTP
public extension Bot {

/// Parameters container struct for `deleteMessage` method
public struct DeleteMessageParams: JSONEncodable {
struct DeleteMessageParams: JSONEncodable {

/// Unique identifier for the target chat or username of the target channel (in the format @channelusername)
var chatId: ChatId
Expand All @@ -30,7 +30,7 @@ public extension Bot {
/**
Use this method to delete a message, including service messages, with the following limitations:
- A message can only be deleted if it was sent less than 48 hours ago.
- Bots can delete outgoing messages in groups and supergroups.
- Bots can delete outgoing messages in private chats, groups, and supergroups.
- Bots granted can_post_messages permissions can delete outgoing messages in channels.
- If the bot is an administrator of a group, it can delete any message there.
- If the bot has can_delete_messages permission in a supergroup or a channel, it can delete any message there.
Expand All @@ -45,7 +45,7 @@ public extension Bot {
- Returns: Future of `Bool` type
*/
@discardableResult
public func deleteMessage(params: DeleteMessageParams) throws -> Future<Bool> {
func deleteMessage(params: DeleteMessageParams) throws -> Future<Bool> {
let body = try httpBody(for: params)
let headers = httpHeaders(for: params)
let response: Future<TelegramContainer<Bool>>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import HTTP
public extension Bot {

/// Parameters container struct for `deleteStickerFromSet` method
public struct DeleteStickerFromSetParams: JSONEncodable {
struct DeleteStickerFromSetParams: JSONEncodable {

/// File identifier of the sticker
var sticker: String
Expand All @@ -34,7 +34,7 @@ public extension Bot {
- Returns: Future of `Bool` type
*/
@discardableResult
public func deleteStickerFromSet(params: DeleteStickerFromSetParams) throws -> Future<Bool> {
func deleteStickerFromSet(params: DeleteStickerFromSetParams) throws -> Future<Bool> {
let body = try httpBody(for: params)
let headers = httpHeaders(for: params)
let response: Future<TelegramContainer<Bool>>
Expand Down
2 changes: 1 addition & 1 deletion Sources/Telegrammer/Bot/Methods/Bot+deleteWebhook.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public extension Bot {
- Returns: Future of `Bool` type
*/
@discardableResult
public func deleteWebhook() throws -> Future<Bool> {
func deleteWebhook() throws -> Future<Bool> {
let response: Future<TelegramContainer<Bool>>
response = try client.respond(endpoint: "deleteWebhook", body: HTTPBody(), headers: HTTPHeaders())
return response.flatMap(to: Bool.self) { try self.wrap($0) }
Expand Down
4 changes: 2 additions & 2 deletions Sources/Telegrammer/Bot/Methods/Bot+editMessageCaption.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import HTTP
public extension Bot {

/// Parameters container struct for `editMessageCaption` method
public struct EditMessageCaptionParams: JSONEncodable {
struct EditMessageCaptionParams: JSONEncodable {

/// Required if inline_message_id is not specified. Unique identifier for the target chat or username of the target channel (in the format @channelusername)
var chatId: ChatId?
Expand Down Expand Up @@ -59,7 +59,7 @@ public extension Bot {
- Returns: Future of `MessageOrBool` type
*/
@discardableResult
public func editMessageCaption(params: EditMessageCaptionParams? = nil) throws -> Future<MessageOrBool> {
func editMessageCaption(params: EditMessageCaptionParams? = nil) throws -> Future<MessageOrBool> {
let body = try httpBody(for: params)
let headers = httpHeaders(for: params)
let response: Future<TelegramContainer<MessageOrBool>>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import HTTP
public extension Bot {

/// Parameters container struct for `editMessageLiveLocation` method
public struct EditMessageLiveLocationParams: JSONEncodable {
struct EditMessageLiveLocationParams: JSONEncodable {

/// Required if inline_message_id is not specified. Unique identifier for the target chat or username of the target channel (in the format @channelusername)
var chatId: ChatId?
Expand Down Expand Up @@ -59,7 +59,7 @@ public extension Bot {
- Returns: Future of `MessageOrBool` type
*/
@discardableResult
public func editMessageLiveLocation(params: EditMessageLiveLocationParams) throws -> Future<MessageOrBool> {
func editMessageLiveLocation(params: EditMessageLiveLocationParams) throws -> Future<MessageOrBool> {
let body = try httpBody(for: params)
let headers = httpHeaders(for: params)
let response: Future<TelegramContainer<MessageOrBool>>
Expand Down
6 changes: 3 additions & 3 deletions Sources/Telegrammer/Bot/Methods/Bot+editMessageMedia.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import HTTP
public extension Bot {

/// Parameters container struct for `editMessageMedia` method
public struct EditMessageMediaParams: JSONEncodable {
struct EditMessageMediaParams: JSONEncodable {

/// Required if inline_message_id is not specified. Unique identifier for the target chat or username of the target channel (in the format @channelusername)
var chatId: ChatId?
Expand Down Expand Up @@ -43,7 +43,7 @@ public extension Bot {
}

/**
Use this method to edit audio, document, photo, or video messages. If a message is a part of a message album, then it can be edited only to a photo or a video. Otherwise, message type can be changed arbitrarily. When inline message is edited, new file can't be uploaded. Use previously uploaded file via its file_id or specify a URL. On success, if the edited message was sent by the bot, the edited Message is returned, otherwise True is returned.
Use this method to edit animation, audio, document, photo, or video messages. If a message is a part of a message album, then it can be edited only to a photo or a video. Otherwise, message type can be changed arbitrarily. When inline message is edited, new file can't be uploaded. Use previously uploaded file via its file_id or specify a URL. On success, if the edited message was sent by the bot, the edited Message is returned, otherwise True is returned.

SeeAlso Telegram Bot API Reference:
[EditMessageMediaParams](https://core.telegram.org/bots/api#editmessagemedia)
Expand All @@ -54,7 +54,7 @@ public extension Bot {
- Returns: Future of `MessageOrBool` type
*/
@discardableResult
public func editMessageMedia(params: EditMessageMediaParams) throws -> Future<MessageOrBool> {
func editMessageMedia(params: EditMessageMediaParams) throws -> Future<MessageOrBool> {
let body = try httpBody(for: params)
let headers = httpHeaders(for: params)
let response: Future<TelegramContainer<MessageOrBool>>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import HTTP
public extension Bot {

/// Parameters container struct for `editMessageReplyMarkup` method
public struct EditMessageReplyMarkupParams: JSONEncodable {
struct EditMessageReplyMarkupParams: JSONEncodable {

/// Required if inline_message_id is not specified. Unique identifier for the target chat or username of the target channel (in the format @channelusername)
var chatId: ChatId?
Expand Down Expand Up @@ -49,7 +49,7 @@ public extension Bot {
- Returns: Future of `MessageOrBool` type
*/
@discardableResult
public func editMessageReplyMarkup(params: EditMessageReplyMarkupParams? = nil) throws -> Future<MessageOrBool> {
func editMessageReplyMarkup(params: EditMessageReplyMarkupParams? = nil) throws -> Future<MessageOrBool> {
let body = try httpBody(for: params)
let headers = httpHeaders(for: params)
let response: Future<TelegramContainer<MessageOrBool>>
Expand Down
4 changes: 2 additions & 2 deletions Sources/Telegrammer/Bot/Methods/Bot+editMessageText.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import HTTP
public extension Bot {

/// Parameters container struct for `editMessageText` method
public struct EditMessageTextParams: JSONEncodable {
struct EditMessageTextParams: JSONEncodable {

/// Required if inline_message_id is not specified. Unique identifier for the target chat or username of the target channel (in the format @channelusername)
var chatId: ChatId?
Expand Down Expand Up @@ -64,7 +64,7 @@ public extension Bot {
- Returns: Future of `MessageOrBool` type
*/
@discardableResult
public func editMessageText(params: EditMessageTextParams) throws -> Future<MessageOrBool> {
func editMessageText(params: EditMessageTextParams) throws -> Future<MessageOrBool> {
let body = try httpBody(for: params)
let headers = httpHeaders(for: params)
let response: Future<TelegramContainer<MessageOrBool>>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import HTTP
public extension Bot {

/// Parameters container struct for `exportChatInviteLink` method
public struct ExportChatInviteLinkParams: JSONEncodable {
struct ExportChatInviteLinkParams: JSONEncodable {

/// Unique identifier for the target chat or username of the target channel (in the format @channelusername)
var chatId: ChatId
Expand All @@ -34,7 +34,7 @@ public extension Bot {
- Returns: Future of `String` type
*/
@discardableResult
public func exportChatInviteLink(params: ExportChatInviteLinkParams) throws -> Future<String> {
func exportChatInviteLink(params: ExportChatInviteLinkParams) throws -> Future<String> {
let body = try httpBody(for: params)
let headers = httpHeaders(for: params)
let response: Future<TelegramContainer<String>>
Expand Down
4 changes: 2 additions & 2 deletions Sources/Telegrammer/Bot/Methods/Bot+forwardMessage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import HTTP
public extension Bot {

/// Parameters container struct for `forwardMessage` method
public struct ForwardMessageParams: JSONEncodable {
struct ForwardMessageParams: JSONEncodable {

/// Unique identifier for the target chat or username of the target channel (in the format @channelusername)
var chatId: ChatId
Expand Down Expand Up @@ -49,7 +49,7 @@ public extension Bot {
- Returns: Future of `Message` type
*/
@discardableResult
public func forwardMessage(params: ForwardMessageParams) throws -> Future<Message> {
func forwardMessage(params: ForwardMessageParams) throws -> Future<Message> {
let body = try httpBody(for: params)
let headers = httpHeaders(for: params)
let response: Future<TelegramContainer<Message>>
Expand Down
Loading

0 comments on commit 9ee8624

Please sign in to comment.