Class: HttpClientGenerator::Resource

Inherits:
Object
  • Object
show all
Defined in:
lib/http_client_generator/resource.rb

Overview

:nodoc:

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(verb:, content_type:, timeout:, name:, base:, req_plugs:, resp_head_plugs:, resp_plugs:, stream: false) ⇒ Resource

rubocop:disable Metrics/ParameterLists



10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/http_client_generator/resource.rb', line 10

def initialize(verb:, content_type:, timeout:, name:, base:, req_plugs:, resp_head_plugs:, resp_plugs:,
               stream: false)
  @verb = verb
  @base = base
  @content_type = content_type
  @timeout = timeout
  @name = name
  @stream = stream
  @req_plugs = select_plugs(req_plugs)
  @resp_head_plugs = select_plugs(resp_head_plugs)
  @resp_plugs = select_plugs(resp_plugs)
  validate_streaming_plugs!
end

Instance Attribute Details

#baseObject (readonly)

Returns the value of attribute base.



7
8
9
# File 'lib/http_client_generator/resource.rb', line 7

def base
  @base
end

#content_typeObject (readonly)

Returns the value of attribute content_type.



7
8
9
# File 'lib/http_client_generator/resource.rb', line 7

def content_type
  @content_type
end

#nameObject (readonly)

Returns the value of attribute name.



7
8
9
# File 'lib/http_client_generator/resource.rb', line 7

def name
  @name
end

#req_plugsObject (readonly)

Returns the value of attribute req_plugs.



7
8
9
# File 'lib/http_client_generator/resource.rb', line 7

def req_plugs
  @req_plugs
end

#resp_head_plugsObject (readonly)

Returns the value of attribute resp_head_plugs.



7
8
9
# File 'lib/http_client_generator/resource.rb', line 7

def resp_head_plugs
  @resp_head_plugs
end

#resp_plugsObject (readonly)

Returns the value of attribute resp_plugs.



7
8
9
# File 'lib/http_client_generator/resource.rb', line 7

def resp_plugs
  @resp_plugs
end

#streamObject (readonly)

Returns the value of attribute stream.



7
8
9
# File 'lib/http_client_generator/resource.rb', line 7

def stream
  @stream
end

#timeoutObject (readonly)

Returns the value of attribute timeout.



7
8
9
# File 'lib/http_client_generator/resource.rb', line 7

def timeout
  @timeout
end

#verbObject (readonly)

Returns the value of attribute verb.



7
8
9
# File 'lib/http_client_generator/resource.rb', line 7

def verb
  @verb
end

Instance Method Details

#perform_request(url_helper, url_options, body, rest_args, timeout_override) ⇒ Object

rubocop:enable Metrics/ParameterLists



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/http_client_generator/resource.rb', line 25

def perform_request(url_helper, url_options, body, rest_args, timeout_override)
  request = prepare_request(url_helper, url_options, body, rest_args, timeout_override)

  response = perform_http_request(request)
  request.response_status = response.status.code
  request = process_response_head(request)

  return response.body if stream

  request.response_body = response.to_s

  process_response(request)
rescue HTTP::Error => e
  request.raise_error(e)
end