|
| 1 | +# frozen_string_literal: true |
| 2 | + |
1 | 3 | require "active_support" |
2 | 4 | require "active_support/version" |
3 | 5 | require "action_controller" |
4 | 6 | require "uri" |
5 | 7 |
|
6 | | -if |
7 | | - Gem::Version.new(ActiveSupport::VERSION::STRING) < Gem::Version.new("3") |
8 | | -then # rails 2.x |
| 8 | +if Gem::Version.new(ActiveSupport::VERSION::STRING) < Gem::Version.new("3") |
| 9 | + # rails 2.x |
9 | 10 | require "action_controller/request" |
10 | 11 | unless ActionController::Request::HTTP_METHODS.include?("patch") |
11 | 12 | ActionController::Request::HTTP_METHODS << "patch" |
12 | 13 | ActionController::Request::HTTP_METHOD_LOOKUP["PATCH"] = :patch |
13 | 14 | ActionController::Request::HTTP_METHOD_LOOKUP["patch"] = :patch |
14 | 15 | end |
15 | 16 |
|
16 | | -elsif |
17 | | - Gem::Version.new(ActiveSupport::VERSION::STRING) < Gem::Version.new("4") |
18 | | -then # rails 3.x |
| 17 | +elsif Gem::Version.new(ActiveSupport::VERSION::STRING) < Gem::Version.new("4") |
| 18 | + # rails 3.x |
19 | 19 | require "action_dispatch/http/request" |
20 | 20 | unless ActionDispatch::Request::HTTP_METHODS.include?("patch") |
21 | 21 | ActionDispatch::Request::HTTP_METHODS << "patch" |
|
27 | 27 | require "action_dispatch/http/request" |
28 | 28 | end |
29 | 29 |
|
30 | | -module OAuth::RequestProxy |
31 | | - class ActionControllerRequest < OAuth::RequestProxy::Base |
32 | | - proxies(defined?(ActionDispatch::AbstractRequest) ? ActionDispatch::AbstractRequest : ActionDispatch::Request) |
| 30 | +module OAuth |
| 31 | + module RequestProxy |
| 32 | + class ActionControllerRequest < OAuth::RequestProxy::Base |
| 33 | + proxies(defined?(::ActionDispatch::AbstractRequest) ? ::ActionDispatch::AbstractRequest : ::ActionDispatch::Request) |
33 | 34 |
|
34 | | - def method |
35 | | - request.method.to_s.upcase |
36 | | - end |
| 35 | + def method |
| 36 | + request.method.to_s.upcase |
| 37 | + end |
37 | 38 |
|
38 | | - def uri |
39 | | - request.url |
40 | | - end |
| 39 | + def uri |
| 40 | + request.url |
| 41 | + end |
41 | 42 |
|
42 | | - def parameters |
43 | | - if options[:clobber_request] |
44 | | - options[:parameters] || {} |
45 | | - else |
46 | | - params = request_params.merge(query_params).merge(header_params) |
47 | | - params.stringify_keys! if params.respond_to?(:stringify_keys!) |
48 | | - params.merge(options[:parameters] || {}) |
| 43 | + def parameters |
| 44 | + if options[:clobber_request] |
| 45 | + options[:parameters] || {} |
| 46 | + else |
| 47 | + params = request_params.merge(query_params).merge(header_params) |
| 48 | + params.stringify_keys! if params.respond_to?(:stringify_keys!) |
| 49 | + params.merge(options[:parameters] || {}) |
| 50 | + end |
49 | 51 | end |
50 | | - end |
51 | 52 |
|
52 | | - # Override from OAuth::RequestProxy::Base to avoid roundtrip |
53 | | - # conversion to Hash or Array and thus preserve the original |
54 | | - # parameter names |
55 | | - def parameters_for_signature |
56 | | - params = [] |
57 | | - params << options[:parameters].to_query if options[:parameters] |
| 53 | + # Override from OAuth::RequestProxy::Base to avoid roundtrip |
| 54 | + # conversion to Hash or Array and thus preserve the original |
| 55 | + # parameter names |
| 56 | + def parameters_for_signature |
| 57 | + params = [] |
| 58 | + params << options[:parameters].to_query if options[:parameters] |
58 | 59 |
|
59 | | - unless options[:clobber_request] |
60 | | - params << header_params.to_query |
61 | | - params << request.query_string unless query_string_blank? |
| 60 | + unless options[:clobber_request] |
| 61 | + params << header_params.to_query |
| 62 | + params << request.query_string unless query_string_blank? |
62 | 63 |
|
63 | | - if raw_post_signature? |
64 | | - params << request.raw_post |
| 64 | + params << request.raw_post if raw_post_signature? |
65 | 65 | end |
66 | | - end |
67 | 66 |
|
68 | | - params. |
69 | | - join("&").split("&"). |
70 | | - reject { |s| s.match(/\A\s*\z/) }. |
71 | | - map { |p| p.split("=").map{|esc| CGI.unescape(esc)} }. |
72 | | - reject { |kv| kv[0] == "oauth_signature"} |
73 | | - end |
| 67 | + params. |
| 68 | + join("&").split("&"). |
| 69 | + reject { |s| s.match(/\A\s*\z/) }. |
| 70 | + map { |p| p.split("=").map { |esc| CGI.unescape(esc) } }. |
| 71 | + reject { |kv| kv[0] == "oauth_signature" } |
| 72 | + end |
74 | 73 |
|
75 | | - def raw_post_signature? |
76 | | - (request.post? || request.put?) && request.content_type.to_s.downcase.start_with?("application/x-www-form-urlencoded") |
77 | | - end |
| 74 | + def raw_post_signature? |
| 75 | + (request.post? || request.put?) && request.content_type.to_s.downcase.start_with?("application/x-www-form-urlencoded") |
| 76 | + end |
78 | 77 |
|
79 | | - protected |
| 78 | + protected |
80 | 79 |
|
81 | | - def query_params |
82 | | - request.query_parameters |
83 | | - end |
| 80 | + def query_params |
| 81 | + request.query_parameters |
| 82 | + end |
84 | 83 |
|
85 | | - def request_params |
86 | | - request.request_parameters |
| 84 | + def request_params |
| 85 | + request.request_parameters |
| 86 | + end |
87 | 87 | end |
88 | | - |
89 | 88 | end |
90 | 89 | end |
0 commit comments