telegram-loggerbot-ruby 0.0.2 → 0.0.3

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: 28c42ae72e9892aca97bb0685c76f5ad38b5470d
4
- data.tar.gz: b33a12d6e1e759432438a940ab4c08e710f68dff
3
+ metadata.gz: a2a79a7791abf4b30dd3cf62eb81aea5d433b09d
4
+ data.tar.gz: bc64e07a38230ef3ec5e3e9f8f5055f390989c02
5
5
  SHA512:
6
- metadata.gz: 70e4315d2198a49daed350087eaabe0be4e8dd4f3e2c7e867d0289942d9e9ca62728b4b211bab3aa96dcebc6e4331d4de0da7a7a9687d50c5d047f02c4757b1b
7
- data.tar.gz: b554b092dd8ea101f78a564a1e11cda2b43edfc806b12af67dec0fae9610c3207ee1a00190eb9b3962333efa9d699aac79e9d4675580bd6c91f1bef4da93173a
6
+ metadata.gz: 69cf7a897084fe6d0dd28b822c028a02fefebdb6158b0ad139b6b617a97b90ecd1fb8321aa623b25922c9d5391aefc992c64c580c094580a678aa3c3490d458b
7
+ data.tar.gz: 2f2f40fa602754e1e757c1eab25d58a03473c2e391c515697617338241e5d378725c2353414e9cca80c2042781b858b16f7994591b495bad216e9c6e3beb873c
@@ -1,8 +1,8 @@
1
1
  sudo: false
2
2
  language: ruby
3
3
  rvm:
4
- - 2.1
5
- - 2.2
6
- - 2.3
7
- - 2.4
4
+ - 2.1.10
5
+ - 2.2.6
6
+ - 2.3.3
7
+ - 2.4.0
8
8
  before_install: gem install bundler -v 1.13.6
data/README.md CHANGED
@@ -1,15 +1,17 @@
1
- ![preview1](https://github.com/a0s/telegram-loggerbot-ruby/raw/master/img/preview1.jpg)![preview2](https://github.com/a0s/telegram-loggerbot-ruby/raw/master/img/preview2.jpg)
1
+ #Telegram::LoggerBot
2
+
3
+ [![Build Status](https://travis-ci.org/a0s/telegram-loggerbot-ruby.svg?branch=master)](https://travis-ci.org/a0s/telegram-loggerbot-ruby)
2
4
 
3
- #telegram-loggerbot-ruby
5
+ Telegram::LoggerBot allows to send event logs directly to the Telegram chat
4
6
 
5
- Allows to send event logs directly to the telegram chat
7
+ ![preview1](https://github.com/a0s/telegram-loggerbot-ruby/raw/master/img/preview1.jpg)![preview2](https://github.com/a0s/telegram-loggerbot-ruby/raw/master/img/preview2.jpg)
6
8
 
7
9
  ## Installation
8
10
 
9
11
  Add this line to your application's Gemfile:
10
12
 
11
13
  ```ruby
12
- gem 'loggerbot'
14
+ gem 'telegram-loggerbot-ruby'
13
15
  ```
14
16
 
15
17
  And then execute:
@@ -38,6 +40,7 @@ Initialize with obtained TOKEN and TELEGRAM_USER_ID:
38
40
  Telegram::LoggerBot.configure do |config|
39
41
  config.token = TOKEN # required
40
42
  config.chat_id = USER_ID_OR_CHAT_ID # required
43
+ config.enabled = false # optional, true by default
41
44
  config.level = Logger::INFO # optional, default is Logger::DEBUG
42
45
  config.next_logger = App.existing_logger_instance # optional
43
46
  config.api = App.existing_telegram_bot_api_instance # optional
@@ -52,6 +55,7 @@ or in classic style:
52
55
  logger = Telegram::LoggerBot.new(
53
56
  token: TOKEN, # required
54
57
  chat_id: USER_ID_OR_CHAT_ID, # required
58
+ enabled: false, # optional, true by default
55
59
  level: Logger::INFO, # optional, default is Logger::DEBUG
56
60
  next_logger: App.existing_logger_instance, # optional
57
61
  api: App.existing_telegram_bot_api_instance # optional
@@ -1,7 +1,7 @@
1
1
  module Telegram
2
2
  module LoggerBot
3
3
  class Configuration
4
- attr_accessor :token, :chat_id, :level, :next_logger, :api
4
+ attr_accessor :token, :chat_id, :level, :next_logger, :api, :enabled
5
5
  end
6
6
  end
7
7
  end
@@ -7,13 +7,15 @@ module Telegram
7
7
  def initialize(args = {})
8
8
  @default_formatter = args[:default_formatter] || Formatter.new
9
9
 
10
- @level, @chat_id, @token, @next_logger, @api = args.values_at(:level, :chat_id, :token, :next_logger, :api)
11
-
12
- @level ||= Telegram::LoggerBot.configuration.level || DEBUG
13
- @chat_id ||= Telegram::LoggerBot.configuration.chat_id || fail(ChatIdMissed)
14
- @token ||= Telegram::LoggerBot.configuration.token || fail(TokenMissed)
15
- @next_logger ||= Telegram::LoggerBot.configuration.next_logger
16
- @api ||= Telegram::LoggerBot.configuration.api || Telegram::Bot::Api.new(@token)
10
+ @level = args[:level] || Telegram::LoggerBot.configuration.level || DEBUG
11
+ @chat_id = args[:chat_id] || Telegram::LoggerBot.configuration.chat_id || fail(ChatIdMissed)
12
+ @token = args[:token] || Telegram::LoggerBot.configuration.token || fail(TokenMissed)
13
+ @next_logger = args[:next_logger] || Telegram::LoggerBot.configuration.next_logger
14
+ @api = args[:api] || Telegram::LoggerBot.configuration.api || Telegram::Bot::Api.new(@token)
15
+
16
+ @enabled = args[:enabled] unless args[:enabled].nil?
17
+ @enabled = Telegram::LoggerBot.configuration.enabled unless Telegram::LoggerBot.configuration.enabled.nil?
18
+ @enabled = true if @enabled.nil?
17
19
  end
18
20
 
19
21
  def clear_markdown(str)
@@ -94,14 +96,16 @@ module Telegram
94
96
  end
95
97
  end
96
98
 
97
- time = Time.now
99
+ if @enabled
100
+ time = Time.now
98
101
 
99
- text = "#{format_severity_icon(severity)}*#{format_severity(severity)}*"
100
- text << " _#{clear_markdown(progname)}_" if progname
101
- text << "\n#{format_time_icon(time)}#{time}"
102
+ text = "#{format_severity_icon(severity)}*#{format_severity(severity)}*"
103
+ text << " _#{clear_markdown(progname)}_" if progname
104
+ text << "\n#{format_time_icon(time)}#{time}"
102
105
 
103
- @api.send_message(chat_id: @chat_id, text: text, parse_mode: 'Markdown')
104
- @api.send_message(chat_id: @chat_id, text: message)
106
+ @api.send_message(chat_id: @chat_id, text: text, parse_mode: 'Markdown')
107
+ @api.send_message(chat_id: @chat_id, text: message)
108
+ end
105
109
 
106
110
  if @next_logger
107
111
  @next_logger.add(severity, message, progname, &block)
@@ -1,5 +1,5 @@
1
1
  module Telegram
2
2
  module LoggerBot
3
- VERSION = '0.0.2'.freeze
3
+ VERSION = '0.0.3'.freeze
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: telegram-loggerbot-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Anton Osenenko
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-02-07 00:00:00.000000000 Z
11
+ date: 2017-02-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: telegram-bot-ruby