Class: OoAuth::RequestProxy
- Inherits:
-
Object
- Object
- OoAuth::RequestProxy
- Defined in:
- lib/oo_auth/request_proxy.rb
Instance Attribute Summary collapse
-
#body ⇒ Object
readonly
Returns the value of attribute body.
-
#headers ⇒ Object
readonly
Returns the value of attribute headers.
-
#host ⇒ Object
readonly
Returns the value of attribute host.
-
#method ⇒ Object
readonly
Returns the value of attribute method.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
-
#port ⇒ Object
readonly
Returns the value of attribute port.
-
#ssl ⇒ Object
readonly
Returns the value of attribute ssl.
Class Method Summary collapse
-
.parse(header) ⇒ Object
Parse an Authorization / WWW-Authenticate header into a hash.
Instance Method Summary collapse
- #authorization ⇒ Object
- #authorization=(header) ⇒ Object
-
#initialize(*args) ⇒ RequestProxy
constructor
A new instance of RequestProxy.
- #normalized_request_uri ⇒ Object
- #oauth_params ⇒ Object
- #oauth_params_without_signature ⇒ Object
-
#params_array(object) ⇒ Object
FIXME: cf nested params implementation in oauth gem TODO: support oauth body signature for non-formencoded content types.
- #params_decode(string) ⇒ Object
-
#params_encode(params) ⇒ Object
cf.
- #post? ⇒ Boolean
- #signature_base_string(params = {}) ⇒ Object
Constructor Details
#initialize(*args) ⇒ RequestProxy
Returns a new instance of RequestProxy.
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/oo_auth/request_proxy.rb', line 31 def initialize(*args) case args.size when 1 # ActionDispatch request request = args[0] @port = request.port @ssl = request.ssl? @path = request.fullpath @host = request.host @headers = request.headers when 2 # Net:HTTP request http, request = args[0], args[1] @port = http.port @ssl = http.use_ssl? @path = request.path @host = http.address @headers = request else raise ArgumentError, 'wrong number of arguments' end @method = request.method @body = request.body end |
Instance Attribute Details
#body ⇒ Object (readonly)
Returns the value of attribute body.
4 5 6 |
# File 'lib/oo_auth/request_proxy.rb', line 4 def body @body end |
#headers ⇒ Object (readonly)
Returns the value of attribute headers.
4 5 6 |
# File 'lib/oo_auth/request_proxy.rb', line 4 def headers @headers end |
#host ⇒ Object (readonly)
Returns the value of attribute host.
4 5 6 |
# File 'lib/oo_auth/request_proxy.rb', line 4 def host @host end |
#method ⇒ Object (readonly)
Returns the value of attribute method.
4 5 6 |
# File 'lib/oo_auth/request_proxy.rb', line 4 def method @method end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
4 5 6 |
# File 'lib/oo_auth/request_proxy.rb', line 4 def path @path end |
#port ⇒ Object (readonly)
Returns the value of attribute port.
4 5 6 |
# File 'lib/oo_auth/request_proxy.rb', line 4 def port @port end |
#ssl ⇒ Object (readonly)
Returns the value of attribute ssl.
4 5 6 |
# File 'lib/oo_auth/request_proxy.rb', line 4 def ssl @ssl end |
Class Method Details
.parse(header) ⇒ Object
Parse an Authorization / WWW-Authenticate header into a hash. Takes care of unescaping and removing surrounding quotes. Raises a OAuth::Problem if the header is not parsable into a valid hash. Does not validate the keys or values.
hash = parse(headers['Authorization'] || headers['WWW-Authenticate'])
hash['oauth_timestamp']
#=>"1234567890"
17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/oo_auth/request_proxy.rb', line 17 def parse(header) header = header.to_s return unless header.start_with?('OAuth ') # decompose params = header[6, header.length].split(',').inject({}) do |hsh, str| key, value = str.split('=').map { |s| OoAuth.unescape(s.strip) } if PARAMETERS.include?(key) hsh[key] = value.sub(/^\"(.*)\"$/, '\1') end hsh end end |
Instance Method Details
#authorization ⇒ Object
81 82 83 |
# File 'lib/oo_auth/request_proxy.rb', line 81 def headers['Authorization'] end |
#authorization=(header) ⇒ Object
85 86 87 |
# File 'lib/oo_auth/request_proxy.rb', line 85 def (header) headers['Authorization'] = header end |
#normalized_request_uri ⇒ Object
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/oo_auth/request_proxy.rb', line 54 def normalized_request_uri if self.port == Net::HTTP.default_port scheme, port = :http, nil elsif self.port == Net::HTTP.https_default_port scheme, port = :https, nil elsif ssl scheme, port = :https, self.port else scheme, port = :http, self.port end uri = "#{scheme}://#{host.downcase}" uri += ":#{port}" if port uri += path.split('?').first uri end |
#oauth_params ⇒ Object
71 72 73 |
# File 'lib/oo_auth/request_proxy.rb', line 71 def oauth_params self.class.parse() end |
#oauth_params_without_signature ⇒ Object
75 76 77 78 79 |
# File 'lib/oo_auth/request_proxy.rb', line 75 def oauth_params_without_signature params = oauth_params params.delete('oauth_signature') params end |
#params_array(object) ⇒ Object
FIXME: cf nested params implementation in oauth gem TODO: support oauth body signature for non-formencoded content types
107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 |
# File 'lib/oo_auth/request_proxy.rb', line 107 def params_array(object) case object when Array then object when Hash then object.to_a when RequestProxy tmp = object.path.split('?') params = tmp[1] ? params_decode(tmp[1]) : [] if object.post? && object.headers['Content-Type'].to_s.start_with?('application/x-www-form-urlencoded') params.concat params_decode(object.body) end params else raise "error: cannot convert #{object.class} object to params array" end end |
#params_decode(string) ⇒ Object
123 124 125 126 127 128 |
# File 'lib/oo_auth/request_proxy.rb', line 123 def params_decode(string) string.split('&').each_with_object([]) do |param, array| k, v = *param.split('=') array << [OoAuth.unescape(k), v && OoAuth.unescape(v)] end end |
#params_encode(params) ⇒ Object
131 132 133 |
# File 'lib/oo_auth/request_proxy.rb', line 131 def params_encode(params) params.map { |k, v| [OoAuth.escape(k), OoAuth.escape(v)] }.sort.map { |k, v| "#{k}=#{v}" }.join('&') end |
#post? ⇒ Boolean
96 97 98 |
# File 'lib/oo_auth/request_proxy.rb', line 96 def post? 'POST' == method end |