Module: VagrantPlugins::Deltacloud::HttpUtils

Includes:
RequestLogger
Included in:
DeltacloudClient
Defined in:
lib/vagrant-deltacloud-provider/client/http_utils.rb,
lib/vagrant-deltacloud-provider/client/request_logger.rb

Defined Under Namespace

Modules: RequestLogger

Instance Method Summary collapse

Methods included from RequestLogger

#log_request, #log_response

Instance Method Details

#delete(env, url, headers = {}) ⇒ Object



58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/vagrant-deltacloud-provider/client/http_utils.rb', line 58

def delete(env, url, headers = {})
  config = env[:machine].provider_config
  calling_method = caller[0][/`.*'/][1..-2]
  @logger.debug("#{calling_method} - start")

  headers.merge!(accept: 'json', content_type: 'json')

  url = config.deltacloud_api_url + url +
    '?format=json'

  resource = RestClient::Resource.new(
    url,
    config.username + '+' + config.tenant_name,
    config.password)
  log_request(:DELETE, url, headers)

  resource.delete(headers: headers) { |res| handle_response(res) }.tap do
    @logger.debug("#{calling_method} - end")
  end
end

#get(env, url, headers = {}) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/vagrant-deltacloud-provider/client/http_utils.rb', line 12

def get(env, url, headers = {})
  config = env[:machine].provider_config
  calling_method = caller[0][/`.*'/][1..-2]
  @logger.debug("#{calling_method} - start")

  headers.merge!(accept: 'json', content_type: 'json')

  url = config.deltacloud_api_url + url +
    '?format=json'

  resource = RestClient::Resource.new(
    url,
    config.username + '+' + config.tenant_name,
    config.password)

  log_request(:GET, url, headers)

  resource.get(headers: headers) { |res| handle_response(res) }.tap do
    @logger.debug("#{calling_method} - end")
  end
end

#post(env, url, body = nil) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/vagrant-deltacloud-provider/client/http_utils.rb', line 34

def post(env, url, body = nil)
  config = env[:machine].provider_config
  calling_method = caller[0][/`.*'/][1..-2]
  @logger.debug("#{calling_method} - start")
  headers = {}
  headers.merge!(accept: 'json')

  url = config.deltacloud_api_url + url +
    '?format=json'

  resource = RestClient::Resource.new(
    url,
    config.username + '+' + config.tenant_name,
    config.password)

  log_request(:POST, url, body, headers)

  resource.post(
    body,
    headers: headers) { |res| handle_response(res) }.tap do
      @logger.debug("#{calling_method} - end")
    end
end