Class: AzureBlob::Http

Inherits:
Object
  • Object
show all
Includes:
REXML
Defined in:
lib/azure_blob/http.rb

Overview

:nodoc:

Defined Under Namespace

Classes: Error, FileNotFoundError, ForbiddenError, IntegrityError, TimeoutError

Instance Method Summary collapse

Constructor Details

#initialize(uri, headers = {}, signer: nil, metadata: {}, tags: {}, debug: false, raise_on_error: true) ⇒ Http

Returns a new instance of Http.



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/azure_blob/http.rb', line 28

def initialize(uri, headers = {}, signer: nil, metadata: {}, tags: {}, debug: false, raise_on_error: true)
  @raise_on_error = raise_on_error
  @date = Time.now.httpdate
  @uri = uri
  @signer = signer
  @headers = headers.merge(
    .new().headers,
    Tags.new(tags).headers,
  )

  sanitize_headers

  @http = Net::HTTP.new(uri.hostname, uri.port)
  @http.use_ssl = uri.port == 443
  @http.set_debug_output($stdout) if debug
end

Instance Method Details

#deleteObject



81
82
83
84
85
86
87
88
# File 'lib/azure_blob/http.rb', line 81

def delete
  sign_request("DELETE") if signer
  @response = http.start do |http|
    http.delete(uri, headers)
  end
  raise_error  unless success?
  response.body
end

#getObject



45
46
47
48
49
50
51
52
# File 'lib/azure_blob/http.rb', line 45

def get
  sign_request("GET") if signer
  @response = http.start do |http|
    http.get(uri, headers)
  end
  raise_error  unless success?
  response.body
end

#headObject



72
73
74
75
76
77
78
79
# File 'lib/azure_blob/http.rb', line 72

def head
  sign_request("HEAD") if signer
  @response = http.start do |http|
    http.head(uri, headers)
  end
  raise_error  unless success?
  response
end

#post(content = "") ⇒ Object



63
64
65
66
67
68
69
70
# File 'lib/azure_blob/http.rb', line 63

def post(content = "")
  sign_request("POST") if signer
  @response = http.start do |http|
    http.post(uri, content, headers)
  end
  raise_error  unless success?
  response.body
end

#put(content = "") ⇒ Object



54
55
56
57
58
59
60
61
# File 'lib/azure_blob/http.rb', line 54

def put(content = "")
  sign_request("PUT") if signer
  @response = http.start do |http|
    http.put(uri, content, headers)
  end
  raise_error  unless success?
  true
end

#success?Boolean

Returns:



90
91
92
# File 'lib/azure_blob/http.rb', line 90

def success?
  status < Net::HTTPSuccess
end