telegrammer 0.1.0 → 0.2.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: 01192345cd31357f67504923fbd3cb1933e99b4e
4
- data.tar.gz: a06447a0d0bde6d7d0f9cf03a09e0b51faba93a4
3
+ metadata.gz: fdc5d677c010ce352e77dff0485af04688cd6937
4
+ data.tar.gz: ecaaf9602bf7bc7912e1fd0665d088f0773e8b61
5
5
  SHA512:
6
- metadata.gz: d8d582a1eb2c96034917e98133a7b8eae71ef67dc6e63582fdaefbd5500cf9b1637fd097760f5b2907b0b0a566f11484decad6f9e801d7710dd5929ac607445a
7
- data.tar.gz: d3e478e64f1bca7af8eae29785abcb9fe04df2dd8f482e6f1e03e11a20b0b3c74663d63e87f378939a033cc0c3bc50a0155219e1fc1ff3b21d618c67ae53b475
6
+ metadata.gz: 6bc3a0bb233f5fc8c1255cae7a3087442f5ec4fa930da8b8840163f3c9e73582d741bd8c0f403b114f7a954cfa658a356be75adffaff805ca5e980b15df58bb8
7
+ data.tar.gz: 6af421ebee380d692566e26cac7857de19b8be19911022f8ac6c68315e98829fbe25823f2c7d0b6b8d8a9d47cd9785eff2ed5818ed01bd938003ad9f3c0e863b
data/CHANGELOG.md CHANGED
@@ -1,3 +1,8 @@
1
+ v0.2.0
2
+ ======
3
+
4
+ * Simplified internals for send operations to reuse as much as possible.
5
+
1
6
  v0.1.0
2
7
  ======
3
8
 
@@ -109,21 +109,12 @@ module Telegrammer
109
109
  #
110
110
  # @return [Telegrammer::DataTypes::Message] Message object sent to the user or group chat
111
111
  def send_message(params)
112
- params_validation = {
113
- chat_id: { required: true, class: [Fixnum] },
112
+ extra_params_validation = {
114
113
  text: { required: true, class: [String] },
115
- disable_web_page_preview: { required: false, class: [TrueClass, FalseClass] },
116
- reply_to_message_id: { required: false, class: [Fixnum] },
117
- reply_markup: { required: false, class: [
118
- Telegrammer::DataTypes::ReplyKeyboardMarkup,
119
- Telegrammer::DataTypes::ReplyKeyboardHide,
120
- Telegrammer::DataTypes::ForceReply,
121
- ]}
114
+ disable_web_page_preview: { required: false, class: [TrueClass, FalseClass] }
122
115
  }
123
116
 
124
- response = api_request("sendMessage", params, params_validation)
125
-
126
- Telegrammer::DataTypes::Message.new(response.result)
117
+ send_something(:message, params, extra_params_validation)
127
118
  end
128
119
 
129
120
  # Forward message to a user or group chat.
@@ -178,21 +169,12 @@ module Telegrammer
178
169
  # @see #send_document
179
170
  # @return [Telegrammer::DataTypes::Message] Message object sent to the user or group chat
180
171
  def send_photo(params)
181
- params_validation = {
182
- chat_id: { required: true, class: [Fixnum] },
183
- photo: { required: true, class: [File, String] },
184
- caption: { required: false, class: [String] },
185
- reply_to_message_id: { required: false, class: [String] },
186
- reply_markup: { required: false, class: [
187
- Telegrammer::DataTypes::ReplyKeyboardMarkup,
188
- Telegrammer::DataTypes::ReplyKeyboardHide,
189
- Telegrammer::DataTypes::ForceReply,
190
- ]}
172
+ extra_params_validation = {
173
+ photo: { required: false, class: [File, String] },
174
+ caption: { required: false, class: [String] }
191
175
  }
192
176
 
193
- response = api_request("sendPhoto", params, params_validation)
194
-
195
- Telegrammer::DataTypes::Message.new(response.result)
177
+ send_something(:photo, params, extra_params_validation)
196
178
  end
197
179
 
198
180
  # Sends audio file to a user or group chat.
@@ -216,20 +198,11 @@ module Telegrammer
216
198
  # @see #send_document
217
199
  # @return [Telegrammer::DataTypes::Message] Message object sent to the user or group chat
218
200
  def send_audio(params)
219
- params_validation = {
220
- chat_id: { required: true, class: [Fixnum] },
221
- audio: { required: true, class: [File, String] },
222
- reply_to_message_id: { required: false, class: [String] },
223
- reply_markup: { required: false, class: [
224
- Telegrammer::DataTypes::ReplyKeyboardMarkup,
225
- Telegrammer::DataTypes::ReplyKeyboardHide,
226
- Telegrammer::DataTypes::ForceReply,
227
- ]}
201
+ extra_params_validation = {
202
+ audio: { required: false, class: [File, String] }
228
203
  }
229
204
 
230
- response = api_request("sendAudio", params, params_validation)
231
-
232
- Telegrammer::DataTypes::Message.new(response.result)
205
+ send_something(:audio, params, extra_params_validation)
233
206
  end
234
207
 
235
208
  # Sends a document to a user or group chat.
@@ -250,20 +223,11 @@ module Telegrammer
250
223
  #
251
224
  # @return [Telegrammer::DataTypes::Message] Message object sent to the user or group chat
252
225
  def send_document(params)
253
- params_validation = {
254
- chat_id: { required: true, class: [Fixnum] },
255
- document: { required: false, class: [File, String] },
256
- reply_to_message_id: { required: false, class: [String] },
257
- reply_markup: { required: false, class: [
258
- Telegrammer::DataTypes::ReplyKeyboardMarkup,
259
- Telegrammer::DataTypes::ReplyKeyboardHide,
260
- Telegrammer::DataTypes::ForceReply,
261
- ]}
226
+ extra_params_validation = {
227
+ document: { required: false, class: [File, String] }
262
228
  }
263
229
 
264
- response = api_request("sendDocument", params, params_validation)
265
-
266
- Telegrammer::DataTypes::Message.new(response.result)
230
+ send_something(:document, params, extra_params_validation)
267
231
  end
268
232
 
269
233
  # Send WebP images as stickers.
@@ -285,20 +249,11 @@ module Telegrammer
285
249
  # @see #send_document
286
250
  # @return [Telegrammer::DataTypes::Message] Message object sent to the user or group chat
287
251
  def send_sticker(params)
288
- params_validation = {
289
- chat_id: { required: true, class: [Fixnum] },
290
- sticker: { required: true, class: [File, String] },
291
- reply_to_message_id: { required: false, class: [String] },
292
- reply_markup: { required: false, class: [
293
- Telegrammer::DataTypes::ReplyKeyboardMarkup,
294
- Telegrammer::DataTypes::ReplyKeyboardHide,
295
- Telegrammer::DataTypes::ForceReply,
296
- ]}
252
+ extra_params_validation = {
253
+ sticker: { required: true, class: [File, String] }
297
254
  }
298
255
 
299
- response = api_request("sendSticker", params, params_validation)
300
-
301
- Telegrammer::DataTypes::Message.new(response.result)
256
+ send_something(:sticker, params, extra_params_validation)
302
257
  end
303
258
 
304
259
  # Sends a video file to a user or group chat.
@@ -322,20 +277,11 @@ module Telegrammer
322
277
  # @see #send_document
323
278
  # @return [Telegrammer::DataTypes::Message] Message object sent to the user or group chat
324
279
  def send_video(params)
325
- params_validation = {
326
- chat_id: { required: true, class: [Fixnum] },
327
- video: { required: true, class: [File, String] },
328
- reply_to_message_id: { required: false, class: [String] },
329
- reply_markup: { required: false, class: [
330
- Telegrammer::DataTypes::ReplyKeyboardMarkup,
331
- Telegrammer::DataTypes::ReplyKeyboardHide,
332
- Telegrammer::DataTypes::ForceReply,
333
- ]}
280
+ extra_params_validation = {
281
+ video: { required: true, class: [File, String] }
334
282
  }
335
283
 
336
- response = api_request("sendVideo", params, params_validation)
337
-
338
- Telegrammer::DataTypes::Message.new(response.result)
284
+ send_something(:video, params, extra_params_validation)
339
285
  end
340
286
 
341
287
  # Sends point on the map to a user or group chat.
@@ -356,21 +302,12 @@ module Telegrammer
356
302
  #
357
303
  # @return [Telegrammer::DataTypes::Message] Message object sent to the user or group chat
358
304
  def send_location(params)
359
- params_validation = {
360
- chat_id: { required: true, class: [Fixnum] },
305
+ extra_params_validation = {
361
306
  latitude: { required: true, class: [Float] },
362
- longitude: { required: true, class: [Float] },
363
- reply_to_message_id: { required: false, class: [String] },
364
- reply_markup: { required: false, class: [
365
- Telegrammer::DataTypes::ReplyKeyboardMarkup,
366
- Telegrammer::DataTypes::ReplyKeyboardHide,
367
- Telegrammer::DataTypes::ForceReply,
368
- ]}
307
+ longitude: { required: true, class: [Float] }
369
308
  }
370
309
 
371
- response = api_request("sendLocation", params, params_validation)
372
-
373
- Telegrammer::DataTypes::Message.new(response.result)
310
+ send_something(:location, params, extra_params_validation)
374
311
  end
375
312
 
376
313
  # Sends a status action to a user or group chat.
@@ -470,5 +407,21 @@ module Telegrammer
470
407
 
471
408
  ApiResponse.new(response)
472
409
  end
410
+
411
+ def send_something(object_kind, params, extra_params_validation = {})
412
+ params_validation = {
413
+ chat_id: { required: true, class: [Fixnum] },
414
+ reply_to_message_id: { required: false, class: [String] },
415
+ reply_markup: { required: false, class: [
416
+ Telegrammer::DataTypes::ReplyKeyboardMarkup,
417
+ Telegrammer::DataTypes::ReplyKeyboardHide,
418
+ Telegrammer::DataTypes::ForceReply,
419
+ ]}
420
+ }
421
+
422
+ response = api_request("send#{object_kind.to_s.capitalize}", params, extra_params_validation.merge(params_validation))
423
+
424
+ Telegrammer::DataTypes::Message.new(response.result)
425
+ end
473
426
  end
474
427
  end
@@ -1,3 +1,3 @@
1
1
  module Telegrammer
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: telegrammer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Luis Mayoral
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-06-28 00:00:00.000000000 Z
11
+ date: 2015-06-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: typhoeus