Class: DTK::Common::Response::RestClientWrapper

Inherits:
Object
  • Object
show all
Extended by:
DTK::Common::ResponseTokens
Defined in:
lib/response.rb

Constant Summary

Constants included from DTK::Common::ResponseTokens

DTK::Common::ResponseTokens::DataField, DTK::Common::ResponseTokens::ErrorsField, DTK::Common::ResponseTokens::ErrorsOriginalException, DTK::Common::ResponseTokens::ErrorsSubFieldCode, DTK::Common::ResponseTokens::GenericError, DTK::Common::ResponseTokens::StatusField, DTK::Common::ResponseTokens::StatusNotok, DTK::Common::ResponseTokens::StatusOK, DTK::Common::ResponseTokens::ValidationField

Class Method Summary collapse

Class Method Details

.delete(url, body = {}, opts = {}) ⇒ Object



185
186
187
# File 'lib/response.rb', line 185

def delete(url, body={}, opts={})
  delete_raw(url,body,opts){|raw_response|Response.new(json_parse_if_needed(raw_response))}
end

.delete_raw(url, body = {}, opts = {}, &block) ⇒ Object



172
173
174
175
176
177
178
179
# File 'lib/response.rb', line 172

def delete_raw(url,body={},opts={},&block)
  error_handling(opts) do
    # DELETE method supports only query params
    url_with_params = generate_query_params_url(url, body)
    raw_response = ::RestClient::Resource.new(url_with_params,opts).delete()
    block ? block.call(raw_response) : raw_response
  end
end

.get(url, body = {}, opts = {}) ⇒ Object



161
162
163
# File 'lib/response.rb', line 161

def get(url, body={}, opts={})
  get_raw(url,body, opts){|raw_response|Response.new(json_parse_if_needed(raw_response))}
end

.get_raw(url, body = {}, opts = {}, &block) ⇒ Object



153
154
155
156
157
158
159
# File 'lib/response.rb', line 153

def get_raw(url,body={},opts={},&block)
  error_handling(opts) do
    url_with_params = generate_query_params_url(url, body)
    raw_response = ::RestClient::Resource.new(url_with_params,opts).get()
    block ? block.call(raw_response) : raw_response
  end
end

.json_parse_if_needed(item) ⇒ Object



189
190
191
# File 'lib/response.rb', line 189

def json_parse_if_needed(item)
  item.kind_of?(String) ? JSON.parse(item) : item
end

.post(url, body = {}, opts = {}) ⇒ Object



181
182
183
# File 'lib/response.rb', line 181

def post(url,body={},opts={})
  post_raw(url,body,opts){|raw_response|Response.new(json_parse_if_needed(raw_response))}
end

.post_raw(url, body = {}, opts = {}, &block) ⇒ Object



165
166
167
168
169
170
# File 'lib/response.rb', line 165

def post_raw(url,body={},opts={},&block)
  error_handling(opts) do
    raw_response = ::RestClient::Resource.new(url,opts).post(body)
    block ? block.call(raw_response) : raw_response
  end
end