Module: Airborne::RestClientRequester
- Defined in:
- lib/spaceborne.rb
Overview
spaceborne enhancements
Instance Method Summary collapse
- #body?(method) ⇒ Boolean
- #calc_body(options, local) ⇒ Object
- #calc_headers(options, local) ⇒ Object
- #handle_proxy(_options, local) ⇒ Object
- #make_request(method, url, options = {}) ⇒ Object
- #send_restclient(method, url, body, headers) ⇒ Object
- #split_options(options) ⇒ Object
Instance Method Details
#body?(method) ⇒ Boolean
68 69 70 71 72 73 74 75 |
# File 'lib/spaceborne.rb', line 68 def body?(method) case method when :post, :patch, :put true else false end end |
#calc_body(options, local) ⇒ Object
99 100 101 102 103 104 105 106 |
# File 'lib/spaceborne.rb', line 99 def calc_body(, local) return '' unless [:body] if local[:nonjson_data] || !local[:is_hash] [:body] else [:body].to_json end end |
#calc_headers(options, local) ⇒ Object
86 87 88 89 90 91 92 |
# File 'lib/spaceborne.rb', line 86 def calc_headers(, local) headers = base_headers.merge([:headers] || {}) headers[:no_restclient_headers] = true return headers unless local[:is_hash] headers.delete('Content-Type') if [:nonjson_data] headers end |
#handle_proxy(_options, local) ⇒ Object
94 95 96 97 |
# File 'lib/spaceborne.rb', line 94 def handle_proxy(, local) return unless local[:proxy] RestClient.proxy = local[:proxy] end |
#make_request(method, url, options = {}) ⇒ Object
116 117 118 119 120 121 122 123 124 125 |
# File 'lib/spaceborne.rb', line 116 def make_request(method, url, = {}) @json_body = nil = () handle_proxy(, ) hdrs = calc_headers(, ) @request_body = calc_body(, ) send_restclient(method, get_url(url), @request_body, hdrs) rescue RestClient::Exception => e e.response end |
#send_restclient(method, url, body, headers) ⇒ Object
108 109 110 111 112 113 114 |
# File 'lib/spaceborne.rb', line 108 def send_restclient(method, url, body, headers) if body?(method) RestClient.send(method, url, body, headers) else RestClient.send(method, url, headers) end end |
#split_options(options) ⇒ Object
77 78 79 80 81 82 83 84 |
# File 'lib/spaceborne.rb', line 77 def () local = {} local[:nonjson_data] = .dig(:headers, :nonjson_data) [:headers].delete(:nonjson_data) if local[:nonjson_data] local[:is_hash] = [:body].is_a?(Hash) local[:proxy] = .dig(:headers, :use_proxy) local end |