fdk 0.0.11 → 0.0.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +5 -5
- data/README.md +4 -5
- data/lib/fdk/runner.rb +15 -16
- data/lib/fdk/version.rb +1 -1
- metadata +25 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 3f057f3e89f9eb850ed4985a5f6126c8e8bfa48d
|
4
|
+
data.tar.gz: 9cae6ab2bf5440ead52770fd6bd9169f3aa16827
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 53027dd0dc51188135be54f0d6a669cf5dbb3e32a5b6bcecc504c7e96312ecb3237f9c5572b0e7675171fbbd9c0705ee1ac079851503b72d41c405308d652bfe
|
7
|
+
data.tar.gz: 3e8f21b25c20dd5e8595c53a0cfa80fb1c7cef152a1f3f5914d628cd13b3b86a547a4a80494215ea11f52ba75ca0a3a8dc2ed5bc7fd259e01cace8203e6d8931
|
data/README.md
CHANGED
@@ -37,13 +37,12 @@ FDK.handle(myfunction)
|
|
37
37
|
require 'fdk'
|
38
38
|
|
39
39
|
def myfunction(context:, input:)
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
{ message: "Hello #{input['name']}!" }
|
40
|
+
input_value = input.respond_to?(:fetch) ? input.fetch('name') : input
|
41
|
+
name = input_value.to_s.strip.empty? ? 'World' : input_value
|
42
|
+
{ message: "Hello #{name}!" }
|
44
43
|
end
|
45
44
|
|
46
|
-
FDK.handle(:myfunction)
|
45
|
+
FDK.handle(function: :myfunction)
|
47
46
|
```
|
48
47
|
|
49
48
|
## Running the example that is in the root directory of this repo
|
data/lib/fdk/runner.rb
CHANGED
@@ -6,7 +6,7 @@ require 'json'
|
|
6
6
|
require 'yajl'
|
7
7
|
|
8
8
|
module FDK
|
9
|
-
def self.handle(
|
9
|
+
def self.handle(function, input_stream: STDIN, output_stream: STDOUT)
|
10
10
|
format = ENV['FN_FORMAT']
|
11
11
|
if format == 'cloudevent'
|
12
12
|
parser = Yajl::Parser.new
|
@@ -15,22 +15,22 @@ module FDK
|
|
15
15
|
context = Context.new(event)
|
16
16
|
body = event['data']
|
17
17
|
# Skipping json parsing of body because it would already be a parsed map according to the format spec defined here: https://github.com/cloudevents/spec/blob/master/serialization.md#json
|
18
|
-
se = FDK.single_event(function:
|
18
|
+
se = FDK.single_event(function: function, context: context, input: body)
|
19
19
|
|
20
20
|
# Respond with modified event
|
21
21
|
event['data'] = se
|
22
22
|
event['extensions']['protocol'] = {
|
23
23
|
headers: {
|
24
|
-
|
24
|
+
'Content-Type' => ['application/json']
|
25
25
|
},
|
26
|
-
'status_code' => 200
|
26
|
+
'status_code' => 200
|
27
27
|
}
|
28
|
-
|
29
|
-
|
30
|
-
|
28
|
+
output_stream.puts event.to_json
|
29
|
+
output_stream.puts
|
30
|
+
output_stream.flush
|
31
31
|
end
|
32
32
|
|
33
|
-
|
33
|
+
input_stream.each_line { |line| parser.parse_chunk(line) }
|
34
34
|
|
35
35
|
elsif format == 'json'
|
36
36
|
parser = Yajl::Parser.new
|
@@ -41,7 +41,7 @@ module FDK
|
|
41
41
|
if context.content_type == 'application/json' && body != ''
|
42
42
|
body = Yajl::Parser.parse(body)
|
43
43
|
end
|
44
|
-
se = FDK.single_event(function:
|
44
|
+
se = FDK.single_event(function: function, context: context, input: body)
|
45
45
|
response = {
|
46
46
|
headers: {
|
47
47
|
'Content-Type' => ['application/json']
|
@@ -49,12 +49,12 @@ module FDK
|
|
49
49
|
'status_code' => 200,
|
50
50
|
body: se.to_json
|
51
51
|
}
|
52
|
-
|
53
|
-
|
54
|
-
|
52
|
+
output_stream.puts response.to_json
|
53
|
+
output_stream.puts
|
54
|
+
output_stream.flush
|
55
55
|
end
|
56
56
|
|
57
|
-
|
57
|
+
input_stream.each_line { |line| parser.parse_chunk(line) }
|
58
58
|
|
59
59
|
elsif format == 'default'
|
60
60
|
event = {}
|
@@ -63,14 +63,13 @@ module FDK
|
|
63
63
|
'type' => 'http',
|
64
64
|
'request_url' => ENV['FN_REQUEST_URL']
|
65
65
|
}
|
66
|
-
|
67
|
-
puts FDK.single_event(function: func, context: c, input: STDIN.read).to_json
|
66
|
+
output_stream.puts FDK.single_event(function: function, context: Context.new(event), input: input_stream.read).to_json
|
68
67
|
else
|
69
68
|
raise "Format '#{format}' not supported in Ruby FDK."
|
70
69
|
end
|
71
70
|
end
|
72
71
|
|
73
72
|
def self.single_event(function:, context:, input:)
|
74
|
-
send
|
73
|
+
send(function, context: context, input: input)
|
75
74
|
end
|
76
75
|
end
|
data/lib/fdk/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fdk
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.12
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Travis Reeder
|
8
|
+
- Ewan Slater
|
8
9
|
autorequire:
|
9
10
|
bindir: bin
|
10
11
|
cert_chain: []
|
11
|
-
date: 2018-
|
12
|
+
date: 2018-09-10 00:00:00.000000000 Z
|
12
13
|
dependencies:
|
13
14
|
- !ruby/object:Gem::Dependency
|
14
15
|
name: json
|
@@ -30,9 +31,30 @@ dependencies:
|
|
30
31
|
- - ">="
|
31
32
|
- !ruby/object:Gem::Version
|
32
33
|
version: 2.1.0
|
34
|
+
- !ruby/object:Gem::Dependency
|
35
|
+
name: yajl-ruby
|
36
|
+
requirement: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.2'
|
41
|
+
- - ">="
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: 1.2.1
|
44
|
+
type: :runtime
|
45
|
+
prerelease: false
|
46
|
+
version_requirements: !ruby/object:Gem::Requirement
|
47
|
+
requirements:
|
48
|
+
- - "~>"
|
49
|
+
- !ruby/object:Gem::Version
|
50
|
+
version: '1.2'
|
51
|
+
- - ">="
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: 1.2.1
|
33
54
|
description: Ruby Function Developer Kit for Fn Project.
|
34
55
|
email:
|
35
56
|
- treeder@gmail.com
|
57
|
+
- ewan.slater@gmail.com
|
36
58
|
executables: []
|
37
59
|
extensions: []
|
38
60
|
extra_rdoc_files: []
|
@@ -63,7 +85,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
63
85
|
version: '0'
|
64
86
|
requirements: []
|
65
87
|
rubyforge_project:
|
66
|
-
rubygems_version: 2.
|
88
|
+
rubygems_version: 2.6.14
|
67
89
|
signing_key:
|
68
90
|
specification_version: 4
|
69
91
|
summary: Ruby FDK for Fn Project
|