logkeeper_api 0.0.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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: aec8f1fac99b9f0a35c2ce74accf847a4fbd8326
4
+ data.tar.gz: 20327028e2da82df022fd514888d80b031560ded
5
+ SHA512:
6
+ metadata.gz: 9f5eea613fceba01027738941a3361d360a1625ec5e4efe64e7314869247d550ec3d464009f8be71d7fb7031f8569982273af79cdcf5ece041ba762d284ca12c
7
+ data.tar.gz: 5238b1d166254a5308ed1026d4df6bd4a5329573158ddccc3d434e5809e7f75e343eee66fca6d961c2a8db71f810b94e9bc7588c400339e173ddeb2117e3cade
data/.gitignore ADDED
@@ -0,0 +1,13 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
12
+ .idea/
13
+ .rspec
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.4.4
5
+ before_install: gem install bundler -v 1.16.2
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in sentinel_api.gemspec
6
+ gemspec
data/README.md ADDED
@@ -0,0 +1,48 @@
1
+ # Sentinel
2
+
3
+ This is a gem for ErrorReportApi server integration.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'sentinel_api'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install sentinel_api
20
+
21
+ Add initializer file
22
+
23
+ $ rails g sentinel_api:install
24
+
25
+ Don't forget to configure your ErrorReporterAPI server uri and method
26
+
27
+ ## Usage
28
+
29
+ There are 3 methods, which produce 3 log level messages:
30
+ info, warn, error.
31
+
32
+ You can use this gem in 3 ways:
33
+ * provide hash with 3 keys: message, info, tags
34
+ * provide message, exception and tags - info would be made from exception's class message and backtrace
35
+ * provide message and exception - no tags would be sent
36
+ * provide only exception, exception message would be used, no tags
37
+ ```ruby
38
+ SentinelApi.info({ message: 'your custom error message', info: 'system info or other information', tags: ['tag1', 'tag2']})
39
+ SentinelApi.warn('your message', exception, ['tag1', 'tag2'])
40
+ SentinelApi.error('your message', exception)
41
+ ```
42
+
43
+ ## Development
44
+
45
+ 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.
46
+
47
+ 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 tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
48
+
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "sentinel_api"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,17 @@
1
+ require 'rails/generators'
2
+ require 'rails/generators/base'
3
+
4
+ module SentinelApi
5
+ module Generators
6
+ class InstallGenerator < ::Rails::Generators::Base
7
+ source_root File.expand_path('./templates', __dir__)
8
+
9
+ desc "Creates SentinelApi initializer"
10
+ def create_sentinel_initializer
11
+ template 'initializer.rb', 'config/initializers/sentinel_api.rb'
12
+
13
+ puts 'Done'
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,4 @@
1
+ SentinelApi.configure do |config|
2
+ # config.uri = 'http://localhost:3000/reports'
3
+ # config.method = 'post'
4
+ end
@@ -0,0 +1,29 @@
1
+ require 'httparty'
2
+
3
+ module SentinelApi
4
+ class Client
5
+ class << self
6
+ def send_to_server(record)
7
+ response = ::HTTParty.public_send(configuration.method, configuration.uri, prepare_request(record))
8
+ unless response.code == 200
9
+ SentinelApi.default_logger.warn("We sent logs(#{record}) to API Server and got #{response.code} instead of status")
10
+ end
11
+ rescue => e
12
+ SentinelApi.default_logger.warn("Troubles with ErrorReporter API call\n #{e.message}\n #{e.backtrace}")
13
+ end
14
+
15
+ private
16
+
17
+ def prepare_request(record)
18
+ {
19
+ headers: { 'Content-Type' => 'application/json' },
20
+ body: { request_params: record }.to_json
21
+ }
22
+ end
23
+
24
+ def configuration
25
+ SentinelApi.configuration
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,42 @@
1
+ require 'logger'
2
+ module SentinelApi
3
+ class Configuration
4
+ attr_accessor :uri
5
+ attr_accessor :level
6
+ attr_accessor :method
7
+
8
+ DEFAULT_URI = (ENV['sentinel_uri'] || 'http://localhost:3000/reports').freeze
9
+ DEFAULT_METHOD = (ENV['sentinel_method'] || 'post').freeze
10
+
11
+ def initialize
12
+ @uri = DEFAULT_URI
13
+ @method = DEFAULT_METHOD
14
+ end
15
+
16
+ def merge(options)
17
+ new_configuration = clone
18
+ new_configuration.merge!(options)
19
+
20
+ new_configuration
21
+ end
22
+
23
+ def merge!(options)
24
+ options.each do |name, value|
25
+ variable_name = "@#{name}"
26
+ next unless instance_variable_defined?(variable_name)
27
+
28
+ instance_variable_set(variable_name, value)
29
+ end
30
+
31
+ self
32
+ end
33
+
34
+ def default_logger
35
+ @default_logger ||= defined?(::Rails) ? ::Rails.logger : ::Logger.new(STDERR)
36
+ end
37
+
38
+ def use_ssl?
39
+ uri.match(/^https:/) ? true : false
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,68 @@
1
+ require 'active_support/core_ext/hash/indifferent_access'
2
+
3
+ module SentinelApi
4
+ class Notifier
5
+ class << self
6
+
7
+ def warn(*args)
8
+ log('WARN', args)
9
+ end
10
+
11
+ def info(*args)
12
+ log('INFO', args)
13
+ end
14
+
15
+ def error(*args)
16
+ log('ERROR', args)
17
+ end
18
+
19
+ private_class_method
20
+
21
+ def log(level = nil, args)
22
+ level ||= configuration.level
23
+ message, info, tags = extract_arguments(args)
24
+
25
+ SentinelApi::Client.send_to_server({ level: level, message: message, info: info, tags: tags })
26
+ end
27
+
28
+ def extract_arguments(args)
29
+ message = nil
30
+ exception = nil
31
+ tags = nil
32
+ if args.count == 1 && args[0].is_a?(Hash)
33
+ result = args[0].with_indifferent_access
34
+ return [result[:message], result[:info], result[:tags]]
35
+ elsif args.count == 1 && args[0].is_a?(Exception)
36
+ return [args[0].message, prepare_info(args[0]), []]
37
+ else
38
+ args.each do |arg|
39
+ if arg.is_a?(String)
40
+ message = arg
41
+ elsif arg.is_a?(Exception)
42
+ exception = arg
43
+ elsif RUBY_PLATFORM == 'java' && arg.is_a?(java.lang.Exception)
44
+ exception = arg
45
+ elsif arg.is_a?(Array)
46
+ tags = arg
47
+
48
+ tags = nil if tags.empty?
49
+ end
50
+ end
51
+ end
52
+
53
+ [message, prepare_info(exception), tags]
54
+ end
55
+
56
+ def prepare_info(exception)
57
+ "#{exception.class}: #{exception.message}, \n#{exception.backtrace.join("\n")}"
58
+ rescue
59
+ "#{exception.class}: #{exception.message}"
60
+ end
61
+
62
+
63
+ def configuration
64
+ SentinelApi.configuration
65
+ end
66
+ end
67
+ end
68
+ end
@@ -0,0 +1,3 @@
1
+ module SentinelApi
2
+ VERSION = "0.0.2"
3
+ end
@@ -0,0 +1,32 @@
1
+ require "sentinel_api/version"
2
+ require 'sentinel_api/configuration'
3
+ require 'sentinel_api/notifier'
4
+ require 'sentinel_api/client'
5
+ require 'forwardable'
6
+
7
+ module SentinelApi
8
+ PUBLIC_NOTIFIER_METHODS = %w(warn info error).freeze
9
+ class << self
10
+ extend Forwardable
11
+
12
+ def_delegators :notifier, *PUBLIC_NOTIFIER_METHODS
13
+
14
+ def configuration
15
+ @configuration ||= Configuration.new
16
+ end
17
+
18
+ def configure
19
+ yield(configuration)
20
+ end
21
+
22
+ def notifier
23
+ Notifier
24
+ end
25
+
26
+ def default_logger
27
+ configuration.default_logger
28
+ end
29
+
30
+ end
31
+
32
+ end
@@ -0,0 +1,44 @@
1
+ puts __FILE__
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ puts "LIB #{lib}"
4
+ puts "LOADPATH #{$LOAD_PATH.include?(lib)}"
5
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
6
+ require "sentinel_api/version"
7
+
8
+ Gem::Specification.new do |spec|
9
+ spec.name = "logkeeper_api"
10
+ spec.version = SentinelApi::VERSION
11
+ spec.authors = ["Intelllex"]
12
+ spec.email = ["tech@intelllex.com"]
13
+
14
+ spec.summary = %q{Gem to connect to ErrorReporterAPI}
15
+ spec.description = %q{This is a gem to connect to ErrorReporterAPI}
16
+ spec.homepage = "https://gitlab.com/intelllex/sentinel"
17
+ spec.license = "MIT"
18
+
19
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
20
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
21
+ if spec.respond_to?(:metadata)
22
+ spec.metadata["allowed_push_host"] = "https://rubygems.org"
23
+ else
24
+ raise "RubyGems 2.0 or newer is required to protect against " \
25
+ "public gem pushes."
26
+ end
27
+
28
+ # Specify which files should be added to the gem when it is released.
29
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
30
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
31
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
32
+ end
33
+ spec.bindir = "exe"
34
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
35
+ spec.require_paths = ["lib"]
36
+
37
+ spec.add_runtime_dependency "httparty", "~> 0.16"
38
+ spec.add_runtime_dependency "activesupport", "~> 5.2"
39
+ spec.add_development_dependency "bundler", "~> 1.16"
40
+ spec.add_development_dependency "pry", '~> 0'
41
+ spec.add_development_dependency 'pry-byebug', '~> 3.6'
42
+ spec.add_development_dependency "rake", "~> 10.0"
43
+ spec.add_development_dependency "rspec", "~> 3.0"
44
+ end
metadata ADDED
@@ -0,0 +1,159 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: logkeeper_api
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ platform: ruby
6
+ authors:
7
+ - Intelllex
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2018-12-19 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: httparty
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '0.16'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '0.16'
27
+ - !ruby/object:Gem::Dependency
28
+ name: activesupport
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '5.2'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '5.2'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.16'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.16'
55
+ - !ruby/object:Gem::Dependency
56
+ name: pry
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: pry-byebug
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '3.6'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '3.6'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rake
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '10.0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '10.0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: rspec
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '3.0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '3.0'
111
+ description: This is a gem to connect to ErrorReporterAPI
112
+ email:
113
+ - tech@intelllex.com
114
+ executables: []
115
+ extensions: []
116
+ extra_rdoc_files: []
117
+ files:
118
+ - ".gitignore"
119
+ - ".rspec"
120
+ - ".travis.yml"
121
+ - Gemfile
122
+ - README.md
123
+ - Rakefile
124
+ - bin/console
125
+ - bin/setup
126
+ - lib/generators/sentinel_api/install_generator.rb
127
+ - lib/generators/sentinel_api/templates/initializer.rb
128
+ - lib/sentinel_api.rb
129
+ - lib/sentinel_api/client.rb
130
+ - lib/sentinel_api/configuration.rb
131
+ - lib/sentinel_api/notifier.rb
132
+ - lib/sentinel_api/version.rb
133
+ - logkeeper_api.gemspec
134
+ homepage: https://gitlab.com/intelllex/sentinel
135
+ licenses:
136
+ - MIT
137
+ metadata:
138
+ allowed_push_host: https://rubygems.org
139
+ post_install_message:
140
+ rdoc_options: []
141
+ require_paths:
142
+ - lib
143
+ required_ruby_version: !ruby/object:Gem::Requirement
144
+ requirements:
145
+ - - ">="
146
+ - !ruby/object:Gem::Version
147
+ version: '0'
148
+ required_rubygems_version: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - ">="
151
+ - !ruby/object:Gem::Version
152
+ version: '0'
153
+ requirements: []
154
+ rubyforge_project:
155
+ rubygems_version: 2.6.14
156
+ signing_key:
157
+ specification_version: 4
158
+ summary: Gem to connect to ErrorReporterAPI
159
+ test_files: []