Class: CloudQuery::Request

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Request

Returns a new instance of Request.



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/cloud_query/request.rb', line 5

def initialize(options={})
  @method = options[:method] || 'POST'
  @headers = options[:headers] || {}
  @scheme = options[:scheme] || SCHEME
  @host = options[:host] || HOST
  @port = options[:port] || (@scheme == 'https' ? URI::HTTPS::DEFAULT_PORT : URI::HTTP::DEFAULT_PORT)
  @path = options[:path] || PATH
  @params = options[:params] || {}
  if ['PUT', 'DELETE'].include?(@method)
    @params['_method'] = @method
    @method = 'POST'
  end
  @body = options[:body]
  
  @account = options[:account]
  @secret = options[:secret]
end

Instance Attribute Details

#bodyObject

Returns the value of attribute body.



3
4
5
# File 'lib/cloud_query/request.rb', line 3

def body
  @body
end

#headersObject

Returns the value of attribute headers.



3
4
5
# File 'lib/cloud_query/request.rb', line 3

def headers
  @headers
end

#hostObject

Returns the value of attribute host.



3
4
5
# File 'lib/cloud_query/request.rb', line 3

def host
  @host
end

#methodObject

Returns the value of attribute method.



3
4
5
# File 'lib/cloud_query/request.rb', line 3

def method
  @method
end

#paramsObject

Returns the value of attribute params.



3
4
5
# File 'lib/cloud_query/request.rb', line 3

def params
  @params
end

#pathObject

Returns the value of attribute path.



3
4
5
# File 'lib/cloud_query/request.rb', line 3

def path
  @path
end

#portObject

Returns the value of attribute port.



3
4
5
# File 'lib/cloud_query/request.rb', line 3

def port
  @port
end

#schemeObject

Returns the value of attribute scheme.



3
4
5
# File 'lib/cloud_query/request.rb', line 3

def scheme
  @scheme
end

Instance Method Details

#request_uri(account = @account, secret = @secret) ⇒ Object



23
24
25
26
27
28
29
30
31
32
# File 'lib/cloud_query/request.rb', line 23

def request_uri(=@account, secret=@secret)
  query = query_str(signature_params())
  uri = if query.empty?
    @path.dup
  else
    "#{@path}?#{query}"
  end
  uri = append_signature(uri, secret) if secret
  uri
end

#url(account = @account, secret = @secret) ⇒ Object



34
35
36
# File 'lib/cloud_query/request.rb', line 34

def url(=@account, secret=@secret)
  base_uri.merge(request_uri(, secret)).to_s
end