kns_endpoint 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/LICENSE +21 -0
  2. data/lib/endpoint.rb +92 -0
  3. metadata +76 -0
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License
2
+
3
+ Copyright (c) 2010 Kynetx Inc.
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/lib/endpoint.rb ADDED
@@ -0,0 +1,92 @@
1
+ require 'httparty'
2
+ module Kynetx
3
+
4
+ class Endpoint
5
+
6
+ @@events = {}
7
+ @@directives = {}
8
+
9
+ def initialize
10
+ end
11
+
12
+
13
+ def self.event(e, params={}, &block)
14
+
15
+ @@events[e] = { :params => params }
16
+
17
+ @@events[e][:block] = block_given? ? block : lambda { |p| p }
18
+
19
+
20
+ end
21
+
22
+ def self.directive(d, &block)
23
+ raise "Directive must supply a block." unless block_given?
24
+ @@directives[d] = block
25
+ end
26
+
27
+ def self.ruleset(r); @@ruleset = r end
28
+
29
+ def self.domain(d); @@domain = d end
30
+
31
+
32
+
33
+ def signal(e, params)
34
+ run_event(e, params)
35
+ end
36
+
37
+
38
+ private
39
+
40
+ def run_event(e, params)
41
+
42
+ # setup the parameters and call the block
43
+
44
+ @@events[e][:block].call(params)
45
+
46
+ # run the event
47
+
48
+ resp = HTTParty.get "http://cs.kobj.net/blue/event/#{@@domain.to_s}/#{e.to_s}/#{@@ruleset.to_s}", :query => params
49
+
50
+ # execute the returned directives
51
+ directive_output = []
52
+ resp["directives"].each do |d|
53
+ o = run_directive(d["name"].to_sym, symbolize_keys(d["options"])) if @@directives.keys.include?(d["name"].to_sym)
54
+ directive_output.push o
55
+ end
56
+
57
+ return directive_output
58
+
59
+ end
60
+
61
+
62
+ def run_directive(d, params)
63
+ begin
64
+ return @@directives[d].call(params)
65
+ rescue Exception => e
66
+ puts "Error in directive (#{d.to_s}): #{e.message}\n#{e.backtrace.join("\n")}"
67
+ end
68
+
69
+ end
70
+
71
+ def symbolize_keys(hash)
72
+ hash.inject({}){|result, (key, value)|
73
+ new_key = case key
74
+ when String then key.to_sym
75
+ else key
76
+ end
77
+ new_value = case value
78
+ when Hash then symbolize_keys(value)
79
+ else value
80
+ end
81
+ result[new_key] = new_value
82
+ result
83
+ }
84
+ end
85
+
86
+
87
+
88
+ end
89
+
90
+
91
+ end
92
+
metadata ADDED
@@ -0,0 +1,76 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: kns_endpoint
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 0
8
+ - 1
9
+ version: 0.0.1
10
+ platform: ruby
11
+ authors:
12
+ - Michael Farmer
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2010-08-30 00:00:00 -06:00
18
+ default_executable:
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: httparty
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ">="
26
+ - !ruby/object:Gem::Version
27
+ segments:
28
+ - 0
29
+ - 5
30
+ - 2
31
+ version: 0.5.2
32
+ type: :runtime
33
+ version_requirements: *id001
34
+ description: " Build a Kynetx Endpoint in Ruby. Adds the ability to raise, or signal, events on the KNS Platform with\n a simple DSL to your existing or new ruby scripts or applications.\n"
35
+ email: mjf@kynetx.com
36
+ executables: []
37
+
38
+ extensions: []
39
+
40
+ extra_rdoc_files:
41
+ - LICENSE
42
+ files:
43
+ - lib/endpoint.rb
44
+ - LICENSE
45
+ has_rdoc: true
46
+ homepage: http://github.com/kynetx/kns_endpoint
47
+ licenses: []
48
+
49
+ post_install_message:
50
+ rdoc_options:
51
+ - --charset=UTF-8
52
+ require_paths:
53
+ - lib
54
+ required_ruby_version: !ruby/object:Gem::Requirement
55
+ requirements:
56
+ - - ">="
57
+ - !ruby/object:Gem::Version
58
+ segments:
59
+ - 0
60
+ version: "0"
61
+ required_rubygems_version: !ruby/object:Gem::Requirement
62
+ requirements:
63
+ - - ">="
64
+ - !ruby/object:Gem::Version
65
+ segments:
66
+ - 0
67
+ version: "0"
68
+ requirements: []
69
+
70
+ rubyforge_project:
71
+ rubygems_version: 1.3.6
72
+ signing_key:
73
+ specification_version: 3
74
+ summary: Creates a Kynetx KNS Endpoint
75
+ test_files: []
76
+