swiftner 0.0.3 → 0.0.5

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: fcaad19a345368e1cd1c8660d53bcab7a8f5152c59221e335bf9c8057f17fbd1
4
+ data.tar.gz: d1b40c55191e99e2326aac0850bc342f0eadde486f69c772a0fc828d9ad2c3e0
5
5
  SHA512:
6
- metadata.gz: 42390d0d4f6bc5b6ee40a91deaeafc27c78c17fb2c4bd5663d91338dc376c5f22dfd818759cc9a627e8e3a1c7dded5a40b411baaae93faf124daa6c3a44f3620
7
- data.tar.gz: 89f9c9ceab9e07ad7884fadb389830b5ff2f8cc36d9eda4898c17366fc8a1433179f956f79961c7b808bd644b8d688618e06b0147567ccafaa3d5e2bf37ec690
6
+ metadata.gz: e847384adbdb29330517d383c310085b8fc34b3e47f9b4fddcba6d12c08dca276128eaa65e1fabc9d7149adeeeee5ac4ddf80ff9f5770a86862a190b3d37b2a3
7
+ data.tar.gz: b74036ad768d3faa6c90d5564ef246153a01736785174cc2393410cb65559de4dbe41b35718313b85b27e50bcc81a3713c1f0f436cdf7f9730a9b3e8f1ac8726
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)
@@ -30,11 +30,11 @@ module Swiftner
30
30
  def handle_response(response)
31
31
  case response.code
32
32
  when 200 then response
33
- when 401 then raise Unauthorized
34
- when 403 then raise Forbidden
35
- when 404 then raise NotFound
36
- when 500 then raise InternalError
37
- else raise Error, "Unknown error occurred"
33
+ when 401 then raise Unauthorized.from_response(response)
34
+ when 403 then raise Forbidden.from_response(response)
35
+ when 404 then raise NotFound.from_response(response)
36
+ when 500 then raise InternalError.from_response(response)
37
+ else raise Error.new("Unknown error occurred", response: response)
38
38
  end
39
39
  end
40
40
  end
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Swiftner
4
+ # Encapsulates all errors that can be raised by the Swiftner API
5
+ class Error < StandardError
6
+ attr_reader :response
7
+
8
+ def self.from_response(response)
9
+ return new(response["detail"], response: response) if response.key?("detail")
10
+
11
+ new(response.to_s, response: response)
12
+ end
13
+
14
+ def initialize(message, response: nil)
15
+ @response = response
16
+ super(message)
17
+ end
18
+ end
19
+
20
+ class Forbidden < Error; end
21
+ class Unauthorized < Error; end
22
+ class NotFound < Error; end
23
+ class InternalError < Error; end
24
+ end
@@ -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.5"
5
5
  end
data/lib/swiftner.rb CHANGED
@@ -1,21 +1,18 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require_relative "swiftner/error"
3
4
  require_relative "swiftner/API/service"
5
+ require_relative "swiftner/API/space"
4
6
  require_relative "swiftner/API/transcription"
5
7
  require_relative "swiftner/API/upload"
6
8
  require_relative "swiftner/API/video_content"
9
+ require_relative "swiftner/API/linked_content"
7
10
  require_relative "swiftner/configuration"
8
11
  require_relative "swiftner/client"
9
12
  require_relative "swiftner/version"
10
13
 
11
14
  ### Swiftner
12
15
  module Swiftner
13
- class Error < StandardError; end
14
- class Forbidden < Error; end
15
- class Unauthorized < Error; end
16
- class NotFound < Error; end
17
- class InternalError < Error; end
18
-
19
16
  class << self
20
17
  attr_accessor :configuration
21
18
  end
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.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Martin Ulleberg
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-02-23 00:00:00.000000000 Z
11
+ date: 2024-03-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: httparty
@@ -38,14 +38,16 @@ 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
45
47
  - lib/swiftner/client.rb
46
48
  - lib/swiftner/configuration.rb
49
+ - lib/swiftner/error.rb
47
50
  - lib/swiftner/version.rb
48
- - swiftner.gemspec
49
51
  homepage: https://swiftner.com
50
52
  licenses: []
51
53
  metadata:
@@ -68,7 +70,7 @@ 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
73
+ rubygems_version: 3.5.5
72
74
  signing_key:
73
75
  specification_version: 4
74
76
  summary: API wrapper for Swiftner's AI transcription service.
data/swiftner.gemspec DELETED
@@ -1,40 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative "lib/swiftner/version"
4
-
5
- Gem::Specification.new do |spec|
6
- spec.name = "swiftner"
7
- spec.version = Swiftner::VERSION
8
- spec.authors = ["Martin Ulleberg"]
9
- spec.email = ["martin.ulleberg@gmail.com"]
10
-
11
- spec.summary = "API wrapper for Swiftner's AI transcription service."
12
- spec.description = "This gem provides an easy-to-use interface for Swiftner's API, allowing seamless integration of\
13
- AI-driven transcription services into your Ruby applications."
14
- spec.homepage = "https://swiftner.com"
15
- spec.required_ruby_version = ">= 3.0.0"
16
-
17
- spec.metadata["homepage_uri"] = spec.homepage
18
- spec.metadata["source_code_uri"] = "https://github.com/swiftner/swiftner_ruby"
19
- spec.metadata["changelog_uri"] = "https://github.com/swiftner/swiftner_ruby/blob/main/CHANGELOG.md"
20
-
21
- # Specify which files should be added to the gem when it is released.
22
- # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
23
- spec.files = Dir.chdir(__dir__) do
24
- `git ls-files -z`.split("\x0").reject do |f|
25
- (File.expand_path(f) == __FILE__) ||
26
- f.start_with?(*%w[bin/ test/ spec/ features/ .git .github appveyor Gemfile])
27
- end
28
- end
29
- spec.bindir = "exe"
30
- spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
31
- spec.require_paths = ["lib"]
32
-
33
- spec.add_dependency "httparty", "~> 0.21"
34
- # Uncomment to register a new dependency of your gem
35
- # spec.add_dependency "example-gem", "~> 1.0"
36
-
37
- # For more information and examples about making a new gem, check out our
38
- # guide at: https://bundler.io/guides/creating_gem.html
39
- spec.metadata["rubygems_mfa_required"] = "true"
40
- end