swiftner 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0bccfb7a6a850c917d592bd4dbfaf84ed83f167443056642653e151e029c10e0
4
- data.tar.gz: a8d9567709a73226085a560cb1ada880075067407276002eec0584e908520f47
3
+ metadata.gz: df81ce74f315ba2773be31747e089c77e955415362d0de93c6f0ac5e2d844086
4
+ data.tar.gz: 91ef8ff69dc8e7d8aa987d0296a45a04c02e3dc35c7466dbc2b872bf8345d43e
5
5
  SHA512:
6
- metadata.gz: 42390d0d4f6bc5b6ee40a91deaeafc27c78c17fb2c4bd5663d91338dc376c5f22dfd818759cc9a627e8e3a1c7dded5a40b411baaae93faf124daa6c3a44f3620
7
- data.tar.gz: 89f9c9ceab9e07ad7884fadb389830b5ff2f8cc36d9eda4898c17366fc8a1433179f956f79961c7b808bd644b8d688618e06b0147567ccafaa3d5e2bf37ec690
6
+ metadata.gz: a530d61cdf3023d1c9df3881ce151e346b15480f5b7ff067d69801cfc07597047d7b5985cc991e72b93a8ed7a6e33408687dbc324bc5ccc0ce4f316a1d915434
7
+ data.tar.gz: 244fd82157219579145a47d20f21734b77923b5ad88b0dd725f85ea37c371f588dd510b48cf8fc259c0d2ed0be89d9e8f1dd3d3a848bf746b6dff11669eb1f4a
data/README.md CHANGED
@@ -63,6 +63,32 @@ upload.delete
63
63
  upload.transcribe("no")
64
64
  ```
65
65
 
66
+ ### Working with Linked Content
67
+ ```ruby
68
+ @linked_content_service = Swiftner::API::LinkedContent
69
+
70
+ # Find linked contents
71
+ linked_contents = @linked_content_service.find_linked_contents
72
+
73
+ # Find linked content
74
+ linked_content = @linked_content_service.find(1)
75
+
76
+ # Create an upload
77
+ linked_content = @linked_content_service.create(sample_attributes)
78
+
79
+ # Find linked content transcriptions
80
+ transcriptions = linked_content.transcriptions
81
+
82
+ # Batch create linked content
83
+ linked_contents = @linked_content_service.batch_create([sample_attributes, sample_attributes])
84
+
85
+ # Restart transcription process
86
+ linked_content.transcribe
87
+
88
+ # Delete linked content
89
+ linked_content.delete
90
+ ```
91
+
66
92
  ### Handling Exceptions
67
93
  The Swiftner API Ruby Client includes custom exceptions for handling API errors. These inherit from either the base Swiftner::Error class or the standard Ruby StandardError class.
68
94
  ```ruby
@@ -0,0 +1,76 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Swiftner
4
+ module API
5
+ # Represents a LinkedContent service responsible for finding, creating, and updating linked content.
6
+ # Inherits from the Service class.
7
+ # Provides methods for interacting with linked content.
8
+ class LinkedContent < Service
9
+ def self.find_linked_contents
10
+ response = client.get("/linked-content/get-all/")
11
+ map_collection(response)
12
+ end
13
+
14
+ def self.find(linked_content_id)
15
+ response = client.get("/linked-content/get/#{linked_content_id}")
16
+ build(response.parsed_response)
17
+ end
18
+
19
+ def self.create(attributes)
20
+ validate_required(attributes, :url)
21
+
22
+ response = client.post(
23
+ "/linked-content/create",
24
+ body: attributes.to_json,
25
+ headers: { "Content-Type" => "application/json" }
26
+ )
27
+
28
+ build(response.parsed_response)
29
+ end
30
+
31
+ def self.batch_create(array_of_attributes)
32
+ array_of_attributes.each { |attributes| validate_required(attributes, :url) }
33
+
34
+ response = client.post(
35
+ "/linked-content/batch-create",
36
+ body: array_of_attributes.to_json,
37
+ headers: { "Content-Type" => "application/json" }
38
+ )
39
+
40
+ map_collection(response)
41
+ end
42
+
43
+ def update(attributes)
44
+ attributes = attributes.transform_keys(&:to_s)
45
+ @details = @details.merge(attributes)
46
+
47
+ client.put(
48
+ "/linked-content/update/#{id}",
49
+ body: @details.to_json,
50
+ headers: { "Content-Type" => "application/json" }
51
+ )
52
+ self
53
+ end
54
+
55
+ def transcriptions
56
+ response = client.get("/linked-content/get/#{id}/transcriptions")
57
+ response.map { |transcription| API::Transcription.build(transcription) }
58
+ end
59
+
60
+ def delete
61
+ client.delete("/linked-content/delete/#{id}")
62
+ end
63
+
64
+ def transcribe
65
+ response = client.post(
66
+ "/linked-content/transcribe/#{id}",
67
+ body: @details.to_json,
68
+ headers: { "Content-Type" => "application/json" }
69
+ )
70
+ @details = @details.merge(response.parsed_response)
71
+
72
+ self
73
+ end
74
+ end
75
+ end
76
+ end
@@ -14,6 +14,19 @@ module Swiftner
14
14
  Swiftner.configuration.client
15
15
  end
16
16
 
17
+ def self.validate_required(attributes, *keys)
18
+ attr_str_keys = attributes.transform_keys(&:to_s)
19
+ missing_keys = keys.map(&:to_s).reject { |key| attr_str_keys.key?(key) }
20
+
21
+ return unless missing_keys.any?
22
+
23
+ raise ArgumentError, "Key(s) '#{missing_keys.join(", ")}' are missing in attributes. #{attributes.inspect}"
24
+ end
25
+
26
+ def self.map_collection(response)
27
+ response.map { |item| build(item) }
28
+ end
29
+
17
30
  def initialize(attributes = {}, client = self.class.client)
18
31
  raise Swiftner::Error, "Client must be set" if client.nil?
19
32
 
@@ -0,0 +1,50 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Swiftner
4
+ module API
5
+ # Represents a Space service responsible for finding, creating, and deleting spaces.
6
+ # Inherits from the Service class.
7
+ # Provides methods for interacting with spaces.
8
+ class Space < Service
9
+ def self.find_spaces
10
+ response = client.get("/space/get-spaces")
11
+ map_collection(response)
12
+ end
13
+
14
+ def self.find(space_id)
15
+ response = client.get("/space/get/#{space_id}")
16
+ build(response.parsed_response)
17
+ end
18
+
19
+ def self.create(attributes)
20
+ validate_required(attributes, :name, :description)
21
+
22
+ response = client.post(
23
+ "/space/create",
24
+ body: attributes.to_json,
25
+ headers: { "Content-Type" => "application/json" }
26
+ )
27
+
28
+ build(response.parsed_response)
29
+ end
30
+
31
+ def update(attributes)
32
+ attributes = attributes.transform_keys(&:to_s)
33
+ @details = @details.merge(attributes)
34
+
35
+ self.class.validate_required(@details, :name, :description)
36
+
37
+ client.put(
38
+ "/space/update/#{id}",
39
+ body: @details.to_json,
40
+ headers: { "Content-Type" => "application/json" }
41
+ )
42
+ self
43
+ end
44
+
45
+ def delete
46
+ client.delete("/space/delete/#{id}")
47
+ end
48
+ end
49
+ end
50
+ end
@@ -8,7 +8,7 @@ module Swiftner
8
8
  class Upload < Service
9
9
  def self.find_uploads
10
10
  response = client.get("/upload/get-uploads/")
11
- response.map { |upload| build(upload) }
11
+ map_collection(response)
12
12
  end
13
13
 
14
14
  def self.find(upload_id)
@@ -7,7 +7,7 @@ module Swiftner
7
7
  class VideoContent < Service
8
8
  def self.find_video_contents
9
9
  response = client.get("/video-content/get-all/")
10
- response.map { |upload| build(upload) }
10
+ map_collection(response)
11
11
  end
12
12
 
13
13
  def self.find(id)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Swiftner
4
- VERSION = "0.0.3"
4
+ VERSION = "0.0.4"
5
5
  end
data/lib/swiftner.rb CHANGED
@@ -1,9 +1,11 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require_relative "swiftner/API/service"
4
+ require_relative "swiftner/API/space"
4
5
  require_relative "swiftner/API/transcription"
5
6
  require_relative "swiftner/API/upload"
6
7
  require_relative "swiftner/API/video_content"
8
+ require_relative "swiftner/API/linked_content"
7
9
  require_relative "swiftner/configuration"
8
10
  require_relative "swiftner/client"
9
11
  require_relative "swiftner/version"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: swiftner
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Martin Ulleberg
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-02-23 00:00:00.000000000 Z
11
+ date: 2024-03-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: httparty
@@ -38,7 +38,9 @@ files:
38
38
  - README.md
39
39
  - Rakefile
40
40
  - lib/swiftner.rb
41
+ - lib/swiftner/API/linked_content.rb
41
42
  - lib/swiftner/API/service.rb
43
+ - lib/swiftner/API/space.rb
42
44
  - lib/swiftner/API/transcription.rb
43
45
  - lib/swiftner/API/upload.rb
44
46
  - lib/swiftner/API/video_content.rb
@@ -53,7 +55,7 @@ metadata:
53
55
  source_code_uri: https://github.com/swiftner/swiftner_ruby
54
56
  changelog_uri: https://github.com/swiftner/swiftner_ruby/blob/main/CHANGELOG.md
55
57
  rubygems_mfa_required: 'true'
56
- post_install_message:
58
+ post_install_message:
57
59
  rdoc_options: []
58
60
  require_paths:
59
61
  - lib
@@ -68,8 +70,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
68
70
  - !ruby/object:Gem::Version
69
71
  version: '0'
70
72
  requirements: []
71
- rubygems_version: 3.4.22
72
- signing_key:
73
+ rubygems_version: 3.5.3
74
+ signing_key:
73
75
  specification_version: 4
74
76
  summary: API wrapper for Swiftner's AI transcription service.
75
77
  test_files: []