telegram-bot-ruby 0.4.2 → 0.5.0.beta1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (49) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +5 -0
  3. data/README.md +2 -10
  4. data/lib/telegram/bot/api.rb +36 -19
  5. data/lib/telegram/bot/botan/api.rb +11 -7
  6. data/lib/telegram/bot/client.rb +5 -5
  7. data/lib/telegram/bot/configuration.rb +11 -0
  8. data/lib/telegram/bot/exceptions/response_error.rb +1 -1
  9. data/lib/telegram/bot/types/base.rb +4 -0
  10. data/lib/telegram/bot/types/callback_query.rb +13 -0
  11. data/lib/telegram/bot/types/chosen_inline_result.rb +3 -1
  12. data/lib/telegram/bot/types/inline_keyboard_button.rb +16 -0
  13. data/lib/telegram/bot/types/inline_keyboard_markup.rb +16 -0
  14. data/lib/telegram/bot/types/inline_query.rb +2 -1
  15. data/lib/telegram/bot/types/inline_query_result_article.rb +2 -4
  16. data/lib/telegram/bot/types/inline_query_result_audio.rb +16 -0
  17. data/lib/telegram/bot/types/inline_query_result_cached_audio.rb +13 -0
  18. data/lib/telegram/bot/types/inline_query_result_cached_document.rb +16 -0
  19. data/lib/telegram/bot/types/inline_query_result_cached_gif.rb +15 -0
  20. data/lib/telegram/bot/types/inline_query_result_cached_mpeg4_gif.rb +15 -0
  21. data/lib/telegram/bot/types/inline_query_result_cached_photo.rb +16 -0
  22. data/lib/telegram/bot/types/inline_query_result_cached_sticker.rb +13 -0
  23. data/lib/telegram/bot/types/inline_query_result_cached_video.rb +16 -0
  24. data/lib/telegram/bot/types/inline_query_result_cached_voice.rb +14 -0
  25. data/lib/telegram/bot/types/inline_query_result_contact.rb +18 -0
  26. data/lib/telegram/bot/types/inline_query_result_document.rb +20 -0
  27. data/lib/telegram/bot/types/inline_query_result_gif.rb +2 -3
  28. data/lib/telegram/bot/types/inline_query_result_location.rb +18 -0
  29. data/lib/telegram/bot/types/inline_query_result_mpeg4_gif.rb +2 -3
  30. data/lib/telegram/bot/types/inline_query_result_photo.rb +3 -4
  31. data/lib/telegram/bot/types/inline_query_result_venue.rb +20 -0
  32. data/lib/telegram/bot/types/inline_query_result_video.rb +5 -5
  33. data/lib/telegram/bot/types/inline_query_result_voice.rb +15 -0
  34. data/lib/telegram/bot/types/input_contact_message_content.rb +11 -0
  35. data/lib/telegram/bot/types/input_location_message_content.rb +10 -0
  36. data/lib/telegram/bot/types/input_message_content.rb +8 -0
  37. data/lib/telegram/bot/types/input_text_message_content.rb +11 -0
  38. data/lib/telegram/bot/types/input_venue_message_content.rb +13 -0
  39. data/lib/telegram/bot/types/keyboard_button.rb +15 -0
  40. data/lib/telegram/bot/types/message.rb +11 -4
  41. data/lib/telegram/bot/types/message_entity.rb +12 -0
  42. data/lib/telegram/bot/types/reply_keyboard_markup.rb +8 -1
  43. data/lib/telegram/bot/types/update.rb +1 -0
  44. data/lib/telegram/bot/types/venue.rb +12 -0
  45. data/lib/telegram/bot/types.rb +26 -1
  46. data/lib/telegram/bot/version.rb +1 -1
  47. data/lib/telegram/bot.rb +20 -2
  48. data/telegram-bot-ruby.gemspec +1 -3
  49. metadata +31 -33
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8650ba94f288d865b3e28b7c048b1ae1a9b9d94e
4
- data.tar.gz: 19164744782cc7cdca0baef1bffe18317137a1c0
3
+ metadata.gz: 789950417db18c87aeeaf3ada4788131e8d1e5a0
4
+ data.tar.gz: 8240d4073e39f8d7400df0682689e1aec49839d5
5
5
  SHA512:
6
- metadata.gz: 6b56bf52fcb734518d9d588d572945b97b13315e514adefead8210f6e69e8cc847272a279f155fbb6ecb428ea493be6d7e9d043d528335868ee6ff320186ffd3
7
- data.tar.gz: 1c13c8cd9c5852dabd60557ae9e367d890b576309101bb0840bb01c6598d62c012d29d8a60d034d575f8a4a28d6dae70871db04d43236f950ec5fe44c7212af2
6
+ metadata.gz: 8c5819e6e65f453afc80df9354b21783912e3f1f76a15b4bd0fc2ceefe9b1a2472e8c04b661a4175a32e3d2adadf149ae061dd00c2ed5386e27621cf430cf424
7
+ data.tar.gz: 28170029b9b8b8066e693f30687fa8eb3a3168d73a92ef35a18fcc5bf149ceee8358d767a0a4603899a1c3cac560ff9bf3519c6489cf9dd80ed04f7ef517dba5
data/CHANGELOG.md CHANGED
@@ -1,5 +1,10 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.5.0
4
+
5
+ - Replace [httparty](https://github.com/jnunemaker/httparty) with [faraday](https://github.com/lostisland/faraday)
6
+ - Implement [Bot API 2.0](https://core.telegram.org/bots/2-0-intro)
7
+
3
8
  ## 0.4.2
4
9
 
5
10
  - Let `Client#logger` be overwritten later (use `attr_accessor` instead of `attr_reader`)
data/README.md CHANGED
@@ -110,7 +110,7 @@ Your bot can even upload files ([photos](https://core.telegram.org/bots/api#send
110
110
  bot.listen do |message|
111
111
  case message.text
112
112
  when '/photo'
113
- bot.api.send_photo(chat_id: message.chat.id, photo: File.new('~/Desktop/jennifer.jpg'))
113
+ bot.api.send_photo(chat_id: message.chat.id, photo: Faraday::UploadIO.new('~/Desktop/jennifer.jpg', 'image/jpeg'))
114
114
  end
115
115
  end
116
116
  ```
@@ -120,7 +120,7 @@ end
120
120
  By default, bot doesn't log anything (uses `NullLoger`). You can change this behavior and provide your own logger class. See example below:
121
121
 
122
122
  ```ruby
123
- Telegram::Bot::Client.run(token, logger: Logger.new($stdout)) do |bot|
123
+ Telegram::Bot::Client.run(token, logger: Logger.new($stderr)) do |bot|
124
124
  bot.logger.info('Bot has been started')
125
125
  bot.listen do |message|
126
126
  # ...
@@ -155,14 +155,6 @@ end
155
155
  - Telegram's user id (required)
156
156
  - hash of additional properties (optional)
157
157
 
158
- ## Connection pool size
159
-
160
- Sometimes you need to do some heavy work in another thread and send response from there. In this case you have to increase your connection pool size (by default it's *1*). You can do it by setting env variable `TELEGRAM_BOT_POOL_SIZE`:
161
-
162
- ```shell
163
- $ TELEGRAM_BOT_POOL_SIZE=4 ruby bot.rb
164
- ```
165
-
166
158
  ## Boilerplates
167
159
 
168
160
  If you don't know how to setup database for your bot or how to use it with different languages here are some boilerplates which can help you to start faster:
@@ -1,34 +1,43 @@
1
1
  module Telegram
2
2
  module Bot
3
3
  class Api
4
- include HTTMultiParty
5
-
6
4
  ENDPOINTS = %w(
7
- getMe sendMessage forwardMessage sendPhoto sendAudio sendDocument
8
- sendSticker sendVideo sendVoice sendLocation sendChatAction
9
- getUserProfilePhotos getUpdates setWebhook getFile answerInlineQuery
5
+ getUpdates setWebhook getMe sendMessage forwardMessage sendPhoto
6
+ sendAudio sendDocument sendSticker sendVideo sendVoice sendLocation
7
+ sendVenue sendContact sendChatAction getUserProfilePhotos getFile
8
+ kickChatMember unbanChatMember answerCallbackQuery editMessageText
9
+ editMessageCaption editMessageReplyMarkup answerInlineQuery
10
10
  ).freeze
11
11
  REPLY_MARKUP_TYPES = [
12
12
  Telegram::Bot::Types::ReplyKeyboardMarkup,
13
13
  Telegram::Bot::Types::ReplyKeyboardHide,
14
- Telegram::Bot::Types::ForceReply
14
+ Telegram::Bot::Types::ForceReply,
15
+ Telegram::Bot::Types::InlineKeyboardMarkup
15
16
  ].freeze
16
17
  INLINE_QUERY_RESULT_TYPES = [
17
18
  Telegram::Bot::Types::InlineQueryResultArticle,
19
+ Telegram::Bot::Types::InlineQueryResultPhoto,
18
20
  Telegram::Bot::Types::InlineQueryResultGif,
19
21
  Telegram::Bot::Types::InlineQueryResultMpeg4Gif,
20
- Telegram::Bot::Types::InlineQueryResultPhoto,
21
- Telegram::Bot::Types::InlineQueryResultVideo
22
+ Telegram::Bot::Types::InlineQueryResultVideo,
23
+ Telegram::Bot::Types::InlineQueryResultAudio,
24
+ Telegram::Bot::Types::InlineQueryResultVoice,
25
+ Telegram::Bot::Types::InlineQueryResultDocument,
26
+ Telegram::Bot::Types::InlineQueryResultLocation,
27
+ Telegram::Bot::Types::InlineQueryResultVenue,
28
+ Telegram::Bot::Types::InlineQueryResultContact,
29
+ Telegram::Bot::Types::InlineQueryResultCachedPhoto,
30
+ Telegram::Bot::Types::InlineQueryResultCachedGif,
31
+ Telegram::Bot::Types::InlineQueryResultCachedMpeg4Gif,
32
+ Telegram::Bot::Types::InlineQueryResultCachedSticker,
33
+ Telegram::Bot::Types::InlineQueryResultCachedDocument,
34
+ Telegram::Bot::Types::InlineQueryResultCachedVideo,
35
+ Telegram::Bot::Types::InlineQueryResultCachedVoice,
36
+ Telegram::Bot::Types::InlineQueryResultCachedAudio
22
37
  ].freeze
23
- POOL_SIZE = ENV.fetch('TELEGRAM_BOT_POOL_SIZE', 1).to_i.freeze
24
38
 
25
39
  attr_reader :token
26
40
 
27
- base_uri 'https://api.telegram.org'
28
- persistent_connection_adapter pool_size: POOL_SIZE,
29
- keep_alive: 30,
30
- force_retry: true
31
-
32
41
  def initialize(token)
33
42
  @token = token
34
43
  end
@@ -49,12 +58,12 @@ module Telegram
49
58
 
50
59
  def call(endpoint, raw_params = {})
51
60
  params = build_params(raw_params)
52
- response = self.class.post("/bot#{token}/#{endpoint}", query: params)
53
- if response.code == 200
54
- response.to_hash
61
+ response = conn.post("/bot#{token}/#{endpoint}", params)
62
+ if response.status == 200
63
+ JSON.parse(response.body)
55
64
  else
56
- fail Exceptions::ResponseError.new(response),
57
- 'Telegram API has returned the error.'
65
+ raise Exceptions::ResponseError.new(response),
66
+ 'Telegram API has returned the error.'
58
67
  end
59
68
  end
60
69
 
@@ -85,6 +94,14 @@ module Telegram
85
94
  words.drop(1).map(&:capitalize!)
86
95
  words.join
87
96
  end
97
+
98
+ def conn
99
+ @conn ||= Faraday.new(url: 'https://api.telegram.org') do |faraday|
100
+ faraday.request :multipart
101
+ faraday.request :url_encoded
102
+ faraday.adapter Telegram::Bot.configuration.adapter
103
+ end
104
+ end
88
105
  end
89
106
  end
90
107
  end
@@ -2,20 +2,24 @@ module Telegram
2
2
  module Bot
3
3
  module Botan
4
4
  class Api
5
- include HTTParty
6
-
7
5
  attr_reader :token
8
6
 
9
- base_uri 'https://api.botan.io'
10
-
11
7
  def initialize(token)
12
8
  @token = token
13
9
  end
14
10
 
15
11
  def track(event, uid, properties = {})
16
- self.class.post('/track',
17
- query: { token: token, name: event, uid: uid },
18
- body: properties.to_json)
12
+ query_str = URI.encode_www_form(token: token, name: event, uid: uid)
13
+ conn.post("/track?#{query_str}", properties.to_json)
14
+ end
15
+
16
+ private
17
+
18
+ def conn
19
+ @conn ||= Faraday.new(url: 'https://api.botan.io') do |faraday|
20
+ faraday.request :url_encoded
21
+ faraday.adapter Telegram::Bot.configuration.adapter
22
+ end
19
23
  end
20
24
  end
21
25
  end
@@ -1,9 +1,6 @@
1
1
  module Telegram
2
2
  module Bot
3
3
  class Client
4
- TIMEOUT_EXCEPTIONS = [Timeout::Error]
5
- TIMEOUT_EXCEPTIONS << Net::ReadTimeout if Net.const_defined?(:ReadTimeout)
6
-
7
4
  attr_reader :api, :offset, :timeout
8
5
  attr_accessor :logger
9
6
 
@@ -42,7 +39,7 @@ module Telegram
42
39
  log_incoming_message(message)
43
40
  yield message
44
41
  end
45
- rescue *TIMEOUT_EXCEPTIONS
42
+ rescue Faraday::TimeoutError
46
43
  retry
47
44
  end
48
45
 
@@ -53,7 +50,10 @@ module Telegram
53
50
  end
54
51
 
55
52
  def extract_message(update)
56
- update.inline_query || update.chosen_inline_result || update.message
53
+ update.inline_query ||
54
+ update.chosen_inline_result ||
55
+ update.callback_query ||
56
+ update.message
57
57
  end
58
58
 
59
59
  def log_incoming_message(message)
@@ -0,0 +1,11 @@
1
+ module Telegram
2
+ module Bot
3
+ class Configuration
4
+ attr_accessor :adapter
5
+
6
+ def initialize
7
+ @adapter = Faraday.default_adapter
8
+ end
9
+ end
10
+ end
11
+ end
@@ -23,7 +23,7 @@ module Telegram
23
23
  @data ||= begin
24
24
  JSON.parse(response.body)
25
25
  rescue JSON::ParserError
26
- { error_code: response.code, uri: response.request.last_uri.to_s }
26
+ { error_code: response.status, uri: response.request.last_uri.to_s }
27
27
  end
28
28
  end
29
29
  end
@@ -3,6 +3,10 @@ module Telegram
3
3
  module Types
4
4
  class Base
5
5
  include Virtus.model
6
+
7
+ def compact_attributes
8
+ attributes.dup.delete_if { |_, v| v.nil? }
9
+ end
6
10
  end
7
11
  end
8
12
  end
@@ -0,0 +1,13 @@
1
+ module Telegram
2
+ module Bot
3
+ module Types
4
+ class CallbackQuery < Base
5
+ attribute :id, String
6
+ attribute :from, User
7
+ attribute :message, Message
8
+ attribute :inline_message_id, String
9
+ attribute :data, String
10
+ end
11
+ end
12
+ end
13
+ end
@@ -4,9 +4,11 @@ module Telegram
4
4
  class ChosenInlineResult < Base
5
5
  attribute :result_id, String
6
6
  attribute :from, User
7
+ attribute :location, Location
8
+ attribute :inline_message_id, String
7
9
  attribute :query, String
8
10
 
9
- alias_method :to_s, :query
11
+ alias to_s query
10
12
  end
11
13
  end
12
14
  end
@@ -0,0 +1,16 @@
1
+ module Telegram
2
+ module Bot
3
+ module Types
4
+ class InlineKeyboardButton < Base
5
+ attribute :text, String
6
+ attribute :url, String
7
+ attribute :callback_data, String
8
+ attribute :switch_inline_query, String
9
+
10
+ def to_h
11
+ super.delete_if { |_, v| v.nil? }
12
+ end
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,16 @@
1
+ module Telegram
2
+ module Bot
3
+ module Types
4
+ class InlineKeyboardMarkup < Base
5
+ attribute :inline_keyboard, Array[Array[InlineKeyboardButton]]
6
+
7
+ def to_h
8
+ hsh = super
9
+ hsh[:inline_keyboard].map! { |a| a.map(&:to_h) }
10
+
11
+ hsh
12
+ end
13
+ end
14
+ end
15
+ end
16
+ end
@@ -4,10 +4,11 @@ module Telegram
4
4
  class InlineQuery < Base
5
5
  attribute :id, String
6
6
  attribute :from, User
7
+ attribute :location, Location
7
8
  attribute :query, String
8
9
  attribute :offset, String
9
10
 
10
- alias_method :to_s, :query
11
+ alias to_s query
11
12
  end
12
13
  end
13
14
  end
@@ -5,10 +5,8 @@ module Telegram
5
5
  attribute :type, String, default: 'article'
6
6
  attribute :id, String
7
7
  attribute :title, String
8
- attribute :message_text, String
9
- attribute :parse_mode, String
10
- attribute :parse_mode, String
11
- attribute :disable_web_page_preview, Boolean
8
+ attribute :input_message_content, InputMessageContent
9
+ attribute :reply_markup, InlineKeyboardMarkup
12
10
  attribute :url, String
13
11
  attribute :hide_url, Boolean
14
12
  attribute :description, String
@@ -0,0 +1,16 @@
1
+ module Telegram
2
+ module Bot
3
+ module Types
4
+ class InlineQueryResultAudio < Base
5
+ attribute :type, String, default: 'audio'
6
+ attribute :id, String
7
+ attribute :audio_url, String
8
+ attribute :title, String
9
+ attribute :performer, String
10
+ attribute :audio_duration, Integer
11
+ attribute :reply_markup, InlineKeyboardMarkup
12
+ attribute :input_message_content, InputMessageContent
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,13 @@
1
+ module Telegram
2
+ module Bot
3
+ module Types
4
+ class InlineQueryResultCachedAudio < Base
5
+ attribute :type, String, default: 'audio'
6
+ attribute :id, String
7
+ attribute :audio_file_id, String
8
+ attribute :reply_markup, InlineKeyboardMarkup
9
+ attribute :input_message_content, InputMessageContent
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,16 @@
1
+ module Telegram
2
+ module Bot
3
+ module Types
4
+ class InlineQueryResultCachedDocument < Base
5
+ attribute :type, String, default: 'document'
6
+ attribute :id, String
7
+ attribute :title, String
8
+ attribute :document_file_id, String
9
+ attribute :description, String
10
+ attribute :caption, String
11
+ attribute :reply_markup, InlineKeyboardMarkup
12
+ attribute :input_message_content, InputMessageContent
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,15 @@
1
+ module Telegram
2
+ module Bot
3
+ module Types
4
+ class InlineQueryResultCachedGif < Base
5
+ attribute :type, String, default: 'gif'
6
+ attribute :id, String
7
+ attribute :gif_file_id, String
8
+ attribute :title, String
9
+ attribute :caption, String
10
+ attribute :reply_markup, InlineKeyboardMarkup
11
+ attribute :input_message_content, InputMessageContent
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,15 @@
1
+ module Telegram
2
+ module Bot
3
+ module Types
4
+ class InlineQueryResultCachedMpeg4Gif < Base
5
+ attribute :type, String, default: 'mpeg4_gif'
6
+ attribute :id, String
7
+ attribute :mpeg4_file_id, String
8
+ attribute :title, String
9
+ attribute :caption, String
10
+ attribute :reply_markup, InlineKeyboardMarkup
11
+ attribute :input_message_content, InputMessageContent
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,16 @@
1
+ module Telegram
2
+ module Bot
3
+ module Types
4
+ class InlineQueryResultCachedPhoto < Base
5
+ attribute :type, String, default: 'photo'
6
+ attribute :id, String
7
+ attribute :photo_file_id, String
8
+ attribute :title, String
9
+ attribute :description, String
10
+ attribute :caption, String
11
+ attribute :reply_markup, InlineKeyboardMarkup
12
+ attribute :input_message_content, InputMessageContent
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,13 @@
1
+ module Telegram
2
+ module Bot
3
+ module Types
4
+ class InlineQueryResultCachedSticker < Base
5
+ attribute :type, String, default: 'sticker'
6
+ attribute :id, String
7
+ attribute :sticker_file_id, String
8
+ attribute :reply_markup, InlineKeyboardMarkup
9
+ attribute :input_message_content, InputMessageContent
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,16 @@
1
+ module Telegram
2
+ module Bot
3
+ module Types
4
+ class InlineQueryResultCachedVideo < Base
5
+ attribute :type, String, default: 'video'
6
+ attribute :id, String
7
+ attribute :video_file_id, String
8
+ attribute :title, String
9
+ attribute :description, String
10
+ attribute :caption, String
11
+ attribute :reply_markup, InlineKeyboardMarkup
12
+ attribute :input_message_content, InputMessageContent
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,14 @@
1
+ module Telegram
2
+ module Bot
3
+ module Types
4
+ class InlineQueryResultCachedVoice < Base
5
+ attribute :type, String, default: 'voice'
6
+ attribute :id, String
7
+ attribute :voice_file_id, String
8
+ attribute :title, String
9
+ attribute :reply_markup, InlineKeyboardMarkup
10
+ attribute :input_message_content, InputMessageContent
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,18 @@
1
+ module Telegram
2
+ module Bot
3
+ module Types
4
+ class InlineQueryResultContact < Base
5
+ attribute :type, String, default: 'contact'
6
+ attribute :id, String
7
+ attribute :phone_number, String
8
+ attribute :first_name, String
9
+ attribute :last_name, String
10
+ attribute :reply_markup, InlineKeyboardMarkup
11
+ attribute :input_message_content, InputMessageContent
12
+ attribute :thumb_url, String
13
+ attribute :thumb_width, Integer
14
+ attribute :thumb_height, Integer
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,20 @@
1
+ module Telegram
2
+ module Bot
3
+ module Types
4
+ class InlineQueryResultDocument < Base
5
+ attribute :type, String, default: 'document'
6
+ attribute :id, String
7
+ attribute :title, String
8
+ attribute :caption, String
9
+ attribute :document_url, String
10
+ attribute :mime_type, String
11
+ attribute :description, String
12
+ attribute :reply_markup, InlineKeyboardMarkup
13
+ attribute :input_message_content, InputMessageContent
14
+ attribute :thumb_url, String
15
+ attribute :thumb_width, Integer
16
+ attribute :thumb_height, Integer
17
+ end
18
+ end
19
+ end
20
+ end
@@ -10,9 +10,8 @@ module Telegram
10
10
  attribute :thumb_url, String
11
11
  attribute :title, String
12
12
  attribute :caption, String
13
- attribute :message_text, String
14
- attribute :parse_mode, String
15
- attribute :disable_web_page_preview, Boolean
13
+ attribute :reply_markup, InlineKeyboardMarkup
14
+ attribute :input_message_content, InputMessageContent
16
15
  end
17
16
  end
18
17
  end
@@ -0,0 +1,18 @@
1
+ module Telegram
2
+ module Bot
3
+ module Types
4
+ class InlineQueryResultLocation < Base
5
+ attribute :type, String, default: 'location'
6
+ attribute :id, String
7
+ attribute :latitude, Float
8
+ attribute :longitude, Float
9
+ attribute :title, String
10
+ attribute :reply_markup, InlineKeyboardMarkup
11
+ attribute :input_message_content, InputMessageContent
12
+ attribute :thumb_url, String
13
+ attribute :thumb_width, Integer
14
+ attribute :thumb_height, Integer
15
+ end
16
+ end
17
+ end
18
+ end
@@ -10,9 +10,8 @@ module Telegram
10
10
  attribute :thumb_url, String
11
11
  attribute :title, String
12
12
  attribute :caption, String
13
- attribute :message_text, String
14
- attribute :parse_mode, String
15
- attribute :disable_web_page_preview, Boolean
13
+ attribute :reply_markup, InlineKeyboardMarkup
14
+ attribute :input_message_content, InputMessageContent
16
15
  end
17
16
  end
18
17
  end
@@ -5,15 +5,14 @@ module Telegram
5
5
  attribute :type, String, default: 'photo'
6
6
  attribute :id, String
7
7
  attribute :photo_url, String
8
+ attribute :thumb_url, String
8
9
  attribute :photo_width, Integer
9
10
  attribute :photo_height, Integer
10
- attribute :thumb_url, String
11
11
  attribute :title, String
12
12
  attribute :description, String
13
13
  attribute :caption, String
14
- attribute :message_text, String
15
- attribute :parse_mode, String
16
- attribute :disable_web_page_preview, Boolean
14
+ attribute :reply_markup, InlineKeyboardMarkup
15
+ attribute :input_message_content, InputMessageContent
17
16
  end
18
17
  end
19
18
  end
@@ -0,0 +1,20 @@
1
+ module Telegram
2
+ module Bot
3
+ module Types
4
+ class InlineQueryResultVenue < Base
5
+ attribute :type, String, default: 'venue'
6
+ attribute :id, String
7
+ attribute :latitude, Float
8
+ attribute :longitude, Float
9
+ attribute :title, String
10
+ attribute :address, String
11
+ attribute :foursquare_id, String
12
+ attribute :reply_markup, InlineKeyboardMarkup
13
+ attribute :input_message_content, InputMessageContent
14
+ attribute :thumb_url, String
15
+ attribute :thumb_width, Integer
16
+ attribute :thumb_height, Integer
17
+ end
18
+ end
19
+ end
20
+ end
@@ -6,15 +6,15 @@ module Telegram
6
6
  attribute :id, String
7
7
  attribute :video_url, String
8
8
  attribute :mime_type, String
9
- attribute :message_text, String
10
- attribute :parse_mode, String
11
- attribute :disable_web_page_preview, Boolean
9
+ attribute :thumb_url, String
10
+ attribute :title, String
11
+ attribute :caption, String
12
12
  attribute :video_width, Integer
13
13
  attribute :video_height, Integer
14
14
  attribute :video_duration, Integer
15
- attribute :thumb_url, String
16
- attribute :title, String
17
15
  attribute :description, String
16
+ attribute :reply_markup, InlineKeyboardMarkup
17
+ attribute :input_message_content, InputMessageContent
18
18
  end
19
19
  end
20
20
  end
@@ -0,0 +1,15 @@
1
+ module Telegram
2
+ module Bot
3
+ module Types
4
+ class InlineQueryResultVoice < Base
5
+ attribute :type, String, default: 'voice'
6
+ attribute :id, String
7
+ attribute :voice_url, String
8
+ attribute :title, String
9
+ attribute :voice_duration, Integer
10
+ attribute :reply_markup, InlineKeyboardMarkup
11
+ attribute :input_message_content, InputMessageContent
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,11 @@
1
+ module Telegram
2
+ module Bot
3
+ module Types
4
+ class InputContactMessageContent < InputMessageContent
5
+ attribute :phone_number, String
6
+ attribute :first_name, String
7
+ attribute :last_name, String
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,10 @@
1
+ module Telegram
2
+ module Bot
3
+ module Types
4
+ class InputLocationMessageContent < InputMessageContent
5
+ attribute :latitude, Float
6
+ attribute :longitude, Float
7
+ end
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,8 @@
1
+ module Telegram
2
+ module Bot
3
+ module Types
4
+ class InputMessageContent < Base
5
+ end
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,11 @@
1
+ module Telegram
2
+ module Bot
3
+ module Types
4
+ class InputTextMessageContent < InputMessageContent
5
+ attribute :message_text, String
6
+ attribute :parse_mode, String
7
+ attribute :disable_web_page_preview, Boolean
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,13 @@
1
+ module Telegram
2
+ module Bot
3
+ module Types
4
+ class InputVenueMessageContent < InputMessageContent
5
+ attribute :latitude, Float
6
+ attribute :longitude, Float
7
+ attribute :title, String
8
+ attribute :address, String
9
+ attribute :foursquare_id, String
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,15 @@
1
+ module Telegram
2
+ module Bot
3
+ module Types
4
+ class KeyboardButton < Base
5
+ attribute :text, String
6
+ attribute :request_contact, Boolean
7
+ attribute :request_location, Boolean
8
+
9
+ def to_h
10
+ super.delete_if { |_, v| v.nil? }
11
+ end
12
+ end
13
+ end
14
+ end
15
+ end
@@ -5,10 +5,12 @@ module Telegram
5
5
  attribute :message_id, Integer
6
6
  attribute :from, User
7
7
  attribute :date, Integer
8
+ attribute :chat, Chat
8
9
  attribute :forward_from, User
9
10
  attribute :forward_date, Integer
10
11
  attribute :reply_to_message, Message
11
12
  attribute :text, String
13
+ attribute :entities, Array[MessageEntity]
12
14
  attribute :audio, Audio
13
15
  attribute :document, Document
14
16
  attribute :photo, Array[PhotoSize]
@@ -18,15 +20,20 @@ module Telegram
18
20
  attribute :caption, String
19
21
  attribute :contact, Contact
20
22
  attribute :location, Location
21
- attribute :new_chat_participant, User
22
- attribute :left_chat_participant, User
23
+ attribute :venue, Venue
24
+ attribute :new_chat_member, User
25
+ attribute :left_chat_member, User
23
26
  attribute :new_chat_title, String
24
27
  attribute :new_chat_photo, Array[PhotoSize]
25
28
  attribute :delete_chat_photo, Boolean
26
29
  attribute :group_chat_created, Boolean
27
- attribute :chat, Chat
30
+ attribute :supergroup_chat_created, Boolean
31
+ attribute :channel_chat_created, Boolean
32
+ attribute :migrate_to_chat_id, Integer
33
+ attribute :migrate_from_chat_id, Integer
34
+ attribute :pinned_message, Message
28
35
 
29
- alias_method :to_s, :text
36
+ alias to_s text
30
37
  end
31
38
  end
32
39
  end
@@ -0,0 +1,12 @@
1
+ module Telegram
2
+ module Bot
3
+ module Types
4
+ class MessageEntity < Base
5
+ attribute :type, String
6
+ attribute :offset, Integer
7
+ attribute :length, Integer
8
+ attribute :url, String
9
+ end
10
+ end
11
+ end
12
+ end
@@ -2,10 +2,17 @@ module Telegram
2
2
  module Bot
3
3
  module Types
4
4
  class ReplyKeyboardMarkup < Base
5
- attribute :keyboard, Array[Array[String]]
5
+ attribute :keyboard, Array[Array[KeyboardButton]]
6
6
  attribute :resize_keyboard, Boolean, default: false
7
7
  attribute :one_time_keyboard, Boolean, default: false
8
8
  attribute :selective, Boolean, default: false
9
+
10
+ def to_h
11
+ hsh = super
12
+ hsh[:keyboard].map! { |a| a.map(&:to_h) }
13
+
14
+ hsh
15
+ end
9
16
  end
10
17
  end
11
18
  end
@@ -6,6 +6,7 @@ module Telegram
6
6
  attribute :message, Message
7
7
  attribute :inline_query, InlineQuery
8
8
  attribute :chosen_inline_result, ChosenInlineResult
9
+ attribute :callback_query, CallbackQuery
9
10
  end
10
11
  end
11
12
  end
@@ -0,0 +1,12 @@
1
+ module Telegram
2
+ module Bot
3
+ module Types
4
+ class Venue < Base
5
+ attribute :location, Location
6
+ attribute :title, String
7
+ attribute :address, String
8
+ attribute :foursquare_id, String
9
+ end
10
+ end
11
+ end
12
+ end
@@ -9,15 +9,40 @@ require 'telegram/bot/types/voice'
9
9
  require 'telegram/bot/types/contact'
10
10
  require 'telegram/bot/types/location'
11
11
  require 'telegram/bot/types/chat'
12
+ require 'telegram/bot/types/message_entity'
13
+ require 'telegram/bot/types/venue'
12
14
  require 'telegram/bot/types/message'
15
+ require 'telegram/bot/types/input_message_content'
16
+ require 'telegram/bot/types/input_contact_message_content'
17
+ require 'telegram/bot/types/input_location_message_content'
18
+ require 'telegram/bot/types/input_text_message_content'
19
+ require 'telegram/bot/types/input_venue_message_content'
20
+ require 'telegram/bot/types/inline_keyboard_button'
21
+ require 'telegram/bot/types/inline_keyboard_markup'
13
22
  require 'telegram/bot/types/inline_query'
14
23
  require 'telegram/bot/types/inline_query_result_article'
15
- require 'telegram/bot/types/inline_query_result_photo'
24
+ require 'telegram/bot/types/inline_query_result_audio'
25
+ require 'telegram/bot/types/inline_query_result_cached_audio'
26
+ require 'telegram/bot/types/inline_query_result_cached_document'
27
+ require 'telegram/bot/types/inline_query_result_cached_gif'
28
+ require 'telegram/bot/types/inline_query_result_cached_mpeg4_gif'
29
+ require 'telegram/bot/types/inline_query_result_cached_photo'
30
+ require 'telegram/bot/types/inline_query_result_cached_sticker'
31
+ require 'telegram/bot/types/inline_query_result_cached_video'
32
+ require 'telegram/bot/types/inline_query_result_cached_voice'
33
+ require 'telegram/bot/types/inline_query_result_contact'
34
+ require 'telegram/bot/types/inline_query_result_document'
16
35
  require 'telegram/bot/types/inline_query_result_gif'
36
+ require 'telegram/bot/types/inline_query_result_location'
17
37
  require 'telegram/bot/types/inline_query_result_mpeg4_gif'
38
+ require 'telegram/bot/types/inline_query_result_photo'
39
+ require 'telegram/bot/types/inline_query_result_venue'
18
40
  require 'telegram/bot/types/inline_query_result_video'
41
+ require 'telegram/bot/types/inline_query_result_voice'
19
42
  require 'telegram/bot/types/chosen_inline_result'
43
+ require 'telegram/bot/types/callback_query'
20
44
  require 'telegram/bot/types/update'
45
+ require 'telegram/bot/types/keyboard_button'
21
46
  require 'telegram/bot/types/reply_keyboard_markup'
22
47
  require 'telegram/bot/types/reply_keyboard_hide'
23
48
  require 'telegram/bot/types/force_reply'
@@ -1,5 +1,5 @@
1
1
  module Telegram
2
2
  module Bot
3
- VERSION = '0.4.2'
3
+ VERSION = '0.5.0.beta1'.freeze
4
4
  end
5
5
  end
data/lib/telegram/bot.rb CHANGED
@@ -1,6 +1,7 @@
1
- require 'httmultiparty'
2
- require 'persistent_httparty'
3
1
  require 'virtus'
2
+ require 'logger'
3
+ require 'json'
4
+ require 'faraday'
4
5
 
5
6
  require 'telegram/bot/types'
6
7
  require 'telegram/bot/exceptions'
@@ -8,3 +9,20 @@ require 'telegram/bot/api'
8
9
  require 'telegram/bot/null_logger'
9
10
  require 'telegram/bot/client'
10
11
  require 'telegram/bot/version'
12
+ require 'telegram/bot/configuration'
13
+
14
+ module Telegram
15
+ module Bot
16
+ class << self
17
+ attr_writer :configuration
18
+ end
19
+
20
+ def self.configuration
21
+ @configuration ||= Configuration.new
22
+ end
23
+
24
+ def self.configure
25
+ yield(configuration)
26
+ end
27
+ end
28
+ end
@@ -17,8 +17,7 @@ Gem::Specification.new do |spec|
17
17
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
18
18
  spec.require_paths = ['lib']
19
19
 
20
- spec.add_dependency 'httmultiparty'
21
- spec.add_dependency 'persistent_httparty'
20
+ spec.add_dependency 'faraday'
22
21
  spec.add_dependency 'virtus'
23
22
 
24
23
  spec.add_development_dependency 'bundler', '~> 1.9'
@@ -27,5 +26,4 @@ Gem::Specification.new do |spec|
27
26
  spec.add_development_dependency 'rubocop'
28
27
  spec.add_development_dependency 'rspec', '~> 3.4'
29
28
  spec.add_development_dependency 'rubocop-rspec', '~> 1.4'
30
- spec.add_development_dependency 'nokogiri', '~> 1.6'
31
29
  end
metadata CHANGED
@@ -1,31 +1,17 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: telegram-bot-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.2
4
+ version: 0.5.0.beta1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alexander Tipugin
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-04-06 00:00:00.000000000 Z
11
+ date: 2016-04-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: httmultiparty
15
- requirement: !ruby/object:Gem::Requirement
16
- requirements:
17
- - - ">="
18
- - !ruby/object:Gem::Version
19
- version: '0'
20
- type: :runtime
21
- prerelease: false
22
- version_requirements: !ruby/object:Gem::Requirement
23
- requirements:
24
- - - ">="
25
- - !ruby/object:Gem::Version
26
- version: '0'
27
- - !ruby/object:Gem::Dependency
28
- name: persistent_httparty
14
+ name: faraday
29
15
  requirement: !ruby/object:Gem::Requirement
30
16
  requirements:
31
17
  - - ">="
@@ -136,20 +122,6 @@ dependencies:
136
122
  - - "~>"
137
123
  - !ruby/object:Gem::Version
138
124
  version: '1.4'
139
- - !ruby/object:Gem::Dependency
140
- name: nokogiri
141
- requirement: !ruby/object:Gem::Requirement
142
- requirements:
143
- - - "~>"
144
- - !ruby/object:Gem::Version
145
- version: '1.6'
146
- type: :development
147
- prerelease: false
148
- version_requirements: !ruby/object:Gem::Requirement
149
- requirements:
150
- - - "~>"
151
- - !ruby/object:Gem::Version
152
- version: '1.6'
153
125
  description:
154
126
  email:
155
127
  - atipugin@gmail.com
@@ -174,6 +146,7 @@ files:
174
146
  - lib/telegram/bot/botan.rb
175
147
  - lib/telegram/bot/botan/api.rb
176
148
  - lib/telegram/bot/client.rb
149
+ - lib/telegram/bot/configuration.rb
177
150
  - lib/telegram/bot/exceptions.rb
178
151
  - lib/telegram/bot/exceptions/base.rb
179
152
  - lib/telegram/bot/exceptions/response_error.rb
@@ -181,26 +154,51 @@ files:
181
154
  - lib/telegram/bot/types.rb
182
155
  - lib/telegram/bot/types/audio.rb
183
156
  - lib/telegram/bot/types/base.rb
157
+ - lib/telegram/bot/types/callback_query.rb
184
158
  - lib/telegram/bot/types/chat.rb
185
159
  - lib/telegram/bot/types/chosen_inline_result.rb
186
160
  - lib/telegram/bot/types/contact.rb
187
161
  - lib/telegram/bot/types/document.rb
188
162
  - lib/telegram/bot/types/file.rb
189
163
  - lib/telegram/bot/types/force_reply.rb
164
+ - lib/telegram/bot/types/inline_keyboard_button.rb
165
+ - lib/telegram/bot/types/inline_keyboard_markup.rb
190
166
  - lib/telegram/bot/types/inline_query.rb
191
167
  - lib/telegram/bot/types/inline_query_result_article.rb
168
+ - lib/telegram/bot/types/inline_query_result_audio.rb
169
+ - lib/telegram/bot/types/inline_query_result_cached_audio.rb
170
+ - lib/telegram/bot/types/inline_query_result_cached_document.rb
171
+ - lib/telegram/bot/types/inline_query_result_cached_gif.rb
172
+ - lib/telegram/bot/types/inline_query_result_cached_mpeg4_gif.rb
173
+ - lib/telegram/bot/types/inline_query_result_cached_photo.rb
174
+ - lib/telegram/bot/types/inline_query_result_cached_sticker.rb
175
+ - lib/telegram/bot/types/inline_query_result_cached_video.rb
176
+ - lib/telegram/bot/types/inline_query_result_cached_voice.rb
177
+ - lib/telegram/bot/types/inline_query_result_contact.rb
178
+ - lib/telegram/bot/types/inline_query_result_document.rb
192
179
  - lib/telegram/bot/types/inline_query_result_gif.rb
180
+ - lib/telegram/bot/types/inline_query_result_location.rb
193
181
  - lib/telegram/bot/types/inline_query_result_mpeg4_gif.rb
194
182
  - lib/telegram/bot/types/inline_query_result_photo.rb
183
+ - lib/telegram/bot/types/inline_query_result_venue.rb
195
184
  - lib/telegram/bot/types/inline_query_result_video.rb
185
+ - lib/telegram/bot/types/inline_query_result_voice.rb
186
+ - lib/telegram/bot/types/input_contact_message_content.rb
187
+ - lib/telegram/bot/types/input_location_message_content.rb
188
+ - lib/telegram/bot/types/input_message_content.rb
189
+ - lib/telegram/bot/types/input_text_message_content.rb
190
+ - lib/telegram/bot/types/input_venue_message_content.rb
191
+ - lib/telegram/bot/types/keyboard_button.rb
196
192
  - lib/telegram/bot/types/location.rb
197
193
  - lib/telegram/bot/types/message.rb
194
+ - lib/telegram/bot/types/message_entity.rb
198
195
  - lib/telegram/bot/types/photo_size.rb
199
196
  - lib/telegram/bot/types/reply_keyboard_hide.rb
200
197
  - lib/telegram/bot/types/reply_keyboard_markup.rb
201
198
  - lib/telegram/bot/types/sticker.rb
202
199
  - lib/telegram/bot/types/update.rb
203
200
  - lib/telegram/bot/types/user.rb
201
+ - lib/telegram/bot/types/venue.rb
204
202
  - lib/telegram/bot/types/video.rb
205
203
  - lib/telegram/bot/types/voice.rb
206
204
  - lib/telegram/bot/version.rb
@@ -219,9 +217,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
219
217
  version: '0'
220
218
  required_rubygems_version: !ruby/object:Gem::Requirement
221
219
  requirements:
222
- - - ">="
220
+ - - ">"
223
221
  - !ruby/object:Gem::Version
224
- version: '0'
222
+ version: 1.3.1
225
223
  requirements: []
226
224
  rubyforge_project:
227
225
  rubygems_version: 2.4.5.1