telegram-bot-ruby 2.4.0 → 2.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (95) hide show
  1. checksums.yaml +4 -4
  2. data/.claude/skills/update-api/SKILL.md +70 -0
  3. data/.gitignore +1 -0
  4. data/.rubocop.yml +19 -0
  5. data/CHANGELOG.md +16 -0
  6. data/README.md +40 -23
  7. data/lib/telegram/bot/api/endpoints.rb +110 -62
  8. data/lib/telegram/bot/api.rb +13 -1
  9. data/lib/telegram/bot/configuration.rb +2 -1
  10. data/lib/telegram/bot/types/accepted_gift_types.rb +15 -0
  11. data/lib/telegram/bot/types/business_bot_rights.rb +24 -0
  12. data/lib/telegram/bot/types/business_connection.rb +1 -1
  13. data/lib/telegram/bot/types/callback_query.rb +4 -0
  14. data/lib/telegram/bot/types/chat.rb +1 -0
  15. data/lib/telegram/bot/types/chat_administrator_rights.rb +2 -0
  16. data/lib/telegram/bot/types/chat_full_info.rb +7 -1
  17. data/lib/telegram/bot/types/chat_member_administrator.rb +2 -0
  18. data/lib/telegram/bot/types/chat_member_member.rb +1 -0
  19. data/lib/telegram/bot/types/chat_member_restricted.rb +2 -0
  20. data/lib/telegram/bot/types/chat_owner_changed.rb +11 -0
  21. data/lib/telegram/bot/types/chat_owner_left.rb +11 -0
  22. data/lib/telegram/bot/types/chat_permissions.rb +1 -0
  23. data/lib/telegram/bot/types/checklist.rb +15 -0
  24. data/lib/telegram/bot/types/checklist_task.rb +16 -0
  25. data/lib/telegram/bot/types/checklist_tasks_added.rb +12 -0
  26. data/lib/telegram/bot/types/checklist_tasks_done.rb +13 -0
  27. data/lib/telegram/bot/types/direct_message_price_changed.rb +12 -0
  28. data/lib/telegram/bot/types/direct_messages_topic.rb +12 -0
  29. data/lib/telegram/bot/types/external_reply_info.rb +1 -0
  30. data/lib/telegram/bot/types/forum_topic.rb +1 -0
  31. data/lib/telegram/bot/types/forum_topic_created.rb +1 -0
  32. data/lib/telegram/bot/types/gift.rb +7 -0
  33. data/lib/telegram/bot/types/gift_background.rb +13 -0
  34. data/lib/telegram/bot/types/gift_info.rb +20 -0
  35. data/lib/telegram/bot/types/inline_keyboard_button.rb +2 -0
  36. data/lib/telegram/bot/types/input_checklist.rb +16 -0
  37. data/lib/telegram/bot/types/input_checklist_task.rb +14 -0
  38. data/lib/telegram/bot/types/input_file.rb +10 -0
  39. data/lib/telegram/bot/types/input_profile_photo.rb +15 -0
  40. data/lib/telegram/bot/types/input_profile_photo_animated.rb +13 -0
  41. data/lib/telegram/bot/types/input_profile_photo_static.rb +12 -0
  42. data/lib/telegram/bot/types/input_story_content.rb +15 -0
  43. data/lib/telegram/bot/types/input_story_content_photo.rb +12 -0
  44. data/lib/telegram/bot/types/input_story_content_video.rb +15 -0
  45. data/lib/telegram/bot/types/keyboard_button.rb +2 -0
  46. data/lib/telegram/bot/types/location_address.rb +14 -0
  47. data/lib/telegram/bot/types/message.rb +24 -1
  48. data/lib/telegram/bot/types/message_entity.rb +2 -0
  49. data/lib/telegram/bot/types/owned_gift.rb +15 -0
  50. data/lib/telegram/bot/types/owned_gift_regular.rb +25 -0
  51. data/lib/telegram/bot/types/owned_gift_unique.rb +19 -0
  52. data/lib/telegram/bot/types/owned_gifts.rb +13 -0
  53. data/lib/telegram/bot/types/paid_message_price_changed.rb +11 -0
  54. data/lib/telegram/bot/types/reply_parameters.rb +1 -0
  55. data/lib/telegram/bot/types/star_amount.rb +12 -0
  56. data/lib/telegram/bot/types/story_area.rb +12 -0
  57. data/lib/telegram/bot/types/story_area_position.rb +16 -0
  58. data/lib/telegram/bot/types/story_area_type.rb +18 -0
  59. data/lib/telegram/bot/types/story_area_type_link.rb +12 -0
  60. data/lib/telegram/bot/types/story_area_type_location.rb +14 -0
  61. data/lib/telegram/bot/types/story_area_type_suggested_reaction.rb +14 -0
  62. data/lib/telegram/bot/types/story_area_type_unique_gift.rb +12 -0
  63. data/lib/telegram/bot/types/story_area_type_weather.rb +14 -0
  64. data/lib/telegram/bot/types/suggested_post_approval_failed.rb +12 -0
  65. data/lib/telegram/bot/types/suggested_post_approved.rb +13 -0
  66. data/lib/telegram/bot/types/suggested_post_declined.rb +12 -0
  67. data/lib/telegram/bot/types/suggested_post_info.rb +13 -0
  68. data/lib/telegram/bot/types/suggested_post_paid.rb +14 -0
  69. data/lib/telegram/bot/types/suggested_post_parameters.rb +12 -0
  70. data/lib/telegram/bot/types/suggested_post_price.rb +12 -0
  71. data/lib/telegram/bot/types/suggested_post_refunded.rb +12 -0
  72. data/lib/telegram/bot/types/transaction_partner_user.rb +2 -0
  73. data/lib/telegram/bot/types/unique_gift.rb +22 -0
  74. data/lib/telegram/bot/types/unique_gift_backdrop.rb +13 -0
  75. data/lib/telegram/bot/types/unique_gift_backdrop_colors.rb +14 -0
  76. data/lib/telegram/bot/types/unique_gift_colors.rb +16 -0
  77. data/lib/telegram/bot/types/unique_gift_info.rb +17 -0
  78. data/lib/telegram/bot/types/unique_gift_model.rb +14 -0
  79. data/lib/telegram/bot/types/unique_gift_symbol.rb +13 -0
  80. data/lib/telegram/bot/types/user.rb +2 -0
  81. data/lib/telegram/bot/types/user_profile_audios.rb +12 -0
  82. data/lib/telegram/bot/types/user_rating.rb +14 -0
  83. data/lib/telegram/bot/types/video.rb +1 -0
  84. data/lib/telegram/bot/types/video_quality.rb +16 -0
  85. data/lib/telegram/bot/version.rb +1 -1
  86. data/rakelib/builders/endpoints_builder.rb +51 -0
  87. data/rakelib/builders/type_builder.rb +140 -0
  88. data/rakelib/parse.rake +31 -0
  89. data/rakelib/parsers/methods_parser.rb +115 -0
  90. data/rakelib/parsers/types_parser.rb +273 -0
  91. data/rakelib/rebuild.rake +30 -0
  92. data/rakelib/templates/endpoints.erb +13 -0
  93. metadata +65 -9
  94. data/rakelib/parse_schema.rake +0 -73
  95. data/rakelib/rebuild_types.rake +0 -90
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Telegram
4
+ module Bot
5
+ module Types
6
+ class StoryAreaTypeLink < Base
7
+ attribute :type, Types::String.constrained(eql: 'link').default('link')
8
+ attribute :url, Types::String
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Telegram
4
+ module Bot
5
+ module Types
6
+ class StoryAreaTypeLocation < Base
7
+ attribute :type, Types::String.constrained(eql: 'location').default('location')
8
+ attribute :latitude, Types::Float
9
+ attribute :longitude, Types::Float
10
+ attribute? :address, LocationAddress
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Telegram
4
+ module Bot
5
+ module Types
6
+ class StoryAreaTypeSuggestedReaction < Base
7
+ attribute :type, Types::String.constrained(eql: 'suggested_reaction').default('suggested_reaction')
8
+ attribute :reaction_type, ReactionType
9
+ attribute? :is_dark, Types::Bool
10
+ attribute? :is_flipped, Types::Bool
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Telegram
4
+ module Bot
5
+ module Types
6
+ class StoryAreaTypeUniqueGift < Base
7
+ attribute :type, Types::String.constrained(eql: 'unique_gift').default('unique_gift')
8
+ attribute :name, Types::String
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Telegram
4
+ module Bot
5
+ module Types
6
+ class StoryAreaTypeWeather < Base
7
+ attribute :type, Types::String.constrained(eql: 'weather').default('weather')
8
+ attribute :temperature, Types::Float
9
+ attribute :emoji, Types::String
10
+ attribute :background_color, Types::Integer
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Telegram
4
+ module Bot
5
+ module Types
6
+ class SuggestedPostApprovalFailed < Base
7
+ attribute? :suggested_post_message, Message
8
+ attribute :price, SuggestedPostPrice
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Telegram
4
+ module Bot
5
+ module Types
6
+ class SuggestedPostApproved < Base
7
+ attribute? :suggested_post_message, Message
8
+ attribute? :price, SuggestedPostPrice
9
+ attribute :send_date, Types::Integer
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Telegram
4
+ module Bot
5
+ module Types
6
+ class SuggestedPostDeclined < Base
7
+ attribute? :suggested_post_message, Message
8
+ attribute? :comment, Types::String
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Telegram
4
+ module Bot
5
+ module Types
6
+ class SuggestedPostInfo < Base
7
+ attribute :state, Types::String
8
+ attribute? :price, SuggestedPostPrice
9
+ attribute? :send_date, Types::Integer
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Telegram
4
+ module Bot
5
+ module Types
6
+ class SuggestedPostPaid < Base
7
+ attribute? :suggested_post_message, Message
8
+ attribute :currency, Types::String
9
+ attribute? :amount, Types::Integer
10
+ attribute? :star_amount, StarAmount
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Telegram
4
+ module Bot
5
+ module Types
6
+ class SuggestedPostParameters < Base
7
+ attribute? :price, SuggestedPostPrice
8
+ attribute? :send_date, Types::Integer
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Telegram
4
+ module Bot
5
+ module Types
6
+ class SuggestedPostPrice < Base
7
+ attribute :currency, Types::String
8
+ attribute :amount, Types::Integer.constrained(min_size: 5, max_size: 100_000)
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Telegram
4
+ module Bot
5
+ module Types
6
+ class SuggestedPostRefunded < Base
7
+ attribute? :suggested_post_message, Message
8
+ attribute :reason, Types::String
9
+ end
10
+ end
11
+ end
12
+ end
@@ -5,6 +5,7 @@ module Telegram
5
5
  module Types
6
6
  class TransactionPartnerUser < Base
7
7
  attribute :type, Types::String.constrained(eql: 'user').default('user')
8
+ attribute :transaction_type, Types::String
8
9
  attribute :user, User
9
10
  attribute? :affiliate, AffiliateInfo
10
11
  attribute? :invoice_payload, Types::String
@@ -12,6 +13,7 @@ module Telegram
12
13
  attribute? :paid_media, Types::Array.of(PaidMedia)
13
14
  attribute? :paid_media_payload, Types::String
14
15
  attribute? :gift, Gift
16
+ attribute? :premium_subscription_duration, Types::Integer
15
17
  end
16
18
  end
17
19
  end
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Telegram
4
+ module Bot
5
+ module Types
6
+ class UniqueGift < Base
7
+ attribute :gift_id, Types::String
8
+ attribute :base_name, Types::String
9
+ attribute :name, Types::String
10
+ attribute :number, Types::Integer
11
+ attribute :model, UniqueGiftModel
12
+ attribute :symbol, UniqueGiftSymbol
13
+ attribute :backdrop, UniqueGiftBackdrop
14
+ attribute? :is_premium, Types::True
15
+ attribute? :is_burned, Types::True
16
+ attribute? :is_from_blockchain, Types::True
17
+ attribute? :colors, UniqueGiftColors
18
+ attribute? :publisher_chat, Chat
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Telegram
4
+ module Bot
5
+ module Types
6
+ class UniqueGiftBackdrop < Base
7
+ attribute :name, Types::String
8
+ attribute :colors, UniqueGiftBackdropColors
9
+ attribute :rarity_per_mille, Types::Integer
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Telegram
4
+ module Bot
5
+ module Types
6
+ class UniqueGiftBackdropColors < Base
7
+ attribute :center_color, Types::Integer
8
+ attribute :edge_color, Types::Integer
9
+ attribute :symbol_color, Types::Integer
10
+ attribute :text_color, Types::Integer
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Telegram
4
+ module Bot
5
+ module Types
6
+ class UniqueGiftColors < Base
7
+ attribute :model_custom_emoji_id, Types::String
8
+ attribute :symbol_custom_emoji_id, Types::String
9
+ attribute :light_theme_main_color, Types::Integer
10
+ attribute :light_theme_other_colors, Types::Array.of(Types::Integer)
11
+ attribute :dark_theme_main_color, Types::Integer
12
+ attribute :dark_theme_other_colors, Types::Array.of(Types::Integer)
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Telegram
4
+ module Bot
5
+ module Types
6
+ class UniqueGiftInfo < Base
7
+ attribute :gift, UniqueGift
8
+ attribute :origin, Types::String
9
+ attribute? :last_resale_currency, Types::String
10
+ attribute? :last_resale_amount, Types::Integer
11
+ attribute? :owned_gift_id, Types::String
12
+ attribute? :transfer_star_count, Types::Integer
13
+ attribute? :next_transfer_date, Types::Integer
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Telegram
4
+ module Bot
5
+ module Types
6
+ class UniqueGiftModel < Base
7
+ attribute :name, Types::String
8
+ attribute :sticker, Sticker
9
+ attribute :rarity_per_mille, Types::Integer
10
+ attribute? :rarity, Types::String
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Telegram
4
+ module Bot
5
+ module Types
6
+ class UniqueGiftSymbol < Base
7
+ attribute :name, Types::String
8
+ attribute :sticker, Sticker
9
+ attribute :rarity_per_mille, Types::Integer
10
+ end
11
+ end
12
+ end
13
+ end
@@ -17,6 +17,8 @@ module Telegram
17
17
  attribute? :supports_inline_queries, Types::Bool
18
18
  attribute? :can_connect_to_business, Types::Bool
19
19
  attribute? :has_main_web_app, Types::Bool
20
+ attribute? :has_topics_enabled, Types::Bool
21
+ attribute? :allows_users_to_create_topics, Types::Bool
20
22
  end
21
23
  end
22
24
  end
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Telegram
4
+ module Bot
5
+ module Types
6
+ class UserProfileAudios < Base
7
+ attribute :total_count, Types::Integer
8
+ attribute :audios, Types::Array.of(Audio)
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Telegram
4
+ module Bot
5
+ module Types
6
+ class UserRating < Base
7
+ attribute :level, Types::Integer
8
+ attribute :rating, Types::Integer
9
+ attribute :current_level_rating, Types::Integer
10
+ attribute? :next_level_rating, Types::Integer
11
+ end
12
+ end
13
+ end
14
+ end
@@ -12,6 +12,7 @@ module Telegram
12
12
  attribute? :thumbnail, PhotoSize
13
13
  attribute? :cover, Types::Array.of(PhotoSize)
14
14
  attribute? :start_timestamp, Types::Integer
15
+ attribute? :qualities, Types::Array.of(VideoQuality)
15
16
  attribute? :file_name, Types::String
16
17
  attribute? :mime_type, Types::String
17
18
  attribute? :file_size, Types::Integer
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Telegram
4
+ module Bot
5
+ module Types
6
+ class VideoQuality < Base
7
+ attribute :file_id, Types::String
8
+ attribute :file_unique_id, Types::String
9
+ attribute :width, Types::Integer
10
+ attribute :height, Types::Integer
11
+ attribute :codec, Types::String
12
+ attribute? :file_size, Types::Integer
13
+ end
14
+ end
15
+ end
16
+ end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Telegram
4
4
  module Bot
5
- VERSION = '2.4.0'
5
+ VERSION = '2.6.0'
6
6
  end
7
7
  end
@@ -0,0 +1,51 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'erb'
4
+
5
+ module Builders
6
+ class EndpointsBuilder
7
+ attr_reader :methods, :templates_dir
8
+
9
+ def initialize(methods, templates_dir:)
10
+ @methods = methods.transform_values { |type| convert_to_types_format(type) }
11
+ @templates_dir = templates_dir
12
+ end
13
+
14
+ def build
15
+ template_path = File.join(templates_dir, 'endpoints.erb')
16
+ template = ERB.new(File.read(template_path), trim_mode: '-')
17
+
18
+ b = binding
19
+ b.local_variable_set(:methods, methods)
20
+
21
+ template.result(b)
22
+ end
23
+
24
+ private
25
+
26
+ def convert_to_types_format(type)
27
+ return convert_union_type(type) if type.include?(' | ')
28
+
29
+ convert_single_type(type)
30
+ end
31
+
32
+ def convert_union_type(type)
33
+ type.split(' | ').map { |t| convert_to_types_format(t.strip) }.join(' | ')
34
+ end
35
+
36
+ def convert_single_type(type)
37
+ return convert_array_type(type) if type.start_with?('Array<')
38
+
39
+ convert_primitive_type(type)
40
+ end
41
+
42
+ def convert_array_type(type)
43
+ inner_type = type.match(/Array<(.+)>/)[1]
44
+ "Types::Array.of(#{convert_to_types_format(inner_type)})"
45
+ end
46
+
47
+ def convert_primitive_type(type)
48
+ type == 'Boolean' ? 'Types::Bool' : "Types::#{type}"
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,140 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'erb'
4
+
5
+ module Builders
6
+ class TypeBuilder
7
+ DRY_TYPES = %w[string integer float decimal array hash symbol boolean date date_time time range].freeze
8
+
9
+ attr_reader :name, :attributes, :templates_dir
10
+
11
+ def initialize(name, attributes, templates_dir:)
12
+ @name = name
13
+ @attributes = deep_dup(attributes)
14
+ @templates_dir = templates_dir
15
+ end
16
+
17
+ def build
18
+ if empty_type?
19
+ build_empty_type
20
+ else
21
+ build_full_type
22
+ end
23
+ end
24
+
25
+ def self.underscore(camel_cased_word)
26
+ camel_cased_word.to_s.gsub('::', '/')
27
+ .gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2')
28
+ .gsub(/([a-z\d])([A-Z])/, '\1_\2')
29
+ .tr('-', '_')
30
+ .downcase
31
+ end
32
+
33
+ private
34
+
35
+ def empty_type?
36
+ attributes[:type].is_a?(Array)
37
+ end
38
+
39
+ def build_empty_type
40
+ attrs = attributes[:type].join(" |\n ")
41
+ render_template('empty_type.erb', name: name, attributes: attrs)
42
+ end
43
+
44
+ def build_full_type
45
+ process_attributes!
46
+ render_template('type.erb', name: name, attributes: attributes)
47
+ end
48
+
49
+ def process_attributes!
50
+ attributes.each_pair do |attr_name, properties|
51
+ process_attribute!(attr_name, properties)
52
+ end
53
+ end
54
+
55
+ def process_attribute!(attr_name, properties)
56
+ process_type!(attr_name, properties)
57
+ process_items!(attr_name, properties)
58
+
59
+ original_type = properties[:type]
60
+ apply_required!(attr_name, properties, original_type)
61
+ apply_min_max!(attr_name, properties)
62
+ apply_default!(attr_name, properties, original_type)
63
+
64
+ normalize_boolean_type!(attr_name)
65
+ end
66
+
67
+ def normalize_boolean_type!(attr_name)
68
+ attributes[attr_name][:type] = 'Types::True' if attributes[attr_name][:type] == 'Types::Boolean.default(true)'
69
+ attributes[attr_name][:type] = attributes[attr_name][:type].gsub('Types::Boolean', 'Types::Bool')
70
+ end
71
+
72
+ def process_type!(attr_name, properties)
73
+ attributes[attr_name][:type] = if properties[:type].is_a?(Array)
74
+ properties[:type].map { |t| add_module_types(t) }.join(' | ')
75
+ else
76
+ add_module_types(properties[:type])
77
+ end
78
+ end
79
+
80
+ def process_items!(attr_name, properties)
81
+ if properties[:items].is_a?(String)
82
+ attributes[attr_name][:type] += ".of(#{add_module_types(properties[:items])})"
83
+ elsif properties[:items] && properties[:items][:type] == 'array'
84
+ attributes[attr_name][:type] += ".of(Types::Array.of(#{properties[:items][:items]}))"
85
+ end
86
+ end
87
+
88
+ def apply_required!(attr_name, properties, original_type)
89
+ return unless properties[:required_value]
90
+
91
+ attributes[attr_name][:type] += ".constrained(eql: #{typecast(original_type, properties[:required_value])})"
92
+ end
93
+
94
+ def apply_min_max!(attr_name, properties)
95
+ return unless properties[:min_size] || properties[:max_size]
96
+
97
+ constrain = '.constrained(minmax)'
98
+ constrain = properties[:min_size] ? constrain.gsub('min', "min_size: #{properties[:min_size]}, ") : ''
99
+ constrain = constrain.gsub('max', "max_size: #{properties[:max_size]}") if properties[:max_size]
100
+ attributes[attr_name][:type] += constrain
101
+ end
102
+
103
+ def apply_default!(attr_name, properties, original_type)
104
+ return if properties[:default].nil?
105
+
106
+ attributes[attr_name][:type] += ".default(#{typecast(original_type, properties[:default])})"
107
+ end
108
+
109
+ def add_module_types(type)
110
+ return 'Types::Float' if type == 'number'
111
+
112
+ DRY_TYPES.include?(type) ? "Types::#{type.capitalize}" : type
113
+ end
114
+
115
+ def typecast(type, obj)
116
+ type == 'Types::String' ? "'#{obj}'" : obj
117
+ end
118
+
119
+ def render_template(template_name, vars)
120
+ template_path = File.join(templates_dir, template_name)
121
+ template = ERB.new(File.read(template_path))
122
+
123
+ # Create binding with the variables
124
+ b = binding
125
+ vars.each { |k, v| b.local_variable_set(k, v) }
126
+
127
+ template.result(b).gsub(" \n", '')
128
+ end
129
+
130
+ def deep_dup(hash)
131
+ hash.transform_values do |v|
132
+ case v
133
+ when Hash then deep_dup(v)
134
+ when Array then v.dup
135
+ else v
136
+ end
137
+ end
138
+ end
139
+ end
140
+ end
@@ -0,0 +1,31 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'json'
4
+ require_relative 'parsers/types_parser'
5
+ require_relative 'parsers/methods_parser'
6
+
7
+ namespace :parse do
8
+ desc 'Parse types from Telegram Bot API HTML documentation'
9
+ task :types do
10
+ puts 'Parsing types from Telegram Bot API...'
11
+
12
+ result = Parsers::TypesParser.new.parse
13
+
14
+ puts "Found #{result.keys.count} types"
15
+
16
+ File.write "#{__dir__}/../data/types.json", JSON.pretty_generate(result)
17
+ puts 'Written to data/types.json'
18
+ end
19
+
20
+ desc 'Parse methods from Telegram Bot API HTML documentation'
21
+ task :methods do
22
+ puts 'Parsing methods from Telegram Bot API...'
23
+
24
+ result = Parsers::MethodsParser.new.parse
25
+
26
+ puts "Found #{result.keys.count} methods"
27
+
28
+ File.write "#{__dir__}/../data/methods.json", JSON.pretty_generate(result)
29
+ puts 'Written to data/methods.json'
30
+ end
31
+ end