Module: Auth0::Mixins::HTTPProxy
- Included in:
- Auth0::Mixins
- Defined in:
- lib/auth0/mixins/httpproxy.rb
Overview
here’s the proxy for Rest calls based on rest-client, we’re building all request on that gem for now, if you want to feel free to use your own http client
Instance Attribute Summary collapse
-
#base_uri ⇒ Object
Returns the value of attribute base_uri.
-
#headers ⇒ Object
Returns the value of attribute headers.
-
#timeout ⇒ Object
Returns the value of attribute timeout.
Instance Method Summary collapse
- #add_headers(h = {}) ⇒ Object
- #call(method, url, timeout, headers, body = nil) ⇒ Object
- #safe_parse_json(body) ⇒ Object
- #url(path) ⇒ Object
Instance Attribute Details
#base_uri ⇒ Object
Returns the value of attribute base_uri.
6 7 8 |
# File 'lib/auth0/mixins/httpproxy.rb', line 6 def base_uri @base_uri end |
#headers ⇒ Object
Returns the value of attribute headers.
6 7 8 |
# File 'lib/auth0/mixins/httpproxy.rb', line 6 def headers @headers end |
#timeout ⇒ Object
Returns the value of attribute timeout.
6 7 8 |
# File 'lib/auth0/mixins/httpproxy.rb', line 6 def timeout @timeout end |
Instance Method Details
#add_headers(h = {}) ⇒ Object
36 37 38 39 40 |
# File 'lib/auth0/mixins/httpproxy.rb', line 36 def add_headers(h = {}) raise ArgumentError, 'Headers must be an object which responds to #to_hash' unless h.respond_to?(:to_hash) @headers ||= {} @headers.merge!(h.to_hash) end |
#call(method, url, timeout, headers, body = nil) ⇒ Object
48 49 50 51 52 |
# File 'lib/auth0/mixins/httpproxy.rb', line 48 def call(method, url, timeout, headers, body = nil) RestClient::Request.execute(method: method, url: url, timeout: timeout, headers: headers, payload: body) rescue RestClient::Exception => e e.response end |
#safe_parse_json(body) ⇒ Object
42 43 44 45 46 |
# File 'lib/auth0/mixins/httpproxy.rb', line 42 def safe_parse_json(body) JSON.parse(body.to_s) rescue JSON::ParserError body end |
#url(path) ⇒ Object
32 33 34 |
# File 'lib/auth0/mixins/httpproxy.rb', line 32 def url(path) "#{base_uri}#{path}" end |