ya_telegram_bot 0.3.0 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c607a290b4ddc0b1aa0e6655266736dfc049db55
4
- data.tar.gz: d5de93cfa149d2e35f0f46053117335fdc3d6efd
3
+ metadata.gz: 824c8bc77b35bdf7d81bc9a111e2f893d8a03349
4
+ data.tar.gz: c852921184c91322dbbf2828e64f70a639913bbf
5
5
  SHA512:
6
- metadata.gz: a72d2a026a4bbe3e6d12f4e77db06a7b249df924236c42aed30dbdd60700e86a7ff46a9cff8ae7d69c7c24aff60b8343d044cd25f907f0708b360c84bd2aeda7
7
- data.tar.gz: dadfbb256be7c04a62dbb82f61710564b861a7da99ec8d2695bd3f94e29c5666ac7cf67e198e6476ae8677f4d4be5b341d52461b3abc4698cd5b8a6b5d26d40d
6
+ metadata.gz: 37e3bc364b16c3516cb84d5a68ab208a56a2ab290143bb4a43a7f484d236a428a71563419a8c17583572f6931ae898f128c306b61bbcfe8f7640b5983dfab834
7
+ data.tar.gz: 8e214248e540cf8ec074ceea7252b1320b009bf8f8d12000fafd8efc692729dbfb2107cc5f279e77ffe0714f4e3c52d2a1753e44ac96ea6bd5bef7ee78e1bc82
data/README.md CHANGED
@@ -2,10 +2,9 @@
2
2
 
3
3
  **IN DEV**
4
4
 
5
- ## What's new **0.3.0**
5
+ ## What's new **0.4.0**
6
6
 
7
- * Class `YATelegramBot::TelegramAPI::User`.
8
- * Class `YATelegramBot::TelegramAPI::Chat`.
7
+ * `#send_photo` method on `Base`, `User`, `Chat`
9
8
 
10
9
  ## Usage
11
10
 
@@ -43,6 +42,9 @@ user.send_text text: '*hey hey!*',
43
42
  chat = Bot.updates[0].chat
44
43
  chat.send_text text: "Hi, #{chat.type == :private ? 'dude' : 'all'}!"
45
44
 
45
+ # send photo
46
+ user.send_photo file: File.new('my_awesome_photo.png'), caption: 'awesome photo'
47
+
46
48
  ```
47
49
 
48
50
  ## Contributing
@@ -53,6 +53,24 @@ module YATelegramBot
53
53
  response['ok'] && Message.new(response['result'], self)
54
54
  end
55
55
 
56
+ #
57
+ # send photo message to user.
58
+ #
59
+ # required params:
60
+ # * :chat [Fixnum] id of chat
61
+ # * :file [File] your photo
62
+ #
63
+ # additional params:
64
+ # * :caption [String] caption for your photo
65
+ # * :reply_to [Fixnum] id of message you reply
66
+ #
67
+ def send_photo(params = {})
68
+ response = send_api_request 'sendPhoto',
69
+ params_for_sending_photo(params)
70
+
71
+ response['ok'] && Message.new(response['result'], self)
72
+ end
73
+
56
74
  private
57
75
 
58
76
  def params_for_sending_text(params)
@@ -68,8 +86,22 @@ module YATelegramBot
68
86
  result
69
87
  end
70
88
 
89
+ def params_for_sending_photo(params)
90
+ fail NoChatSpecified unless params[:chat]
91
+ fail NoFileSpecified unless params[:file] && params[:file].is_a?(File)
92
+
93
+ result = { chat_id: params[:chat],
94
+ photo: params[:file] }
95
+
96
+ result[:caption] = params[:caption] if params[:caption]
97
+ result[:reply_to_message_id] = params[:reply_to].to_i if params[:reply_to]
98
+
99
+ result
100
+ end
101
+
71
102
  def send_api_request(method, params = {})
72
103
  fail NoTokenSpecified unless defined?(@token)
104
+
73
105
  @telegram_api_url = 'https://api.telegram.org' unless defined? @telegram_api_url
74
106
  JSON.parse RestClient.post "#{@telegram_api_url}/#{@api_request_prefix}/#{method}",
75
107
  params
@@ -1,7 +1,8 @@
1
1
  module YATelegramBot
2
- class NoTokenSpecified; end
3
- class ResponseIsNotOk; end
4
- class NoChatSpecified; end
5
- class NoMessageSpecified; end
6
- class InitWithoutBot; end
2
+ class NoTokenSpecified < StandardError; end
3
+ class NoFileSpecified < StandardError; end
4
+ class ResponseIsNotOk < StandardError; end
5
+ class NoChatSpecified < StandardError; end
6
+ class NoMessageSpecified < StandardError; end
7
+ class InitWithoutBot < StandardError; end
7
8
  end
@@ -27,7 +27,7 @@ module YATelegramBot
27
27
  end
28
28
 
29
29
  #
30
- # uses bot to send text to this user.
30
+ # uses bot to send text to this chat.
31
31
  #
32
32
  # @param params [Hash] params for Base#send_text. This method will only set :chat to self[:id]
33
33
  #
@@ -37,6 +37,18 @@ module YATelegramBot
37
37
  params[:chat] = id
38
38
  @bot.send_text params
39
39
  end
40
+
41
+ #
42
+ # uses bot to send photo to this chat.
43
+ #
44
+ # @param params [Hash] params for Base#send_photo. This method will only set :chat to self[:id]
45
+ #
46
+ def send_photo(params = {})
47
+ fail InitWithoutBot unless @bot
48
+
49
+ params[:chat] = id
50
+ @bot.send_photo params
51
+ end
40
52
  end
41
53
  end
42
54
  end
@@ -49,6 +49,8 @@ module YATelegramBot
49
49
  # * :text [String]
50
50
  # * :as_plain_message [Boolean] default: true. If it's true, method won't set :reply_to parameter
51
51
  #
52
+ # TODO: what about files?
53
+ #
52
54
  # @example message.reply(text: 'Hi, *friend*!', markdown: true)
53
55
  #
54
56
  def reply(params = {})
@@ -35,6 +35,18 @@ module YATelegramBot
35
35
  params[:chat] = id
36
36
  @bot.send_text params
37
37
  end
38
+
39
+ #
40
+ # uses bot to send photo to this user.
41
+ #
42
+ # @param params [Hash] params for Base#send_photo. This method will only set :chat to self[:id]
43
+ #
44
+ def send_photo(params = {})
45
+ fail InitWithoutBot unless @bot
46
+
47
+ params[:chat] = id
48
+ @bot.send_photo params
49
+ end
38
50
  end
39
51
  end
40
52
  end
@@ -1,3 +1,3 @@
1
1
  module YATelegramBot
2
- VERSION = '0.3.0'.freeze
2
+ VERSION = '0.4.0'.freeze
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ya_telegram_bot
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dmitriy Non