functions_framework 0.2.0 → 0.4.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -87,7 +87,7 @@ module FunctionsFramework
87
87
  function = ::FunctionsFramework.global_registry[name]
88
88
  case function&.type
89
89
  when :http
90
- Testing.interpret_response { function.call request }
90
+ Testing.interpret_response { function.new_call.call request }
91
91
  when nil
92
92
  raise "Unknown function name #{name}"
93
93
  else
@@ -97,7 +97,7 @@ module FunctionsFramework
97
97
 
98
98
  ##
99
99
  # Call the given event function for testing. The underlying function must
100
- # be of type `:event` or `:cloud_event`.
100
+ # be of type :cloud_event`.
101
101
  #
102
102
  # @param name [String] The name of the function to call
103
103
  # @param event [FunctionsFramework::CloudEvets::Event] The event to send
@@ -106,8 +106,8 @@ module FunctionsFramework
106
106
  def call_event name, event
107
107
  function = ::FunctionsFramework.global_registry[name]
108
108
  case function&.type
109
- when :event, :cloud_event
110
- function.call event
109
+ when :cloud_event
110
+ function.new_call.call event
111
111
  nil
112
112
  when nil
113
113
  raise "Unknown function name #{name}"
@@ -116,30 +116,52 @@ module FunctionsFramework
116
116
  end
117
117
  end
118
118
 
119
+ ##
120
+ # Make a Rack request, for passing to a function test.
121
+ #
122
+ # @param url [URI,String] The URL to get, including query params.
123
+ # @param method [String] The HTTP method (defaults to "GET").
124
+ # @param body [String] The HTTP body, if any.
125
+ # @param headers [Array,Hash] HTTP headers. May be given as a hash (of
126
+ # header names mapped to values), an array of strings (where each
127
+ # string is of the form `Header-Name: Header value`), or an array of
128
+ # two-element string arrays.
129
+ # @return [Rack::Request]
130
+ #
131
+ def make_request url, method: ::Rack::GET, body: nil, headers: []
132
+ env = Testing.build_standard_env URI(url), headers
133
+ env[::Rack::REQUEST_METHOD] = method
134
+ env[::Rack::RACK_INPUT] = ::StringIO.new body if body
135
+ ::Rack::Request.new env
136
+ end
137
+
119
138
  ##
120
139
  # Make a simple GET request, for passing to a function test.
121
140
  #
122
141
  # @param url [URI,String] The URL to get.
142
+ # @param headers [Array,Hash] HTTP headers. May be given as a hash (of
143
+ # header names mapped to values), an array of strings (where each
144
+ # string is of the form `Header-Name: Header value`), or an array of
145
+ # two-element string arrays.
123
146
  # @return [Rack::Request]
124
147
  #
125
148
  def make_get_request url, headers = []
126
- env = Testing.build_standard_env URI(url), headers
127
- env[::Rack::REQUEST_METHOD] = ::Rack::GET
128
- ::Rack::Request.new env
149
+ make_request url, headers: headers
129
150
  end
130
151
 
131
152
  ##
132
153
  # Make a simple POST request, for passing to a function test.
133
154
  #
134
155
  # @param url [URI,String] The URL to post to.
135
- # @param data [String] The body to post.
156
+ # @param body [String] The body to post.
157
+ # @param headers [Array,Hash] HTTP headers. May be given as a hash (of
158
+ # header names mapped to values), an array of strings (where each
159
+ # string is of the form `Header-Name: Header value`), or an array of
160
+ # two-element string arrays.
136
161
  # @return [Rack::Request]
137
162
  #
138
- def make_post_request url, data, headers = []
139
- env = Testing.build_standard_env URI(url), headers
140
- env[::Rack::REQUEST_METHOD] = ::Rack::POST
141
- env[::Rack::RACK_INPUT] = ::StringIO.new data
142
- ::Rack::Request.new env
163
+ def make_post_request url, body, headers = []
164
+ make_request url, method: ::Rack::POST, body: body, headers: headers
143
165
  end
144
166
 
145
167
  ##
@@ -245,7 +267,11 @@ module FunctionsFramework
245
267
  ::Rack::RACK_ERRORS => ::StringIO.new
246
268
  }
247
269
  headers.each do |header|
248
- name, value = header.split ":"
270
+ if header.is_a? String
271
+ name, value = header.split ":"
272
+ elsif header.is_a? Array
273
+ name, value = header
274
+ end
249
275
  next unless name && value
250
276
  name = name.strip.upcase.tr "-", "_"
251
277
  name = "HTTP_#{name}" unless ["CONTENT_TYPE", "CONTENT_LENGTH"].include? name
@@ -17,5 +17,5 @@ module FunctionsFramework
17
17
  # Version of the Ruby Functions Framework
18
18
  # @return [String]
19
19
  #
20
- VERSION = "0.2.0".freeze
20
+ VERSION = "0.4.1".freeze
21
21
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: functions_framework
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel Azuma
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-06-25 00:00:00.000000000 Z
11
+ date: 2020-07-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: puma
@@ -38,104 +38,6 @@ dependencies:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: '2.1'
41
- - !ruby/object:Gem::Dependency
42
- name: google-style
43
- requirement: !ruby/object:Gem::Requirement
44
- requirements:
45
- - - "~>"
46
- - !ruby/object:Gem::Version
47
- version: 1.24.0
48
- type: :development
49
- prerelease: false
50
- version_requirements: !ruby/object:Gem::Requirement
51
- requirements:
52
- - - "~>"
53
- - !ruby/object:Gem::Version
54
- version: 1.24.0
55
- - !ruby/object:Gem::Dependency
56
- name: minitest
57
- requirement: !ruby/object:Gem::Requirement
58
- requirements:
59
- - - "~>"
60
- - !ruby/object:Gem::Version
61
- version: '5.13'
62
- type: :development
63
- prerelease: false
64
- version_requirements: !ruby/object:Gem::Requirement
65
- requirements:
66
- - - "~>"
67
- - !ruby/object:Gem::Version
68
- version: '5.13'
69
- - !ruby/object:Gem::Dependency
70
- name: minitest-focus
71
- requirement: !ruby/object:Gem::Requirement
72
- requirements:
73
- - - "~>"
74
- - !ruby/object:Gem::Version
75
- version: '1.1'
76
- type: :development
77
- prerelease: false
78
- version_requirements: !ruby/object:Gem::Requirement
79
- requirements:
80
- - - "~>"
81
- - !ruby/object:Gem::Version
82
- version: '1.1'
83
- - !ruby/object:Gem::Dependency
84
- name: minitest-rg
85
- requirement: !ruby/object:Gem::Requirement
86
- requirements:
87
- - - "~>"
88
- - !ruby/object:Gem::Version
89
- version: '5.2'
90
- type: :development
91
- prerelease: false
92
- version_requirements: !ruby/object:Gem::Requirement
93
- requirements:
94
- - - "~>"
95
- - !ruby/object:Gem::Version
96
- version: '5.2'
97
- - !ruby/object:Gem::Dependency
98
- name: redcarpet
99
- requirement: !ruby/object:Gem::Requirement
100
- requirements:
101
- - - "~>"
102
- - !ruby/object:Gem::Version
103
- version: '3.5'
104
- type: :development
105
- prerelease: false
106
- version_requirements: !ruby/object:Gem::Requirement
107
- requirements:
108
- - - "~>"
109
- - !ruby/object:Gem::Version
110
- version: '3.5'
111
- - !ruby/object:Gem::Dependency
112
- name: toys
113
- requirement: !ruby/object:Gem::Requirement
114
- requirements:
115
- - - "~>"
116
- - !ruby/object:Gem::Version
117
- version: 0.10.0
118
- type: :development
119
- prerelease: false
120
- version_requirements: !ruby/object:Gem::Requirement
121
- requirements:
122
- - - "~>"
123
- - !ruby/object:Gem::Version
124
- version: 0.10.0
125
- - !ruby/object:Gem::Dependency
126
- name: yard
127
- requirement: !ruby/object:Gem::Requirement
128
- requirements:
129
- - - "~>"
130
- - !ruby/object:Gem::Version
131
- version: 0.9.24
132
- type: :development
133
- prerelease: false
134
- version_requirements: !ruby/object:Gem::Requirement
135
- requirements:
136
- - - "~>"
137
- - !ruby/object:Gem::Version
138
- version: 0.9.24
139
41
  description: The Functions Framework implementation for Ruby.
140
42
  email:
141
43
  - dazuma@google.com
@@ -162,6 +64,8 @@ files:
162
64
  - lib/functions_framework/cloud_events/content_type.rb
163
65
  - lib/functions_framework/cloud_events/errors.rb
164
66
  - lib/functions_framework/cloud_events/event.rb
67
+ - lib/functions_framework/cloud_events/event/field_interpreter.rb
68
+ - lib/functions_framework/cloud_events/event/v0.rb
165
69
  - lib/functions_framework/cloud_events/event/v1.rb
166
70
  - lib/functions_framework/cloud_events/http_binding.rb
167
71
  - lib/functions_framework/cloud_events/json_format.rb
@@ -174,7 +78,11 @@ files:
174
78
  homepage: https://github.com/GoogleCloudPlatform/functions-framework-ruby
175
79
  licenses:
176
80
  - Apache-2.0
177
- metadata: {}
81
+ metadata:
82
+ changelog_uri: https://github.com/GoogleCloudPlatform/functions-framework-ruby/blob/master/CHANGELOG.md
83
+ source_code_uri: https://github.com/GoogleCloudPlatform/functions-framework-ruby
84
+ bug_tracker_uri: https://github.com/GoogleCloudPlatform/functions-framework-ruby/issues
85
+ documentation_uri: https://rubydoc.info/gems/functions_framework/0.4.1
178
86
  post_install_message:
179
87
  rdoc_options: []
180
88
  require_paths: