Class: Swiftner::API::Upload

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

Overview

The ‘Upload` class is responsible for managing uploads in the Swiftner API. It provides methods for finding uploads, creating uploads, deleting uploads, and retrieving transcriptions related to an upload.

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) ⇒ Object



19
20
21
22
23
24
25
26
# File 'lib/swiftner/API/upload.rb', line 19

def self.create(attributes)
  response = client.post(
    "/upload/create",
    body: attributes.to_json,
    headers: { "Content-Type" => "application/json" }
  )
  build(response.parsed_response) if response.success?
end

.find(upload_id) ⇒ Object



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

def self.find(upload_id)
  response = client.get("/upload/get/#{upload_id}")
  build(response.parsed_response)
end

.find_uploadsObject



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

def self.find_uploads
  response = client.get("/upload/get-uploads/")
  map_collection(response)
end

Instance Method Details

#deleteObject



28
29
30
# File 'lib/swiftner/API/upload.rb', line 28

def delete
  client.delete("/upload/delete/#{id}")
end

#transcribe(language) ⇒ Object



37
38
39
40
41
42
43
44
45
46
# File 'lib/swiftner/API/upload.rb', line 37

def transcribe(language)
  transcription = {
    video_content_id: id,
    language: language,
    start: 0.0,
    end: details["duration"],
    duration: details["duration"]
  }
  API::Transcription.create(transcription)
end

#transcriptionsObject



32
33
34
35
# File 'lib/swiftner/API/upload.rb', line 32

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