lib/faastruby-rpc/function.rb in faastruby-rpc-0.2.2 vs lib/faastruby-rpc/function.rb in faastruby-rpc-0.2.3

- old
+ new

@@ -1,7 +1,6 @@ module FaaStRuby - FAASTRUBY_WORKSPACE_BASE_HOST = ENV['FAASTRUBY_WORKSPACE_BASE_HOST'] module RPC class ExecutionError < StandardError end class Response attr_reader :body, :code, :headers, :klass @@ -14,10 +13,15 @@ def body=(value) @body = value end end class Function + @@region = ENV['REGION'] + @@endpoint_base_host = ENV['ENDPOINT_BASE_HOST'] + def self.workspace=(workspace) + @@workspace = workspace + end def initialize(path, raise_errors: true) @response = nil @path = path @methods = { 'post' => Net::HTTP::Post, @@ -36,10 +40,10 @@ end self end def get_endpoint(query_params) - return "https://#{FAASTRUBY_WORKSPACE_BASE_HOST}/#{@path}#{query_params}" if FAASTRUBY_WORKSPACE_BASE_HOST + return "https://#{@@workspace}.#{@@region}.#{@@endpoint_base_host}/#{@path}#{query_params}" if @@endpoint_base_host && @@region && @@workspace return "http://localhost:3000/#{@path}#{query_params}" end def execute(req_body: nil, query_params: {}, headers: {}, method: 'post') url = get_endpoint(convert_query_params(query_params))