Created
September 16, 2015 07:07
-
-
Save Aupajo/7da0ba926bbca6fe0804 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class OAuthState | |
attr_reader :request | |
def initialize(request) | |
@request = request | |
end | |
def match_and_unpack_state | |
match?.tap { unpack_state } | |
end | |
def self.matches?(request) | |
self.new(request).match_and_unpack_state | |
end | |
private | |
def unpack_state | |
request.params.delete(:state) | |
self.class.params.zip(ordered_params[1..-1]) do |param, value| | |
request.params[param] = value | |
end | |
end | |
def match? | |
action == self.class.action | |
end | |
def ordered_params | |
@ordered_params ||= @request.params.fetch(:state).split(",") | |
end | |
def action | |
ordered_params.first | |
end | |
end | |
class ConnectionState < OAuthState | |
def self.action | |
'connect' | |
end | |
def self.params | |
%i( project_id is_production ) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment