Class: FakeGrandIdSimple
Defined Under Namespace
Classes: FakePerson
Constant Summary
GrandIdSimple::DEFAULT_BASE_URL, GrandIdSimple::VERSION
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
Returns a new instance of FakeGrandIdSimple.
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
|
# File 'lib/fake_grand_id_simple.rb', line 26
def initialize(&block)
super(nil, nil)
@block = block
@people = []
@server = WEBrick::HTTPServer.new(Port: 0)
@app = Sinatra.new do
get '/' do
return redirect params[:callback_url] if params[:session_id]
settings.people.map do |person|
%(<a href="#{FakeGrandIdSimple.add_query_parameter(params[:callback_url], 'grandidsession', person.session_id)}">#{person.name}</a><br/>)
end.join
end
end
@app.set :people, @people
@server.mount('/', Rack::Handler::WEBrick, @app)
@base_url = "http://localhost:#{@server.config[:Port]}"
end
|
Class Method Details
.add_query_parameter(url, name, value) ⇒ Object
19
20
21
22
23
24
|
# File 'lib/fake_grand_id_simple.rb', line 19
def self.add_query_parameter(url, name, value)
uri = URI.parse(url)
new_query_ar = URI.decode_www_form(uri.query || '') << [name, value]
uri.query = URI.encode_www_form(new_query_ar)
uri.to_s
end
|
Instance Method Details
#federated_login(**options) ⇒ Object
49
50
51
52
53
|
# File 'lib/fake_grand_id_simple.rb', line 49
def federated_login(**options)
@people.concat(@block.call) if @people.empty?
redirect_url = FakeGrandIdSimple.add_query_parameter(@base_url, 'callback_url', options[:callbackUrl])
Login.new(redirect_url: redirect_url)
end
|
#get_session(session_id) ⇒ Object
55
56
57
|
# File 'lib/fake_grand_id_simple.rb', line 55
def get_session(session_id)
@people.find {|person| person.session_id == session_id }
end
|
#logout(_session_id) ⇒ Object
59
60
61
|
# File 'lib/fake_grand_id_simple.rb', line 59
def logout(_session_id)
true
end
|
#start! ⇒ Object
45
46
47
|
# File 'lib/fake_grand_id_simple.rb', line 45
def start!
@server_thread = Thread.start { @server.start }
end
|