telerb 0.1.1 → 0.1.2

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
  SHA256:
3
- metadata.gz: 2eb70663a11c93169a9b1499a8a4c6a2290d4482fc022fd495bf3cc8eb4f05d8
4
- data.tar.gz: 6df1d4ed6f24f4fc33245f8593f1eca7c15ab442ef9b94d23d6d5e8126b7f61b
3
+ metadata.gz: 964e045af44fde247f3ea066345633b07deec2e907458fb01964bb7ef1b00d06
4
+ data.tar.gz: 129d9502dce5ca0bb59f285e08d56e0f05c8a2fad8cea44b5dc68a0550a5b17d
5
5
  SHA512:
6
- metadata.gz: 76b8dea62d0519a382fd14d020d619b9f42d471246b452a9918173ac669add4c396338167b719f81848a7305c899b6b413830b6f3c2a082fac47011bf5c5f6ba
7
- data.tar.gz: f4a7ac3d109cac951537ff5e330cc598daaf270cc8026e8a40c779d2ae1a204f50322308e45ec568bdb289cbe6f7c98fa4d0966928919982db9efe236cb64ac5
6
+ metadata.gz: 99b367e66da11237a96803259beb804f9ede27b3c8878d04540312fd1a6729bf725ee322c85865fc7a573e97be4c290ff7e9e9202c1945f66cab9458f777d4d1
7
+ data.tar.gz: 7fa9aac46a5aac79af2af8af27f5ff79e30b20b8f513d0e19efb19905a4e70323cff3749a372076dad3b87b92f9903d10c85ab8cfff496b4151b207feaddc4ba
data/CHANGELOG.md CHANGED
@@ -3,3 +3,15 @@
3
3
  ## [0.1.0] - 2024-04-06
4
4
 
5
5
  - Initial release
6
+
7
+ ## [0.1.1] - 2024-04-07
8
+
9
+ - Implement the photo sending method
10
+
11
+ - Improvements to the http service
12
+
13
+ ## [0.1.2] - 2024-04-07
14
+
15
+ - Add error handling to methods
16
+ - Implements The Audio, Video, Document sending method
17
+ - Improvement in media delivery Service
data/README.md CHANGED
@@ -30,6 +30,12 @@ bot.listen do |message|
30
30
  bot.send_message(chat_id, 'Hello World', message_id)
31
31
  # Send a Photo
32
32
  bot.send_photo(chat_id, "./exemple.png", "test", message_id)
33
+ # Send Document
34
+ bot.send_document(chat_id, "./exemple.rar", "test", message_id)
35
+ # Send Audio
36
+ bot.send_audio(chat_id, "./exemple.mp3", "test", message_id)
37
+ # Send Video
38
+ bot.send_video(chat_id, "./exemple.mp4", "test", message_id)
33
39
  end
34
40
  ```
35
41
  The ***message_id*** parameter is only necessary if you want the message to be sent as a reply.
@@ -50,4 +56,4 @@ The gem is available as open source under the terms of the [MIT License](https:/
50
56
 
51
57
  ## Code of Conduct
52
58
 
53
- Everyone interacting in the TelegrambotRuby project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/codebyallan/TeleRb/blob/master/CODE_OF_CONDUCT.md).
59
+ Everyone interacting in the TeleRb project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/codebyallan/TeleRb/blob/master/CODE_OF_CONDUCT.md).
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module TeleRb
4
- VERSION = "0.1.1"
4
+ VERSION = "0.1.2"
5
5
  end
data/lib/telerb.rb CHANGED
@@ -24,31 +24,63 @@ module TeleRb
24
24
  block.call update["message"] if block_given? && update["message"]
25
25
  @offset = update["update_id"] + 1
26
26
  end
27
- sleep 2
27
+ rescue StandardError => e
28
+ puts "Error in listen method: #{e.message}"
28
29
  end
30
+ sleep 2
29
31
  end
30
32
 
31
33
  def send_message(chat_id, text, reply_to_message_id = nil)
32
- response = CLIENT.post("#{@base_uri}#{@token}/sendMessage",
33
- { chat_id: chat_id, text: text, reply_to_message_id: reply_to_message_id })
34
- response.parsed_response
34
+ CLIENT.post("#{@base_uri}#{@token}/sendMessage",
35
+ { chat_id: chat_id, text: text, reply_to_message_id: reply_to_message_id })
36
+ "Message sent successfully!"
37
+ rescue StandardError => e
38
+ puts "Error sending message: #{e.message}"
39
+ nil
35
40
  end
36
41
 
37
42
  def send_photo(chat_id, photo_path, caption = nil, reply_to_message_id = nil)
38
- response = CLIENT.post("#{@base_uri}#{@token}/sendPhoto",
39
- {
40
- chat_id: chat_id,
41
- reply_to_message_id: reply_to_message_id,
42
- photo: File.new(photo_path, "rb"),
43
- caption: caption
44
- },
45
- { "Content-Type" => "multipart/form-data" })
46
- response.parsed_response
43
+ send_media(chat_id, photo_path, caption, reply_to_message_id, "sendPhoto", :photo)
44
+ end
45
+
46
+ def send_audio(chat_id, audio_path, caption = nil, reply_to_message_id = nil)
47
+ send_media(chat_id, audio_path, caption, reply_to_message_id, "sendAudio", :audio)
48
+ end
49
+
50
+ def send_video(chat_id, video_path, caption = nil, reply_to_message_id = nil)
51
+ send_media(chat_id, video_path, caption, reply_to_message_id, "sendVideo", :video)
52
+ end
53
+
54
+ def send_document(chat_id, document_path, caption = nil, reply_to_message_id = nil)
55
+ send_media(chat_id, document_path, caption, reply_to_message_id, "sendDocument", :document)
56
+ end
57
+
58
+ private
59
+
60
+ def send_media(chat_id, media_path, caption = nil, reply_to_message_id = nil, method, filekey)
61
+ raise ArgumentError, "Invalid media type: {#{filekey.capitalize}" unless %i[photo audio video
62
+ document].include?(filekey)
63
+
64
+ CLIENT.post("#{@base_uri}#{@token}/#{method}",
65
+ {
66
+ chat_id: chat_id,
67
+ reply_to_message_id: reply_to_message_id,
68
+ filekey.to_sym => File.new(media_path, "rb"),
69
+ caption: caption
70
+ },
71
+ { "Content-Type" => "multipart/form-data" })
72
+ "#{filekey.capitalize} Sent with success!"
73
+ rescue StandardError => e
74
+ puts "Error when sending #{filekey.capitalize}: #{e.message}"
75
+ nil
47
76
  end
48
77
 
49
78
  def get_updates(offset = nil)
50
79
  response = CLIENT.get("#{@base_uri}#{@token}/getUpdates", { offset: offset })
51
80
  response.parsed_response["result"]
81
+ rescue StandardError => e
82
+ puts "Error in get_updates method: #{e.message}"
83
+ []
52
84
  end
53
85
  end
54
86
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: telerb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - CodeByAllan