bernard 0.0.0 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +3 -0
- data/.rspec +2 -0
- data/.ruby-version +1 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +52 -0
- data/LICENSE.txt +21 -0
- data/README.md +9 -0
- data/Rakefile +6 -0
- data/bernard.gemspec +24 -0
- data/bin/.keep +0 -0
- data/lib/bernard/.keep +0 -0
- data/lib/bernard/exception.rb +3 -0
- data/lib/bernard/schema.rb +5 -0
- data/lib/bernard/version.rb +3 -0
- data/lib/bernard.rb +57 -1
- data/test/.keep +0 -0
- metadata +75 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fd466e27be29274756368250e35c489fd65c4a37
|
4
|
+
data.tar.gz: 14875501d58f8ffafd0f611488695162d4f75b64
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 11a5fe4879d483b4e5f536a05076f1b9cbd83c87d2a48f20f996ce197c3f9cb9c22a4b6bce89447cce271652f1d404631c347dcf2eac6e6e692a9db8c0433176
|
7
|
+
data.tar.gz: 14776960c759e3e69ba0e3de42222a5e573b275f90270f24146825ceae653e8925192480bb9d7f210f4fd87a1b9ecc3d76ef488d3d2877b75a60489abed8e5ff
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
2.3.0
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
bernard (0.0.0)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: https://rubygems.org/
|
8
|
+
specs:
|
9
|
+
addressable (2.4.0)
|
10
|
+
coderay (1.1.1)
|
11
|
+
crack (0.4.3)
|
12
|
+
safe_yaml (~> 1.0.0)
|
13
|
+
diff-lcs (1.2.5)
|
14
|
+
hashdiff (0.3.0)
|
15
|
+
method_source (0.8.2)
|
16
|
+
pry (0.10.3)
|
17
|
+
coderay (~> 1.1.0)
|
18
|
+
method_source (~> 0.8.1)
|
19
|
+
slop (~> 3.4)
|
20
|
+
rake (11.1.2)
|
21
|
+
rspec (3.4.0)
|
22
|
+
rspec-core (~> 3.4.0)
|
23
|
+
rspec-expectations (~> 3.4.0)
|
24
|
+
rspec-mocks (~> 3.4.0)
|
25
|
+
rspec-core (3.4.4)
|
26
|
+
rspec-support (~> 3.4.0)
|
27
|
+
rspec-expectations (3.4.0)
|
28
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
29
|
+
rspec-support (~> 3.4.0)
|
30
|
+
rspec-mocks (3.4.1)
|
31
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
32
|
+
rspec-support (~> 3.4.0)
|
33
|
+
rspec-support (3.4.1)
|
34
|
+
safe_yaml (1.0.4)
|
35
|
+
slop (3.6.0)
|
36
|
+
webmock (1.24.2)
|
37
|
+
addressable (>= 2.3.6)
|
38
|
+
crack (>= 0.3.2)
|
39
|
+
hashdiff
|
40
|
+
|
41
|
+
PLATFORMS
|
42
|
+
ruby
|
43
|
+
|
44
|
+
DEPENDENCIES
|
45
|
+
bernard!
|
46
|
+
pry
|
47
|
+
rake
|
48
|
+
rspec
|
49
|
+
webmock
|
50
|
+
|
51
|
+
BUNDLED WITH
|
52
|
+
1.12.2
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2016 The Dextrous Web Ltd
|
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
ADDED
data/Rakefile
ADDED
data/bernard.gemspec
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
lib = File.expand_path('../lib', __FILE__)
|
2
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
|
+
require 'bernard/version'
|
4
|
+
|
5
|
+
Gem::Specification.new do |gem|
|
6
|
+
gem.name = 'bernard'
|
7
|
+
gem.version = Bernard::VERSION
|
8
|
+
gem.date = '2016-05-11'
|
9
|
+
gem.summary = 'Sends event data to visualisation services'
|
10
|
+
gem.description = 'Sends event data to visualisation services.'
|
11
|
+
gem.authors = ['Tom Hipkin', 'Robert Lee-Cann']
|
12
|
+
gem.email = ['tomh@dxw.com', 'leeky@dxw.com']
|
13
|
+
gem.files = ['lib/bernard.rb']
|
14
|
+
gem.homepage = 'http://rubygems.org/gems/bernard'
|
15
|
+
gem.license = 'MIT'
|
16
|
+
|
17
|
+
gem.require_paths = ['lib']
|
18
|
+
gem.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(spec|features)/}) }
|
19
|
+
|
20
|
+
gem.add_development_dependency 'rake', '11.1.2'
|
21
|
+
gem.add_development_dependency 'rspec', '3.4.0'
|
22
|
+
gem.add_development_dependency 'pry', '0.10.3'
|
23
|
+
gem.add_development_dependency 'webmock', '1.24.2'
|
24
|
+
end
|
data/bin/.keep
ADDED
File without changes
|
data/lib/bernard/.keep
ADDED
File without changes
|
data/lib/bernard.rb
CHANGED
@@ -1,3 +1,59 @@
|
|
1
|
+
require 'bernard/exception'
|
2
|
+
require 'bernard/schema'
|
3
|
+
require 'bernard/version'
|
4
|
+
|
5
|
+
require 'json'
|
6
|
+
require 'net/https'
|
7
|
+
require 'uri'
|
8
|
+
|
1
9
|
class Bernard
|
2
|
-
|
10
|
+
BASE_URI = 'https://api.keen.io'
|
11
|
+
|
12
|
+
attr_reader :project_id, :write_key
|
13
|
+
|
14
|
+
def project_id=(id)
|
15
|
+
project_id = String(id).strip.downcase
|
16
|
+
raise Bernard::Exception unless !!(project_id =~ /\A[0-9a-f]{24}\Z/)
|
17
|
+
|
18
|
+
@project_id = project_id
|
19
|
+
end
|
20
|
+
|
21
|
+
def write_key=(key)
|
22
|
+
write_key = String(key).strip.downcase
|
23
|
+
raise Bernard::Exception unless !!(write_key =~ /\A[0-9a-f]{192}\Z/)
|
24
|
+
|
25
|
+
@write_key = write_key
|
26
|
+
end
|
27
|
+
|
28
|
+
def publish(event, metadata)
|
29
|
+
event = String(event).strip.downcase
|
30
|
+
|
31
|
+
uri = URI.parse(BASE_URI)
|
32
|
+
|
33
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
34
|
+
http.open_timeout = 5
|
35
|
+
http.read_timeout = 5
|
36
|
+
http.use_ssl = true
|
37
|
+
|
38
|
+
request = Net::HTTP::Post.new("/3.0/projects/#{project_id}/events/#{event}")
|
39
|
+
request['Authorization'] = write_key
|
40
|
+
request['Content-Type'] = 'application/json'
|
41
|
+
request.body = metadata.to_json
|
42
|
+
|
43
|
+
begin
|
44
|
+
response = http.request(request)
|
45
|
+
rescue Timeout::Error
|
46
|
+
return false
|
47
|
+
end
|
48
|
+
|
49
|
+
response.code == '201'
|
50
|
+
end
|
51
|
+
|
52
|
+
def tick(event)
|
53
|
+
publish(:tick, type: event, count: 1)
|
54
|
+
end
|
55
|
+
|
56
|
+
def gauge(event, value)
|
57
|
+
publish(:gauge, type: event, value: Float(value))
|
58
|
+
end
|
3
59
|
end
|
data/test/.keep
ADDED
File without changes
|
metadata
CHANGED
@@ -1,25 +1,96 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bernard
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tom Hipkin
|
8
|
-
-
|
8
|
+
- Robert Lee-Cann
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
date: 2016-05-11 00:00:00.000000000 Z
|
13
|
-
dependencies:
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rake
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
requirements:
|
18
|
+
- - '='
|
19
|
+
- !ruby/object:Gem::Version
|
20
|
+
version: 11.1.2
|
21
|
+
type: :development
|
22
|
+
prerelease: false
|
23
|
+
version_requirements: !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - '='
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
version: 11.1.2
|
28
|
+
- !ruby/object:Gem::Dependency
|
29
|
+
name: rspec
|
30
|
+
requirement: !ruby/object:Gem::Requirement
|
31
|
+
requirements:
|
32
|
+
- - '='
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: 3.4.0
|
35
|
+
type: :development
|
36
|
+
prerelease: false
|
37
|
+
version_requirements: !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - '='
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: 3.4.0
|
42
|
+
- !ruby/object:Gem::Dependency
|
43
|
+
name: pry
|
44
|
+
requirement: !ruby/object:Gem::Requirement
|
45
|
+
requirements:
|
46
|
+
- - '='
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: 0.10.3
|
49
|
+
type: :development
|
50
|
+
prerelease: false
|
51
|
+
version_requirements: !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - '='
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: 0.10.3
|
56
|
+
- !ruby/object:Gem::Dependency
|
57
|
+
name: webmock
|
58
|
+
requirement: !ruby/object:Gem::Requirement
|
59
|
+
requirements:
|
60
|
+
- - '='
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: 1.24.2
|
63
|
+
type: :development
|
64
|
+
prerelease: false
|
65
|
+
version_requirements: !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - '='
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: 1.24.2
|
14
70
|
description: Sends event data to visualisation services.
|
15
71
|
email:
|
16
72
|
- tomh@dxw.com
|
17
|
-
-
|
73
|
+
- leeky@dxw.com
|
18
74
|
executables: []
|
19
75
|
extensions: []
|
20
76
|
extra_rdoc_files: []
|
21
77
|
files:
|
78
|
+
- ".gitignore"
|
79
|
+
- ".rspec"
|
80
|
+
- ".ruby-version"
|
81
|
+
- Gemfile
|
82
|
+
- Gemfile.lock
|
83
|
+
- LICENSE.txt
|
84
|
+
- README.md
|
85
|
+
- Rakefile
|
86
|
+
- bernard.gemspec
|
87
|
+
- bin/.keep
|
22
88
|
- lib/bernard.rb
|
89
|
+
- lib/bernard/.keep
|
90
|
+
- lib/bernard/exception.rb
|
91
|
+
- lib/bernard/schema.rb
|
92
|
+
- lib/bernard/version.rb
|
93
|
+
- test/.keep
|
23
94
|
homepage: http://rubygems.org/gems/bernard
|
24
95
|
licenses:
|
25
96
|
- MIT
|