Class: Swiftner::API::Chapter

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

#client, #details, #id

Class Method Summary collapse

Instance Method Summary collapse

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.

Parameters:

  • attributes (Hash)

Options Hash (attributes):

  • :title (String) — default: required
  • :duration (String) — default: required
  • :video_content_id (Integer) — default: required
  • :start (String) — default: required
  • :start_seconds (String) — default: optional
  • :language (String) — default: optional

Returns:



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.

Parameters:

  • chapter_id (Integer)

Returns:



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.

Parameters:

  • video_content_id (Integer)

Returns:



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

#deleteHash

Returns:

  • (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.

Parameters:

  • attributes (Hash)

Options Hash (attributes):

  • :title (String) — default: optional
  • :duration (String) — default: optional
  • :video_content_id (Integer) — default: optional
  • :start (String) — default: optional
  • :start_seconds (String) — default: optional
  • :language (String) — default: optional

Returns:



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