bernard 0.3.0 → 0.4.0

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: ddba97c1717f871b71e0d8b206fa8a85e90896b2
4
- data.tar.gz: ff3ed7b6f55f910966ed98348192031591382239
3
+ metadata.gz: cb3c234efb7347577546da62322f8e0be7f7e468
4
+ data.tar.gz: dfee53a17404e085fcdc7edfdac20dfcffeae862
5
5
  SHA512:
6
- metadata.gz: 69dca033e296b405b6cd3ce4c80fcc43bd04d7e4aabf3bd5f2e3fb90dc9c1c1bb6ade7138bba859dd5b93b8c648ae2fe981f974e55f4b72033da7a28efbd82a5
7
- data.tar.gz: a10ef9b2bf6074a2428b2172fe5690b214212312e3a1ca5b8b882d46497a4aae8f09c51dc93190b8b23168b1c5f9eab11107dea6fab95ea1ac35358f030487c2
6
+ metadata.gz: 20728ae23d447582f13da324337cbeb50d2469dba56fa2449306c3d8bdd1322935b518a51a92ca477db67959de33920f81d8106d06a75021b501d7be6d19e530
7
+ data.tar.gz: 848b93233a3010ace79c7680682638a92778326edfea34db3203d14546ae9f80ff02c0ecf86bdd787f743c40f03bebf3288b942e44b5f49e3259c80c3f1203e0
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- bernard (0.3.0)
4
+ bernard (0.4.0)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -33,7 +33,7 @@ GEM
33
33
  rspec-support (3.4.1)
34
34
  safe_yaml (1.0.4)
35
35
  slop (3.6.0)
36
- webmock (1.24.2)
36
+ webmock (1.24.6)
37
37
  addressable (>= 2.3.6)
38
38
  crack (>= 0.3.2)
39
39
  hashdiff
data/README.md CHANGED
@@ -2,6 +2,9 @@
2
2
 
3
3
  Sends event data to visualisation services.
4
4
 
5
+ Currently supporting:
6
+ - Keen.io
7
+
5
8
  ![bernard](http://dogkeg.com/wp-content/uploads/2015/10/saint_bernard__dog_keg_barrel-30-640x427-e1446127647535.jpg)
6
9
 
7
10
 
@@ -9,7 +12,7 @@ Sends event data to visualisation services.
9
12
 
10
13
  Add this line to your application's Gemfile:
11
14
  ```ruby
12
- gem 'bernard', '~> 0.2.0'
15
+ gem 'bernard', '~> 0.4.0'
13
16
  ```
14
17
 
15
18
  And then execute:
@@ -17,7 +20,7 @@ And then execute:
17
20
  $ bundle
18
21
  ```
19
22
 
20
- ## Setup
23
+ ## Basic setup
21
24
  To use Bernard you can either create an initializer or construct it as you need it.
22
25
 
23
26
  Create a new initializer `config/bernard.rb` in your application
@@ -25,6 +28,7 @@ Create a new initializer `config/bernard.rb` in your application
25
28
  Bernard::Keen::Client.configure do |client|
26
29
  client.config = {
27
30
  uri: URI('https://api.keen.io'),
31
+ application_name: '<YOUR APPLICATION NAME>',
28
32
  project_id: '<YOUR PROJECT ID>',
29
33
  write_key: '<YOUR WRITE KEY>',
30
34
  read_key: '<YOUR READ KEY>'
@@ -32,18 +36,6 @@ Bernard::Keen::Client.configure do |client|
32
36
  end
33
37
  ```
34
38
 
35
- OR
36
-
37
- Create a new client on the fly:
38
- ```ruby
39
- client = Bernard::Keen::Client.new(
40
- uri: URI('https://api.keen.io')
41
- project_id: '<YOUR PROJECT ID>'
42
- write_key: '<YOUR WRITE KEY>'
43
- ready_key: '<YOUR READ KEY>'
44
- )
45
- ```
46
-
47
39
  ## Usage
48
40
 
49
41
  ### Tick
@@ -67,6 +59,53 @@ Update an event to a new value.
67
59
  client.gauge('office_noise_level', '43')
68
60
  ```
69
61
 
62
+ ---
63
+
64
+ ## Advanced configuration
65
+
66
+ ### Easier way to make a client
67
+ Instead of using an initializer you could create a new client on the fly:
68
+ ```ruby
69
+ client = Bernard::Keen::Client.new(
70
+ uri: URI('https://api.keen.io')
71
+ application_name: '<YOUR APPLICATION NAME>'
72
+ project_id: '<YOUR PROJECT ID>'
73
+ write_key: '<YOUR WRITE KEY>'
74
+ ready_key: '<YOUR READ KEY>'
75
+ )
76
+ ```
77
+
78
+ ### Run asynchronously
79
+
80
+ Given that this Gem is making HTTP requests which can be slow, we'd advise using
81
+ a worker like [Sidekiq](https://github.com/mperham/sidekiq).
82
+
83
+ For example adding this to your applications's `workers/bernard_worker.rb` file:
84
+ ```ruby
85
+ require 'bernard'
86
+
87
+ class BernardWorker
88
+ include Sidekiq::Worker
89
+
90
+ def perform(event_type, event_name, value = 0)
91
+ case event_type.to_sym
92
+ when :tick then Bernard::Keen::Client.new.tick(event_name)
93
+ when :count then Bernard::Keen::Client.new.count(event_name, value)
94
+ when :gauge then Bernard::Keen::Client.new.gauge(event_name, value)
95
+ else
96
+ end
97
+ end
98
+ end
99
+ ```
100
+
101
+ and invoke using this worker instead to ensure it doesn't interrupt your application's processes:
102
+
103
+ ```ruby
104
+ BernardWorker.perform_async(:tick, :vote)
105
+ BernardWorker.perform_async(:count, :visitors, 3)
106
+ BernardWorker.perform_async(:gauge, :temperature, 32.5)
107
+ ```
108
+
70
109
  ## License
71
110
 
72
111
  (c) 2016 The Dextrous Web Ltd. Released under the MIT license.
@@ -14,6 +14,7 @@ module Bernard
14
14
  def config=(args)
15
15
  @config = {
16
16
  uri: args[:uri],
17
+ application_name: args[:application_name],
17
18
  project_id: args[:project_id],
18
19
  write_key: args[:write_key],
19
20
  read_key: args[:read_key]
@@ -23,12 +24,13 @@ module Bernard
23
24
 
24
25
  include Bernard::Keen::Methods
25
26
 
26
- attr_reader :uri, :project_id, :write_key, :read_key
27
+ attr_reader :uri, :application_name, :project_id, :write_key, :read_key
27
28
 
28
29
  def initialize(args = {})
29
30
  config = config_from(args)
30
31
 
31
32
  @uri = config.fetch(:uri, nil)
33
+ @application_name = config.fetch(:application_name, nil)
32
34
  @project_id = config.fetch(:project_id, nil)
33
35
  @write_key = config.fetch(:write_key, nil)
34
36
  @read_key = config.fetch(:read_key, nil)
@@ -50,6 +52,11 @@ module Bernard
50
52
  @uri = value
51
53
  end
52
54
 
55
+ def application_name=(value)
56
+ raise(Bernard::ArgumentError, 'Missing application_name') unless value
57
+ @application_name = value
58
+ end
59
+
53
60
  def project_id=(value)
54
61
  raise(Bernard::ArgumentError, 'Missing project_id') unless value
55
62
  @project_id = value
@@ -14,14 +14,14 @@ module Bernard
14
14
  end
15
15
 
16
16
  def write(event, metadata)
17
-
18
17
  event = String(event).strip.downcase
18
+ payload = metadata.merge!(default_params).to_json
19
19
  uri.path = "/3.0/projects/#{project_id}/events/#{event}"
20
20
 
21
21
  request = Net::HTTP::Post.new(uri.path)
22
22
  request['Authorization'] = write_key
23
23
  request['Content-Type'] = 'application/json'
24
- request.body = metadata.to_json
24
+ request.body = payload
25
25
 
26
26
  begin
27
27
  connection = Bernard::Connection.new(uri).call
@@ -30,6 +30,12 @@ module Bernard
30
30
  return false
31
31
  end
32
32
  end
33
+
34
+ private def default_params
35
+ {
36
+ application_name: application_name
37
+ }
38
+ end
33
39
  end
34
40
  end
35
41
  end
@@ -1,3 +1,3 @@
1
1
  module Bernard
2
- VERSION = '0.3.0'.freeze
2
+ VERSION = '0.4.0'.freeze
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bernard
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tom Hipkin