Class: Duracloud::Request

Inherits:
Object
  • Object
show all
Defined in:
lib/duracloud/request.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(http_method, url, **options) ⇒ Request

def initialize(client, http_method, url, body: nil, headers: nil, query: nil)

Parameters:

  • http_method (Symbol)

    the lower-case symbol corresponding to HTTP method

  • url (String)

    relative or absolute URL

  • body (String)

    the body of the request

  • headers (Hash)

    HTTP headers

  • query (Hash)

    Query string parameters



20
21
22
23
24
# File 'lib/duracloud/request.rb', line 20

def initialize(http_method, url, **options)
  @http_method = http_method
  @url         = Addressable::URI.parse(url).normalize.to_s
  set_options(options.dup)
end

Instance Attribute Details

#bodyObject (readonly)

Returns the value of attribute body.



7
8
9
# File 'lib/duracloud/request.rb', line 7

def body
  @body
end

#headersObject (readonly)

Returns the value of attribute headers.



7
8
9
# File 'lib/duracloud/request.rb', line 7

def headers
  @headers
end

#http_methodObject (readonly)

Returns the value of attribute http_method.



7
8
9
# File 'lib/duracloud/request.rb', line 7

def http_method
  @http_method
end

#queryObject (readonly)

Returns the value of attribute query.



7
8
9
# File 'lib/duracloud/request.rb', line 7

def query
  @query
end

#urlObject (readonly)

Returns the value of attribute url.



7
8
9
# File 'lib/duracloud/request.rb', line 7

def url
  @url
end

Class Method Details

.execute(http_method, url, **options, &block) ⇒ Object



9
10
11
12
# File 'lib/duracloud/request.rb', line 9

def self.execute(http_method, url, **options, &block)
  request = new(http_method, url, **options)
  request.execute(&block)
end

Instance Method Details

#execute(&block) ⇒ Object



26
27
28
29
30
# File 'lib/duracloud/request.rb', line 26

def execute(&block)
  Response.new(original_response(&block)).tap do |response|
    log_request(response)
  end
end