telegram-bot-ruby 0.3.4 → 0.3.5

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c0be0d9f9b09686f972ed3bbbd2647e93dd757a4
4
- data.tar.gz: 0b0508dd065cb45c221d0b77354e8881a93c876b
3
+ metadata.gz: c12e00f696103b14d70d141923f8cbe57ab6b902
4
+ data.tar.gz: 83e391cc4f2a89c8a6eed5e43d8ff5e304b05ca3
5
5
  SHA512:
6
- metadata.gz: b36eac94ac838a19e51e2735a49274b994e0fc1b998050f9009ad3cffd43809cadf4304529d6c0893a905e58cefa532d0ee6d85de79dc3c89c30c7259c85c4cd
7
- data.tar.gz: 0d4298c22bf1bdf9e58ae0af41b2573334dc8893e0b708dd2c1c64906b41c5faadce5f7a9d89f688ed90598259a9a87d9d1172441e5fc80f14d86203c8612a91
6
+ metadata.gz: c2cbfb05f587b9644f58b0a5281a2f5364038b04c6f0bf195135d3e422fb1eb091fbe7e3d20ff4fff3facc02d17da477ccfc6219ac647f873f93a118b4754849
7
+ data.tar.gz: b912880f81e021d5d96f908d29bd2842614991721a3b4c0ee7f2e386021bc71e7c28d426f4836a68ca1f664db2065035264457f3ab3e44adbd299ccf3e45e13a
data/README.md CHANGED
@@ -38,15 +38,15 @@ Telegram::Bot::Client.run(token) do |bot|
38
38
  bot.listen do |message|
39
39
  case message.text
40
40
  when '/start'
41
- bot.api.sendMessage(chat_id: message.chat.id, text: "Hello, #{message.from.first_name}")
41
+ bot.api.send_message(chat_id: message.chat.id, text: "Hello, #{message.from.first_name}")
42
42
  when '/stop'
43
- bot.api.sendMessage(chat_id: message.chat.id, text: "Bye, #{message.from.first_name}")
43
+ bot.api.send_message(chat_id: message.chat.id, text: "Bye, #{message.from.first_name}")
44
44
  end
45
45
  end
46
46
  end
47
47
  ```
48
48
 
49
- Note that `bot.api` object implements [Telegram Bot API methods](https://core.telegram.org/bots/api#available-methods) as is. So you can invoke any method inside the block without any problems.
49
+ Note that `bot.api` object implements [Telegram Bot API methods](https://core.telegram.org/bots/api#available-methods) as is. So you can invoke any method inside the block without any problems. All methods are available in both *snake_case* and *camelCase* notations.
50
50
 
51
51
  Same thing about `message` object - it implements [Message](https://core.telegram.org/bots/api#message) spec, so you always know what to expect from it.
52
52
 
@@ -63,11 +63,11 @@ bot.listen do |message|
63
63
  answers =
64
64
  Telegram::Bot::Types::ReplyKeyboardMarkup
65
65
  .new(keyboard: [%w(A B), %w(C D)], one_time_keyboard: true)
66
- bot.api.sendMessage(chat_id: message.chat.id, text: question, reply_markup: answers)
66
+ bot.api.send_message(chat_id: message.chat.id, text: question, reply_markup: answers)
67
67
  when '/stop'
68
68
  # See more: https://core.telegram.org/bots/api#replykeyboardhide
69
69
  kb = Telegram::Bot::Types::ReplyKeyboardHide.new(hide_keyboard: true)
70
- bot.api.sendMessage(chat_id: message.chat.id, text: 'Sorry to see you go :(', reply_markup: kb)
70
+ bot.api.send_message(chat_id: message.chat.id, text: 'Sorry to see you go :(', reply_markup: kb)
71
71
  end
72
72
  end
73
73
  ```
@@ -80,7 +80,7 @@ Your bot can even upload files ([photos](https://core.telegram.org/bots/api#send
80
80
  bot.listen do |message|
81
81
  case message.text
82
82
  when '/photo'
83
- bot.api.sendPhoto(chat_id: message.chat.id, photo: File.new('~/Desktop/jennifer.jpg'))
83
+ bot.api.send_photo(chat_id: message.chat.id, photo: File.new('~/Desktop/jennifer.jpg'))
84
84
  end
85
85
  end
86
86
  ```
@@ -127,7 +127,11 @@ end
127
127
 
128
128
  ## Connection pool size
129
129
 
130
- Sometimes you need to do some heavy work in another thread and send response from where.
130
+ 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`:
131
+
132
+ ```shell
133
+ $ TELEGRAM_BOT_POOL_SIZE=4 ruby bot.rb
134
+ ```
131
135
 
132
136
  ## Contributing
133
137
 
@@ -7,11 +7,11 @@ Telegram::Bot::Client.run(token) do |bot|
7
7
  bot.listen do |message|
8
8
  case message.text
9
9
  when '/start'
10
- bot.api.sendMessage(chat_id: message.chat.id, text: "Hello, #{message.from.first_name}!")
10
+ bot.api.send_message(chat_id: message.chat.id, text: "Hello, #{message.from.first_name}!")
11
11
  when '/end'
12
- bot.api.sendMessage(chat_id: message.chat.id, text: "Bye, #{message.from.first_name}!")
12
+ bot.api.send_message(chat_id: message.chat.id, text: "Bye, #{message.from.first_name}!")
13
13
  else
14
- bot.api.sendMessage(chat_id: message.chat.id, text: "I don't understand you :(")
14
+ bot.api.send_message(chat_id: message.chat.id, text: "I don't understand you :(")
15
15
  end
16
16
  end
17
17
  end
@@ -25,7 +25,10 @@ module Telegram
25
25
  end
26
26
 
27
27
  def method_missing(method_name, *args, &block)
28
- ENDPOINTS.include?(method_name.to_s) ? call(method_name, *args) : super
28
+ endpoint = method_name.to_s
29
+ endpoint = camelize(endpoint) if endpoint.include?('_')
30
+
31
+ ENDPOINTS.include?(endpoint) ? call(endpoint, *args) : super
29
32
  end
30
33
 
31
34
  def call(endpoint, raw_params = {})
@@ -55,6 +58,12 @@ module Telegram
55
58
  return value unless REPLY_MARKUP_TYPES.include?(value.class)
56
59
  value.to_h.to_json
57
60
  end
61
+
62
+ def camelize(method_name)
63
+ words = method_name.split('_')
64
+ words.drop(1).map(&:capitalize!)
65
+ words.join
66
+ end
58
67
  end
59
68
  end
60
69
  end
@@ -1,5 +1,5 @@
1
1
  module Telegram
2
2
  module Bot
3
- VERSION = '0.3.4'
3
+ VERSION = '0.3.5'
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: telegram-bot-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.4
4
+ version: 0.3.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alexander Tipugin
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2015-09-11 00:00:00.000000000 Z
11
+ date: 2015-09-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: httmultiparty