faastruby-rpc 0.2.1 → 0.2.2

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
2
  SHA256:
3
- metadata.gz: a7ca42876deb3b89a2ce6f08e5076e920622e7e0ff90d02f97e2c27d80000191
4
- data.tar.gz: 4d3ca69fd16b80edf8d2a34d8832491b512e358a4a43f9dbaeb9d482d52c685d
3
+ metadata.gz: 3549d86d75838deeb0ee5ab553304ae42471c35b588ca0193053f8e3d96d1aea
4
+ data.tar.gz: cfcd04067a0eea97c821ee10d1783fd6e8f8d7738edfb88ed210c863fd97ac33
5
5
  SHA512:
6
- metadata.gz: 7cc828cf2f83f4662261948ad038ca5a547e2a88400a5dfbe0deac4e51e62d7e983e4476a05abe01576847ce6e598368c34c3dd0f75869abfeb3c3ffd5a090ab
7
- data.tar.gz: 6f46911239ee2a27399cdceac025ba726ee461888dc0dab2cb704fb33abb9474048b17de1220c5b59e73ad55b86847677d428b648711894bb22681bcf330f034
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,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- faastruby-rpc (0.2.0)
4
+ faastruby-rpc (0.2.1)
5
5
  oj (~> 3.6)
6
6
 
7
7
  GEM
@@ -1,5 +1,5 @@
1
1
  module FaaStRuby
2
- FAASTRUBY_HOST = ENV['FAASTRUBY_HOST'] || "http://localhost:3000"
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 = "#{FAASTRUBY_HOST}/#{@path}#{convert_query_params(query_params)}"
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
- response = fetch(use_ssl: use_ssl, uri: uri, headers: headers, method: @methods[method], req_body: req_body)
49
+ function_response = fetch(use_ssl: use_ssl, uri: uri, headers: headers, method: @methods[method], req_body: req_body)
45
50
  resp_headers = {}
46
- response.each{|k,v| resp_headers[k] = v}
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(response.body)
55
+ resp_body = Oj.load(function_response.body)
51
56
  rescue Oj::ParseError => e
52
- if response.body.is_a?(String)
53
- resp_body = response.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(response.body)
68
+ resp_body = YAML.load(function_response.body)
64
69
  else
65
- resp_body = response.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
- raise FaaStRuby::RPC::ExecutionError.new("Function #{@path} returned status code #{response.code} - #{resp_body['error']} - #{resp_body['location']}") if response.code.to_i >= 400 && @raise_errors
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
@@ -1,5 +1,5 @@
1
1
  module FaaStRuby
2
2
  module RPC
3
- VERSION = '0.2.1'
3
+ VERSION = '0.2.2'
4
4
  end
5
5
  end
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.1
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-01-03 00:00:00.000000000 Z
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.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.