Class: Chef::Provider::HttpRequest

Inherits:
Chef::Provider show all
Defined in:
lib/chef/provider/http_request.rb

Instance Attribute Summary collapse

Attributes inherited from Chef::Provider

#current_resource, #new_resource, #node

Instance Method Summary collapse

Methods inherited from Chef::Provider

#action_nothing, build_from_file, #initialize

Methods included from Mixin::ConvertToClassName

#convert_to_class_name, #filename_to_qualified_string

Methods included from Mixin::RecipeDefinitionDSLCore

#method_missing

Constructor Details

This class inherits a constructor from Chef::Provider

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Chef::Mixin::RecipeDefinitionDSLCore

Instance Attribute Details

#restObject

Returns the value of attribute rest.



25
26
27
# File 'lib/chef/provider/http_request.rb', line 25

def rest
  @rest
end

Instance Method Details

#action_deleteObject

Send a DELETE request to @new_resource.url



77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/chef/provider/http_request.rb', line 77

def action_delete
  body = @rest.run_request(
    :DELETE,
    @rest.create_url("#{@new_resource.url}"),
    false,
    10,
    false
  )
  @new_resource.updated = true
  Chef::Log.info("#{@new_resource} DELETE to #{@new_resource.url} successful")
  Chef::Log.debug("#{@new_resource} DELETE request response: #{body}")
end

#action_getObject

Send a GET request to @new_resource.url, with ?message=@new_resource.message



32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/chef/provider/http_request.rb', line 32

def action_get  
  message = check_message(@new_resource.message)
  body = @rest.run_request(
    :GET, 
    @rest.create_url("#{@new_resource.url}?message=#{message}"),
    false,
    10,
    false
  )
  @new_resource.updated = true
  Chef::Log.info("#{@new_resource} GET to #{@new_resource.url} successful")
  Chef::Log.debug("#{@new_resource} GET request response: #{body}")
end

#action_postObject

Send a POST request to @new_resource.url, with the message as the payload



62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/chef/provider/http_request.rb', line 62

def action_post
  message = check_message(@new_resource.message)
  body = @rest.run_request(
    :POST,
    @rest.create_url("#{@new_resource.url}"),
    message,
    10,
    false
  )
  @new_resource.updated = true
  Chef::Log.info("#{@new_resource} POST to #{@new_resource.url} message: #{message.inspect} successful")
  Chef::Log.debug("#{@new_resource} POST request response: #{body}")
end

#action_putObject

Send a PUT request to @new_resource.url, with the message as the payload



47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/chef/provider/http_request.rb', line 47

def action_put 
  message = check_message(@new_resource.message)
  body = @rest.run_request(
    :PUT,
    @rest.create_url("#{@new_resource.url}"),
    message,
    10,
    false
  )
  @new_resource.updated = true
  Chef::Log.info("#{@new_resource} PUT to #{@new_resource.url} successful")
  Chef::Log.debug("#{@new_resource} PUT request response: #{body}")
end

#load_current_resourceObject



27
28
29
# File 'lib/chef/provider/http_request.rb', line 27

def load_current_resource
  @rest = Chef::REST.new(@new_resource.url)
end