kns_endpoint 0.1.7 → 0.1.8
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/kns_endpoint.rb +21 -8
- metadata +7 -7
data/lib/kns_endpoint.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
require 'rest_client'
|
2
2
|
require 'json'
|
3
|
+
require 'logger'
|
3
4
|
|
4
5
|
module Kynetx
|
5
6
|
|
@@ -11,6 +12,7 @@ module Kynetx
|
|
11
12
|
@@use_session = true;
|
12
13
|
@@environment = :production
|
13
14
|
@@ruleset = nil
|
15
|
+
RestClient.log = Logger.new(STDOUT) if $KNS_ENDPOINT_DEBUG
|
14
16
|
|
15
17
|
def initialize(opts={})
|
16
18
|
@environment = opts[:environment] if opts[:environment]
|
@@ -20,6 +22,9 @@ module Kynetx
|
|
20
22
|
@logging = opts[:logging] if opts[:logging]
|
21
23
|
|
22
24
|
# set the defaults
|
25
|
+
@events = @@events
|
26
|
+
@directives = @@directives
|
27
|
+
@domain = @@domain
|
23
28
|
@environment ||= @@environment
|
24
29
|
@use_session ||= @@use_session
|
25
30
|
@ruleset ||= @@ruleset
|
@@ -28,6 +33,7 @@ module Kynetx
|
|
28
33
|
@logging ||= false
|
29
34
|
@log = []
|
30
35
|
raise "Undefined ruleset." unless @ruleset
|
36
|
+
raise "Undefined Domain" unless @domain
|
31
37
|
end
|
32
38
|
|
33
39
|
## Endpoint DSL
|
@@ -97,17 +103,21 @@ module Kynetx
|
|
97
103
|
begin
|
98
104
|
# setup the parameters and call the block
|
99
105
|
|
100
|
-
if
|
101
|
-
|
106
|
+
if @events.keys.include? e
|
107
|
+
@events[e][:block].call(params)
|
102
108
|
else
|
103
109
|
raise "Undefined event #{e.to_s}"
|
104
110
|
end
|
105
111
|
|
106
|
-
raise "Undefined Domain" unless @@domain
|
107
112
|
|
108
|
-
api_call = "https://cs.kobj.net/blue/event/#{
|
109
|
-
|
110
|
-
|
113
|
+
api_call = "https://cs.kobj.net/blue/event/#{@domain.to_s}/#{e.to_s}/#{@ruleset}"
|
114
|
+
|
115
|
+
if @use_session && @session
|
116
|
+
@headers[:cookies] = {"SESSION_ID" => @session, "domain" => "kobj.net"}
|
117
|
+
else
|
118
|
+
# @session = nil
|
119
|
+
@headers = {}
|
120
|
+
end
|
111
121
|
|
112
122
|
timeout(@query_timeout) do
|
113
123
|
params[@ruleset.to_s + ":kynetx_app_version"] = "dev" unless @environment == :production
|
@@ -115,6 +125,8 @@ module Kynetx
|
|
115
125
|
if $KNS_ENDPOINT_DEBUG
|
116
126
|
puts "-- NEW REQUEST --"
|
117
127
|
puts "-- URL: " + api_call
|
128
|
+
puts "-- SESSION: #{@session.inspect}"
|
129
|
+
puts "-- USE_SESSION: #{@use_session.inspect}"
|
118
130
|
puts "-- HEADERS:\n#{headers.inspect}"
|
119
131
|
puts "-- PARAMS:\n#{params.inspect}"
|
120
132
|
end
|
@@ -142,6 +154,7 @@ module Kynetx
|
|
142
154
|
if $KNS_ENDPOINT_DEBUG
|
143
155
|
puts "-- RESPONSE --"
|
144
156
|
puts "-- CODE: #{response.code}"
|
157
|
+
puts "-- SESSION: #{@session}"
|
145
158
|
puts "-- COOKIES: #{response.cookies.inspect}"
|
146
159
|
puts "-- HEADERS: #{response.headers.inspect}"
|
147
160
|
puts "-- BODY: \n" + response.to_s
|
@@ -156,7 +169,7 @@ module Kynetx
|
|
156
169
|
# execute the returned directives
|
157
170
|
directive_output = []
|
158
171
|
kns_json["directives"].each do |d|
|
159
|
-
o = run_directive(d["name"].to_sym, d["options"]) if
|
172
|
+
o = run_directive(d["name"].to_sym, d["options"]) if @directives.keys.include?(d["name"].to_sym)
|
160
173
|
directive_output.push o
|
161
174
|
end
|
162
175
|
|
@@ -167,7 +180,7 @@ module Kynetx
|
|
167
180
|
|
168
181
|
def run_directive(d, params)
|
169
182
|
begin
|
170
|
-
return
|
183
|
+
return @directives[d].call(symbolize_keys(params))
|
171
184
|
rescue Exception => e
|
172
185
|
raise "Error in directive (#{d.to_s}): #{e.message}"
|
173
186
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: kns_endpoint
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 11
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 1
|
9
|
-
-
|
10
|
-
version: 0.1.
|
9
|
+
- 8
|
10
|
+
version: 0.1.8
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Michael Farmer
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2010-
|
18
|
+
date: 2010-12-22 00:00:00 -07:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -26,12 +26,12 @@ dependencies:
|
|
26
26
|
requirements:
|
27
27
|
- - ~>
|
28
28
|
- !ruby/object:Gem::Version
|
29
|
-
hash:
|
29
|
+
hash: 7
|
30
30
|
segments:
|
31
31
|
- 1
|
32
|
-
- 2
|
33
32
|
- 4
|
34
|
-
|
33
|
+
- 0
|
34
|
+
version: 1.4.0
|
35
35
|
type: :runtime
|
36
36
|
version_requirements: *id001
|
37
37
|
- !ruby/object:Gem::Dependency
|