telegrama 0.1.3 → 0.2.0

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: a091a95e5e3a04865deef8b71ecf50da3f947026c0a1ad411d7d5827a5b6cc34
4
- data.tar.gz: 2029971f6180699d8efba99814ed5305103f23a52507f2b0be3a452c0e8f0f9a
3
+ metadata.gz: dc97c0b840468fc67d8be828329aa6b99df3f3a785c9b24ccdd5f508777ea4aa
4
+ data.tar.gz: 3e68d1a677c64f60efdef48c93d14925ba16286388031b6585c0a328f7466f8b
5
5
  SHA512:
6
- metadata.gz: '048dee76d2c78e1813abf08a19524388983edb40fee8a0f53f274d92aa37e8f032e0149cf3b0628edb24bc8e94a4d0428f96565570c2ac5ff30db52b7944ca6d'
7
- data.tar.gz: 1703bd66425bb79171a64626da8d08bad982f0d1536846c9bc2b215bd5e06e6c3086fe0366003ee1f5c5319c32e5e69fe22e368025eb99f776e43ed24936456d
6
+ metadata.gz: 85b746d44608935c125176f96c36216963d196b7665d3f5ecbd5b0855fd168d7979ed17f772d4a64ad728cf2a935373a7009a1a9c982d7d5de8bae90b4271e62
7
+ data.tar.gz: 3e0df23462571c09f43df2adaa38d68dcfd70476b87d02d5f7eb68a0163d180bc592f08869c092f3936922fea7542b0e8be2fe512ec485e7cef521e9f79f5d9b
data/.simplecov ADDED
@@ -0,0 +1,35 @@
1
+ # frozen_string_literal: true
2
+
3
+ # SimpleCov configuration file (auto-loaded before test suite)
4
+ # This keeps test_helper.rb clean and follows best practices
5
+
6
+ SimpleCov.start do
7
+ # Use SimpleFormatter for terminal-only output (no HTML generation)
8
+ formatter SimpleCov::Formatter::SimpleFormatter
9
+
10
+ # Track coverage for the lib directory (gem source code)
11
+ add_filter "/test/"
12
+
13
+ # Track the lib and app directories
14
+ track_files "{lib,app}/**/*.rb"
15
+
16
+ # Enable branch coverage for more detailed metrics
17
+ enable_coverage :branch
18
+
19
+ # Set minimum coverage threshold to prevent coverage regression
20
+ minimum_coverage line: 80, branch: 75
21
+
22
+ # Disambiguate parallel test runs
23
+ command_name "Job #{ENV['TEST_ENV_NUMBER']}" if ENV['TEST_ENV_NUMBER']
24
+ end
25
+
26
+ # Print coverage summary to terminal after tests complete
27
+ SimpleCov.at_exit do
28
+ SimpleCov.result.format!
29
+ puts "\n" + "=" * 60
30
+ puts "COVERAGE SUMMARY"
31
+ puts "=" * 60
32
+ puts "Line Coverage: #{SimpleCov.result.covered_percent.round(2)}%"
33
+ puts "Branch Coverage: #{SimpleCov.result.coverage_statistics[:branch]&.percent&.round(2) || 'N/A'}%"
34
+ puts "=" * 60
35
+ end
data/AGENTS.md ADDED
@@ -0,0 +1,5 @@
1
+ # AGENTS.md
2
+
3
+ This file provides guidance to AI Agents (like OpenAI's Codex, Cursor Agent, Claude Code, etc) when working with code in this repository.
4
+
5
+ Please go ahead and read the full context for this project at `.cursor/rules/0-overview.mdc` and `.cursor/rules/1-quality.mdc` now. Also read the README for a good overview of the project.
data/Appraisals ADDED
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Note: Rails < 7.2 is not compatible with Ruby 3.4
4
+ # (Logger became a bundled gem in Ruby 3.4, and only Rails 7.2+ handles this)
5
+ # See: https://stdgems.org/logger/
6
+
7
+ # Test against Rails 7.2 (minimum version compatible with Ruby 3.4)
8
+ appraise "rails-7.2" do
9
+ gem "rails", "~> 7.2.0"
10
+ end
11
+
12
+ # Test against Rails 8.0
13
+ appraise "rails-8.0" do
14
+ gem "rails", "~> 8.0.0"
15
+ end
16
+
17
+ # Test against Rails 8.1 (latest)
18
+ appraise "rails-8.1" do
19
+ gem "rails", "~> 8.1.0"
20
+ end
data/CHANGELOG.md CHANGED
@@ -1,3 +1,13 @@
1
+ ## [0.2.0] - 2026-01-17
2
+
3
+ - Added Minitest test suite
4
+ - Fixed duplicate Error class definition causing conflicts
5
+ - Fixed missing `log_info` method
6
+ - Fixed `parse_mode: nil` handling to properly respect explicit nil override
7
+ - Fixed `strip_markdown` method to correctly strip markdown characters
8
+ - Fixed `retry_delay` validation to accept float values (e.g., 0.5 seconds)
9
+ - Added Ruby 3.5+ compatibility with `ostruct` dependency
10
+
1
11
  ## [0.1.3] - 2025-02-28
2
12
 
3
13
  - Added client options for retries and timeout
data/CLAUDE.md ADDED
@@ -0,0 +1,5 @@
1
+ # CLAUDE.md
2
+
3
+ This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
4
+
5
+ Please go ahead and read the full context for this project at `.cursor/rules/0-overview.mdc` and `.cursor/rules/1-quality.mdc` now. Also read the README for a good overview of the project.
data/README.md CHANGED
@@ -1,8 +1,11 @@
1
- # 💬 `telegrama` – a tiny wrapper to send admin Telegram messages
1
+ # 💬 `telegrama` – Send Telegram admin notifications in your Rails app
2
2
 
3
- [![Gem Version](https://badge.fury.io/rb/telegrama.svg?v=0.1.1)](https://badge.fury.io/rb/telegrama?v=0.1.1)
3
+ [![Gem Version](https://badge.fury.io/rb/telegrama.svg)](https://badge.fury.io/rb/telegrama) [![Build Status](https://github.com/rameerez/telegrama/workflows/Tests/badge.svg)](https://github.com/rameerez/telegrama/actions)
4
4
 
5
- Send quick, simple admin / logging Telegram messages via a Telegram bot.
5
+ > [!TIP]
6
+ > **🚀 Ship your next Rails app 10x faster!** I've built **[RailsFast](https://railsfast.com/?ref=telegrama)**, a production-ready Rails boilerplate template that comes with everything you need to launch a software business in days, not weeks. Go [check it out](https://railsfast.com/?ref=telegrama)!
7
+
8
+ `telegrama` lets you send quick, simple admin / logging Telegram messages via a Telegram bot.
6
9
 
7
10
  Useful for Rails developers using Telegram messages for notifications, admin alerts, errors, logs, daily summaries, and status updates, like:
8
11
 
@@ -264,7 +267,7 @@ Telegrama includes a sophisticated state machine-based markdown formatter that p
264
267
 
265
268
  The formatter is designed to be robust even with complex inputs, ensuring your messages always look great in Telegram:
266
269
 
267
- ```ruby
270
+ ````ruby
268
271
  # Complex formatting example that works perfectly
269
272
  message = <<~MSG
270
273
  📊 *Monthly Report*
@@ -287,20 +290,18 @@ message = <<~MSG
287
290
  MSG
288
291
 
289
292
  Telegrama.send_message(message)
293
+ ````
290
294
 
291
295
  ## Testing
292
296
 
293
- The gem includes a comprehensive test suite.
297
+ The gem includes a Minitest test suite.
294
298
 
295
299
  To run the tests:
296
300
 
297
301
  ```bash
298
- bundle install
299
302
  bundle exec rake test
300
303
  ```
301
304
 
302
- The test suite uses SQLite3 in-memory database and requires no additional setup.
303
-
304
305
  ## Development
305
306
 
306
307
  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.
@@ -313,4 +314,4 @@ Bug reports and pull requests are welcome on GitHub at https://github.com/rameer
313
314
 
314
315
  ## License
315
316
 
316
- The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
317
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
@@ -0,0 +1,19 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "irb"
6
+ gem "rake", "~> 13.0"
7
+ gem "rails", "~> 7.2.0"
8
+
9
+ group :test do
10
+ gem "appraisal"
11
+ gem "minitest", "~> 6.0"
12
+ gem "minitest-mock"
13
+ gem "minitest-reporters", "~> 1.6"
14
+ gem "rack-test"
15
+ gem "simplecov", require: false
16
+ gem "webmock", "~> 3.23"
17
+ end
18
+
19
+ gemspec path: "../"
@@ -0,0 +1,19 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "irb"
6
+ gem "rake", "~> 13.0"
7
+ gem "rails", "~> 8.0.0"
8
+
9
+ group :test do
10
+ gem "appraisal"
11
+ gem "minitest", "~> 6.0"
12
+ gem "minitest-mock"
13
+ gem "minitest-reporters", "~> 1.6"
14
+ gem "rack-test"
15
+ gem "simplecov", require: false
16
+ gem "webmock", "~> 3.23"
17
+ end
18
+
19
+ gemspec path: "../"
@@ -0,0 +1,19 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "irb"
6
+ gem "rake", "~> 13.0"
7
+ gem "rails", "~> 8.1.0"
8
+
9
+ group :test do
10
+ gem "appraisal"
11
+ gem "minitest", "~> 6.0"
12
+ gem "minitest-mock"
13
+ gem "minitest-reporters", "~> 1.6"
14
+ gem "rack-test"
15
+ gem "simplecov", require: false
16
+ gem "webmock", "~> 3.23"
17
+ end
18
+
19
+ gemspec path: "../"
@@ -21,7 +21,8 @@ module Telegrama
21
21
  client_opts = client_opts.merge(@config)
22
22
 
23
23
  # Default to MarkdownV2 parse mode unless explicitly overridden
24
- parse_mode = options[:parse_mode] || Telegrama.configuration.default_parse_mode
24
+ # Use key? to allow explicit nil override (for plain text without formatting)
25
+ parse_mode = options.key?(:parse_mode) ? options[:parse_mode] : Telegrama.configuration.default_parse_mode
25
26
 
26
27
  # Allow runtime formatting options, merging with configured defaults
27
28
  formatting_opts = options.delete(:formatting) || {}
@@ -159,6 +160,4 @@ module Telegrama
159
160
  defined?(Rails) && Rails.respond_to?(:logger) ? Rails.logger : Logger.new($stdout)
160
161
  end
161
162
  end
162
-
163
- class Error < StandardError; end
164
163
  end
@@ -134,7 +134,8 @@ module Telegrama
134
134
  raise ArgumentError, "Telegrama configuration error: client_options must be a hash."
135
135
  end
136
136
 
137
- [:timeout, :retry_count, :retry_delay].each do |key|
137
+ # timeout and retry_count must be positive integers
138
+ [:timeout, :retry_count].each do |key|
138
139
  if client_options.key?(key)
139
140
  val = client_options[key]
140
141
  unless val.is_a?(Integer) && val.positive?
@@ -142,6 +143,14 @@ module Telegrama
142
143
  end
143
144
  end
144
145
  end
146
+
147
+ # retry_delay can be a positive integer or float (e.g., 0.5 seconds)
148
+ if client_options.key?(:retry_delay)
149
+ val = client_options[:retry_delay]
150
+ unless val.is_a?(Numeric) && val.positive?
151
+ raise ArgumentError, "Telegrama configuration error: client_options[:retry_delay] must be a positive number."
152
+ end
153
+ end
145
154
  end
146
155
  end
147
156
  end
@@ -473,8 +473,34 @@ module Telegrama
473
473
  # @param text [String] The text with markdown formatting
474
474
  # @return [String] The text with markdown formatting removed
475
475
  def self.strip_markdown(text)
476
- # Remove all markdown syntax for plain text delivery
477
- text.gsub(/[*_~`]|\[.*?\]\(.*?\)/, '')
476
+ result = text.dup
477
+
478
+ # Remove markdown links [text](url) -> text
479
+ result.gsub!(/\[([^\]]*)\]\([^)]*\)/, '\1')
480
+
481
+ # Remove triple backtick code blocks (preserve content)
482
+ result.gsub!(/```[a-z]*\n?(.*?)```/m, '\1')
483
+
484
+ # Remove inline code backticks (preserve content)
485
+ result.gsub!(/`([^`]*)`/, '\1')
486
+
487
+ # Remove bold formatting (both ** and *)
488
+ result.gsub!(/\*\*([^*]*)\*\*/, '\1')
489
+ result.gsub!(/\*([^*]*)\*/, '\1')
490
+
491
+ # Remove italic formatting (both __ and _)
492
+ result.gsub!(/__([^_]*)__/, '\1')
493
+ result.gsub!(/(?<![\\])_([^_]*)_/, '\1')
494
+
495
+ # Remove strikethrough
496
+ result.gsub!(/~~([^~]*)~~/, '\1')
497
+ result.gsub!(/~([^~]*)~/, '\1')
498
+
499
+ # Remove any remaining unmatched formatting characters at word boundaries
500
+ # but preserve them in the middle of words (like file_name)
501
+ result.gsub!(/(?<=\s)[*_~`]+|[*_~`]+(?=\s|$)/, '')
502
+
503
+ result
478
504
  end
479
505
 
480
506
  # Convert HTML to Telegram MarkdownV2 format
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Telegrama
4
- VERSION = "0.1.3"
4
+ VERSION = "0.2.0"
5
5
  end
data/lib/telegrama.rb CHANGED
@@ -40,11 +40,20 @@ module Telegrama
40
40
 
41
41
  # Helper method for logging errors
42
42
  def log_error(message)
43
- if defined?(Rails)
43
+ if defined?(Rails) && Rails.respond_to?(:logger)
44
44
  Rails.logger.error("[Telegrama] #{message}")
45
45
  else
46
46
  warn("[Telegrama] #{message}")
47
47
  end
48
48
  end
49
+
50
+ # Helper method for logging info messages
51
+ def log_info(message)
52
+ if defined?(Rails) && Rails.respond_to?(:logger)
53
+ Rails.logger.info("[Telegrama] #{message}")
54
+ else
55
+ puts("[Telegrama] #{message}")
56
+ end
57
+ end
49
58
  end
50
59
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: telegrama
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Javi R
8
8
  bindir: exe
9
9
  cert_chain: []
10
- date: 2025-02-28 00:00:00.000000000 Z
10
+ date: 2026-01-17 00:00:00.000000000 Z
11
11
  dependencies:
12
12
  - !ruby/object:Gem::Dependency
13
13
  name: rails
@@ -23,6 +23,20 @@ dependencies:
23
23
  - - ">="
24
24
  - !ruby/object:Gem::Version
25
25
  version: 6.0.0
26
+ - !ruby/object:Gem::Dependency
27
+ name: ostruct
28
+ requirement: !ruby/object:Gem::Requirement
29
+ requirements:
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: '0.5'
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ">="
38
+ - !ruby/object:Gem::Version
39
+ version: '0.5'
26
40
  description: Send quick, simple admin / logging Telegram messages via a Telegram bot.
27
41
  Useful for Rails developers using Telegram messages for notifications, admin alerts,
28
42
  daily summaries, and status updates. Parses and escapes Markdown for beautifully
@@ -34,10 +48,17 @@ executables: []
34
48
  extensions: []
35
49
  extra_rdoc_files: []
36
50
  files:
51
+ - ".simplecov"
52
+ - AGENTS.md
53
+ - Appraisals
37
54
  - CHANGELOG.md
55
+ - CLAUDE.md
38
56
  - LICENSE.txt
39
57
  - README.md
40
58
  - Rakefile
59
+ - gemfiles/rails_7.2.gemfile
60
+ - gemfiles/rails_8.0.gemfile
61
+ - gemfiles/rails_8.1.gemfile
41
62
  - lib/telegrama.rb
42
63
  - lib/telegrama/client.rb
43
64
  - lib/telegrama/configuration.rb