faastruby-rpc 0.2.1 → 0.2.2
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 +4 -4
- data/CHANGELOG.md +4 -0
- data/Gemfile.lock +1 -1
- data/lib/faastruby-rpc/function.rb +27 -11
- data/lib/faastruby-rpc/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3549d86d75838deeb0ee5ab553304ae42471c35b588ca0193053f8e3d96d1aea
|
4
|
+
data.tar.gz: cfcd04067a0eea97c821ee10d1783fd6e8f8d7738edfb88ed210c863fd97ac33
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c7a2897bb1c884105668b0ec7a6f9247c1e31f9e2fb230ca0b4078f80fbff5ed0124a7041906c3a50e212c1033e0043d3ad60d2368de17efa4ef3e5d5e954a0b
|
7
|
+
data.tar.gz: eb69a1bcc203c6eeb4733e1898e5218b8ddcd6b9f0c9e1ddc8ac938bdbaf86fffb00fe6fb16d6bd6fd8d858da56f9dd4a85120d23c56bbb7a0786d6c5b35c577
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,9 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
+
## 0.2.2 - Mar 8 2019
|
4
|
+
- Improved response string from invoked function when there's an error.
|
5
|
+
- Catch method missing calls and try them against the result once it arrives
|
6
|
+
|
3
7
|
## 0.2.1 - Jan 3rd 2019
|
4
8
|
- Pass a block when calling a function and the code will be executed when the function responds, and the block's return value will replace the function's response body
|
5
9
|
|
data/Gemfile.lock
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
module FaaStRuby
|
2
|
-
|
2
|
+
FAASTRUBY_WORKSPACE_BASE_HOST = ENV['FAASTRUBY_WORKSPACE_BASE_HOST']
|
3
3
|
module RPC
|
4
4
|
class ExecutionError < StandardError
|
5
5
|
end
|
@@ -37,20 +37,25 @@ module FaaStRuby
|
|
37
37
|
self
|
38
38
|
end
|
39
39
|
|
40
|
+
def get_endpoint(query_params)
|
41
|
+
return "https://#{FAASTRUBY_WORKSPACE_BASE_HOST}/#{@path}#{query_params}" if FAASTRUBY_WORKSPACE_BASE_HOST
|
42
|
+
return "http://localhost:3000/#{@path}#{query_params}"
|
43
|
+
end
|
44
|
+
|
40
45
|
def execute(req_body: nil, query_params: {}, headers: {}, method: 'post')
|
41
|
-
url =
|
46
|
+
url = get_endpoint(convert_query_params(query_params))
|
42
47
|
uri = URI.parse(url)
|
43
48
|
use_ssl = uri.scheme == 'https' ? true : false
|
44
|
-
|
49
|
+
function_response = fetch(use_ssl: use_ssl, uri: uri, headers: headers, method: @methods[method], req_body: req_body)
|
45
50
|
resp_headers = {}
|
46
|
-
|
51
|
+
function_response.each{|k,v| resp_headers[k] = v}
|
47
52
|
case resp_headers['content-type']
|
48
53
|
when 'application/json'
|
49
54
|
begin
|
50
|
-
resp_body = Oj.load(
|
55
|
+
resp_body = Oj.load(function_response.body)
|
51
56
|
rescue Oj::ParseError => e
|
52
|
-
if
|
53
|
-
resp_body =
|
57
|
+
if function_response.body.is_a?(String)
|
58
|
+
resp_body = function_response.body
|
54
59
|
else
|
55
60
|
raise e if @raise_errors
|
56
61
|
resp_body = {
|
@@ -60,12 +65,16 @@ module FaaStRuby
|
|
60
65
|
end
|
61
66
|
end
|
62
67
|
when 'application/yaml'
|
63
|
-
resp_body = YAML.load(
|
68
|
+
resp_body = YAML.load(function_response.body)
|
64
69
|
else
|
65
|
-
resp_body =
|
70
|
+
resp_body = function_response.body
|
71
|
+
end
|
72
|
+
if function_response.code.to_i >= 400 && @raise_errors
|
73
|
+
location = resp_body['location'] ? " @ #{resp_body['location']}" : nil
|
74
|
+
error_msg = "#{resp_body['error']}#{location}"
|
75
|
+
raise FaaStRuby::RPC::ExecutionError.new("Function '#{@path}' returned status code #{function_response.code}: #{error_msg}")
|
66
76
|
end
|
67
|
-
|
68
|
-
@response = FaaStRuby::RPC::Response.new(resp_body, response.code.to_i, resp_headers)
|
77
|
+
@response = FaaStRuby::RPC::Response.new(resp_body, function_response.code.to_i, resp_headers)
|
69
78
|
self
|
70
79
|
end
|
71
80
|
|
@@ -73,6 +82,11 @@ module FaaStRuby
|
|
73
82
|
!@response.nil?
|
74
83
|
end
|
75
84
|
|
85
|
+
def method_missing(m, *args, &block)
|
86
|
+
rsp = response.body
|
87
|
+
rsp.send(m.to_sym, *args, &block)
|
88
|
+
end
|
89
|
+
|
76
90
|
def response
|
77
91
|
wait unless returned?
|
78
92
|
@response
|
@@ -82,6 +96,8 @@ module FaaStRuby
|
|
82
96
|
body.to_s || ""
|
83
97
|
end
|
84
98
|
|
99
|
+
# alias_method :read, :to_s
|
100
|
+
|
85
101
|
def body
|
86
102
|
# wait unless returned?
|
87
103
|
response.body
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: faastruby-rpc
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Paulo Arruda
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-
|
11
|
+
date: 2019-03-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: oj
|
@@ -123,7 +123,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
123
123
|
version: '0'
|
124
124
|
requirements: []
|
125
125
|
rubyforge_project:
|
126
|
-
rubygems_version: 2.7.
|
126
|
+
rubygems_version: 2.7.8
|
127
127
|
signing_key:
|
128
128
|
specification_version: 4
|
129
129
|
summary: FaaStRuby RPC - Wrapper to make it easy to call FaaStRuby functions.
|