Skip to content

Commit

Permalink
Make types coercible
Browse files Browse the repository at this point in the history
  • Loading branch information
vladislav-yashin committed Jun 28, 2021
1 parent 4360b63 commit 979d2ca
Show file tree
Hide file tree
Showing 464 changed files with 1,241 additions and 1,224 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
## [Unreleased]

## [1.7.0.2] - 2021-06-28

- Make types coercible

## [1.7.0.1] - 2021-06-25

- Initial release
12 changes: 6 additions & 6 deletions bin/parser
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ def parse_tl_type(type)
if (vector = type.scan(/[vV]ector<(.*)>/)).length > 0
"TD::Types::Array.of(#{parse_tl_type(vector[0][0])})"
elsif type.match?(/[iI]nt\d\d/)
'TD::Types::Integer'
'TD::Types::Coercible::Integer'
elsif type.match?(/[dD]ouble/)
'TD::Types::Float'
'TD::Types::Coercible::Float'
elsif type.match?(/[bB]ytes/)
'TD::Types::String'
'TD::Types::Coercible::String'
else
"TD::Types::#{type.camelcase}"
end
Expand Down Expand Up @@ -186,9 +186,9 @@ end

def type_to_comment_type(type)
type.gsub('TD::Types::Array.of(', 'Array<').gsub(')', '>').
gsub('TD::Types::Integer', 'Integer').
gsub('TD::Types::Float', 'Float').
gsub('TD::Types::String', 'String').
gsub('TD::Types::Coercible::Integer', 'Integer').
gsub('TD::Types::Coercible::Float', 'Float').
gsub('TD::Types::Coercible::String', 'String').
gsub('TD::Types::Bool', 'Boolean')
end

Expand Down
339 changes: 171 additions & 168 deletions lib/tdlib/client_methods.rb

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion lib/tdlib/types/account_ttl.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ module TD::Types
# @attr days [Integer] Number of days of inactivity before the account will be flagged for deletion; should range
# from 30-366 days.
class AccountTtl < Base
attribute :days, TD::Types::Integer
attribute :days, TD::Types::Coercible::Integer
end
end
12 changes: 6 additions & 6 deletions lib/tdlib/types/address.rb
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
module TD::Types
# Describes an address.
#
# @attr country_code [String] A two-letter ISO 3166-1 alpha-2 country code.
# @attr state [String] State, if applicable.
# @attr city [String] City.
# @attr street_line1 [String] First line of the address.
# @attr street_line2 [String] Second line of the address.
# @attr postal_code [String] Address postal code.
# @attr country_code [TD::Types::String] A two-letter ISO 3166-1 alpha-2 country code.
# @attr state [TD::Types::String] State, if applicable.
# @attr city [TD::Types::String] City.
# @attr street_line1 [TD::Types::String] First line of the address.
# @attr street_line2 [TD::Types::String] Second line of the address.
# @attr postal_code [TD::Types::String] Address postal code.
class Address < Base
attribute :country_code, TD::Types::String
attribute :state, TD::Types::String
Expand Down
4 changes: 2 additions & 2 deletions lib/tdlib/types/animated_chat_photo.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ module TD::Types
# @attr file [TD::Types::File] Information about the animation file.
# @attr main_frame_timestamp [Float] Timestamp of the frame, used as a static chat photo.
class AnimatedChatPhoto < Base
attribute :length, TD::Types::Integer
attribute :length, TD::Types::Coercible::Integer
attribute :file, TD::Types::File
attribute :main_frame_timestamp, TD::Types::Float
attribute :main_frame_timestamp, TD::Types::Coercible::Float
end
end
10 changes: 5 additions & 5 deletions lib/tdlib/types/animation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,17 @@ module TD::Types
# @attr duration [Integer] Duration of the animation, in seconds; as defined by the sender.
# @attr width [Integer] Width of the animation.
# @attr height [Integer] Height of the animation.
# @attr file_name [String] Original name of the file; as defined by the sender.
# @attr mime_type [String] MIME type of the file, usually "image/gif" or "video/mp4".
# @attr file_name [TD::Types::String] Original name of the file; as defined by the sender.
# @attr mime_type [TD::Types::String] MIME type of the file, usually "image/gif" or "video/mp4".
# @attr has_stickers [Boolean] True, if stickers were added to the animation.
# The list of corresponding sticker set can be received using getAttachedStickerSets.
# @attr minithumbnail [TD::Types::Minithumbnail, nil] Animation minithumbnail; may be null.
# @attr thumbnail [TD::Types::Thumbnail, nil] Animation thumbnail in JPEG or MPEG4 format; may be null.
# @attr animation [TD::Types::File] File containing the animation.
class Animation < Base
attribute :duration, TD::Types::Integer
attribute :width, TD::Types::Integer
attribute :height, TD::Types::Integer
attribute :duration, TD::Types::Coercible::Integer
attribute :width, TD::Types::Coercible::Integer
attribute :height, TD::Types::Coercible::Integer
attribute :file_name, TD::Types::String
attribute :mime_type, TD::Types::String
attribute :has_stickers, TD::Types::Bool
Expand Down
10 changes: 5 additions & 5 deletions lib/tdlib/types/audio.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@ module TD::Types
# Audio is usually in MP3 or M4A format.
#
# @attr duration [Integer] Duration of the audio, in seconds; as defined by the sender.
# @attr title [String] Title of the audio; as defined by the sender.
# @attr performer [String] Performer of the audio; as defined by the sender.
# @attr file_name [String] Original name of the file; as defined by the sender.
# @attr mime_type [String] The MIME type of the file; as defined by the sender.
# @attr title [TD::Types::String] Title of the audio; as defined by the sender.
# @attr performer [TD::Types::String] Performer of the audio; as defined by the sender.
# @attr file_name [TD::Types::String] Original name of the file; as defined by the sender.
# @attr mime_type [TD::Types::String] The MIME type of the file; as defined by the sender.
# @attr album_cover_minithumbnail [TD::Types::Minithumbnail, nil] The minithumbnail of the album cover; may be null.
# @attr album_cover_thumbnail [TD::Types::Thumbnail, nil] The thumbnail of the album cover in JPEG format; as defined
# by the sender.
# The full size thumbnail should be extracted from the downloaded file; may be null.
# @attr audio [TD::Types::File] File containing the audio.
class Audio < Base
attribute :duration, TD::Types::Integer
attribute :duration, TD::Types::Coercible::Integer
attribute :title, TD::Types::String
attribute :performer, TD::Types::String
attribute :file_name, TD::Types::String
Expand Down
4 changes: 2 additions & 2 deletions lib/tdlib/types/authentication_code_info.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module TD::Types
# Information about the authentication code that was sent.
#
# @attr phone_number [String] A phone number that is being authenticated.
# @attr phone_number [TD::Types::String] A phone number that is being authenticated.
# @attr type [TD::Types::AuthenticationCodeType] Describes the way the code was sent to the user.
# @attr next_type [TD::Types::AuthenticationCodeType, nil] Describes the way the next code will be sent to the user;
# may be null.
Expand All @@ -10,6 +10,6 @@ class AuthenticationCodeInfo < Base
attribute :phone_number, TD::Types::String
attribute :type, TD::Types::AuthenticationCodeType
attribute :next_type, TD::Types::AuthenticationCodeType.optional.default(nil)
attribute :timeout, TD::Types::Integer
attribute :timeout, TD::Types::Coercible::Integer
end
end
2 changes: 1 addition & 1 deletion lib/tdlib/types/authentication_code_type/call.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ module TD::Types
#
# @attr length [Integer] Length of the code.
class AuthenticationCodeType::Call < AuthenticationCodeType
attribute :length, TD::Types::Integer
attribute :length, TD::Types::Coercible::Integer
end
end
2 changes: 1 addition & 1 deletion lib/tdlib/types/authentication_code_type/flash_call.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module TD::Types
# An authentication code is delivered by an immediately cancelled call to the specified phone number.
# The number from which the call was made is the code.
#
# @attr pattern [String] Pattern of the phone number from which the call will be made.
# @attr pattern [TD::Types::String] Pattern of the phone number from which the call will be made.
class AuthenticationCodeType::FlashCall < AuthenticationCodeType
attribute :pattern, TD::Types::String
end
Expand Down
2 changes: 1 addition & 1 deletion lib/tdlib/types/authentication_code_type/sms.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ module TD::Types
#
# @attr length [Integer] Length of the code.
class AuthenticationCodeType::Sms < AuthenticationCodeType
attribute :length, TD::Types::Integer
attribute :length, TD::Types::Coercible::Integer
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ module TD::Types
#
# @attr length [Integer] Length of the code.
class AuthenticationCodeType::TelegramMessage < AuthenticationCodeType
attribute :length, TD::Types::Integer
attribute :length, TD::Types::Coercible::Integer
end
end
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module TD::Types
# The user needs to confirm authorization on another logged in device by scanning a QR code with the provided link.
#
# @attr link [String] A tg:// URL for the QR code.
# @attr link [TD::Types::String] A tg:// URL for the QR code.
# The link will be updated frequently.
class AuthorizationState::WaitOtherDeviceConfirmation < AuthorizationState
attribute :link, TD::Types::String
Expand Down
6 changes: 3 additions & 3 deletions lib/tdlib/types/authorization_state/wait_password.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
module TD::Types
# The user has been authorized, but needs to enter a password to start using the application.
#
# @attr password_hint [String, nil] Hint for the password; may be empty.
# @attr password_hint [TD::Types::String, nil] Hint for the password; may be empty.
# @attr has_recovery_email_address [Boolean] True, if a recovery email address has been set up.
# @attr recovery_email_address_pattern [String, nil] Pattern of the email address to which the recovery email was
# sent; empty until a recovery email has been sent.
# @attr recovery_email_address_pattern [TD::Types::String, nil] Pattern of the email address to which the recovery
# email was sent; empty until a recovery email has been sent.
class AuthorizationState::WaitPassword < AuthorizationState
attribute :password_hint, TD::Types::String.optional.default(nil)
attribute :has_recovery_email_address, TD::Types::Bool
Expand Down
8 changes: 4 additions & 4 deletions lib/tdlib/types/auto_download_settings.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ module TD::Types
# @attr use_less_data_for_calls [Boolean] True, if "use less data for calls" option needs to be enabled.
class AutoDownloadSettings < Base
attribute :is_auto_download_enabled, TD::Types::Bool
attribute :max_photo_file_size, TD::Types::Integer
attribute :max_video_file_size, TD::Types::Integer
attribute :max_other_file_size, TD::Types::Integer
attribute :video_upload_bitrate, TD::Types::Integer
attribute :max_photo_file_size, TD::Types::Coercible::Integer
attribute :max_video_file_size, TD::Types::Coercible::Integer
attribute :max_other_file_size, TD::Types::Coercible::Integer
attribute :video_upload_bitrate, TD::Types::Coercible::Integer
attribute :preload_large_videos, TD::Types::Bool
attribute :preload_next_audio, TD::Types::Bool
attribute :use_less_data_for_calls, TD::Types::Bool
Expand Down
4 changes: 2 additions & 2 deletions lib/tdlib/types/background.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ module TD::Types
# @attr id [Integer] Unique background identifier.
# @attr is_default [Boolean] True, if this is one of default backgrounds.
# @attr is_dark [Boolean] True, if the background is dark and is recommended to be used with dark theme.
# @attr name [String] Unique background name.
# @attr name [TD::Types::String] Unique background name.
# @attr document [TD::Types::Document, nil] Document with the background; may be null.
# Null only for filled backgrounds.
# @attr type [TD::Types::BackgroundType] Type of the background.
class Background < Base
attribute :id, TD::Types::Integer
attribute :id, TD::Types::Coercible::Integer
attribute :is_default, TD::Types::Bool
attribute :is_dark, TD::Types::Bool
attribute :name, TD::Types::String
Expand Down
6 changes: 3 additions & 3 deletions lib/tdlib/types/background_fill/gradient.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ module TD::Types
# @attr rotation_angle [Integer] Clockwise rotation angle of the gradient, in degrees; 0-359.
# Should be always divisible by 45.
class BackgroundFill::Gradient < BackgroundFill
attribute :top_color, TD::Types::Integer
attribute :bottom_color, TD::Types::Integer
attribute :rotation_angle, TD::Types::Integer
attribute :top_color, TD::Types::Coercible::Integer
attribute :bottom_color, TD::Types::Coercible::Integer
attribute :rotation_angle, TD::Types::Coercible::Integer
end
end
2 changes: 1 addition & 1 deletion lib/tdlib/types/background_fill/solid.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ module TD::Types
#
# @attr color [Integer] A color of the background in the RGB24 format.
class BackgroundFill::Solid < BackgroundFill
attribute :color, TD::Types::Integer
attribute :color, TD::Types::Coercible::Integer
end
end
2 changes: 1 addition & 1 deletion lib/tdlib/types/background_type/pattern.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ module TD::Types
# @attr is_moving [Boolean] True, if the background needs to be slightly moved when device is tilted.
class BackgroundType::Pattern < BackgroundType
attribute :fill, TD::Types::BackgroundFill
attribute :intensity, TD::Types::Integer
attribute :intensity, TD::Types::Coercible::Integer
attribute :is_moving, TD::Types::Bool
end
end
4 changes: 2 additions & 2 deletions lib/tdlib/types/bank_card_action_open_url.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
module TD::Types
# Describes an action associated with a bank card number.
#
# @attr text [String] Action text.
# @attr url [String] The URL to be opened.
# @attr text [TD::Types::String] Action text.
# @attr url [TD::Types::String] The URL to be opened.
class BankCardActionOpenUrl < Base
attribute :text, TD::Types::String
attribute :url, TD::Types::String
Expand Down
2 changes: 1 addition & 1 deletion lib/tdlib/types/bank_card_info.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module TD::Types
# Information about a bank card.
#
# @attr title [String] Title of the bank card description.
# @attr title [TD::Types::String] Title of the bank card description.
# @attr actions [Array<TD::Types::BankCardActionOpenUrl>] Actions that can be done with the bank card number.
class BankCardInfo < Base
attribute :title, TD::Types::String
Expand Down
6 changes: 3 additions & 3 deletions lib/tdlib/types/basic_group.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ module TD::Types
# @attr is_active [Boolean] True, if the group is active.
# @attr upgraded_to_supergroup_id [Integer] Identifier of the supergroup to which this group was upgraded; 0 if none.
class BasicGroup < Base
attribute :id, TD::Types::Integer
attribute :member_count, TD::Types::Integer
attribute :id, TD::Types::Coercible::Integer
attribute :member_count, TD::Types::Coercible::Integer
attribute :status, TD::Types::ChatMemberStatus
attribute :is_active, TD::Types::Bool
attribute :upgraded_to_supergroup_id, TD::Types::Integer
attribute :upgraded_to_supergroup_id, TD::Types::Coercible::Integer
end
end
4 changes: 2 additions & 2 deletions lib/tdlib/types/basic_group_full_info.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module TD::Types
# Contains full information about a basic group.
#
# @attr photo [TD::Types::ChatPhoto, nil] Chat photo; may be null.
# @attr description [String] Group description.
# @attr description [TD::Types::String] Group description.
# Updated only after the basic group is opened.
# @attr creator_user_id [Integer] User identifier of the creator of the group; 0 if unknown.
# @attr members [Array<TD::Types::ChatMember>] Group members.
Expand All @@ -12,7 +12,7 @@ module TD::Types
class BasicGroupFullInfo < Base
attribute :photo, TD::Types::ChatPhoto.optional.default(nil)
attribute :description, TD::Types::String
attribute :creator_user_id, TD::Types::Integer
attribute :creator_user_id, TD::Types::Coercible::Integer
attribute :members, TD::Types::Array.of(TD::Types::ChatMember)
attribute :invite_link, TD::Types::ChatInviteLink.optional.default(nil)
end
Expand Down
4 changes: 2 additions & 2 deletions lib/tdlib/types/bot_command.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
module TD::Types
# Represents a command supported by a bot.
#
# @attr command [String] Text of the bot command.
# @attr description [String] Description of the bot command.
# @attr command [TD::Types::String] Text of the bot command.
# @attr description [TD::Types::String] Description of the bot command.
class BotCommand < Base
attribute :command, TD::Types::String
attribute :description, TD::Types::String
Expand Down
2 changes: 1 addition & 1 deletion lib/tdlib/types/bot_info.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module TD::Types
# Provides information about a bot and its supported commands.
#
# @attr description [String] Long description shown on the user info page.
# @attr description [TD::Types::String] Long description shown on the user info page.
# @attr commands [Array<TD::Types::BotCommand>] A list of commands supported by the bot.
class BotInfo < Base
attribute :description, TD::Types::String
Expand Down
4 changes: 2 additions & 2 deletions lib/tdlib/types/call.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ module TD::Types
# @attr is_video [Boolean] True, if the call is a video call.
# @attr state [TD::Types::CallState] Call state.
class Call < Base
attribute :id, TD::Types::Integer
attribute :user_id, TD::Types::Integer
attribute :id, TD::Types::Coercible::Integer
attribute :user_id, TD::Types::Coercible::Integer
attribute :is_outgoing, TD::Types::Bool
attribute :is_video, TD::Types::Bool
attribute :state, TD::Types::CallState
Expand Down
2 changes: 1 addition & 1 deletion lib/tdlib/types/call_id.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ module TD::Types
#
# @attr id [Integer] Call identifier.
class CallId < Base
attribute :id, TD::Types::Integer
attribute :id, TD::Types::Coercible::Integer
end
end
6 changes: 3 additions & 3 deletions lib/tdlib/types/call_protocol.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ module TD::Types
# @attr udp_reflector [Boolean] True, if connection through UDP reflectors is supported.
# @attr min_layer [Integer] The minimum supported API layer; use 65.
# @attr max_layer [Integer] The maximum supported API layer; use 65.
# @attr library_versions [Array<String>] List of supported tgcalls versions.
# @attr library_versions [Array<TD::Types::String>] List of supported tgcalls versions.
class CallProtocol < Base
attribute :udp_p2p, TD::Types::Bool
attribute :udp_reflector, TD::Types::Bool
attribute :min_layer, TD::Types::Integer
attribute :max_layer, TD::Types::Integer
attribute :min_layer, TD::Types::Coercible::Integer
attribute :max_layer, TD::Types::Coercible::Integer
attribute :library_versions, TD::Types::Array.of(TD::Types::String)
end
end
8 changes: 4 additions & 4 deletions lib/tdlib/types/call_server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ module TD::Types
# Describes a server for relaying call data.
#
# @attr id [Integer] Server identifier.
# @attr ip_address [String] Server IPv4 address.
# @attr ipv6_address [String] Server IPv6 address.
# @attr ip_address [TD::Types::String] Server IPv4 address.
# @attr ipv6_address [TD::Types::String] Server IPv6 address.
# @attr port [Integer] Server port number.
# @attr type [TD::Types::CallServerType] Server type.
class CallServer < Base
attribute :id, TD::Types::Integer
attribute :id, TD::Types::Coercible::Integer
attribute :ip_address, TD::Types::String
attribute :ipv6_address, TD::Types::String
attribute :port, TD::Types::Integer
attribute :port, TD::Types::Coercible::Integer
attribute :type, TD::Types::CallServerType
end
end
2 changes: 1 addition & 1 deletion lib/tdlib/types/call_server_type/telegram_reflector.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ module TD::Types
#
# @attr peer_tag [String] A peer tag to be used with the reflector.
class CallServerType::TelegramReflector < CallServerType
attribute :peer_tag, TD::Types::String
attribute :peer_tag, TD::Types::Coercible::String
end
end
4 changes: 2 additions & 2 deletions lib/tdlib/types/call_server_type/webrtc.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
module TD::Types
# A WebRTC server.
#
# @attr username [String] Username to be used for authentication.
# @attr password [String] Authentication password.
# @attr username [TD::Types::String] Username to be used for authentication.
# @attr password [TD::Types::String] Authentication password.
# @attr supports_turn [Boolean] True, if the server supports TURN.
# @attr supports_stun [Boolean] True, if the server supports STUN.
class CallServerType::Webrtc < CallServerType
Expand Down
Loading

0 comments on commit 979d2ca

Please sign in to comment.