Skip to content

Instantly share code, notes, and snippets.

@Aupajo
Created September 16, 2015 07:07
Show Gist options
  • Save Aupajo/7da0ba926bbca6fe0804 to your computer and use it in GitHub Desktop.
Save Aupajo/7da0ba926bbca6fe0804 to your computer and use it in GitHub Desktop.
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