telegram-bot-ruby 2.4.0 → 2.5.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.
- checksums.yaml +4 -4
- data/.rubocop.yml +19 -0
- data/CHANGELOG.md +7 -0
- data/lib/telegram/bot/api/endpoints.rb +102 -62
- data/lib/telegram/bot/types/accepted_gift_types.rb +14 -0
- data/lib/telegram/bot/types/business_bot_rights.rb +24 -0
- data/lib/telegram/bot/types/business_connection.rb +1 -1
- data/lib/telegram/bot/types/chat.rb +1 -0
- data/lib/telegram/bot/types/chat_administrator_rights.rb +1 -0
- data/lib/telegram/bot/types/chat_full_info.rb +3 -1
- data/lib/telegram/bot/types/chat_member_administrator.rb +1 -0
- data/lib/telegram/bot/types/checklist.rb +15 -0
- data/lib/telegram/bot/types/checklist_task.rb +15 -0
- data/lib/telegram/bot/types/checklist_tasks_added.rb +12 -0
- data/lib/telegram/bot/types/checklist_tasks_done.rb +13 -0
- data/lib/telegram/bot/types/direct_message_price_changed.rb +12 -0
- data/lib/telegram/bot/types/direct_messages_topic.rb +12 -0
- data/lib/telegram/bot/types/external_reply_info.rb +1 -0
- data/lib/telegram/bot/types/gift.rb +1 -0
- data/lib/telegram/bot/types/gift_info.rb +18 -0
- data/lib/telegram/bot/types/input_checklist.rb +16 -0
- data/lib/telegram/bot/types/input_checklist_task.rb +14 -0
- data/lib/telegram/bot/types/input_file.rb +10 -0
- data/lib/telegram/bot/types/input_profile_photo.rb +15 -0
- data/lib/telegram/bot/types/input_profile_photo_animated.rb +13 -0
- data/lib/telegram/bot/types/input_profile_photo_static.rb +12 -0
- data/lib/telegram/bot/types/input_story_content.rb +15 -0
- data/lib/telegram/bot/types/input_story_content_photo.rb +12 -0
- data/lib/telegram/bot/types/input_story_content_video.rb +15 -0
- data/lib/telegram/bot/types/location_address.rb +14 -0
- data/lib/telegram/bot/types/message.rb +17 -0
- data/lib/telegram/bot/types/owned_gift.rb +15 -0
- data/lib/telegram/bot/types/owned_gift_regular.rb +23 -0
- data/lib/telegram/bot/types/owned_gift_unique.rb +19 -0
- data/lib/telegram/bot/types/owned_gifts.rb +13 -0
- data/lib/telegram/bot/types/paid_message_price_changed.rb +11 -0
- data/lib/telegram/bot/types/reply_parameters.rb +1 -0
- data/lib/telegram/bot/types/star_amount.rb +12 -0
- data/lib/telegram/bot/types/story_area.rb +12 -0
- data/lib/telegram/bot/types/story_area_position.rb +16 -0
- data/lib/telegram/bot/types/story_area_type.rb +18 -0
- data/lib/telegram/bot/types/story_area_type_link.rb +12 -0
- data/lib/telegram/bot/types/story_area_type_location.rb +14 -0
- data/lib/telegram/bot/types/story_area_type_suggested_reaction.rb +14 -0
- data/lib/telegram/bot/types/story_area_type_unique_gift.rb +12 -0
- data/lib/telegram/bot/types/story_area_type_weather.rb +14 -0
- data/lib/telegram/bot/types/suggested_post_approval_failed.rb +12 -0
- data/lib/telegram/bot/types/suggested_post_approved.rb +13 -0
- data/lib/telegram/bot/types/suggested_post_declined.rb +12 -0
- data/lib/telegram/bot/types/suggested_post_info.rb +13 -0
- data/lib/telegram/bot/types/suggested_post_paid.rb +14 -0
- data/lib/telegram/bot/types/suggested_post_parameters.rb +12 -0
- data/lib/telegram/bot/types/suggested_post_price.rb +12 -0
- data/lib/telegram/bot/types/suggested_post_refunded.rb +12 -0
- data/lib/telegram/bot/types/transaction_partner_user.rb +2 -0
- data/lib/telegram/bot/types/unique_gift.rb +17 -0
- data/lib/telegram/bot/types/unique_gift_backdrop.rb +13 -0
- data/lib/telegram/bot/types/unique_gift_backdrop_colors.rb +14 -0
- data/lib/telegram/bot/types/unique_gift_info.rb +16 -0
- data/lib/telegram/bot/types/unique_gift_model.rb +13 -0
- data/lib/telegram/bot/types/unique_gift_symbol.rb +13 -0
- data/lib/telegram/bot/version.rb +1 -1
- data/rakelib/builders/endpoints_builder.rb +51 -0
- data/rakelib/builders/type_builder.rb +140 -0
- data/rakelib/parse.rake +31 -0
- data/rakelib/parsers/methods_parser.rb +115 -0
- data/rakelib/parsers/types_parser.rb +273 -0
- data/rakelib/rebuild.rake +30 -0
- data/rakelib/templates/endpoints.erb +13 -0
- metadata +57 -9
- data/rakelib/parse_schema.rake +0 -73
- data/rakelib/rebuild_types.rake +0 -90
metadata
CHANGED
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: telegram-bot-ruby
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 2.
|
|
4
|
+
version: 2.5.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Alexander Tipugin
|
|
8
|
-
autorequire:
|
|
9
8
|
bindir: exe
|
|
10
9
|
cert_chain: []
|
|
11
|
-
date:
|
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
|
12
11
|
dependencies:
|
|
13
12
|
- !ruby/object:Gem::Dependency
|
|
14
13
|
name: dry-struct
|
|
@@ -66,7 +65,6 @@ dependencies:
|
|
|
66
65
|
- - "~>"
|
|
67
66
|
- !ruby/object:Gem::Version
|
|
68
67
|
version: '2.6'
|
|
69
|
-
description:
|
|
70
68
|
email:
|
|
71
69
|
- atipugin@gmail.com
|
|
72
70
|
executables: []
|
|
@@ -97,6 +95,7 @@ files:
|
|
|
97
95
|
- lib/telegram/bot/exceptions/response_error.rb
|
|
98
96
|
- lib/telegram/bot/null_logger.rb
|
|
99
97
|
- lib/telegram/bot/types.rb
|
|
98
|
+
- lib/telegram/bot/types/accepted_gift_types.rb
|
|
100
99
|
- lib/telegram/bot/types/affiliate_info.rb
|
|
101
100
|
- lib/telegram/bot/types/animation.rb
|
|
102
101
|
- lib/telegram/bot/types/audio.rb
|
|
@@ -123,6 +122,7 @@ files:
|
|
|
123
122
|
- lib/telegram/bot/types/bot_description.rb
|
|
124
123
|
- lib/telegram/bot/types/bot_name.rb
|
|
125
124
|
- lib/telegram/bot/types/bot_short_description.rb
|
|
125
|
+
- lib/telegram/bot/types/business_bot_rights.rb
|
|
126
126
|
- lib/telegram/bot/types/business_connection.rb
|
|
127
127
|
- lib/telegram/bot/types/business_intro.rb
|
|
128
128
|
- lib/telegram/bot/types/business_location.rb
|
|
@@ -157,11 +157,17 @@ files:
|
|
|
157
157
|
- lib/telegram/bot/types/chat_permissions.rb
|
|
158
158
|
- lib/telegram/bot/types/chat_photo.rb
|
|
159
159
|
- lib/telegram/bot/types/chat_shared.rb
|
|
160
|
+
- lib/telegram/bot/types/checklist.rb
|
|
161
|
+
- lib/telegram/bot/types/checklist_task.rb
|
|
162
|
+
- lib/telegram/bot/types/checklist_tasks_added.rb
|
|
163
|
+
- lib/telegram/bot/types/checklist_tasks_done.rb
|
|
160
164
|
- lib/telegram/bot/types/chosen_inline_result.rb
|
|
161
165
|
- lib/telegram/bot/types/compactable.rb
|
|
162
166
|
- lib/telegram/bot/types/contact.rb
|
|
163
167
|
- lib/telegram/bot/types/copy_text_button.rb
|
|
164
168
|
- lib/telegram/bot/types/dice.rb
|
|
169
|
+
- lib/telegram/bot/types/direct_message_price_changed.rb
|
|
170
|
+
- lib/telegram/bot/types/direct_messages_topic.rb
|
|
165
171
|
- lib/telegram/bot/types/document.rb
|
|
166
172
|
- lib/telegram/bot/types/encrypted_credentials.rb
|
|
167
173
|
- lib/telegram/bot/types/encrypted_passport_element.rb
|
|
@@ -179,6 +185,7 @@ files:
|
|
|
179
185
|
- lib/telegram/bot/types/general_forum_topic_hidden.rb
|
|
180
186
|
- lib/telegram/bot/types/general_forum_topic_unhidden.rb
|
|
181
187
|
- lib/telegram/bot/types/gift.rb
|
|
188
|
+
- lib/telegram/bot/types/gift_info.rb
|
|
182
189
|
- lib/telegram/bot/types/gifts.rb
|
|
183
190
|
- lib/telegram/bot/types/giveaway.rb
|
|
184
191
|
- lib/telegram/bot/types/giveaway_completed.rb
|
|
@@ -210,7 +217,10 @@ files:
|
|
|
210
217
|
- lib/telegram/bot/types/inline_query_result_video.rb
|
|
211
218
|
- lib/telegram/bot/types/inline_query_result_voice.rb
|
|
212
219
|
- lib/telegram/bot/types/inline_query_results_button.rb
|
|
220
|
+
- lib/telegram/bot/types/input_checklist.rb
|
|
221
|
+
- lib/telegram/bot/types/input_checklist_task.rb
|
|
213
222
|
- lib/telegram/bot/types/input_contact_message_content.rb
|
|
223
|
+
- lib/telegram/bot/types/input_file.rb
|
|
214
224
|
- lib/telegram/bot/types/input_invoice_message_content.rb
|
|
215
225
|
- lib/telegram/bot/types/input_location_message_content.rb
|
|
216
226
|
- lib/telegram/bot/types/input_media.rb
|
|
@@ -224,7 +234,13 @@ files:
|
|
|
224
234
|
- lib/telegram/bot/types/input_paid_media_photo.rb
|
|
225
235
|
- lib/telegram/bot/types/input_paid_media_video.rb
|
|
226
236
|
- lib/telegram/bot/types/input_poll_option.rb
|
|
237
|
+
- lib/telegram/bot/types/input_profile_photo.rb
|
|
238
|
+
- lib/telegram/bot/types/input_profile_photo_animated.rb
|
|
239
|
+
- lib/telegram/bot/types/input_profile_photo_static.rb
|
|
227
240
|
- lib/telegram/bot/types/input_sticker.rb
|
|
241
|
+
- lib/telegram/bot/types/input_story_content.rb
|
|
242
|
+
- lib/telegram/bot/types/input_story_content_photo.rb
|
|
243
|
+
- lib/telegram/bot/types/input_story_content_video.rb
|
|
228
244
|
- lib/telegram/bot/types/input_text_message_content.rb
|
|
229
245
|
- lib/telegram/bot/types/input_venue_message_content.rb
|
|
230
246
|
- lib/telegram/bot/types/invoice.rb
|
|
@@ -235,6 +251,7 @@ files:
|
|
|
235
251
|
- lib/telegram/bot/types/labeled_price.rb
|
|
236
252
|
- lib/telegram/bot/types/link_preview_options.rb
|
|
237
253
|
- lib/telegram/bot/types/location.rb
|
|
254
|
+
- lib/telegram/bot/types/location_address.rb
|
|
238
255
|
- lib/telegram/bot/types/login_url.rb
|
|
239
256
|
- lib/telegram/bot/types/mask_position.rb
|
|
240
257
|
- lib/telegram/bot/types/maybe_inaccessible_message.rb
|
|
@@ -254,12 +271,17 @@ files:
|
|
|
254
271
|
- lib/telegram/bot/types/message_reaction_count_updated.rb
|
|
255
272
|
- lib/telegram/bot/types/message_reaction_updated.rb
|
|
256
273
|
- lib/telegram/bot/types/order_info.rb
|
|
274
|
+
- lib/telegram/bot/types/owned_gift.rb
|
|
275
|
+
- lib/telegram/bot/types/owned_gift_regular.rb
|
|
276
|
+
- lib/telegram/bot/types/owned_gift_unique.rb
|
|
277
|
+
- lib/telegram/bot/types/owned_gifts.rb
|
|
257
278
|
- lib/telegram/bot/types/paid_media.rb
|
|
258
279
|
- lib/telegram/bot/types/paid_media_info.rb
|
|
259
280
|
- lib/telegram/bot/types/paid_media_photo.rb
|
|
260
281
|
- lib/telegram/bot/types/paid_media_preview.rb
|
|
261
282
|
- lib/telegram/bot/types/paid_media_purchased.rb
|
|
262
283
|
- lib/telegram/bot/types/paid_media_video.rb
|
|
284
|
+
- lib/telegram/bot/types/paid_message_price_changed.rb
|
|
263
285
|
- lib/telegram/bot/types/passport_data.rb
|
|
264
286
|
- lib/telegram/bot/types/passport_element_error.rb
|
|
265
287
|
- lib/telegram/bot/types/passport_element_error_data_field.rb
|
|
@@ -299,12 +321,29 @@ files:
|
|
|
299
321
|
- lib/telegram/bot/types/shipping_address.rb
|
|
300
322
|
- lib/telegram/bot/types/shipping_option.rb
|
|
301
323
|
- lib/telegram/bot/types/shipping_query.rb
|
|
324
|
+
- lib/telegram/bot/types/star_amount.rb
|
|
302
325
|
- lib/telegram/bot/types/star_transaction.rb
|
|
303
326
|
- lib/telegram/bot/types/star_transactions.rb
|
|
304
327
|
- lib/telegram/bot/types/sticker.rb
|
|
305
328
|
- lib/telegram/bot/types/sticker_set.rb
|
|
306
329
|
- lib/telegram/bot/types/story.rb
|
|
330
|
+
- lib/telegram/bot/types/story_area.rb
|
|
331
|
+
- lib/telegram/bot/types/story_area_position.rb
|
|
332
|
+
- lib/telegram/bot/types/story_area_type.rb
|
|
333
|
+
- lib/telegram/bot/types/story_area_type_link.rb
|
|
334
|
+
- lib/telegram/bot/types/story_area_type_location.rb
|
|
335
|
+
- lib/telegram/bot/types/story_area_type_suggested_reaction.rb
|
|
336
|
+
- lib/telegram/bot/types/story_area_type_unique_gift.rb
|
|
337
|
+
- lib/telegram/bot/types/story_area_type_weather.rb
|
|
307
338
|
- lib/telegram/bot/types/successful_payment.rb
|
|
339
|
+
- lib/telegram/bot/types/suggested_post_approval_failed.rb
|
|
340
|
+
- lib/telegram/bot/types/suggested_post_approved.rb
|
|
341
|
+
- lib/telegram/bot/types/suggested_post_declined.rb
|
|
342
|
+
- lib/telegram/bot/types/suggested_post_info.rb
|
|
343
|
+
- lib/telegram/bot/types/suggested_post_paid.rb
|
|
344
|
+
- lib/telegram/bot/types/suggested_post_parameters.rb
|
|
345
|
+
- lib/telegram/bot/types/suggested_post_price.rb
|
|
346
|
+
- lib/telegram/bot/types/suggested_post_refunded.rb
|
|
308
347
|
- lib/telegram/bot/types/switch_inline_query_chosen_chat.rb
|
|
309
348
|
- lib/telegram/bot/types/text_quote.rb
|
|
310
349
|
- lib/telegram/bot/types/transaction_partner.rb
|
|
@@ -315,6 +354,12 @@ files:
|
|
|
315
354
|
- lib/telegram/bot/types/transaction_partner_telegram_ads.rb
|
|
316
355
|
- lib/telegram/bot/types/transaction_partner_telegram_api.rb
|
|
317
356
|
- lib/telegram/bot/types/transaction_partner_user.rb
|
|
357
|
+
- lib/telegram/bot/types/unique_gift.rb
|
|
358
|
+
- lib/telegram/bot/types/unique_gift_backdrop.rb
|
|
359
|
+
- lib/telegram/bot/types/unique_gift_backdrop_colors.rb
|
|
360
|
+
- lib/telegram/bot/types/unique_gift_info.rb
|
|
361
|
+
- lib/telegram/bot/types/unique_gift_model.rb
|
|
362
|
+
- lib/telegram/bot/types/unique_gift_symbol.rb
|
|
318
363
|
- lib/telegram/bot/types/update.rb
|
|
319
364
|
- lib/telegram/bot/types/user.rb
|
|
320
365
|
- lib/telegram/bot/types/user_chat_boosts.rb
|
|
@@ -333,16 +378,20 @@ files:
|
|
|
333
378
|
- lib/telegram/bot/types/webhook_info.rb
|
|
334
379
|
- lib/telegram/bot/types/write_access_allowed.rb
|
|
335
380
|
- lib/telegram/bot/version.rb
|
|
336
|
-
- rakelib/
|
|
337
|
-
- rakelib/
|
|
381
|
+
- rakelib/builders/endpoints_builder.rb
|
|
382
|
+
- rakelib/builders/type_builder.rb
|
|
383
|
+
- rakelib/parse.rake
|
|
384
|
+
- rakelib/parsers/methods_parser.rb
|
|
385
|
+
- rakelib/parsers/types_parser.rb
|
|
386
|
+
- rakelib/rebuild.rake
|
|
338
387
|
- rakelib/templates/empty_type.erb
|
|
388
|
+
- rakelib/templates/endpoints.erb
|
|
339
389
|
- rakelib/templates/type.erb
|
|
340
390
|
- telegram-bot-ruby.gemspec
|
|
341
391
|
homepage: https://github.com/atipugin/telegram-bot
|
|
342
392
|
licenses: []
|
|
343
393
|
metadata:
|
|
344
394
|
rubygems_mfa_required: 'true'
|
|
345
|
-
post_install_message:
|
|
346
395
|
rdoc_options: []
|
|
347
396
|
require_paths:
|
|
348
397
|
- lib
|
|
@@ -357,8 +406,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
357
406
|
- !ruby/object:Gem::Version
|
|
358
407
|
version: '0'
|
|
359
408
|
requirements: []
|
|
360
|
-
rubygems_version: 3.
|
|
361
|
-
signing_key:
|
|
409
|
+
rubygems_version: 3.6.9
|
|
362
410
|
specification_version: 4
|
|
363
411
|
summary: Ruby wrapper for Telegram's Bot API
|
|
364
412
|
test_files: []
|
data/rakelib/parse_schema.rake
DELETED
|
@@ -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
|
data/rakelib/rebuild_types.rake
DELETED
|
@@ -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
|