fdk 0.0.7 → 0.0.8

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. checksums.yaml +5 -5
  2. data/lib/fdk/runner.rb +83 -38
  3. data/lib/fdk/version.rb +1 -1
  4. metadata +3 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 2e64a0e5796780aa5da851a552a9c5f987b1b259
4
- data.tar.gz: 4fe294730d566e185a03cdcfbddc87b69fd33450
2
+ SHA256:
3
+ metadata.gz: 8958c018c5730c72cf314b69f19e7930ba7995fb3b1dddb3b012ebcf66dc6171
4
+ data.tar.gz: 915b07e47c9f919333e380d919f46abcc50a624bdae77153c503246f2ef61576
5
5
  SHA512:
6
- metadata.gz: 99d1269bad6884de4fab41fc1ea5d45b0a72d29b9b9e4245305b0a2c510a07e400fa162d15758ea1b0ca6253cc99ce1d15c77dd88d1113e7a44e2562b47dd16d
7
- data.tar.gz: ed0b93ab6cd9757e474bc02d0bb752c2861fbc9a2a910fd3a1bedcb79d1e4654e9f485d6a15106851a2388f00cd46ba88315fe56fc8bbedb9c792635c7857b00
6
+ metadata.gz: 235b4bcf982c408099fa2f1713a4cc658af7c9ff86b61cf1e21bbd72645a39594a063f12b9d34c8e73a4b61931e6825f3f8411cd92dc0ede3d03406cd1e201d7
7
+ data.tar.gz: 5f506adf41f2df8e0d719b96162c438f8fec6dc118ea10bb8e08927cf9cda73b58ed3a9b35cae8ae7ca01f04e365a5ead1df5969b584e25519c600dbedb50e96
data/lib/fdk/runner.rb CHANGED
@@ -11,46 +11,91 @@ module FDK
11
11
  format = ENV['FN_FORMAT']
12
12
  if format == "json"
13
13
  obs = ""
14
- endbracket=false
15
- STDIN.each do |line|
16
- # STDERR.puts "LINE: --#{line}--"
17
- # STDERR.flush
18
- ls = line.strip
19
- # STDERR.puts "ls: #{ls}"
20
- if ls == "}"
21
- # STDERR.puts "endbracket true"
22
- endbracket=true
23
- elsif ls == "" && endbracket
24
- # TODO: this isn't very robust, probably needs to be better :/
25
- # STDERR.puts "OBJECT: #{obs}"
26
- payload = JSON.parse(obs)
27
- # STDERR.puts "payload: #{payload.inspect}"
28
- c = Context.new(payload)
29
- # STDERR.puts "context: " + c.inspect
30
- # STDERR.flush
31
- body = payload['body']
32
- if c.content_type == 'application/json'
33
- body = JSON.parse(body)
14
+ first_bracket = false
15
+ # end_bracket=false
16
+ stack_count = 0
17
+ STDIN.each_char do |c|
18
+ # STDERR.puts "c: #{c}"
19
+ if c == '{'
20
+ if !first_bracket
21
+ # STDERR.puts "setting first_bracket"
22
+ first_bracket = true
23
+ end
24
+ stack_count += 1
25
+ elsif c == '}'
26
+ stack_count -= 1
27
+ end
28
+ if first_bracket
29
+ # STDERR.puts "in first_bracket stack_count: #{stack_count}"
30
+ obs += c
31
+ if stack_count == 0 # found last bracket, so close this out
32
+ # STDERR.puts "OBJECT: #{obs}"
33
+ payload = JSON.parse(obs)
34
+ # STDERR.puts "payload: #{payload.inspect}"
35
+ ctx = Context.new(payload)
36
+ # STDERR.puts "context: " + ctx.inspect
37
+ # STDERR.flush
38
+ body = payload['body']
39
+ if ctx.content_type == 'application/json' && body != ""
40
+ body = JSON.parse(body)
41
+ end
42
+ # TODO: begin/rescue so we can respond with proper error response and code
43
+ se = FDK.single_event(func, ctx, body)
44
+ response = {
45
+ headers: {
46
+ 'Content-Type' => 'application/json'
47
+ },
48
+ 'status_code' => 200,
49
+ body: se.to_json,
50
+ }
51
+ STDOUT.puts response.to_json
52
+ STDOUT.puts
53
+ STDOUT.flush
54
+ first_bracket = false
55
+ obs = ""
34
56
  end
35
- # TODO: begin/rescue so we can respond with proper error response and code
36
- s = FDK.single_event(func, c, body)
37
- response = {
38
- headers: {
39
- 'Content-Type' => 'application/json'
40
- },
41
- 'status_code' => 200,
42
- body: s.to_json,
43
- }
44
- STDOUT.puts response.to_json
45
- STDOUT.puts
46
- STDOUT.flush
47
- obs = ""
48
- next
49
- else
50
- endbracket = false
51
57
  end
52
- obs += line
53
58
  end
59
+
60
+ # STDIN.each do |line|
61
+ # STDERR.puts "LINE: --#{line}--"
62
+ # STDERR.flush
63
+ # ls = line.strip
64
+ # STDERR.puts "ls: #{ls}"
65
+ # if ls == "}"
66
+ # # STDERR.puts "endbracket true"
67
+ # endbracket=true
68
+ # elsif ls == "" && endbracket
69
+ # # TODO: this isn't very robust, probably needs to be better :/
70
+ # STDERR.puts "OBJECT: #{obs}"
71
+ # payload = JSON.parse(obs)
72
+ # STDERR.puts "payload: #{payload.inspect}"
73
+ # c = Context.new(payload)
74
+ # STDERR.puts "context: " + c.inspect
75
+ # STDERR.flush
76
+ # body = payload['body']
77
+ # if c.content_type == 'application/json'
78
+ # body = JSON.parse(body)
79
+ # end
80
+ # # TODO: begin/rescue so we can respond with proper error response and code
81
+ # s = FDK.single_event(func, c, body)
82
+ # response = {
83
+ # headers: {
84
+ # 'Content-Type' => 'application/json'
85
+ # },
86
+ # 'status_code' => 200,
87
+ # body: s.to_json,
88
+ # }
89
+ # STDOUT.puts response.to_json
90
+ # STDOUT.puts
91
+ # STDOUT.flush
92
+ # obs = ""
93
+ # next
94
+ # else
95
+ # endbracket = false
96
+ # end
97
+ # obs += line
98
+ # end
54
99
  elsif format == "default"
55
100
  # TODO: check if content type json, and if so, parse it before passing it in
56
101
  body = STDIN.read
@@ -69,7 +114,7 @@ module FDK
69
114
  end
70
115
  puts FDK.single_event(func, c, body).to_json
71
116
  else
72
- raise "Format #{format} not supported in Ruby FDK."
117
+ raise "Format '#{format}' not supported in Ruby FDK."
73
118
  end
74
119
  end
75
120
 
data/lib/fdk/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  module FDK
2
2
 
3
- VERSION = "0.0.7"
3
+ VERSION = "0.0.8"
4
4
 
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fdk
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.7
4
+ version: 0.0.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Travis Reeder
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-11-30 00:00:00.000000000 Z
11
+ date: 2018-03-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: json
@@ -63,7 +63,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
63
63
  version: '0'
64
64
  requirements: []
65
65
  rubyforge_project:
66
- rubygems_version: 2.6.14
66
+ rubygems_version: 2.7.6
67
67
  signing_key:
68
68
  specification_version: 4
69
69
  summary: Ruby FDK for Fn Project