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
@@ -1,73 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'openapi3_parser'
4
-
5
- desc 'Parse types from public json, should be up to date https://github.com/ark0f/tg-bot-api'
6
- task :parse_schema do
7
- document = Openapi3Parser.load_url('https://ark0f.github.io/tg-bot-api/openapi.json')
8
-
9
- result = document.components.schemas.to_h do |type_name, schema|
10
- type_schema = schema.properties.to_h do |property_name, property_schema|
11
- attribute = { type: parse_initial_type(property_schema, property_name) }
12
-
13
- unless property_schema.any_of.nil?
14
- attribute[:type] = property_schema.any_of.map { |item| property_schema.name || item.name || item.type }.uniq
15
- end
16
-
17
- # Input File is literally just a string for our purpose
18
- attribute[:type]&.delete('InputFile')
19
- attribute[:type] = attribute[:type].join if attribute[:type]&.length == 1
20
-
21
- attribute[:required] = true if required_keys(schema).include?(property_name)
22
-
23
- # getting required values from the description, no values in json 😔
24
- required_value = property_schema.description&.match(/always “(.+)”|must be \*(.+)\*/)
25
- attribute[:required_value] = (required_value[1] || required_value[2]).delete('\\') if required_value
26
-
27
- # for some reason every property's minLength is 0 by default, probably parser bug, had to ignore that
28
- attribute[:min_size] = property_schema[:minLength] if property_schema[:minLength] != 0
29
- attribute[:max_size] = property_schema[:maxLength] if property_schema[:maxLength]
30
-
31
- attribute[:items] = property_schema.items.type if property_schema&.items
32
- if property_schema&.type == 'array' && property_schema&.items&.type.nil?
33
- attribute[:items] = property_schema&.items&.name
34
- end
35
-
36
- attribute[:items] = property_schema.items.name if property_schema&.items&.type == 'object'
37
-
38
- # array of arrays
39
- if property_schema&.items&.type == 'array'
40
- attribute[:items] = { type: 'array', items: property_schema.items.items.name }
41
- end
42
-
43
- attribute = apply_default_schema(attribute, property_schema)
44
- [property_name, attribute]
45
- end
46
-
47
- # find empty classes
48
- type_schema[:type] = schema.any_of.map(&:name) if schema.properties.empty? && schema.any_of
49
- [type_name, type_schema]
50
- end
51
-
52
- # Input File is literally just a string for our purpose
53
- File.write "#{__dir__}/../data/type_attributes.json", JSON.pretty_generate(result.except('InputFile'))
54
- end
55
-
56
- def required_keys(schema)
57
- schema.required.to_a || []
58
- end
59
-
60
- def apply_default_schema(attribute, property_schema)
61
- attribute[:default] = property_schema.default unless property_schema.default.nil?
62
- # previous line would have been enough, but had to check the description due to issue: https://github.com/kevindew/openapi3_parser/issues/28
63
- attribute[:default] = false if property_schema.description&.include?('Defaults to *false*')
64
- attribute
65
- end
66
-
67
- def parse_initial_type(property_schema, property_name)
68
- case property_schema.type
69
- when nil then property_name.capitalize.gsub(/_(\w)/) { Regexp.last_match(1).upcase }
70
- when 'object' then property_schema.name
71
- else property_schema.type
72
- end
73
- end
@@ -1,90 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'json'
4
- require 'erb'
5
- DRY_TYPES = %w[string integer float decimal array hash symbol boolean date date_time time range].freeze
6
-
7
- desc 'Rebuild types'
8
- task :rebuild_types do
9
- types = JSON.parse(File.read("#{__dir__}/../data/type_attributes.json"), symbolize_names: true)
10
-
11
- types.each_pair do |name, attributes|
12
- next build_empty_type(name, attributes) if attributes[:type].instance_of?(Array)
13
-
14
- attributes.each_pair do |attr_name, properties|
15
- attributes[attr_name][:type] = add_module_types(properties[:type]) unless properties[:type].is_a?(Array)
16
- if properties[:type].is_a?(Array)
17
- attributes[attr_name][:type] = properties[:type].map do |type|
18
- add_module_types(type)
19
- end.join(' | ')
20
- end
21
-
22
- if properties[:items].instance_of?(String)
23
- attributes[attr_name][:type] += ".of(#{add_module_types(properties[:items])})"
24
- elsif properties[:items] && properties[:items][:type] == 'array'
25
- attributes[attr_name][:type] += ".of(Types::Array.of(#{properties[:items][:items]}))"
26
- end
27
- original_type = properties[:type]
28
-
29
- attributes = apply_required(attributes, attr_name, properties, original_type)
30
- attributes = apply_min_max(attributes, attr_name, properties)
31
- attributes = apply_default(attributes, attr_name, properties, original_type)
32
-
33
- attributes[attr_name][:type] = 'Types::True' if attributes[attr_name][:type] == 'Types::Boolean.default(true)'
34
- attributes[attr_name][:type] = attributes[attr_name][:type].gsub('Types::Boolean', 'Types::Bool')
35
- end
36
-
37
- File.write "#{__dir__}/../lib/telegram/bot/types/#{underscore(name)}.rb",
38
- ERB.new(File.read("#{__dir__}/templates/type.erb")).result(binding).gsub(" \n", '')
39
- end
40
- end
41
-
42
- def build_empty_type(name, attributes)
43
- attributes = attributes[:type].join(" |\n ")
44
- File.write "#{__dir__}/../lib/telegram/bot/types/#{underscore(name)}.rb",
45
- ERB.new(File.read("#{__dir__}/templates/empty_type.erb")).result(binding).gsub(" \n", '')
46
- end
47
-
48
- def apply_default(attributes, attr_name, properties, original_type)
49
- return attributes if properties[:default].nil?
50
-
51
- attributes[attr_name][:type] += ".default(#{typecast(original_type,
52
- properties[:default])})"
53
- attributes
54
- end
55
-
56
- def apply_required(attributes, attr_name, properties, original_type)
57
- return attributes unless properties[:required_value]
58
-
59
- attributes[attr_name][:type] += ".constrained(eql: #{typecast(original_type,
60
- properties[:required_value])})"
61
- attributes
62
- end
63
-
64
- def apply_min_max(attributes, attr_name, properties)
65
- return attributes unless properties[:min_size] || properties[:max_size]
66
-
67
- constrain = '.constrained(minmax)'
68
- constrain = properties[:min_size] ? constrain.gsub('min', "min_size: #{properties[:min_size]}, ") : ''
69
- constrain = constrain.gsub('max', "max_size: #{properties[:max_size]}") if properties[:max_size]
70
- attributes[attr_name][:type] += constrain
71
- attributes
72
- end
73
-
74
- def add_module_types(type)
75
- return 'Types::Float' if type == 'number'
76
-
77
- DRY_TYPES.include?(type) ? "Types::#{type.capitalize}" : type
78
- end
79
-
80
- def underscore(camel_cased_word)
81
- camel_cased_word.to_s.gsub('::', '/')
82
- .gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2')
83
- .gsub(/([a-z\d])([A-Z])/, '\1_\2')
84
- .tr('-', '_')
85
- .downcase
86
- end
87
-
88
- def typecast(type, obj)
89
- type == 'Types::String' ? "'#{obj}'" : obj
90
- end