Class: PlatformSdk::PencilSpaces::Client

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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_tokenObject (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_urlObject (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

#connObject (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

Raises:

  • (ArgumentError)


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

Parameters:

  • user_id (String)
  • redirect_url (String) (defaults to: nil)

    **(Optional)** The URL to redirect the user to after they login

Returns:

Raises:

  • (ArgumentError)


94
95
96
97
98
99
100
101
# File 'lib/platform_sdk/pencil_spaces/client.rb', line 94

def authorize_user(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

Parameters:

Returns:

  • (JSON)

    The newly created 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

Raises:

  • (ArgumentError)


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

Parameters:

  • space_id (String)

Returns:

  • (JSON)

    The space object for the requested space_id



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

Parameters:

  • opts (Hash) (defaults to: {})

    the optional parameters

Options Hash (opts):

  • :page_number (Integer)

    **(Optional)** - The page number of the items to return. The number of items in a page is controlled by the `pageSize` parameter.

  • :page_size (Integer)

    **(Optional)** - The max number of items to return. Setting a larger `pageSize` may result in a longer querying times

  • :filters (String)

    **(Optional)** - A base64 encoded string of the filters you wish to apply to the query. See `spacesFilterSchema` for details on all the filters applicable to your query

Returns:

  • (JSON)


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

Parameters:

Returns:

  • (JSON)

    The updated 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

Parameters:

  • user_id (String)

Returns:

  • (JSON)

    The user object for the requested user_id



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

Parameters:

  • opts (Hash) (defaults to: {})

    the optional parameters

Options Hash (opts):

  • :page_number (Integer)

    **(Optional)** - The page number of the items to return. The number of items in a page is controlled by the `pageSize` parameter.

  • :page_size (Integer)

    **(Optional)** - The max number of items to return. Setting a larger `pageSize` may result in a longer querying times

  • :filters (String)

    **(Optional)** - A base64 encoded string of the filters you wish to apply to the query. See `spacesFilterSchema` for details on all the filters applicable to your query

Returns:

  • (JSON)

    A list of Pencil Spaces users



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