fdk 0.0.11 → 0.0.12

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
- SHA256:
3
- metadata.gz: eb1a57393835969767b31529c287eaf5424798f82e96fb090e1727878cb1a557
4
- data.tar.gz: eb32d2f88da3de6211f92405110bdbf967ea0607248d4a6ed642fd8bbce6dd5b
2
+ SHA1:
3
+ metadata.gz: 3f057f3e89f9eb850ed4985a5f6126c8e8bfa48d
4
+ data.tar.gz: 9cae6ab2bf5440ead52770fd6bd9169f3aa16827
5
5
  SHA512:
6
- metadata.gz: 84c403a1ad1c7dcde9772f020e4bdd94d37aa2297113844d14b14bcc54bb5d397ed6f51977c4507f089c0a678be5020404904a57a71223250bbaff7c20ab5783
7
- data.tar.gz: 36ddfac04af2a711e64aae32ab3621bf0d2ad7f5b1e5da4f0abd7dc2488513b0603fa9a937ef61a38b4bf2beea777c4a5bbdd408f79e03e5b1b9ae13b575f64e
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
- STDERR.puts "request_url: " + context.protocol['request_url']
41
- STDERR.puts "call_id: " + context.call_id
42
- STDERR.puts "input: " + input.to_s
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
@@ -6,7 +6,7 @@ require 'json'
6
6
  require 'yajl'
7
7
 
8
8
  module FDK
9
- def self.handle(func)
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: func, context: context, input: body)
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
- 'Content-Type' => ['application/json']
24
+ 'Content-Type' => ['application/json']
25
25
  },
26
- 'status_code' => 200,
26
+ 'status_code' => 200
27
27
  }
28
- STDOUT.puts event.to_json
29
- STDOUT.puts
30
- STDOUT.flush
28
+ output_stream.puts event.to_json
29
+ output_stream.puts
30
+ output_stream.flush
31
31
  end
32
32
 
33
- STDIN.each_line { |line| parser.parse_chunk(line) }
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: func, context: context, input: body)
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
- STDOUT.puts response.to_json
53
- STDOUT.puts
54
- STDOUT.flush
52
+ output_stream.puts response.to_json
53
+ output_stream.puts
54
+ output_stream.flush
55
55
  end
56
56
 
57
- STDIN.each_line { |line| parser.parse_chunk(line) }
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
- c = Context.new(event)
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 function, context, input
73
+ send(function, context: context, input: input)
75
74
  end
76
75
  end
@@ -1,3 +1,3 @@
1
1
  module FDK
2
- VERSION = "0.0.11"
2
+ VERSION = "0.0.12"
3
3
  end
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.11
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-04-24 00:00:00.000000000 Z
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.7.6
88
+ rubygems_version: 2.6.14
67
89
  signing_key:
68
90
  specification_version: 4
69
91
  summary: Ruby FDK for Fn Project