telerb 0.1.3 → 0.1.5

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
  SHA256:
3
- metadata.gz: f3db2e928c39d62a55c8d9a16bf1b1d6efe3f3022acb0e516ae8f62cc317aa68
4
- data.tar.gz: 27f16654ae9420a8369d2beec14199c225139eac7dd8adccb46387e4cd1bb4f1
3
+ metadata.gz: 368a13df3fb8d9be794e4c1a1ef14e457b01db5f144c2962a344e93d70bf3921
4
+ data.tar.gz: c6117a352b1c0521704ac7ad4abe17149a8018924da52c1197edc2467e80041d
5
5
  SHA512:
6
- metadata.gz: be06d05d8992bc2fbd85b6589db0b7728d88dfd2e4d177f54d2224b18f2782dd038522083868fb0855bb0b36ee9387fcb69cdfcdefc448e3ad958fe3fbae7c53
7
- data.tar.gz: fbd917d08644cdaab74b525f1d96004cb901247d491bda396017805cfdaa522d8712b26a76e163b1d055e43bcfcf395a9046d7cc6b81fc817a5a6b410f78fa16
6
+ metadata.gz: 6707df98472e8704e0e6b92be7bf82b022ef38a82dc110966b0c651bab0acbb053f9a7754dd413d71c8edcf2bd8d9e6dd95a35599b1d6f9a9597cb28b4b529e6
7
+ data.tar.gz: c9b863b42643770bfe5244c9cd3ef2bb8bb97012791ab5d80605cd4556dfe2e181a99ffe67c6479d4f4e8fb81c67a3d7957a7428197b73be5b7b2b856092d9b5
data/.rspec CHANGED
@@ -1,3 +1,3 @@
1
- --format documentation
2
- --color
3
- --require spec_helper
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.rubocop.yml CHANGED
@@ -1,9 +1,9 @@
1
- AllCops:
2
- TargetRubyVersion: 3.0
3
- NewCops: enable
4
-
5
- Style/StringLiterals:
6
- EnforcedStyle: double_quotes
7
-
8
- Style/StringLiteralsInInterpolation:
9
- EnforcedStyle: double_quotes
1
+ AllCops:
2
+ TargetRubyVersion: 3.0
3
+ NewCops: enable
4
+
5
+ Style/StringLiterals:
6
+ EnforcedStyle: double_quotes
7
+
8
+ Style/StringLiteralsInInterpolation:
9
+ EnforcedStyle: double_quotes
data/.ruby-version CHANGED
@@ -1,2 +1,2 @@
1
- # .ruby-version
1
+ # .ruby-version
2
2
  3.2.3
data/CHANGELOG.md CHANGED
@@ -1,21 +1,29 @@
1
- ## [Unreleased]
2
-
3
- ## [0.1.0] - 2024-04-06
4
-
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
18
-
19
- ## [0.1.3] - 2024-04-08
20
-
21
- - Implement the methods to define the commands and obtain the defined commands
1
+ ## [Unreleased]
2
+
3
+ ## [0.1.0] - 2024-04-06
4
+
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
18
+
19
+ ## [0.1.3] - 2024-04-08
20
+
21
+ - Implement the methods to define the commands and obtain the defined commands
22
+
23
+ ## [0.1.4] - 2024-04-09
24
+
25
+ - Implements the forwardMessage method
26
+
27
+ ## [0.1.5] - 2024-04-10
28
+
29
+ - Implement the method to obtain information from a user
data/CODE_OF_CONDUCT.md CHANGED
@@ -1,84 +1,84 @@
1
- # Contributor Covenant Code of Conduct
2
-
3
- ## Our Pledge
4
-
5
- We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone, regardless of age, body size, visible or invisible disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion, or sexual identity and orientation.
6
-
7
- We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and healthy community.
8
-
9
- ## Our Standards
10
-
11
- Examples of behavior that contributes to a positive environment for our community include:
12
-
13
- * Demonstrating empathy and kindness toward other people
14
- * Being respectful of differing opinions, viewpoints, and experiences
15
- * Giving and gracefully accepting constructive feedback
16
- * Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience
17
- * Focusing on what is best not just for us as individuals, but for the overall community
18
-
19
- Examples of unacceptable behavior include:
20
-
21
- * The use of sexualized language or imagery, and sexual attention or
22
- advances of any kind
23
- * Trolling, insulting or derogatory comments, and personal or political attacks
24
- * Public or private harassment
25
- * Publishing others' private information, such as a physical or email
26
- address, without their explicit permission
27
- * Other conduct which could reasonably be considered inappropriate in a
28
- professional setting
29
-
30
- ## Enforcement Responsibilities
31
-
32
- Community leaders are responsible for clarifying and enforcing our standards of acceptable behavior and will take appropriate and fair corrective action in response to any behavior that they deem inappropriate, threatening, offensive, or harmful.
33
-
34
- Community leaders have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, and will communicate reasons for moderation decisions when appropriate.
35
-
36
- ## Scope
37
-
38
- This Code of Conduct applies within all community spaces, and also applies when an individual is officially representing the community in public spaces. Examples of representing our community include using an official e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event.
39
-
40
- ## Enforcement
41
-
42
- Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at allan.pereira.dev@proton.me. All complaints will be reviewed and investigated promptly and fairly.
43
-
44
- All community leaders are obligated to respect the privacy and security of the reporter of any incident.
45
-
46
- ## Enforcement Guidelines
47
-
48
- Community leaders will follow these Community Impact Guidelines in determining the consequences for any action they deem in violation of this Code of Conduct:
49
-
50
- ### 1. Correction
51
-
52
- **Community Impact**: Use of inappropriate language or other behavior deemed unprofessional or unwelcome in the community.
53
-
54
- **Consequence**: A private, written warning from community leaders, providing clarity around the nature of the violation and an explanation of why the behavior was inappropriate. A public apology may be requested.
55
-
56
- ### 2. Warning
57
-
58
- **Community Impact**: A violation through a single incident or series of actions.
59
-
60
- **Consequence**: A warning with consequences for continued behavior. No interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, for a specified period of time. This includes avoiding interactions in community spaces as well as external channels like social media. Violating these terms may lead to a temporary or permanent ban.
61
-
62
- ### 3. Temporary Ban
63
-
64
- **Community Impact**: A serious violation of community standards, including sustained inappropriate behavior.
65
-
66
- **Consequence**: A temporary ban from any sort of interaction or public communication with the community for a specified period of time. No public or private interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, is allowed during this period. Violating these terms may lead to a permanent ban.
67
-
68
- ### 4. Permanent Ban
69
-
70
- **Community Impact**: Demonstrating a pattern of violation of community standards, including sustained inappropriate behavior, harassment of an individual, or aggression toward or disparagement of classes of individuals.
71
-
72
- **Consequence**: A permanent ban from any sort of public interaction within the community.
73
-
74
- ## Attribution
75
-
76
- This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 2.0,
77
- available at https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
78
-
79
- Community Impact Guidelines were inspired by [Mozilla's code of conduct enforcement ladder](https://github.com/mozilla/diversity).
80
-
81
- [homepage]: https://www.contributor-covenant.org
82
-
83
- For answers to common questions about this code of conduct, see the FAQ at
84
- https://www.contributor-covenant.org/faq. Translations are available at https://www.contributor-covenant.org/translations.
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone, regardless of age, body size, visible or invisible disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion, or sexual identity and orientation.
6
+
7
+ We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and healthy community.
8
+
9
+ ## Our Standards
10
+
11
+ Examples of behavior that contributes to a positive environment for our community include:
12
+
13
+ * Demonstrating empathy and kindness toward other people
14
+ * Being respectful of differing opinions, viewpoints, and experiences
15
+ * Giving and gracefully accepting constructive feedback
16
+ * Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience
17
+ * Focusing on what is best not just for us as individuals, but for the overall community
18
+
19
+ Examples of unacceptable behavior include:
20
+
21
+ * The use of sexualized language or imagery, and sexual attention or
22
+ advances of any kind
23
+ * Trolling, insulting or derogatory comments, and personal or political attacks
24
+ * Public or private harassment
25
+ * Publishing others' private information, such as a physical or email
26
+ address, without their explicit permission
27
+ * Other conduct which could reasonably be considered inappropriate in a
28
+ professional setting
29
+
30
+ ## Enforcement Responsibilities
31
+
32
+ Community leaders are responsible for clarifying and enforcing our standards of acceptable behavior and will take appropriate and fair corrective action in response to any behavior that they deem inappropriate, threatening, offensive, or harmful.
33
+
34
+ Community leaders have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, and will communicate reasons for moderation decisions when appropriate.
35
+
36
+ ## Scope
37
+
38
+ This Code of Conduct applies within all community spaces, and also applies when an individual is officially representing the community in public spaces. Examples of representing our community include using an official e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event.
39
+
40
+ ## Enforcement
41
+
42
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at allan.pereira.dev@proton.me. All complaints will be reviewed and investigated promptly and fairly.
43
+
44
+ All community leaders are obligated to respect the privacy and security of the reporter of any incident.
45
+
46
+ ## Enforcement Guidelines
47
+
48
+ Community leaders will follow these Community Impact Guidelines in determining the consequences for any action they deem in violation of this Code of Conduct:
49
+
50
+ ### 1. Correction
51
+
52
+ **Community Impact**: Use of inappropriate language or other behavior deemed unprofessional or unwelcome in the community.
53
+
54
+ **Consequence**: A private, written warning from community leaders, providing clarity around the nature of the violation and an explanation of why the behavior was inappropriate. A public apology may be requested.
55
+
56
+ ### 2. Warning
57
+
58
+ **Community Impact**: A violation through a single incident or series of actions.
59
+
60
+ **Consequence**: A warning with consequences for continued behavior. No interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, for a specified period of time. This includes avoiding interactions in community spaces as well as external channels like social media. Violating these terms may lead to a temporary or permanent ban.
61
+
62
+ ### 3. Temporary Ban
63
+
64
+ **Community Impact**: A serious violation of community standards, including sustained inappropriate behavior.
65
+
66
+ **Consequence**: A temporary ban from any sort of interaction or public communication with the community for a specified period of time. No public or private interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, is allowed during this period. Violating these terms may lead to a permanent ban.
67
+
68
+ ### 4. Permanent Ban
69
+
70
+ **Community Impact**: Demonstrating a pattern of violation of community standards, including sustained inappropriate behavior, harassment of an individual, or aggression toward or disparagement of classes of individuals.
71
+
72
+ **Consequence**: A permanent ban from any sort of public interaction within the community.
73
+
74
+ ## Attribution
75
+
76
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 2.0,
77
+ available at https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
78
+
79
+ Community Impact Guidelines were inspired by [Mozilla's code of conduct enforcement ladder](https://github.com/mozilla/diversity).
80
+
81
+ [homepage]: https://www.contributor-covenant.org
82
+
83
+ For answers to common questions about this code of conduct, see the FAQ at
84
+ https://www.contributor-covenant.org/faq. Translations are available at https://www.contributor-covenant.org/translations.
data/LICENSE.txt CHANGED
@@ -1,21 +1,21 @@
1
- The MIT License (MIT)
2
-
3
- Copyright (c) 2024 CodeByAllan
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in
13
- all copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
- THE SOFTWARE.
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2024 CodeByAllan
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md CHANGED
@@ -1,83 +1,101 @@
1
- # TeleRb
2
-
3
- Minimalist Telegram bot library for ruby
4
-
5
- ## Installation
6
-
7
- Install the gem and add to the application's Gemfile by executing:
8
-
9
- $ bundle add telerb
10
-
11
- If bundler is not being used to manage dependencies, install the gem by executing:
12
-
13
- $ gem install telerb
14
-
15
- ## Usage
16
-
17
- ### Initialize Bot
18
-
19
- ```
20
-
21
- require 'telerb'
22
-
23
- # Create a bot instance
24
- bot = TeleRb::TelegramBot.new
25
- bot.config('YOUR_TOKEN')
26
-
27
- # Initialize bot
28
- bot.listen do |message|
29
- chat_id = message['chat']['id']
30
- message_id = message['message_id']
31
- # Send a text message
32
- bot.send_message(chat_id, 'Hello World', message_id)
33
- end
34
-
35
- ```
36
- The ***message_id*** parameter is only necessary if you want the message to be sent as a reply.
37
-
38
- ### Send Medias
39
- ```
40
-
41
- # Send a Photo
42
- bot.send_photo(chat_id, "./exemple.png", "test", message_id)
43
- # Send Document
44
- bot.send_document(chat_id, "./exemple.rar", "test", message_id)
45
- # Send Audio
46
- bot.send_audio(chat_id, "./exemple.mp3", "test", message_id)
47
- # Send Video
48
- bot.send_video(chat_id, "./exemple.mp4", "test", message_id)
49
-
50
- ```
51
- ### Commands
52
- ```
53
-
54
- COMMANDS = [
55
- { command: "/start", description: "Start bot" },
56
- { command: "/help", description: "Show command list" }
57
- ].freeze
58
-
59
- # Method that records bot commands
60
- bot.set_commands(COMMANDS)
61
-
62
- # Method that returns the available commands
63
- bot.get_commands
64
-
65
- ```
66
-
67
- ## Development
68
-
69
- After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
70
-
71
- To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
72
-
73
- ## Contributing
74
-
75
- Bug reports and pull requests are welcome on GitHub at https://github.com/codebyallan/TeleRb. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/codebyallan/TeleRb/blob/master/CODE_OF_CONDUCT.md).
76
-
77
- ## License
78
-
79
- The gem is available as open source under the terms of the [MIT License](https://github.com/CodeByAllan/TeleRb/blob/master/LICENSE.txt).
80
-
81
- ## Code of Conduct
82
-
83
- 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
+ # TeleRb
2
+
3
+ Minimalist Telegram bot library for ruby
4
+
5
+ ## Installation
6
+
7
+ Install the gem and add to the application's Gemfile by executing:
8
+
9
+ $ bundle add telerb
10
+
11
+ If bundler is not being used to manage dependencies, install the gem by executing:
12
+
13
+ $ gem install telerb
14
+
15
+ ## Usage
16
+
17
+ ### Initialize Bot
18
+
19
+ ```
20
+
21
+ require 'telerb'
22
+
23
+ # Create a bot instance
24
+ bot = TeleRb::TelegramBot.new
25
+ bot.config('YOUR_TOKEN')
26
+
27
+ # Initialize bot
28
+ bot.listen do |message|
29
+ chat_id = message['chat']['id']
30
+ message_id = message['message_id']
31
+ # Send a text message
32
+ bot.send_message(chat_id, 'Hello World', message_id)
33
+ end
34
+
35
+ ```
36
+ The ***message_id*** parameter is only necessary if you want the message to be sent as a reply.
37
+
38
+ ### Send Medias
39
+ ```
40
+
41
+ # Send a Photo
42
+ bot.send_photo(chat_id, "./exemple.png", "test", message_id)
43
+ # Send Document
44
+ bot.send_document(chat_id, "./exemple.rar", "test", message_id)
45
+ # Send Audio
46
+ bot.send_audio(chat_id, "./exemple.mp3", "test", message_id)
47
+ # Send Video
48
+ bot.send_video(chat_id, "./exemple.mp4", "test", message_id)
49
+
50
+ ```
51
+ ### Commands
52
+ ```
53
+
54
+ COMMANDS = [
55
+ { command: "/start", description: "Start bot" },
56
+ { command: "/help", description: "Show command list" }
57
+ ].freeze
58
+
59
+ # Method that records bot commands
60
+ bot.set_commands(COMMANDS)
61
+
62
+ # Method that returns the available commands
63
+ bot.get_commands
64
+
65
+ ```
66
+
67
+ ### Forward Message
68
+
69
+ ```
70
+
71
+ # Method for forwarding a message from one chat to another
72
+ bot.forward_message(from_chat_id, to_chat_id, message_id)
73
+
74
+ ```
75
+
76
+ ### Get User Info
77
+
78
+ ```
79
+
80
+ # Method to obtain information from a user
81
+ bot.user_info(message)
82
+
83
+ ```
84
+
85
+ ## Development
86
+
87
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
88
+
89
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
90
+
91
+ ## Contributing
92
+
93
+ Bug reports and pull requests are welcome on GitHub at https://github.com/codebyallan/TeleRb. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/codebyallan/TeleRb/blob/master/CODE_OF_CONDUCT.md).
94
+
95
+ ## License
96
+
97
+ The gem is available as open source under the terms of the [MIT License](https://github.com/CodeByAllan/TeleRb/blob/master/LICENSE.txt).
98
+
99
+ ## Code of Conduct
100
+
101
+ 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).
data/Rakefile CHANGED
@@ -1,12 +1,12 @@
1
- # frozen_string_literal: true
2
-
3
- require "bundler/gem_tasks"
4
- require "rspec/core/rake_task"
5
-
6
- RSpec::Core::RakeTask.new(:spec)
7
-
8
- require "rubocop/rake_task"
9
-
10
- RuboCop::RakeTask.new
11
-
12
- task default: %i[spec rubocop]
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rspec/core/rake_task"
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ require "rubocop/rake_task"
9
+
10
+ RuboCop::RakeTask.new
11
+
12
+ task default: %i[spec rubocop]
@@ -1,14 +1,14 @@
1
- # frozen_string_literal: true
2
-
3
- require "httparty"
4
- # Class responsability for http services
5
- class HttpClient
6
- include HTTParty
7
- def get(url, options = nil)
8
- self.class.get(url, query: options)
9
- end
10
-
11
- def post(url, options, headers = nil)
12
- self.class.post(url, body: options, headers: headers)
13
- end
14
- end
1
+ # frozen_string_literal: true
2
+
3
+ require "httparty"
4
+ # Class responsability for http services
5
+ class HttpClient
6
+ include HTTParty
7
+ def get(url, options = nil)
8
+ self.class.get(url, query: options)
9
+ end
10
+
11
+ def post(url, options, headers = nil)
12
+ self.class.post(url, body: options, headers: headers)
13
+ end
14
+ end
@@ -1,5 +1,5 @@
1
- # frozen_string_literal: true
2
-
3
- module TeleRb
4
- VERSION = "0.1.3"
5
- end
1
+ # frozen_string_literal: true
2
+
3
+ module TeleRb
4
+ VERSION = "0.1.5"
5
+ end
data/lib/telerb.rb CHANGED
@@ -1,103 +1,116 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative "telerb/version"
4
- require_relative "telerb/http_client"
5
-
6
- module TeleRb
7
- CLIENT = HttpClient.new
8
- # class telegram bot
9
- class TelegramBot
10
- def initialize
11
- @token = nil
12
- @offset = nil
13
- @base_uri = "https://api.telegram.org/bot"
14
- end
15
-
16
- def config(token)
17
- @token = token
18
- end
19
-
20
- def listen(&block)
21
- loop do
22
- updates = get_updates(@offset)
23
- updates.each do |update|
24
- block.call update["message"] if block_given? && update["message"]
25
- @offset = update["update_id"] + 1
26
- end
27
- rescue StandardError => e
28
- puts "Error in listen method: #{e.message}"
29
- end
30
- sleep 2
31
- end
32
-
33
- def send_message(chat_id, text, reply_to_message_id = nil)
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
40
- end
41
-
42
- def send_photo(chat_id, photo_path, caption = nil, reply_to_message_id = nil)
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
- def get_commands
59
- response = CLIENT.get("#{@base_uri}#{@token}/getMyCommands")
60
- response.parsed_response["result"]
61
- rescue StandardError => e
62
- puts "Error getting list of defined commands: #{e.message}"
63
- nil
64
- end
65
-
66
- def set_commands(commands)
67
- CLIENT.post("#{@base_uri}#{@token}/setMyCommands", { commands: commands }.to_json,
68
- { "Content-Type" => "application/json" })
69
- "Commands set successfully"
70
- rescue StandardError => e
71
- puts "Error defining command list: #{e.message}"
72
- nil
73
- end
74
-
75
- private
76
-
77
- def send_media(chat_id, media_path, caption = nil, reply_to_message_id = nil, method, filekey)
78
- raise ArgumentError, "Invalid media type: {#{filekey.capitalize}" unless %i[photo audio video
79
- document].include?(filekey)
80
-
81
- CLIENT.post("#{@base_uri}#{@token}/#{method}",
82
- {
83
- chat_id: chat_id,
84
- reply_to_message_id: reply_to_message_id,
85
- filekey.to_sym => File.new(media_path, "rb"),
86
- caption: caption
87
- },
88
- { "Content-Type" => "multipart/form-data" })
89
- "#{filekey.capitalize} Sent with success!"
90
- rescue StandardError => e
91
- puts "Error when sending #{filekey.capitalize}: #{e.message}"
92
- nil
93
- end
94
-
95
- def get_updates(offset = nil)
96
- response = CLIENT.get("#{@base_uri}#{@token}/getUpdates", { offset: offset })
97
- response.parsed_response["result"]
98
- rescue StandardError => e
99
- puts "Error in get_updates method: #{e.message}"
100
- []
101
- end
102
- end
103
- end
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "telerb/version"
4
+ require_relative "telerb/http_client"
5
+
6
+ module TeleRb
7
+ CLIENT = HttpClient.new
8
+ # class telegram bot
9
+ class TelegramBot
10
+ def initialize
11
+ @token = nil
12
+ @offset = nil
13
+ @base_uri = "https://api.telegram.org/bot"
14
+ end
15
+
16
+ def config(token)
17
+ @token = token
18
+ end
19
+
20
+ def listen(&block)
21
+ loop do
22
+ updates = get_updates(@offset)
23
+ updates.each do |update|
24
+ block.call update["message"] if block_given? && update["message"]
25
+ @offset = update["update_id"] + 1
26
+ end
27
+ rescue StandardError => e
28
+ puts "Error in listen method: #{e.message}"
29
+ end
30
+ sleep 2
31
+ end
32
+
33
+ def send_message(chat_id, text, reply_to_message_id = nil)
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
40
+ end
41
+
42
+ def send_photo(chat_id, photo_path, caption = nil, reply_to_message_id = nil)
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
+ def get_commands
59
+ response = CLIENT.get("#{@base_uri}#{@token}/getMyCommands")
60
+ response.parsed_response["result"]
61
+ rescue StandardError => e
62
+ puts "Error getting list of defined commands: #{e.message}"
63
+ nil
64
+ end
65
+
66
+ def set_commands(commands)
67
+ CLIENT.post("#{@base_uri}#{@token}/setMyCommands", { commands: commands }.to_json,
68
+ { "Content-Type" => "application/json" })
69
+ "Commands set successfully"
70
+ rescue StandardError => e
71
+ puts "Error defining command list: #{e.message}"
72
+ nil
73
+ end
74
+
75
+ def forward_message(from_chat_id, to_chat_id, message_id)
76
+ CLIENT.post("#{@base_uri}#{@token}/forwardMessage",
77
+ { chat_id: to_chat_id, from_chat_id: from_chat_id, message_id: message_id })
78
+ "Forwarding was then done successfully!"
79
+ rescue StandardError => e
80
+ puts "Error forwarding message: #{e.message}"
81
+ nil
82
+ end
83
+
84
+ def user_info(message)
85
+ message["from"]
86
+ end
87
+
88
+ private
89
+
90
+ def send_media(chat_id, media_path, caption = nil, reply_to_message_id = nil, method, filekey)
91
+ raise ArgumentError, "Invalid media type: {#{filekey.capitalize}" unless %i[photo audio video
92
+ document].include?(filekey)
93
+
94
+ CLIENT.post("#{@base_uri}#{@token}/#{method}",
95
+ {
96
+ chat_id: chat_id,
97
+ reply_to_message_id: reply_to_message_id,
98
+ filekey.to_sym => File.new(media_path, "rb"),
99
+ caption: caption
100
+ },
101
+ { "Content-Type" => "multipart/form-data" })
102
+ "#{filekey.capitalize} Sent with success!"
103
+ rescue StandardError => e
104
+ puts "Error when sending #{filekey.capitalize}: #{e.message}"
105
+ nil
106
+ end
107
+
108
+ def get_updates(offset = nil)
109
+ response = CLIENT.get("#{@base_uri}#{@token}/getUpdates", { offset: offset })
110
+ response.parsed_response["result"]
111
+ rescue StandardError => e
112
+ puts "Error in get_updates method: #{e.message}"
113
+ []
114
+ end
115
+ end
116
+ end
data/sig/telerb.rbs CHANGED
@@ -1,4 +1,4 @@
1
- module TeleRb
2
- VERSION: String
3
- # See the writing guide of rbs: https://github.com/ruby/rbs#guides
4
- end
1
+ module TeleRb
2
+ VERSION: String
3
+ # See the writing guide of rbs: https://github.com/ruby/rbs#guides
4
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: telerb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - CodeByAllan
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-04-08 00:00:00.000000000 Z
11
+ date: 2024-04-11 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Ruby library to interact with the Telegram API and create custom bots.
14
14
  email:
@@ -37,7 +37,7 @@ metadata:
37
37
  source_code_uri: https://github.com/CodeByAllan/TeleRb
38
38
  changelog_uri: https://github.com/CodeByAllan/TeleRb/blob/master/CHANGELOG.md
39
39
  rubygems_mfa_required: 'true'
40
- post_install_message:
40
+ post_install_message:
41
41
  rdoc_options: []
42
42
  require_paths:
43
43
  - lib
@@ -52,8 +52,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
52
52
  - !ruby/object:Gem::Version
53
53
  version: '0'
54
54
  requirements: []
55
- rubygems_version: 3.5.7
56
- signing_key:
55
+ rubygems_version: 3.4.19
56
+ signing_key:
57
57
  specification_version: 4
58
58
  summary: Library to interact with the TelegramBot API using Ruby
59
59
  test_files: []