Class: Kameleoon::Network::Request

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

Overview

Request represents HTTP request.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(method, url, content_type, timeout, extra_headers: nil, data: nil) ⇒ Request

Returns a new instance of Request.



22
23
24
25
26
27
28
29
# File 'lib/kameleoon/network/request.rb', line 22

def initialize(method, url, content_type, timeout, extra_headers: nil, data: nil)
  @method = method
  @url = url
  @content_type = content_type
  @timeout = timeout
  @extra_headers = extra_headers
  @data = !data.nil? && data.is_a?(String) ? data.encode('UTF-8') : data
end

Instance Attribute Details

#access_tokenObject (readonly)

Returns the value of attribute access_token.



8
9
10
# File 'lib/kameleoon/network/request.rb', line 8

def access_token
  @access_token
end

#content_typeObject (readonly)

Returns the value of attribute content_type.



8
9
10
# File 'lib/kameleoon/network/request.rb', line 8

def content_type
  @content_type
end

#dataObject (readonly)

Returns the value of attribute data.



8
9
10
# File 'lib/kameleoon/network/request.rb', line 8

def data
  @data
end

#extra_headersObject (readonly)

Returns the value of attribute extra_headers.



8
9
10
# File 'lib/kameleoon/network/request.rb', line 8

def extra_headers
  @extra_headers
end

#methodObject (readonly)

Returns the value of attribute method.



8
9
10
# File 'lib/kameleoon/network/request.rb', line 8

def method
  @method
end

#timeoutObject (readonly)

Returns the value of attribute timeout.



8
9
10
# File 'lib/kameleoon/network/request.rb', line 8

def timeout
  @timeout
end

#urlObject (readonly)

Returns the value of attribute url.



8
9
10
# File 'lib/kameleoon/network/request.rb', line 8

def url
  @url
end

Instance Method Details

#authorize(access_token) ⇒ Object



31
32
33
# File 'lib/kameleoon/network/request.rb', line 31

def authorize(access_token)
  @access_token = access_token
end

#to_sObject



10
11
12
13
14
15
16
17
18
19
20
# File 'lib/kameleoon/network/request.rb', line 10

def to_s
  body = 'null'
  unless @data.nil?
    if @data.is_a?(String)
      body = @data.start_with?('grant_type=client_credentials') ? '****' : @data
    else
      body = @data
    end
  end
  "HttpRequest{Method:'#{@method}',Url:'#{@url}',Headers:#{@extra_headers},Body:'#{body}'}"
end