Class: S3Multipart::Http

Inherits:
Object
  • Object
show all
Defined in:
lib/s3_multipart/http/net_http.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(method, path, options) ⇒ Http

Returns a new instance of Http.



7
8
9
10
11
12
# File 'lib/s3_multipart/http/net_http.rb', line 7

def initialize(method, path, options)
  @method = method
  @path = path
  @headers = options[:headers]
  @body = options[:body]
end

Instance Attribute Details

#bodyObject

Returns the value of attribute body.



5
6
7
# File 'lib/s3_multipart/http/net_http.rb', line 5

def body
  @body
end

#headersObject

Returns the value of attribute headers.



5
6
7
# File 'lib/s3_multipart/http/net_http.rb', line 5

def headers
  @headers
end

#methodObject

Returns the value of attribute method.



5
6
7
# File 'lib/s3_multipart/http/net_http.rb', line 5

def method
  @method
end

#pathObject

Returns the value of attribute path.



5
6
7
# File 'lib/s3_multipart/http/net_http.rb', line 5

def path
  @path
end

#responseObject

Returns the value of attribute response.



5
6
7
# File 'lib/s3_multipart/http/net_http.rb', line 5

def response
  @response
end

Class Method Details

.get(path, options = {}) ⇒ Object



15
16
17
# File 'lib/s3_multipart/http/net_http.rb', line 15

def get(path, options={})
  new(:get, path, options).perform
end

.post(path, options = {}) ⇒ Object



19
20
21
# File 'lib/s3_multipart/http/net_http.rb', line 19

def post(path, options={})
  new(:post, path, options).perform
end

.put(path, options = {}) ⇒ Object



23
24
25
# File 'lib/s3_multipart/http/net_http.rb', line 23

def put(path, options={})
  new(:put, path, options).perform
end

Instance Method Details

#performObject



28
29
30
31
32
33
34
35
36
# File 'lib/s3_multipart/http/net_http.rb', line 28

def perform
  request = request_class.new(path)
  headers.each do |key, val|
    request[key.to_s.split("_").map(&:capitalize).join("-")] = val
  end
  request.body = body if body
  
  @response = http.request(request)
end