Module: Auth0::Mixins::HTTPProxy

Included in:
Auth0::Mixins, Validation::Algorithm::RS256
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

Instance Method Summary collapse

Instance Attribute Details

#base_uriObject

Returns the value of attribute base_uri.



8
9
10
# File 'lib/auth0/mixins/httpproxy.rb', line 8

def base_uri
  @base_uri
end

#headersObject

Returns the value of attribute headers.



8
9
10
# File 'lib/auth0/mixins/httpproxy.rb', line 8

def headers
  @headers
end

#timeoutObject

Returns the value of attribute timeout.



8
9
10
# File 'lib/auth0/mixins/httpproxy.rb', line 8

def timeout
  @timeout
end

Instance Method Details

#add_headers(h = {}) ⇒ Object

Raises:

  • (ArgumentError)


50
51
52
53
54
# File 'lib/auth0/mixins/httpproxy.rb', line 50

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



62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/auth0/mixins/httpproxy.rb', line 62

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
  case e
  when RestClient::RequestTimeout
    raise Auth0::RequestTimeout.new(e.message)
  else
    return e.response
  end
end

#safe_parse_json(body) ⇒ Object



56
57
58
59
60
# File 'lib/auth0/mixins/httpproxy.rb', line 56

def safe_parse_json(body)
  JSON.parse(body.to_s)
rescue JSON::ParserError
  body
end

#url(path) ⇒ Object



46
47
48
# File 'lib/auth0/mixins/httpproxy.rb', line 46

def url(path)
  "#{base_uri}#{path}"
end