loghuman 0.0.1
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 +15 -0
- data/lib/loghuman.rb +77 -0
- metadata +46 -0
checksums.yaml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
---
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
MWNmZTBjMjEzNTcwNmEyMzk0MTZhOTc3YjVjNzgzMTdlNTBkMjJhYg==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
ZDBiNDk0OWQ4M2E3NDUwNzU3ZDE2MmFkMDgwZDMxY2VjMThlYzNhZg==
|
7
|
+
SHA512:
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
MzZlM2FkOGM5OTczM2E3Mzg3ZTZmYzM5MGZhOWRhNjJhYWVhNTQyZGQ2NzYy
|
10
|
+
MjZmZjU2NjhlY2FmYWQ4MWVmY2M2ODMxMzkxMGM4NDJkN2EzYTYyNDM3NTcz
|
11
|
+
MmJjZTVlYmUyNjgxYWEzOGMyM2M2MDhkMzM2MDBhM2IwOTM0ZDQ=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
NGUxNjk3Y2ZkNzFlNzhkM2QwYjFjNzRmZWQxNGRkMzA3N2ZmNWE3ZmMzZmEx
|
14
|
+
OGQzMGE1Nzk3ODNhYzA1ZmM5MDkzNmJiY2M2YmMwNDZmM2M5ZGU4NTY2ZTNj
|
15
|
+
NzdmZDA3ZDZjMjJiMjNhZWU5NDY1NjJlYTczZmFiNWMzY2Q2ZmI=
|
data/lib/loghuman.rb
ADDED
@@ -0,0 +1,77 @@
|
|
1
|
+
require 'net/https'
|
2
|
+
require 'json'
|
3
|
+
|
4
|
+
class LogHuman
|
5
|
+
|
6
|
+
DATA_ENDPOINT = 'https://data.loghuman.com/messages'
|
7
|
+
STATUSES = [ :debug, :success, :info, :warning, :error ]
|
8
|
+
|
9
|
+
@@context = nil
|
10
|
+
@@messages = []
|
11
|
+
|
12
|
+
@@api_key = nil
|
13
|
+
|
14
|
+
def self.api_key= ( api_key )
|
15
|
+
@@api_key = api_key
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.send ( message, status, opts={} )
|
19
|
+
|
20
|
+
if @@api_key.nil?
|
21
|
+
raise "You must set an api key before sending messages: LogHuman.api_key = '*********'"
|
22
|
+
end
|
23
|
+
|
24
|
+
unless STATUSES.include?( status )
|
25
|
+
raise "The message status must be one of #{STATUSES.join(', ')}"
|
26
|
+
end
|
27
|
+
|
28
|
+
payload = opts.merge( {
|
29
|
+
message: message,
|
30
|
+
status: status.to_s,
|
31
|
+
timestamp: (Time.now.to_f * 1000).round,
|
32
|
+
date: Time.now.strftime('%Y-%m-%d')
|
33
|
+
} )
|
34
|
+
|
35
|
+
if @@context.nil?
|
36
|
+
self.execute( [payload] )
|
37
|
+
else
|
38
|
+
@@messages << payload.merge( {
|
39
|
+
context: @@context
|
40
|
+
} )
|
41
|
+
end
|
42
|
+
|
43
|
+
end
|
44
|
+
|
45
|
+
def self.context ( context )
|
46
|
+
@@context = context
|
47
|
+
yield
|
48
|
+
self.execute( @@messages )
|
49
|
+
@@messages = []
|
50
|
+
end
|
51
|
+
|
52
|
+
def self.execute ( payloads )
|
53
|
+
if defined? Sidekiq
|
54
|
+
unless defined? LogHumanWorker
|
55
|
+
require './queues/sidekiq'
|
56
|
+
end
|
57
|
+
LogHumanWorker.perform_async( payloads )
|
58
|
+
else
|
59
|
+
self.api( payloads )
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
private
|
64
|
+
|
65
|
+
def self.api ( payloads )
|
66
|
+
uri = URI.parse( DATA_ENDPOINT )
|
67
|
+
https = Net::HTTP.new( uri.host, uri.port )
|
68
|
+
https.use_ssl = true
|
69
|
+
req = Net::HTTP::Post.new( uri.path )
|
70
|
+
req['User-Agent'] = 'LogHuman Gem 0.0.1'
|
71
|
+
req.basic_auth( @@api_key, nil )
|
72
|
+
req.body = JSON.generate( payloads )
|
73
|
+
res = https.request( req )
|
74
|
+
res.code == '201'
|
75
|
+
end
|
76
|
+
|
77
|
+
end
|
metadata
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: loghuman
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Todd Zusman
|
8
|
+
- Kuldar Kalvik
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2014-03-12 00:00:00.000000000 Z
|
13
|
+
dependencies: []
|
14
|
+
description: LogHuman.com is a service for reading human-readable logs. Visit https://loghuman.com
|
15
|
+
to learn more.
|
16
|
+
email: toddzusman@gmail.com
|
17
|
+
executables: []
|
18
|
+
extensions: []
|
19
|
+
extra_rdoc_files: []
|
20
|
+
files:
|
21
|
+
- lib/loghuman.rb
|
22
|
+
homepage: https://loghuman.com
|
23
|
+
licenses:
|
24
|
+
- MIT
|
25
|
+
metadata: {}
|
26
|
+
post_install_message:
|
27
|
+
rdoc_options: []
|
28
|
+
require_paths:
|
29
|
+
- lib
|
30
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
31
|
+
requirements:
|
32
|
+
- - ! '>='
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: '0'
|
35
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - ! '>='
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '0'
|
40
|
+
requirements: []
|
41
|
+
rubyforge_project:
|
42
|
+
rubygems_version: 2.1.11
|
43
|
+
signing_key:
|
44
|
+
specification_version: 4
|
45
|
+
summary: Lightweight library for sending messages to LogHuman
|
46
|
+
test_files: []
|