lib/airborne/base.rb in airborne-0.0.21 vs lib/airborne/base.rb in airborne-0.0.22
- old
+ new
@@ -1,89 +1,79 @@
require 'json'
require 'active_support/hash_with_indifferent_access'
module Airborne
- include RequestExpectations
+ include RequestExpectations
- def self.configure
- RSpec.configure do |config|
- yield config
- end
- end
+ def self.configure
+ RSpec.configure do |config|
+ yield config
+ end
+ end
- def self.included(base)
- if(!Airborne.configuration.requester_module.nil?)
- base.send(:include, Airborne.configuration.requester_module)
- elsif(!Airborne.configuration.rack_app.nil?)
- base.send(:include, RackTestRequester)
- else
- base.send(:include, RestClientRequester)
- end
- end
+ def self.included(base)
+ if(!Airborne.configuration.requester_module.nil?)
+ base.send(:include, Airborne.configuration.requester_module)
+ elsif(!Airborne.configuration.rack_app.nil?)
+ base.send(:include, RackTestRequester)
+ else
+ base.send(:include, RestClientRequester)
+ end
+ end
- def self.configuration
- RSpec.configuration
- end
+ def self.configuration
+ RSpec.configuration
+ end
- def get(url, headers = nil)
- set_response(make_request(:get, url, {headers: headers}))
- end
+ def get(url, headers = nil)
+ set_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}))
- end
+ def post(url, post_body = nil, headers = nil)
+ set_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}))
- end
+ def patch(url, patch_body = nil, headers = nil )
+ set_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}))
- end
+ def put(url, put_body = nil, headers = nil )
+ set_response(make_request(:put, url, {body: put_body, headers: headers}))
+ end
- def delete(url, headers = nil)
- set_response(make_request(:delete, url, {headers: headers}))
- end
+ def delete(url, headers = nil)
+ set_response(make_request(:delete, url, {headers: headers}))
+ end
- def response
- @response
- end
+ def response
+ @response
+ end
- def headers
- @headers
- end
+ def headers
+ @headers
+ end
- def body
- @body
- end
+ def body
+ @body
+ end
- def json_body
- @json_body
- end
+ def json_body
+ @json_body
+ end
- alias_method :airborne_get, :get
- alias_method :airborne_post, :post
- alias_method :airborne_patch, :patch
- alias_method :airborne_put, :put
- alias_method :airborne_delete, :delete
- alias_method :airborne_response, :response
- alias_method :airborne_headers, :headers
- alias_method :airborne_body, :body
- alias_method :airborne_json_body, :json_body
+ private
- private
+ def get_url(url)
+ base = Airborne.configuration.base_url || ""
+ base + url
+ end
- 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.deep_symbolize_keys) unless res.headers.nil?
- begin
- @json_body = JSON.parse(res.body, symbolize_names: true) unless res.body.empty?
- rescue
- end
- end
+ def set_response(res)
+ @response = res
+ @body = res.body
+ @headers = HashWithIndifferentAccess.new(res.headers.deep_symbolize_keys) unless res.headers.nil?
+ begin
+ @json_body = JSON.parse(res.body, symbolize_names: true) unless res.body.empty?
+ rescue
+ end
+ end
end