ridc 0.0.0 → 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. data/lib/ri_sender.rb +41 -0
  2. data/lib/ridc.rb +9 -4
  3. metadata +2 -1
data/lib/ri_sender.rb ADDED
@@ -0,0 +1,41 @@
1
+ require 'net/http'
2
+ require 'json'
3
+ require 'base64'
4
+ require 'openssl'
5
+ require 'digest/sha1'
6
+
7
+ class RiSender
8
+
9
+ def initialize(customer_key, secret_key, host, port)
10
+ @customer_key = customer_key
11
+ @secret_key = secret_key
12
+ @host = host
13
+ @port = port
14
+ end
15
+
16
+ def send(event)
17
+ req = Net::HTTP::Post.new("/events", initheader = {'Content-Type' => 'application/json'})
18
+
19
+ body = {
20
+ "customerKey" => @customer_key,
21
+ "signature" => sign_with_secret_key(event.to_json),
22
+ "event" => event
23
+ }.to_json
24
+
25
+ req.body = body
26
+ response = Net::HTTP.new(@host, @port).start { |http| http.request(req) }
27
+ response
28
+ end
29
+
30
+ private
31
+
32
+ def sign_with_secret_key(payload)
33
+ signature = Base64.encode64(
34
+ OpenSSL::HMAC.digest(
35
+ OpenSSL::Digest::Digest.new('sha1'),
36
+ @secret_key, payload)
37
+ ).gsub("\n", "")
38
+
39
+ signature
40
+ end
41
+ end
data/lib/ridc.rb CHANGED
@@ -1,5 +1,10 @@
1
- class Ridc
2
- def self.hi
3
- puts "Hello Rails Intelligence World!"
4
- end
1
+ require 'rails'
2
+
3
+ class Ridc < Rails::Railtie
4
+ initializer "rails_intelligence.configure_rails_initialization" do |app|
5
+ ActiveSupport::Notifications.subscribe do |*args|
6
+ event = ActiveSupport::Notifications::Event.new *args
7
+ Rails.logger.info(event.to_json)
8
+ end
9
+ end
5
10
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ridc
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.0
4
+ version: 0.0.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -21,6 +21,7 @@ extensions: []
21
21
  extra_rdoc_files: []
22
22
  files:
23
23
  - lib/ridc.rb
24
+ - lib/ri_sender.rb
24
25
  homepage: http://www.railsintelligence.com
25
26
  licenses:
26
27
  - MIT