Class: Swiftner::API::Chapter
- Defined in:
- lib/swiftner/API/chapter.rb
Overview
Represents a chapter service responsible for finding, creating, and deleting chapters. Inherits from the Service class. Provides methods for interacting with chapters.
Constant Summary collapse
- REQUIRED_ATTRIBUTES =
%i[title duration video_content_id start].freeze
Instance Attribute Summary
Attributes inherited from Service
Class Method Summary collapse
-
.create(attributes) ⇒ Swiftner::API::Chapter
Creates a chapter.
-
.find(chapter_id) ⇒ Swiftner::API::Chapter
Finds chapter by id.
-
.find_chapters(video_content_id) ⇒ Array<Swiftner::API::Chapter>
Finds all chapters for a video content.
Instance Method Summary collapse
- #delete ⇒ Hash
-
#update(attributes) ⇒ Swiftner::API::Chapter
Creates a chapter.
Methods inherited from Service
build, client, #initialize, map_collection, validate_required
Constructor Details
This class inherits a constructor from Swiftner::API::Service
Class Method Details
.create(attributes) ⇒ Swiftner::API::Chapter
Creates a chapter.
35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/swiftner/API/chapter.rb', line 35 def self.create(attributes) validate_required(attributes, *REQUIRED_ATTRIBUTES) response = client.post( "/chapter/create", body: attributes.to_json, headers: { "Content-Type" => "application/json" } ) build(response.parsed_response) end |
.find(chapter_id) ⇒ Swiftner::API::Chapter
Finds chapter by id.
21 22 23 24 |
# File 'lib/swiftner/API/chapter.rb', line 21 def self.find(chapter_id) response = client.get("/chapter/get/#{chapter_id}") build(response.parsed_response) end |
.find_chapters(video_content_id) ⇒ Array<Swiftner::API::Chapter>
Finds all chapters for a video content.
13 14 15 16 |
# File 'lib/swiftner/API/chapter.rb', line 13 def self.find_chapters(video_content_id) response = client.get("/video-content/get/#{video_content_id}/chapters") map_collection(response) end |
Instance Method Details
#delete ⇒ Hash
71 72 73 |
# File 'lib/swiftner/API/chapter.rb', line 71 def delete client.delete("/chapter/delete/#{id}") end |
#update(attributes) ⇒ Swiftner::API::Chapter
Creates a chapter.
56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/swiftner/API/chapter.rb', line 56 def update(attributes) attributes = attributes.transform_keys(&:to_s) @details = @details.merge(attributes) self.class.validate_required(@details, *REQUIRED_ATTRIBUTES) client.put( "/chapter/update/#{id}", body: @details.to_json, headers: { "Content-Type" => "application/json" } ) self end |