lib/airborne/base.rb in airborne-0.1.18 vs lib/airborne/base.rb in airborne-0.1.19
- old
+ new
@@ -28,67 +28,55 @@
def self.configuration
RSpec.configuration
end
def get(url, headers = nil)
- set_response(make_request(:get, url, headers: headers))
+ @response = make_request(:get, url, headers: headers)
end
def post(url, post_body = nil, headers = nil)
- set_response(make_request(:post, url, body: post_body, headers: headers))
+ @response = make_request(:post, url, body: post_body, headers: headers)
end
def patch(url, patch_body = nil, headers = nil)
- set_response(make_request(:patch, url, body: patch_body, headers: headers))
+ @response = make_request(:patch, url, body: patch_body, headers: headers)
end
def put(url, put_body = nil, headers = nil)
- set_response(make_request(:put, url, body: put_body, headers: headers))
+ @response = make_request(:put, url, body: put_body, headers: headers)
end
def delete(url, headers = nil)
- set_response(make_request(:delete, url, headers: headers))
+ @response = make_request(:delete, url, headers: headers)
end
def head(url, headers = nil)
- set_response(make_request(:head, url, headers: headers))
+ @response = make_request(:head, url, headers: headers)
end
def options(url, headers = nil)
- set_response(make_request(:options, url, headers: headers))
+ @response = make_request(:options, url, headers: headers)
end
def response
@response
end
def headers
- @headers
+ HashWithIndifferentAccess.new(response.headers)
end
def body
- @body
+ response.body
end
def json_body
- set_response(response) unless response.nil?
- fail InvalidJsonError, 'Api request returned invalid json' unless @json_body
- @json_body
+ JSON.parse(response.body, symbolize_names: true) rescue fail InvalidJsonError, 'Api request returned invalid json'
end
private
def get_url(url)
base = Airborne.configuration.base_url || ''
base + url
- end
-
- def set_response(res)
- @response = res
- @body = res.body
- @headers = HashWithIndifferentAccess.new(res.headers) unless res.headers.nil?
- begin
- @json_body = JSON.parse(res.body, symbolize_names: true) unless res.body.empty?
- rescue
- end
end
end