Class: S3Restful::S3::Request

Inherits:
Object
  • Object
show all
Includes:
Utils
Defined in:
lib/s3-restful/s3/request.rb

Constant Summary collapse

VALID_HTTP_METHODS =
[:head, :get, :aget, :put, :delete]

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(http_method, url, options = {}) ⇒ Request

Returns a new instance of Request.



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/s3-restful/s3/request.rb', line 10

def initialize(http_method, url, options = {})
  @options = {
    :timeout => 10,
    :retry_count => 4,
    :headers => {},
    :on_error => nil,
    :on_success => nil,
    :data => nil,
    :ssl => {
      :cert_chain_file => nil,
      :verify_peer => false
    }
  }.update(options)
  assert_valid_keys(options, :timeout, :on_success, :on_error, :retry_count, :headers, :data, :ssl, :file)
  @http_method = http_method
  @url = url
  
  validate
end

Instance Attribute Details

#http_methodObject

Returns the value of attribute http_method.



8
9
10
# File 'lib/s3-restful/s3/request.rb', line 8

def http_method
  @http_method
end

#optionsObject

Returns the value of attribute options.



8
9
10
# File 'lib/s3-restful/s3/request.rb', line 8

def options
  @options
end

#responseObject

Returns the value of attribute response.



8
9
10
# File 'lib/s3-restful/s3/request.rb', line 8

def response
  @response
end

#urlObject

Returns the value of attribute url.



8
9
10
# File 'lib/s3-restful/s3/request.rb', line 8

def url
  @url
end

Instance Method Details

#executeObject



30
31
32
33
34
35
36
37
# File 'lib/s3-restful/s3/request.rb', line 30

def execute
  S3Restful::Log.debug "Request: #{http_method.to_s.upcase} #{url}"
  @response = http_class.new(url).send(http_method, :timeout => options[:timeout], :head => options[:headers], :body => options[:data], :ssl => options[:ssl], :file => options[:file])

  @response.errback { error_callback }
  @response.callback { success_callback }
  @response
end

#http_classObject



39
40
41
# File 'lib/s3-restful/s3/request.rb', line 39

def http_class
  EventMachine::HttpRequest
end