ingram_micro_engine 0.0.2 → 0.0.3

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: ca808d5a39c5e0eb92c7ad69a8ab60c66c826f79
4
- data.tar.gz: 43d665f3359f6018812b2c106ca7ec1574fb0931
3
+ metadata.gz: 41711d66e1567d3170b9744518d928fdebaf085c
4
+ data.tar.gz: 5e74a9d1009ea66cabca8741a3f5938c20997bf2
5
5
  SHA512:
6
- metadata.gz: da1d0e59530a17643890d56f6ceba909d8f3cccb05060e8474cb45a77f0e1a36f1e9e4401167583513579cbbf8e5d2b33975ac1fefab989ac2a59569d00b559c
7
- data.tar.gz: db956b313e1d994d0d8b44b2ba63e50f0978e8d2dc0d9827c7d629b75ecc303d258a23ae9255a2178980e5aff3c6417d20e02e76fec5f46b0edd1834929b1914
6
+ metadata.gz: ba8111b1d53ab1735e70bffe77f34f7485461afab8342138461157e34e546797710f82ff0ae9ae5361a77fd6d343f134f1ae9db47df2b9e1ed0a91a86645d52b
7
+ data.tar.gz: 29cf9a9961088a0ef576f92f78c854b05700d91f47f551a59c5fc6f3cbfa509663505f53e7eb93daa185f97b73711220356349345e313a20c072156377e19a55
@@ -3,13 +3,24 @@ module IngramMicroEngine
3
3
  before_action :log_request
4
4
 
5
5
  def event
6
+ IngramMicroEngine.instrument(transaction_name, request_body)
7
+
6
8
  render status: 200, xml: success_response
7
9
  end
8
10
 
9
11
  private
10
12
 
13
+ def transaction_name
14
+ parsed = Nokogiri::XML.parse(request_body)
15
+ parsed.xpath("message/message-header/transaction-name").text
16
+ end
17
+
18
+ def request_body
19
+ @request_body ||= request.body.read
20
+ end
21
+
11
22
  def log_request
12
- IngramMicroEngine.log(request.body.read)
23
+ IngramMicroEngine.log(request_body)
13
24
  end
14
25
 
15
26
  def imm_response(opts={})
@@ -3,7 +3,7 @@ require "ingram_micro_engine/engine"
3
3
 
4
4
  module IngramMicroEngine
5
5
  class << self
6
- attr_accessor :configuration
6
+ attr_accessor :configuration, :backend, :namespace, :adapter
7
7
 
8
8
  def configuration
9
9
  IngramMicro.configuration
@@ -14,6 +14,42 @@ module IngramMicroEngine
14
14
  configuration.logger.info "[IngramMicroEngine] #{message}"
15
15
  end
16
16
  end
17
+
18
+ def instrument(transaction_name, xml)
19
+ backend.instrument namespace.call(transaction_name), xml
20
+ end
21
+
22
+ def subscribe(transaction_name, callable = Proc.new)
23
+ backend.subscribe namespace.to_regexp(transaction_name), adapter.call(callable)
24
+ end
25
+
26
+ def all(callable=Proc.new)
27
+ subscribe nil, callable
28
+ end
29
+ end
30
+
31
+ class Namespace < Struct.new(:value, :delimiter)
32
+ def call(name = nil)
33
+ "#{value}#{delimiter}#{name}"
34
+ end
35
+
36
+ def to_regexp(name = nil)
37
+ %r{^#{Regexp.escape call(name)}}
38
+ end
39
+ end
40
+
41
+ class NotificationAdapter < Struct.new(:subscriber)
42
+ def self.call(callable)
43
+ new(callable)
44
+ end
45
+
46
+ def call(*args)
47
+ payload = args.last
48
+ subscriber.call(payload)
49
+ end
17
50
  end
18
51
 
52
+ self.adapter = NotificationAdapter
53
+ self.namespace = Namespace.new("ingram_micro", ".")
54
+ self.backend = ActiveSupport::Notifications
19
55
  end
@@ -1,3 +1,3 @@
1
1
  module IngramMicroEngine
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ingram_micro_engine
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Le
@@ -90,7 +90,6 @@ extensions: []
90
90
  extra_rdoc_files: []
91
91
  files:
92
92
  - MIT-LICENSE
93
- - README.rdoc
94
93
  - Rakefile
95
94
  - app/assets/javascripts/ingram_micro_engine/application.js
96
95
  - app/assets/stylesheets/ingram_micro_engine/application.css
@@ -1,3 +0,0 @@
1
- = IngramMicroEngine
2
-
3
- This project rocks and uses MIT-LICENSE.