Class: CloudRailSi::ServiceCode::RequestCall

Inherits:
Object
  • Object
show all
Defined in:
lib/cloudrail_si/servicecode/commands/http/RequestCall.rb

Instance Method Summary collapse

Instance Method Details

#capitalize_headers(headers) ⇒ Object



41
42
43
44
45
46
47
48
# File 'lib/cloudrail_si/servicecode/commands/http/RequestCall.rb', line 41

def capitalize_headers(headers)
    return nil if headers.nil?

    ret = {}
    headers.each do |key|
        ret[Helper.upper_case_first_letter(key[0])] = headers[key[0]][0]
    end
end

#execute(environment, parameters) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/cloudrail_si/servicecode/commands/http/RequestCall.rb', line 11

def execute(environment, parameters)
    Helper.assert(parameters.length == 2 &&
                  Helper.is_var_address(parameters[0]) &&
                  Helper.is_var_address(parameters[1]))
    result_var = parameters[0]
    options = Helper.resolve(environment, parameters[1])
    url = options['url']
    method = options['method']
    request_headers = options['requestHeaders']

    request_body = options['requestBody']

    Helper.assert(Helper.is_string(url) && Helper.is_string(method))
    Helper.assert(request_headers.nil? || Helper.is_object(request_headers))
    Helper.assert(request_body.nil? || Helper.is_stream(request_body))

    res = Helper.make_request(url, request_headers, request_body, method)
    response = {}
    response['code'] = res.code.to_i
    response['message'] = Rack::Utils::HTTP_STATUS_CODES[res.code.to_i],
    response['responseHeaders'] = capitalize_headers(res.to_hash),
    response['responseBody'] = res.body

    Helper.log("response:")
    Helper.log(response)
    Helper.log("\n")

    environment.set_variable(result_var, response)
end

#get_identifierObject



7
8
9
# File 'lib/cloudrail_si/servicecode/commands/http/RequestCall.rb', line 7

def get_identifier
    return 'http.requestCall'
end