Class: HelperModule::RichBodyContent

Inherits:
SimpleHttpContent show all
Defined in:
lib/helpers/simple_http_helper.rb

Direct Known Subclasses

PatchContent, PostContent

Instance Method Summary collapse

Methods inherited from SimpleHttpContent

#add_headers, #get_request_klass, #initialize

Constructor Details

This class inherits a constructor from HelperModule::SimpleHttpContent

Instance Method Details

#add_parameters(params = {}, type = 'json') ⇒ Object



135
136
137
138
139
140
141
142
143
# File 'lib/helpers/simple_http_helper.rb', line 135

def add_parameters(params = {}, type = 'json')
  if type == 'json'
    @body = params.to_json
    @content_type = 'application/json'
    @type = type
  else
    raise NotImplementedError, "only support json, #{type} is not supported"
  end
end

#add_url_parameters(params = {}) ⇒ Object



145
146
147
# File 'lib/helpers/simple_http_helper.rb', line 145

def add_url_parameters(params = {})
  @uri.query = URI.encode_www_form(params)
end

#get_requestObject



123
124
125
126
127
128
129
130
131
132
133
# File 'lib/helpers/simple_http_helper.rb', line 123

def get_request
  _request = self.get_request_klass.new(@uri)
  _request.body = @body if @body
  _request.content_type = @content_type if @content_type

  @headers.each_pair do |key, value|
    _request.add_field(key, value)
  end

  _request
end