Module: OpenStax::Connect
- Defined in:
- lib/openstax_connect.rb,
lib/openstax/connect/engine.rb,
lib/openstax/connect/version.rb,
lib/openstax/connect/utilities.rb,
app/models/openstax/connect/user.rb,
lib/openstax/connect/action_list.rb,
lib/openstax/connect/route_helper.rb,
lib/openstax/connect/user_provider.rb,
lib/openstax/connect/current_user_manager.rb,
app/routines/openstax/connect/search_users.rb,
app/helpers/openstax/connect/application_helper.rb,
app/controllers/openstax/connect/dev/dev_controller.rb,
app/controllers/openstax/connect/sessions_controller.rb,
app/controllers/openstax/connect/dev/users_controller.rb,
app/controllers/openstax/connect/application_controller.rb,
app/handlers/openstax/connect/sessions_omniauth_authenticated.rb
Defined Under Namespace
Modules: ApplicationHelper, Dev Classes: AbstractMethodCalled, ActionList, ApplicationController, Configuration, CurrentUserManager, Engine, IllegalArgument, IllegalOperation, IllegalState, NotYetImplemented, RouteHelper, SearchUsers, SecurityTransgression, SessionsController, SessionsOmniauthAuthenticated, User, UserProvider
Constant Summary collapse
- VERSION =
"0.1.0"
Class Method Summary collapse
-
.api_call(http_method, url, options = {}) ⇒ Object
Executes an OpenStax Accounts API call, using the given HTTP method, API url and request options.
- .configuration ⇒ Object
-
.configure {|configuration| ... } ⇒ Object
Configuration machinery.
-
.create_application_user(user, version = nil) ⇒ Object
Creates an ApplicationUser in Accounts for this app and the given OpenStax::Connect::User.
Class Method Details
.api_call(http_method, url, options = {}) ⇒ Object
Executes an OpenStax Accounts API call, using the given HTTP method, API url and request options. Any options accepted by OAuth2 requests can be used, such as :params, :body, :headers, etc, plus the :access_token option, which can be used to manually specify an OAuth access token. On failure, it can throw Faraday::ConnectionFailed for connection errors or OAuth2::Error if Accounts returns an HTTP 400 error, such as 422 Unprocessable Entity. On success, returns an OAuth2::Response object.
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/openstax_connect.rb', line 87 def api_call(http_method, url, = {}) version = .delete(:api_version) unless version.blank? [:headers] ||= {} [:headers].merge!({ 'Accept' => "application/vnd.accounts.openstax.#{version.to_s}" }) end token_string = .delete(:access_token) token = token_string.blank? ? client.client_credentials.get_token : OAuth2::AccessToken.new(client, token_string) api_url = URI.join(configuration.openstax_accounts_url, 'api/', url) token.request(http_method, api_url, ) end |
.configuration ⇒ Object
35 36 37 |
# File 'lib/openstax_connect.rb', line 35 def configuration @configuration ||= Configuration.new end |
.configure {|configuration| ... } ⇒ Object
Configuration machinery.
To configure OpenStax Utilities, put the following code in your applications initialization logic (eg. in the config/initializers in a Rails app)
OpenStax::Connect.configure do |config|
config.<parameter name> = <parameter value>
...
end
Set enable_stubbing to true iff you want this engine to fake all
interaction with the accounts site.
31 32 33 |
# File 'lib/openstax_connect.rb', line 31 def configure yield configuration end |
.create_application_user(user, version = nil) ⇒ Object
Creates an ApplicationUser in Accounts for this app and the given OpenStax::Connect::User. Also takes an optional API version parameter. Defaults to :v1. On failure, throws an Exception, just like api_call. On success, returns an OAuth2::Response object.
108 109 110 111 112 |
# File 'lib/openstax_connect.rb', line 108 def create_application_user(user, version = nil) = {:access_token => user.access_token, :api_version => (version.nil? ? :v1 : version)} api_call(:post, 'application_users', ) end |