Class: PlatformSdk::PencilSpaces::Client
- Inherits:
-
Object
- Object
- PlatformSdk::PencilSpaces::Client
- Defined in:
- lib/platform_sdk/pencil_spaces/client.rb
Overview
OneRoster Client which wraps the swagger generated OneRoster Management APIs
Constant Summary collapse
- VALID_API_USER_ROLES =
The API only supports these roles for API managed users
%i[Teacher Student].freeze
- VALID_SPACE_ROLES =
The API only supports these roles for users in a space
%i[host participant].freeze
- DEFAULT_VISIBILITY =
"private"
Instance Attribute Summary collapse
-
#access_token ⇒ Object
readonly
Returns the value of attribute access_token.
-
#base_url ⇒ Object
readonly
Returns the value of attribute base_url.
-
#conn ⇒ Object
readonly
Returns the value of attribute conn.
Instance Method Summary collapse
- #analytics_sessions(session_id) ⇒ Object
-
#authorize_user(user_id, redirect_url: nil) ⇒ JSON
Create a login link for a user.
- #create_api_user(name, role) ⇒ Object
-
#create_space(title, hosts: [], participants: [], visibility: DEFAULT_VISIBILITY) ⇒ JSON
Create a new Space.
- #end_ongoing_session(space_id) ⇒ Object
-
#initialize(base_url, access_token, conn: nil) ⇒ Client
constructor
A new instance of Client.
-
#space(space_id) ⇒ JSON
Get details for a particular Space.
-
#spaces(opts = {}) ⇒ JSON
Get a list of Spaces accessible by the account associated with your API key.
- #update_space(space_id, title: nil) ⇒ Object
-
#update_users_in_space(space_id, users_to_add: [], users_to_modify: [], users_to_remove: []) ⇒ JSON
Update users in a space.
-
#user(user_id) ⇒ JSON
Get details for a particular User.
-
#users(opts = {}) ⇒ JSON
Get a list of Users accessible by the account associated with your API key.
Constructor Details
#initialize(base_url, access_token, conn: nil) ⇒ Client
Returns a new instance of Client.
15 16 17 18 19 |
# File 'lib/platform_sdk/pencil_spaces/client.rb', line 15 def initialize(base_url, access_token, conn: nil) @access_token = access_token @base_url = base_url @conn = conn || build_connection end |
Instance Attribute Details
#access_token ⇒ Object (readonly)
Returns the value of attribute access_token.
7 8 9 |
# File 'lib/platform_sdk/pencil_spaces/client.rb', line 7 def access_token @access_token end |
#base_url ⇒ Object (readonly)
Returns the value of attribute base_url.
7 8 9 |
# File 'lib/platform_sdk/pencil_spaces/client.rb', line 7 def base_url @base_url end |
#conn ⇒ Object (readonly)
Returns the value of attribute conn.
7 8 9 |
# File 'lib/platform_sdk/pencil_spaces/client.rb', line 7 def conn @conn end |
Instance Method Details
#analytics_sessions(session_id) ⇒ Object
144 145 146 147 148 149 |
# File 'lib/platform_sdk/pencil_spaces/client.rb', line 144 def analytics_sessions(session_id) raise ArgumentError, "session_id must have a value" if session_id.nil? response = get("/analytics/sessions/#{session_id}") response.body end |
#authorize_user(user_id, redirect_url: nil) ⇒ JSON
Create a login link for a user
94 95 96 97 98 99 100 101 |
# File 'lib/platform_sdk/pencil_spaces/client.rb', line 94 def (user_id, redirect_url: nil) raise ArgumentError, "user_id must have a value" if user_id.nil? query_params = {} query_params[:redirectUrl] = redirect_url unless redirect_url.nil? response = get("/users/#{user_id}/authorize", query_params) response.body end |
#create_api_user(name, role) ⇒ Object
103 104 105 106 107 108 |
# File 'lib/platform_sdk/pencil_spaces/client.rb', line 103 def create_api_user(name, role) validate_api_user_role!(role) body = { name:, userRole: role } response = @conn.post("/users/createAPIUser", body.to_json) response.body end |
#create_space(title, hosts: [], participants: [], visibility: DEFAULT_VISIBILITY) ⇒ JSON
Create a new Space
53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/platform_sdk/pencil_spaces/client.rb', line 53 def create_space(title, hosts: [], participants: [], visibility: DEFAULT_VISIBILITY) body = { title:, visibility:, hosts: hosts.map(&:as_json), participants: participants.map(&:as_json), notifyInvitees: false } response = post("/spaces/create", body.to_json) response.body end |
#end_ongoing_session(space_id) ⇒ Object
137 138 139 140 141 142 |
# File 'lib/platform_sdk/pencil_spaces/client.rb', line 137 def end_ongoing_session(space_id) raise ArgumentError, "space_id must have a value" if space_id.nil? response = post("/spaces/#{space_id}/endOngoingSession", {}.to_json) response.body end |
#space(space_id) ⇒ JSON
Get details for a particular Space
41 42 43 44 45 |
# File 'lib/platform_sdk/pencil_spaces/client.rb', line 41 def space(space_id) resource_path = "/spaces/#{space_id}" response = get(resource_path) response.body end |
#spaces(opts = {}) ⇒ JSON
Get a list of Spaces accessible by the account associated with your API key
27 28 29 30 31 32 33 34 35 36 |
# File 'lib/platform_sdk/pencil_spaces/client.rb', line 27 def spaces(opts = {}) # query parameters query_params = opts[:query_params] || {} query_params[:pageNumber] = opts[:page_number] unless opts[:page_number].nil? query_params[:pageSize] = opts[:page_size] unless opts[:page_size].nil? query_params[:filters] = opts[:filters] unless opts[:filters].nil? response = get("/spaces", query_params) response.body end |
#update_space(space_id, title: nil) ⇒ Object
130 131 132 133 134 135 |
# File 'lib/platform_sdk/pencil_spaces/client.rb', line 130 def update_space(space_id, title: nil) validate_update_space_args(space_id, title) body = { space: { title: title } } response = patch("/spaces/#{space_id}", body.to_json) response.body end |
#update_users_in_space(space_id, users_to_add: [], users_to_modify: [], users_to_remove: []) ⇒ JSON
Update users in a space
116 117 118 119 120 121 122 123 124 125 126 127 128 |
# File 'lib/platform_sdk/pencil_spaces/client.rb', line 116 def update_users_in_space(space_id, users_to_add: [], users_to_modify: [], users_to_remove: []) validate_update_users_in_space_args!(space_id, users_to_add, users_to_modify, users_to_remove) body = { notifyInvitees: false, addUsers: users_to_add.map(&:as_json), modifyUsers: users_to_modify.map(&:as_json), removeUsers: users_to_remove.map(&:as_json) } response = patch("/spaces/#{space_id}/updateUsers", body.to_json) response.body end |
#user(user_id) ⇒ JSON
Get details for a particular User
85 86 87 88 |
# File 'lib/platform_sdk/pencil_spaces/client.rb', line 85 def user(user_id) response = get("/users/#{user_id}") response.body end |
#users(opts = {}) ⇒ JSON
Get a list of Users accessible by the account associated with your API key
71 72 73 74 75 76 77 78 79 80 |
# File 'lib/platform_sdk/pencil_spaces/client.rb', line 71 def users(opts = {}) # query parameters query_params = opts[:query_params] || {} query_params[:pageNumber] = opts[:page_number] unless opts[:page_number].nil? query_params[:pageSize] = opts[:page_size] unless opts[:page_size].nil? query_params[:filters] = opts[:filters] unless opts[:filters].nil? response = get("/users", query_params) response.body end |