Class: Swiftner::API::LinkedContent

Inherits:
Service
  • Object
show all
Defined in:
lib/swiftner/API/linked_content.rb

Overview

Represents a LinkedContent service responsible for finding, creating, and updating linked content. Inherits from the Service class. Provides methods for interacting with linked content.

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

.batch_create(array_of_attributes) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
# File 'lib/swiftner/API/linked_content.rb', line 31

def self.batch_create(array_of_attributes)
  array_of_attributes.each { |attributes| validate_required(attributes, :url) }

  response = client.post(
    "/linked-content/batch-create",
    body: array_of_attributes.to_json,
    headers: { "Content-Type" => "application/json" }
  )

  map_collection(response)
end

.create(attributes) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
# File 'lib/swiftner/API/linked_content.rb', line 19

def self.create(attributes)
  validate_required(attributes, :url)

  response = client.post(
    "/linked-content/create",
    body: attributes.to_json,
    headers: { "Content-Type" => "application/json" }
  )

  build(response.parsed_response)
end

.find(linked_content_id) ⇒ Object



14
15
16
17
# File 'lib/swiftner/API/linked_content.rb', line 14

def self.find(linked_content_id)
  response = client.get("/linked-content/get/#{linked_content_id}")
  build(response.parsed_response)
end

.find_linked_contentsObject



9
10
11
12
# File 'lib/swiftner/API/linked_content.rb', line 9

def self.find_linked_contents
  response = client.get("/linked-content/get-all/")
  map_collection(response)
end

Instance Method Details

#deleteObject



60
61
62
# File 'lib/swiftner/API/linked_content.rb', line 60

def delete
  client.delete("/linked-content/delete/#{id}")
end

#transcribeObject



64
65
66
67
68
69
70
71
72
73
# File 'lib/swiftner/API/linked_content.rb', line 64

def transcribe
  response = client.post(
    "/linked-content/transcribe/#{id}",
    body: @details.to_json,
    headers: { "Content-Type" => "application/json" }
  )
  @details = @details.merge(response.parsed_response)

  self
end

#transcriptionsObject



55
56
57
58
# File 'lib/swiftner/API/linked_content.rb', line 55

def transcriptions
  response = client.get("/linked-content/get/#{id}/transcriptions")
  response.map { |transcription| API::Transcription.build(transcription) }
end

#update(attributes) ⇒ Object



43
44
45
46
47
48
49
50
51
52
53
# File 'lib/swiftner/API/linked_content.rb', line 43

def update(attributes)
  attributes = attributes.transform_keys(&:to_s)
  @details = @details.merge(attributes)

  client.put(
    "/linked-content/update/#{id}",
    body: @details.to_json,
    headers: { "Content-Type" => "application/json" }
  )
  self
end