swiftner 0.0.2 → 0.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2012383224b63c20920e314f1f475b3ceefc371b6ffb304b4bab51a8ae2cd8e5
4
- data.tar.gz: 38a3b6e70c2387d6f71992e95c45e22d003f0c4a5772e5fa3cfa18076dd21e42
3
+ metadata.gz: df81ce74f315ba2773be31747e089c77e955415362d0de93c6f0ac5e2d844086
4
+ data.tar.gz: 91ef8ff69dc8e7d8aa987d0296a45a04c02e3dc35c7466dbc2b872bf8345d43e
5
5
  SHA512:
6
- metadata.gz: 3014179290cf659595aaa9d44be639e44c6be0a88ace20146dc8f0069200355aad675252604022f57e0fba793a927d1ae94e242eedc2ce099dd2a00532b56e2e
7
- data.tar.gz: ad51894f768e7bdfccc9f1079e4337b67a17f56993bd20fd228623e1c149fbe104781c7e44055915ef5f9a583228cab3e4bd3262686a1ca2dcc9b6c139b919c1
6
+ metadata.gz: a530d61cdf3023d1c9df3881ce151e346b15480f5b7ff067d69801cfc07597047d7b5985cc991e72b93a8ed7a6e33408687dbc324bc5ccc0ce4f316a1d915434
7
+ data.tar.gz: 244fd82157219579145a47d20f21734b77923b5ad88b0dd725f85ea37c371f588dd510b48cf8fc259c0d2ed0be89d9e8f1dd3d3a848bf746b6dff11669eb1f4a
data/.rubocop.yml CHANGED
@@ -1,5 +1,5 @@
1
1
  AllCops:
2
- TargetRubyVersion: 2.6
2
+ TargetRubyVersion: 3.0
3
3
  NewCops: enable
4
4
 
5
5
  Style/StringLiterals:
data/README.md CHANGED
@@ -25,8 +25,11 @@ This section includes syntax examples of some of the key features of the Swiftne
25
25
 
26
26
  ### Initializing the Client
27
27
  ```ruby
28
- @api_key = "swiftner_api_key"
29
- @client = Swiftner::Client.new(@api_key)
28
+ api_key = "swiftner_api_key"
29
+
30
+ Swiftner.configure do |config|
31
+ config.client = Swiftner::Client.new(api_key)
32
+ end
30
33
  ```
31
34
 
32
35
  ### Working with Video Content
@@ -60,6 +63,32 @@ upload.delete
60
63
  upload.transcribe("no")
61
64
  ```
62
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
+
63
92
  ### Handling Exceptions
64
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.
65
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
@@ -10,7 +10,26 @@ module Swiftner
10
10
  new(details)
11
11
  end
12
12
 
13
- def initialize(attributes = {}, client = Base.client)
13
+ def self.client
14
+ Swiftner.configuration.client
15
+ end
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
+
30
+ def initialize(attributes = {}, client = self.class.client)
31
+ raise Swiftner::Error, "Client must be set" if client.nil?
32
+
14
33
  @id = attributes["id"]
15
34
  @details = attributes
16
35
  @client = client
@@ -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
@@ -7,12 +7,12 @@ module Swiftner
7
7
  # Provides methods for interacting with transcriptions.
8
8
  class Transcription < Service
9
9
  def self.find(transcription_id)
10
- response = Base.client.get("/transcription/get/#{transcription_id}")
10
+ response = client.get("/transcription/get/#{transcription_id}")
11
11
  build(response.parsed_response)
12
12
  end
13
13
 
14
14
  def self.create(attributes)
15
- response = Base.client.post(
15
+ response = client.post(
16
16
  "/transcription/create",
17
17
  body: attributes.to_json,
18
18
  headers: { "Content-Type" => "application/json" }
@@ -7,17 +7,17 @@ module Swiftner
7
7
  # to an upload.
8
8
  class Upload < Service
9
9
  def self.find_uploads
10
- response = Base.client.get("/upload/get-uploads/")
11
- response.map { |upload| build(upload) }
10
+ response = client.get("/upload/get-uploads/")
11
+ map_collection(response)
12
12
  end
13
13
 
14
14
  def self.find(upload_id)
15
- response = Base.client.get("/upload/get/#{upload_id}")
15
+ response = client.get("/upload/get/#{upload_id}")
16
16
  build(response.parsed_response)
17
17
  end
18
18
 
19
19
  def self.create(attributes)
20
- response = Base.client.post(
20
+ response = client.post(
21
21
  "/upload/create",
22
22
  body: attributes.to_json,
23
23
  headers: { "Content-Type" => "application/json" }
@@ -6,12 +6,12 @@ module Swiftner
6
6
  # It allows you to find and update video content.
7
7
  class VideoContent < Service
8
8
  def self.find_video_contents
9
- response = Base.client.get("/video-content/get-all/")
10
- response.map { |upload| build(upload) }
9
+ response = client.get("/video-content/get-all/")
10
+ map_collection(response)
11
11
  end
12
12
 
13
13
  def self.find(id)
14
- response = Base.client.get("/video-content/get/#{id}")
14
+ response = client.get("/video-content/get/#{id}")
15
15
  build(response.parsed_response)
16
16
  end
17
17
 
@@ -16,7 +16,7 @@ module Swiftner
16
16
 
17
17
  %i[get post put delete].each do |http_method|
18
18
  define_method(http_method) do |path, options = {}|
19
- response = self.class.public_send(http_method, build_path(path), options)
19
+ response = self.class.public_send(http_method, path, options)
20
20
  handle_response(response)
21
21
  end
22
22
  end
@@ -27,11 +27,6 @@ module Swiftner
27
27
 
28
28
  private
29
29
 
30
- def build_path(path)
31
- # This is temporary solution because server doesn't accept the API Key in headers for some reason.
32
- "#{path}?api_key_query=#{ENV.fetch("SWIFTNER_API_KEY", "swiftner-api-key")}"
33
- end
34
-
35
30
  def handle_response(response)
36
31
  case response.code
37
32
  when 200 then response
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Swiftner
4
+ ## `Swiftner::Configuration`
5
+ class Configuration
6
+ attr_accessor :client
7
+
8
+ def initialize
9
+ @client = nil
10
+ end
11
+ end
12
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Swiftner
4
- VERSION = "0.0.2"
4
+ VERSION = "0.0.4"
5
5
  end
data/lib/swiftner.rb CHANGED
@@ -1,10 +1,12 @@
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"
7
- require_relative "swiftner/base"
8
+ require_relative "swiftner/API/linked_content"
9
+ require_relative "swiftner/configuration"
8
10
  require_relative "swiftner/client"
9
11
  require_relative "swiftner/version"
10
12
 
@@ -16,7 +18,12 @@ module Swiftner
16
18
  class NotFound < Error; end
17
19
  class InternalError < Error; end
18
20
 
19
- def self.create_client(api_key)
20
- Base.client = Client.new(api_key)
21
+ class << self
22
+ attr_accessor :configuration
23
+ end
24
+
25
+ def self.configure
26
+ self.configuration ||= Configuration.new
27
+ yield(configuration)
21
28
  end
22
29
  end
data/swiftner.gemspec ADDED
@@ -0,0 +1,40 @@
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
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.2
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-13 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,13 +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
- - lib/swiftner/base.rb
46
47
  - lib/swiftner/client.rb
48
+ - lib/swiftner/configuration.rb
47
49
  - lib/swiftner/version.rb
50
+ - swiftner.gemspec
48
51
  homepage: https://swiftner.com
49
52
  licenses: []
50
53
  metadata:
@@ -52,7 +55,7 @@ metadata:
52
55
  source_code_uri: https://github.com/swiftner/swiftner_ruby
53
56
  changelog_uri: https://github.com/swiftner/swiftner_ruby/blob/main/CHANGELOG.md
54
57
  rubygems_mfa_required: 'true'
55
- post_install_message:
58
+ post_install_message:
56
59
  rdoc_options: []
57
60
  require_paths:
58
61
  - lib
@@ -60,15 +63,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
60
63
  requirements:
61
64
  - - ">="
62
65
  - !ruby/object:Gem::Version
63
- version: 2.6.0
66
+ version: 3.0.0
64
67
  required_rubygems_version: !ruby/object:Gem::Requirement
65
68
  requirements:
66
69
  - - ">="
67
70
  - !ruby/object:Gem::Version
68
71
  version: '0'
69
72
  requirements: []
70
- rubygems_version: 3.4.22
71
- signing_key:
73
+ rubygems_version: 3.5.3
74
+ signing_key:
72
75
  specification_version: 4
73
76
  summary: API wrapper for Swiftner's AI transcription service.
74
77
  test_files: []
data/lib/swiftner/base.rb DELETED
@@ -1,12 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Swiftner
4
- ## `Swiftner::Base`
5
- class Base
6
- @client = nil
7
-
8
- class << self
9
- attr_accessor :client
10
- end
11
- end
12
- end