bernard 0.0.0 → 0.1.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
  SHA1:
3
- metadata.gz: 58a4359d0d2a9bde87dc75fb3d2575d5eb833fb5
4
- data.tar.gz: 83ae5e84e405a71da3095f1fffb4a85c547188f4
3
+ metadata.gz: fd466e27be29274756368250e35c489fd65c4a37
4
+ data.tar.gz: 14875501d58f8ffafd0f611488695162d4f75b64
5
5
  SHA512:
6
- metadata.gz: 5e483f202cac603cea0c98daa7181558aa4c14ed3af8d942238314f73305d49ed4b42c4238cd2297cfb65d088e839734ea0bfad18dd281a64cdd4fdb7a28c602
7
- data.tar.gz: 20171f587e78ba76ff36dd07a0651c877cd8f9656d9418f192e91d595659c930c19195cd7f539234061ab3f1fd9d2d52ce0b5d79035fb97e8abd70d783636376
6
+ metadata.gz: 11a5fe4879d483b4e5f536a05076f1b9cbd83c87d2a48f20f996ce197c3f9cb9c22a4b6bce89447cce271652f1d404631c347dcf2eac6e6e692a9db8c0433176
7
+ data.tar.gz: 14776960c759e3e69ba0e3de42222a5e573b275f90270f24146825ceae653e8925192480bb9d7f210f4fd87a1b9ecc3d76ef488d3d2877b75a60489abed8e5ff
data/.gitignore ADDED
@@ -0,0 +1,3 @@
1
+ /.bundle/
2
+ /spec/examples.txt
3
+ /notes.txt
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --require spec_helper
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 2.3.0
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in bernard.gemspec
4
+ gemspec
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
@@ -0,0 +1,9 @@
1
+ # Bernard
2
+
3
+ Sends event data to visualisation services.
4
+
5
+ ![bernard](http://dogkeg.com/wp-content/uploads/2015/10/saint_bernard__dog_keg_barrel-30-640x427-e1446127647535.jpg)
6
+
7
+ ## License
8
+
9
+ (c) 2016 The Dextrous Web Ltd. Released under the MIT license.
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/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
@@ -0,0 +1,3 @@
1
+ class Bernard
2
+ class Exception < StandardError; end
3
+ end
@@ -0,0 +1,5 @@
1
+ class Bernard
2
+ class Schema
3
+
4
+ end
5
+ end
@@ -0,0 +1,3 @@
1
+ class Bernard
2
+ VERSION = '0.1.0'.freeze
3
+ end
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
- VERSION = '0.0.0'.freeze
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.0.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