Class: HttpClientGenerator::Resource

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(verb:, content_type:, name:, base:, req_plugs:, resp_plugs:) ⇒ Resource

Returns a new instance of Resource.



9
10
11
12
13
14
15
16
# File 'lib/http_client_generator/resource.rb', line 9

def initialize(verb:, content_type:, name:, base:, req_plugs:, resp_plugs:)
  @verb = verb
  @base = base
  @content_type = content_type
  @name = name
  @req_plugs = req_plugs
  @resp_plugs = resp_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_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

#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) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/http_client_generator/resource.rb', line 18

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

  request_attributes = [request.verb, request.url]

  if request.body
    request.body = request.body.to_json if request.json?
    request_attributes << { body: request.body }
  end

  request.response_body = HTTP[request.current_headers].public_send(*request_attributes).to_s

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