Class: NeAPI::Testing::FakeAuth
- Inherits:
-
Object
- Object
- NeAPI::Testing::FakeAuth
- Defined in:
- lib/ne_api/testing/fake_auth.rb
Overview
NeAPI::Auth のスタブクラス
Instance Attribute Summary collapse
-
#ne_user ⇒ Object
Returns the value of attribute ne_user.
-
#redirect_url ⇒ Object
Returns the value of attribute redirect_url.
-
#wait_flag ⇒ Object
Returns the value of attribute wait_flag.
Instance Method Summary collapse
-
#initialize(redirect_url: "http://localhost:3000/callback") ⇒ FakeAuth
constructor
A new instance of FakeAuth.
-
#ne_auth(uid, state, client_id = nil, client_secret = nil) ⇒ Hash
認証処理のスタブ.
-
#reset! ⇒ self
スタブをリセットする.
-
#sign_in(client_id = nil, client_secret = nil) ⇒ String
ブラウザを開かずにサインインURLを返す.
-
#stub_auth_failure ⇒ self
認証失敗をシミュレートする.
-
#stub_auth_response(response) ⇒ self
認証レスポンスをカスタマイズする.
-
#tokens ⇒ Hash?
トークンを取得する.
Constructor Details
#initialize(redirect_url: "http://localhost:3000/callback") ⇒ FakeAuth
Returns a new instance of FakeAuth.
21 22 23 24 25 26 27 |
# File 'lib/ne_api/testing/fake_auth.rb', line 21 def initialize(redirect_url: "http://localhost:3000/callback") @redirect_url = redirect_url @ne_user = nil @wait_flag = false @auth_response = nil @should_fail = false end |
Instance Attribute Details
#ne_user ⇒ Object
Returns the value of attribute ne_user.
19 20 21 |
# File 'lib/ne_api/testing/fake_auth.rb', line 19 def ne_user @ne_user end |
#redirect_url ⇒ Object
Returns the value of attribute redirect_url.
19 20 21 |
# File 'lib/ne_api/testing/fake_auth.rb', line 19 def redirect_url @redirect_url end |
#wait_flag ⇒ Object
Returns the value of attribute wait_flag.
19 20 21 |
# File 'lib/ne_api/testing/fake_auth.rb', line 19 def wait_flag @wait_flag end |
Instance Method Details
#ne_auth(uid, state, client_id = nil, client_secret = nil) ⇒ Hash
認証処理のスタブ
75 76 77 78 79 |
# File 'lib/ne_api/testing/fake_auth.rb', line 75 def ne_auth(uid, state, client_id = nil, client_secret = nil) raise NeAPIException, "003001:認証に失敗しました" if @should_fail @ne_user = @auth_response || default_auth_response(uid) end |
#reset! ⇒ self
スタブをリセットする
49 50 51 52 53 54 |
# File 'lib/ne_api/testing/fake_auth.rb', line 49 def reset! @ne_user = nil @auth_response = nil @should_fail = false self end |
#sign_in(client_id = nil, client_secret = nil) ⇒ String
ブラウザを開かずにサインインURLを返す
61 62 63 64 65 |
# File 'lib/ne_api/testing/fake_auth.rb', line 61 def sign_in(client_id = nil, client_secret = nil) # 実際のブラウザは開かない # テスト用にコールバックURLを返す "#{@redirect_url}?uid=test_uid&state=test_state" end |
#stub_auth_failure ⇒ self
認証失敗をシミュレートする
41 42 43 44 |
# File 'lib/ne_api/testing/fake_auth.rb', line 41 def stub_auth_failure @should_fail = true self end |
#stub_auth_response(response) ⇒ self
認証レスポンスをカスタマイズする
33 34 35 36 |
# File 'lib/ne_api/testing/fake_auth.rb', line 33 def stub_auth_response(response) @auth_response = response self end |
#tokens ⇒ Hash?
トークンを取得する
84 85 86 87 88 89 90 91 |
# File 'lib/ne_api/testing/fake_auth.rb', line 84 def tokens return nil if @ne_user.nil? { access_token: @ne_user["access_token"], refresh_token: @ne_user["refresh_token"] } end |