openstax_accounts 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,5 +1,5 @@
1
1
  module OpenStax
2
2
  module Accounts
3
- VERSION = "0.1.0"
3
+ VERSION = "0.2.0"
4
4
  end
5
5
  end
@@ -103,17 +103,28 @@ module OpenStax
103
103
  token.request(http_method, api_url, options)
104
104
  end
105
105
 
106
- # Creates an ApplicationUser in Accounts for this app and the given
107
- # OpenStax::Accounts::User.
106
+ # Creates an ApplicationUser in Accounts for the configured app
107
+ # and the given OpenStax::Accounts::User.
108
108
  # Also takes an optional API version parameter. Defaults to :v1.
109
109
  # On failure, throws an Exception, just like api_call.
110
110
  # On success, returns an OAuth2::Response object.
111
- def create_application_user(user, version = nil)
111
+ def create_application_user(user, version = :v1)
112
112
  options = {:access_token => user.access_token,
113
- :api_version => (version.nil? ? :v1 : version)}
113
+ :api_version => version}
114
114
  api_call(:post, 'application_users', options)
115
115
  end
116
116
 
117
+ # Performs a user search in Accounts for the configured app.
118
+ # Takes a query parameter and an optional API version parameter.
119
+ # API version currently defaults to :v1.
120
+ # On failure, throws an Exception, just like api_call.
121
+ # On success, returns an OAuth2::Response object.
122
+ def user_search(query, version = :v1)
123
+ options = {:params => {:q => query},
124
+ :api_version => version}
125
+ api_call(:get, 'users/search', options)
126
+ end
127
+
117
128
  protected
118
129
 
119
130
  def client
@@ -0,0 +1,7 @@
1
+ module Api
2
+ class UsersController < DummyController
3
+ def search
4
+ dummy(:search)
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,8 @@
1
+ class OauthController < ApplicationController
2
+ respond_to :json
3
+
4
+ def token
5
+ render :json => { :access_token => 'dummy',
6
+ :token_type => 'Dummy' }
7
+ end
8
+ end
@@ -1,11 +1,17 @@
1
1
  Rails.application.routes.draw do
2
- mount OpenStax::Accounts::Engine => "/accounts"
2
+ mount OpenStax::Accounts::Engine => '/accounts'
3
+
4
+ post 'oauth/token', :to => 'oauth#token'
3
5
 
4
6
  namespace :api do
5
- post "dummy", :to => "dummy#dummy"
7
+ post 'dummy', :to => 'dummy#dummy'
6
8
 
7
9
  resource :application_users, :only => :create
10
+
11
+ resource :users, :only => [] do
12
+ get 'search'
13
+ end
8
14
  end
9
15
 
10
- root :to => "application#index"
16
+ root :to => 'application#index'
11
17
  end
@@ -7,8 +7,7 @@ module OpenStax
7
7
  it 'makes api calls' do
8
8
  expect(Api::DummyController.last_action).to be_nil
9
9
  expect(Api::DummyController.last_params).to be_nil
10
- Accounts.api_call(:post, 'dummy', :access_token => user.access_token,
11
- :params => {:test => true})
10
+ Accounts.api_call(:post, 'dummy', :params => {:test => true})
12
11
  expect(Api::DummyController.last_action).to eq :dummy
13
12
  expect(Api::DummyController.last_params).to include 'test' => 'true'
14
13
  end
@@ -20,5 +19,13 @@ module OpenStax
20
19
  expect(Api::ApplicationUsersController.last_action).to eq :create
21
20
  expect(Api::ApplicationUsersController.last_params).not_to be_nil
22
21
  end
22
+
23
+ it 'makes api call to user search' do
24
+ expect(Api::UsersController.last_action).to be_nil
25
+ expect(Api::UsersController.last_params).to be_nil
26
+ Accounts.user_search('sth')
27
+ expect(Api::UsersController.last_action).to eq :search
28
+ expect(Api::UsersController.last_params).to include :q => 'sth'
29
+ end
23
30
  end
24
31
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: openstax_accounts
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -301,7 +301,9 @@ files:
301
301
  - spec/dummy/app/assets/stylesheets/application.css
302
302
  - spec/dummy/app/controllers/api/application_users_controller.rb
303
303
  - spec/dummy/app/controllers/api/dummy_controller.rb
304
+ - spec/dummy/app/controllers/api/users_controller.rb
304
305
  - spec/dummy/app/controllers/application_controller.rb
306
+ - spec/dummy/app/controllers/oauth_controller.rb
305
307
  - spec/dummy/app/helpers/application_helper.rb
306
308
  - spec/dummy/config/application.rb
307
309
  - spec/dummy/config/boot.rb
@@ -345,7 +347,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
345
347
  version: '0'
346
348
  segments:
347
349
  - 0
348
- hash: -2337536802800212146
350
+ hash: -1878082526811201719
349
351
  required_rubygems_version: !ruby/object:Gem::Requirement
350
352
  none: false
351
353
  requirements:
@@ -354,7 +356,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
354
356
  version: '0'
355
357
  segments:
356
358
  - 0
357
- hash: -2337536802800212146
359
+ hash: -1878082526811201719
358
360
  requirements: []
359
361
  rubyforge_project:
360
362
  rubygems_version: 1.8.25
@@ -368,7 +370,9 @@ test_files:
368
370
  - spec/dummy/app/assets/stylesheets/application.css
369
371
  - spec/dummy/app/controllers/api/application_users_controller.rb
370
372
  - spec/dummy/app/controllers/api/dummy_controller.rb
373
+ - spec/dummy/app/controllers/api/users_controller.rb
371
374
  - spec/dummy/app/controllers/application_controller.rb
375
+ - spec/dummy/app/controllers/oauth_controller.rb
372
376
  - spec/dummy/app/helpers/application_helper.rb
373
377
  - spec/dummy/config/application.rb
374
378
  - spec/dummy/config/boot.rb