Class: OpenStax::Connect::Configuration
- Inherits:
-
Object
- Object
- OpenStax::Connect::Configuration
- Defined in:
- lib/openstax_connect.rb
Instance Attribute Summary collapse
-
#default_errors_added_trigger ⇒ Object
Returns the value of attribute default_errors_added_trigger.
-
#default_errors_html_id ⇒ Object
Returns the value of attribute default_errors_html_id.
-
#default_errors_partial ⇒ Object
Returns the value of attribute default_errors_partial.
-
#enable_stubbing ⇒ Object
Returns the value of attribute enable_stubbing.
-
#logout_via ⇒ Object
Returns the value of attribute logout_via.
-
#openstax_application_id ⇒ Object
Returns the value of attribute openstax_application_id.
-
#openstax_application_secret ⇒ Object
Returns the value of attribute openstax_application_secret.
-
#openstax_services_url ⇒ Object
Returns the value of attribute openstax_services_url.
-
#security_transgression_exception ⇒ Object
Returns the value of attribute security_transgression_exception.
-
#user_provider ⇒ Object
OpenStax Connect provides you with an OpenStax::Connect::User object.
Instance Method Summary collapse
- #enable_stubbing? ⇒ Boolean
-
#initialize ⇒ Configuration
constructor
A new instance of Configuration.
Constructor Details
#initialize ⇒ Configuration
Returns a new instance of Configuration.
93 94 95 96 97 98 99 100 101 102 103 104 105 |
# File 'lib/openstax_connect.rb', line 93 def initialize @openstax_application_id = 'SET ME!' @openstax_application_secret = 'SET ME!' @openstax_services_url = 'https://services.openstax.org/' @enable_stubbing = true @logout_via = :get @default_errors_partial = 'openstax/connect/shared/attention' @default_errors_html_id = 'openstax-connect-attention' @default_errors_added_trigger = 'openstax-connect-errors-added' @security_transgression_exception = OpenStax::Connect::SecurityTransgression @user_provider = OpenStax::Connect::UserProvider super end |
Instance Attribute Details
#default_errors_added_trigger ⇒ Object
Returns the value of attribute default_errors_added_trigger.
47 48 49 |
# File 'lib/openstax_connect.rb', line 47 def default_errors_added_trigger @default_errors_added_trigger end |
#default_errors_html_id ⇒ Object
Returns the value of attribute default_errors_html_id.
46 47 48 |
# File 'lib/openstax_connect.rb', line 46 def default_errors_html_id @default_errors_html_id end |
#default_errors_partial ⇒ Object
Returns the value of attribute default_errors_partial.
45 46 47 |
# File 'lib/openstax_connect.rb', line 45 def default_errors_partial @default_errors_partial end |
#enable_stubbing ⇒ Object
Returns the value of attribute enable_stubbing.
42 43 44 |
# File 'lib/openstax_connect.rb', line 42 def enable_stubbing @enable_stubbing end |
#logout_via ⇒ Object
Returns the value of attribute logout_via.
44 45 46 |
# File 'lib/openstax_connect.rb', line 44 def logout_via @logout_via end |
#openstax_application_id ⇒ Object
Returns the value of attribute openstax_application_id.
40 41 42 |
# File 'lib/openstax_connect.rb', line 40 def openstax_application_id @openstax_application_id end |
#openstax_application_secret ⇒ Object
Returns the value of attribute openstax_application_secret.
41 42 43 |
# File 'lib/openstax_connect.rb', line 41 def openstax_application_secret @openstax_application_secret end |
#openstax_services_url ⇒ Object
Returns the value of attribute openstax_services_url.
43 44 45 |
# File 'lib/openstax_connect.rb', line 43 def openstax_services_url @openstax_services_url end |
#security_transgression_exception ⇒ Object
Returns the value of attribute security_transgression_exception.
48 49 50 |
# File 'lib/openstax_connect.rb', line 48 def security_transgression_exception @security_transgression_exception end |
#user_provider ⇒ Object
OpenStax Connect provides you with an OpenStax::Connect::User object. You can use this as your app’s User object without modification, you can modify it to suit your app’s needs (not recommended), or you can provide your own custom User object that references the OpenStax Connect User object.
OpenStax Connect also provides you methods for getting and setting the current signed in user (current_user and current_user= methods). If you choose to create your own custom User object that references the User object provide by Connect, you can teach OpenStax Connect how to translate between your app’s custom User object and OpenStax Connect’s built-in User object.
To do this, you need to set a “user_provider” in this configuration.
config.user_provider = MyUserProvider
The user_provider is a class that provides two class methods:
def self.connect_user_to_app_user(connect_user)
# converts the given connect user to an app user
# if you want to cache the connect_user in the app user
# this is the place to do it.
# If no app user exists for this connect user, one should
# be created.
end
def self.app_user_to_connect_user(app_user)
# converts the given app user to a connect user
end
Connect users are never nil. When a user is signed out, the current connect user is an anonymous user (responding true is “is_anonymous?”). You can follow the same pattern in your app or you can use nil for the current user. Just remember to check the anonymous status of connect users when doing your connect <-> app translations.
The default user_provider just uses OpenStax::Connect::User as the app user.
85 86 87 |
# File 'lib/openstax_connect.rb', line 85 def user_provider @user_provider end |
Instance Method Details
#enable_stubbing? ⇒ Boolean
107 108 109 |
# File 'lib/openstax_connect.rb', line 107 def enable_stubbing? !Rails.env.production? && enable_stubbing end |