Class: Distelli::RequestInfo
- Inherits:
-
Object
- Object
- Distelli::RequestInfo
- Defined in:
- lib/distelli/clientframework.rb
Constant Summary collapse
- VALID_CONTENT_TYPES =
Set.new [ServiceConstants::CONTENT_TYPE_JSON, ServiceConstants::CONTENT_TYPE_XML, ServiceConstants::CONTENT_TYPE_OCTET_STREAM]
- VALID_HTTP_METHODS =
Set.new [ServiceConstants::HTTP_METHOD_GET, ServiceConstants::HTTP_METHOD_PUT, ServiceConstants::HTTP_METHOD_POST, ServiceConstants::HTTP_METHOD_DELETE]
- VALID_RESPONSE_TYPES =
Set.new [ServiceConstants::RESPONSE_TYPE_XML, ServiceConstants::RESPONSE_TYPE_JSON]
Instance Attribute Summary collapse
-
#headers ⇒ Object
Returns the value of attribute headers.
-
#operation ⇒ Object
Returns the value of attribute operation.
-
#query_params ⇒ Object
Returns the value of attribute query_params.
-
#request ⇒ Object
Returns the value of attribute request.
-
#request_bytes ⇒ Object
Returns the value of attribute request_bytes.
-
#request_id ⇒ Object
Returns the value of attribute request_id.
-
#resource ⇒ Object
Returns the value of attribute resource.
Instance Method Summary collapse
- #add_header(header, value) ⇒ Object
- #add_query_param(key, value) ⇒ Object
- #contains_header(header) ⇒ Object
- #content_type ⇒ Object
- #content_type=(content_type) ⇒ Object
- #get_query_string ⇒ Object
- #http_method ⇒ Object
- #http_method=(http_method) ⇒ Object
-
#initialize ⇒ RequestInfo
constructor
A new instance of RequestInfo.
- #remove_header(header) ⇒ Object
- #remove_query_params(key) ⇒ Object
- #response_type ⇒ Object
- #response_type=(response_type) ⇒ Object
-
#to_s ⇒ Object
Lets implement the to_s method of the RequestInfo.
Constructor Details
#initialize ⇒ RequestInfo
Returns a new instance of RequestInfo.
311 312 313 314 315 316 317 318 319 320 321 322 |
# File 'lib/distelli/clientframework.rb', line 311 def initialize() @query_params = Hash.new @headers = Hash.new @resource = "/" @operation = nil @request_id = nil @content_type = ServiceConstants::CONTENT_TYPE_JSON @http_method = "GET" @request = nil @request_bytes = nil @response_type = ServiceConstants::RESPONSE_TYPE_JSON end |
Instance Attribute Details
#headers ⇒ Object
Returns the value of attribute headers.
307 308 309 |
# File 'lib/distelli/clientframework.rb', line 307 def headers @headers end |
#operation ⇒ Object
Returns the value of attribute operation.
307 308 309 |
# File 'lib/distelli/clientframework.rb', line 307 def operation @operation end |
#query_params ⇒ Object
Returns the value of attribute query_params.
307 308 309 |
# File 'lib/distelli/clientframework.rb', line 307 def query_params @query_params end |
#request ⇒ Object
Returns the value of attribute request.
307 308 309 |
# File 'lib/distelli/clientframework.rb', line 307 def request @request end |
#request_bytes ⇒ Object
Returns the value of attribute request_bytes.
307 308 309 |
# File 'lib/distelli/clientframework.rb', line 307 def request_bytes @request_bytes end |
#request_id ⇒ Object
Returns the value of attribute request_id.
307 308 309 |
# File 'lib/distelli/clientframework.rb', line 307 def request_id @request_id end |
#resource ⇒ Object
Returns the value of attribute resource.
307 308 309 |
# File 'lib/distelli/clientframework.rb', line 307 def resource @resource end |
Instance Method Details
#add_header(header, value) ⇒ Object
382 383 384 385 386 387 |
# File 'lib/distelli/clientframework.rb', line 382 def add_header(header, value) if header == nil or value == nil return end @headers[header] = value end |
#add_query_param(key, value) ⇒ Object
403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 |
# File 'lib/distelli/clientframework.rb', line 403 def add_query_param(key, value) if value == nil return end param_values = nil if @query_params.has_key?(key) param_values = @query_params[key] else param_values = Array.new @query_params[key] = param_values end if value.instance_of?(DateTime) #TODO: Check if the timezone is present. if not then set it to UTC param_values.push(value.strftime("%Y-%m-%dT%H:%M:%S%z")) else param_values.push(value.to_s) end end |
#contains_header(header) ⇒ Object
378 379 380 |
# File 'lib/distelli/clientframework.rb', line 378 def contains_header(header) return @headers.has_key?(header) end |
#content_type ⇒ Object
345 346 347 |
# File 'lib/distelli/clientframework.rb', line 345 def content_type @content_type end |
#content_type=(content_type) ⇒ Object
349 350 351 352 353 354 |
# File 'lib/distelli/clientframework.rb', line 349 def content_type=(content_type) if !VALID_CONTENT_TYPES.include?(content_type) raise ClientException.new("Invalid content type: "+content_type) end @content_type = content_type end |
#get_query_string ⇒ Object
324 325 326 327 328 329 330 331 332 333 334 335 |
# File 'lib/distelli/clientframework.rb', line 324 def get_query_string() query_param_list = Array.new @query_params.each_pair do |k,v| v.each do |x| query_param_list.push(k+'='+x) end end if query_param_list.length() > 0 return '?'+query_param_list.join('&') end return nil end |
#http_method ⇒ Object
367 368 369 |
# File 'lib/distelli/clientframework.rb', line 367 def http_method @http_method end |
#http_method=(http_method) ⇒ Object
371 372 373 374 375 376 |
# File 'lib/distelli/clientframework.rb', line 371 def http_method=(http_method) if !VALID_HTTP_METHODS.include?(http_method) raise ClientException.new("Invalid http method: "+http_method) end @http_method = http_method end |
#remove_header(header) ⇒ Object
389 390 391 392 393 394 |
# File 'lib/distelli/clientframework.rb', line 389 def remove_header(header) if header == nil return end @headers.delete(header) end |
#remove_query_params(key) ⇒ Object
396 397 398 399 400 401 |
# File 'lib/distelli/clientframework.rb', line 396 def remove_query_params(key) if not @query_params.has_key?(key) return end @query_params.delete(key) end |
#response_type ⇒ Object
356 357 358 |
# File 'lib/distelli/clientframework.rb', line 356 def response_type @response_type end |
#response_type=(response_type) ⇒ Object
360 361 362 363 364 365 |
# File 'lib/distelli/clientframework.rb', line 360 def response_type=(response_type) if !VALID_RESPONSE_TYPES.include?(response_type) raise ClientException.new("Invalid response type: "+response_type) end @response_type = response_type end |
#to_s ⇒ Object
Lets implement the to_s method of the RequestInfo
338 339 340 341 342 343 |
# File 'lib/distelli/clientframework.rb', line 338 def to_s vars = instance_variables.map do |n| "#{n}=#{instance_variable_get(n).inspect}" end "{%s}" % [vars.join(', ')] end |