Class: Whop_sdk::CourseLessons::Client
- Inherits:
-
Object
- Object
- Whop_sdk::CourseLessons::Client
- Defined in:
- lib/whop_sdk/course_lessons/client.rb
Instance Method Summary collapse
-
#create(request_options: {}, **params) ⇒ Whop_sdk::Types::CourseLesson
Create a new lesson within a course chapter.
-
#delete(request_options: {}, **params) ⇒ Boolean
Permanently delete a lesson and remove it from its chapter.
- #initialize(client:) ⇒ void constructor
-
#list(request_options: {}, **params) ⇒ Whop_sdk::CourseLessons::Types::ListCourseLessonsResponse
Returns a paginated list of lessons within a course or chapter, ordered by position.
-
#mark_as_completed(request_options: {}, **params) ⇒ Boolean
Mark a lesson as completed for the current user after they finish the content.
-
#retrieve(request_options: {}, **params) ⇒ Whop_sdk::Types::CourseLesson
Retrieves the details of an existing course lesson.
-
#start(request_options: {}, **params) ⇒ Boolean
Record that the current user has started viewing a lesson, creating progress tracking records.
-
#submit_assessment(request_options: {}, **params) ⇒ Whop_sdk::CourseLessons::Types::SubmitAssessmentCourseLessonsResponse
Submit answers for a quiz or knowledge check lesson and receive a graded result.
-
#update(request_options: {}, **params) ⇒ Whop_sdk::Types::CourseLesson
Update a lesson's content, type, visibility, assessment questions, or media attachments.
Constructor Details
#initialize(client:) ⇒ void
9 10 11 |
# File 'lib/whop_sdk/course_lessons/client.rb', line 9 def initialize(client:) @client = client end |
Instance Method Details
#create(request_options: {}, **params) ⇒ Whop_sdk::Types::CourseLesson
Create a new lesson within a course chapter. Lessons can contain video, text, or assessment content.
Required permissions:
courses:update
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 |
# File 'lib/whop_sdk/course_lessons/client.rb', line 100 def create(request_options: {}, **params) params = Whop_sdk::Internal::Types::Utils.normalize_keys(params) request = Whop_sdk::Internal::JSON::Request.new( base_url: [:base_url], method: "POST", path: "course_lessons", body: Whop_sdk::CourseLessons::Types::CreateCourseLessonsRequest.new(params).to_h, request_options: ) begin response = @client.send(request) rescue Net::HTTPRequestTimeout raise Whop_sdk::Errors::TimeoutError end code = response.code.to_i if code.between?(200, 299) Whop_sdk::Types::CourseLesson.load(response.body) else error_class = Whop_sdk::Errors::ResponseError.subclass_for_code(code) raise error_class.new(response.body, code: code) end end |
#delete(request_options: {}, **params) ⇒ Boolean
Permanently delete a lesson and remove it from its chapter.
Required permissions:
courses:update
181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 |
# File 'lib/whop_sdk/course_lessons/client.rb', line 181 def delete(request_options: {}, **params) params = Whop_sdk::Internal::Types::Utils.normalize_keys(params) request = Whop_sdk::Internal::JSON::Request.new( base_url: [:base_url], method: "DELETE", path: "course_lessons/#{URI.encode_uri_component(params[:id].to_s)}", request_options: ) begin response = @client.send(request) rescue Net::HTTPRequestTimeout raise Whop_sdk::Errors::TimeoutError end code = response.code.to_i return if code.between?(200, 299) error_class = Whop_sdk::Errors::ResponseError.subclass_for_code(code) raise error_class.new(response.body, code: code) end |
#list(request_options: {}, **params) ⇒ Whop_sdk::CourseLessons::Types::ListCourseLessonsResponse
Returns a paginated list of lessons within a course or chapter, ordered by position.
Required permissions:
courses:read
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/whop_sdk/course_lessons/client.rb', line 41 def list(request_options: {}, **params) params = Whop_sdk::Internal::Types::Utils.normalize_keys(params) query_params = {} query_params["after"] = params[:after] if params.key?(:after) query_params["before"] = params[:before] if params.key?(:before) query_params["first"] = params[:first] if params.key?(:first) query_params["last"] = params[:last] if params.key?(:last) query_params["course_id"] = params[:course_id] if params.key?(:course_id) query_params["chapter_id"] = params[:chapter_id] if params.key?(:chapter_id) Whop_sdk::Internal::CursorItemIterator.new( cursor_field: :end_cursor, item_field: :data, initial_cursor: query_params["after"] ) do |next_cursor| query_params["after"] = next_cursor request = Whop_sdk::Internal::JSON::Request.new( base_url: [:base_url], method: "GET", path: "course_lessons", query: query_params, request_options: ) begin response = @client.send(request) rescue Net::HTTPRequestTimeout raise Whop_sdk::Errors::TimeoutError end code = response.code.to_i if code.between?(200, 299) parsed_response = Whop_sdk::CourseLessons::Types::ListCourseLessonsResponse.load(response.body) [parsed_response, response] else error_class = Whop_sdk::Errors::ResponseError.subclass_for_code(code) raise error_class.new(response.body, code: code) end end end |
#mark_as_completed(request_options: {}, **params) ⇒ Boolean
Mark a lesson as completed for the current user after they finish the content.
261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 |
# File 'lib/whop_sdk/course_lessons/client.rb', line 261 def mark_as_completed(request_options: {}, **params) params = Whop_sdk::Internal::Types::Utils.normalize_keys(params) request = Whop_sdk::Internal::JSON::Request.new( base_url: [:base_url], method: "POST", path: "course_lessons/#{URI.encode_uri_component(params[:lesson_id].to_s)}/mark_as_completed", request_options: ) begin response = @client.send(request) rescue Net::HTTPRequestTimeout raise Whop_sdk::Errors::TimeoutError end code = response.code.to_i return if code.between?(200, 299) error_class = Whop_sdk::Errors::ResponseError.subclass_for_code(code) raise error_class.new(response.body, code: code) end |
#retrieve(request_options: {}, **params) ⇒ Whop_sdk::Types::CourseLesson
Retrieves the details of an existing course lesson.
Required permissions:
courses:read
141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 |
# File 'lib/whop_sdk/course_lessons/client.rb', line 141 def retrieve(request_options: {}, **params) params = Whop_sdk::Internal::Types::Utils.normalize_keys(params) request = Whop_sdk::Internal::JSON::Request.new( base_url: [:base_url], method: "GET", path: "course_lessons/#{URI.encode_uri_component(params[:id].to_s)}", request_options: ) begin response = @client.send(request) rescue Net::HTTPRequestTimeout raise Whop_sdk::Errors::TimeoutError end code = response.code.to_i if code.between?(200, 299) Whop_sdk::Types::CourseLesson.load(response.body) else error_class = Whop_sdk::Errors::ResponseError.subclass_for_code(code) raise error_class.new(response.body, code: code) end end |
#start(request_options: {}, **params) ⇒ Boolean
Record that the current user has started viewing a lesson, creating progress tracking records.
296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 |
# File 'lib/whop_sdk/course_lessons/client.rb', line 296 def start(request_options: {}, **params) params = Whop_sdk::Internal::Types::Utils.normalize_keys(params) request = Whop_sdk::Internal::JSON::Request.new( base_url: [:base_url], method: "POST", path: "course_lessons/#{URI.encode_uri_component(params[:lesson_id].to_s)}/start", request_options: ) begin response = @client.send(request) rescue Net::HTTPRequestTimeout raise Whop_sdk::Errors::TimeoutError end code = response.code.to_i return if code.between?(200, 299) error_class = Whop_sdk::Errors::ResponseError.subclass_for_code(code) raise error_class.new(response.body, code: code) end |
#submit_assessment(request_options: {}, **params) ⇒ Whop_sdk::CourseLessons::Types::SubmitAssessmentCourseLessonsResponse
Submit answers for a quiz or knowledge check lesson and receive a graded result.
336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 |
# File 'lib/whop_sdk/course_lessons/client.rb', line 336 def submit_assessment(request_options: {}, **params) params = Whop_sdk::Internal::Types::Utils.normalize_keys(params) request_data = Whop_sdk::CourseLessons::Types::SubmitAssessmentCourseLessonsRequest.new(params).to_h non_body_param_names = %w[lesson_id] body = request_data.except(*non_body_param_names) request = Whop_sdk::Internal::JSON::Request.new( base_url: [:base_url], method: "POST", path: "course_lessons/#{URI.encode_uri_component(params[:lesson_id].to_s)}/submit_assessment", body: body, request_options: ) begin response = @client.send(request) rescue Net::HTTPRequestTimeout raise Whop_sdk::Errors::TimeoutError end code = response.code.to_i if code.between?(200, 299) Whop_sdk::CourseLessons::Types::SubmitAssessmentCourseLessonsResponse.load(response.body) else error_class = Whop_sdk::Errors::ResponseError.subclass_for_code(code) raise error_class.new(response.body, code: code) end end |
#update(request_options: {}, **params) ⇒ Whop_sdk::Types::CourseLesson
Update a lesson's content, type, visibility, assessment questions, or media attachments.
Required permissions:
courses:update
219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 |
# File 'lib/whop_sdk/course_lessons/client.rb', line 219 def update(request_options: {}, **params) params = Whop_sdk::Internal::Types::Utils.normalize_keys(params) request_data = Whop_sdk::CourseLessons::Types::UpdateCourseLessonsRequest.new(params).to_h non_body_param_names = %w[id] body = request_data.except(*non_body_param_names) request = Whop_sdk::Internal::JSON::Request.new( base_url: [:base_url], method: "PATCH", path: "course_lessons/#{URI.encode_uri_component(params[:id].to_s)}", body: body, request_options: ) begin response = @client.send(request) rescue Net::HTTPRequestTimeout raise Whop_sdk::Errors::TimeoutError end code = response.code.to_i if code.between?(200, 299) Whop_sdk::Types::CourseLesson.load(response.body) else error_class = Whop_sdk::Errors::ResponseError.subclass_for_code(code) raise error_class.new(response.body, code: code) end end |