swiftner 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 2012383224b63c20920e314f1f475b3ceefc371b6ffb304b4bab51a8ae2cd8e5
4
+ data.tar.gz: 38a3b6e70c2387d6f71992e95c45e22d003f0c4a5772e5fa3cfa18076dd21e42
5
+ SHA512:
6
+ metadata.gz: 3014179290cf659595aaa9d44be639e44c6be0a88ace20146dc8f0069200355aad675252604022f57e0fba793a927d1ae94e242eedc2ce099dd2a00532b56e2e
7
+ data.tar.gz: ad51894f768e7bdfccc9f1079e4337b67a17f56993bd20fd228623e1c149fbe104781c7e44055915ef5f9a583228cab3e4bd3262686a1ca2dcc9b6c139b919c1
data/.rubocop.yml ADDED
@@ -0,0 +1,14 @@
1
+ AllCops:
2
+ TargetRubyVersion: 2.6
3
+ NewCops: enable
4
+
5
+ Style/StringLiterals:
6
+ Enabled: true
7
+ EnforcedStyle: double_quotes
8
+
9
+ Style/StringLiteralsInInterpolation:
10
+ Enabled: true
11
+ EnforcedStyle: double_quotes
12
+
13
+ Layout/LineLength:
14
+ Max: 120
data/CHANGELOG.md ADDED
@@ -0,0 +1,9 @@
1
+ ## [Unreleased]
2
+
3
+ ## [0.0.2] - 2024-02-13
4
+
5
+ - Adds the first services supported.
6
+
7
+ ## [0.0.1] - 2024-02-02
8
+
9
+ - Initial release
@@ -0,0 +1,84 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone, regardless of age, body size, visible or invisible disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion, or sexual identity and orientation.
6
+
7
+ We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and healthy community.
8
+
9
+ ## Our Standards
10
+
11
+ Examples of behavior that contributes to a positive environment for our community include:
12
+
13
+ * Demonstrating empathy and kindness toward other people
14
+ * Being respectful of differing opinions, viewpoints, and experiences
15
+ * Giving and gracefully accepting constructive feedback
16
+ * Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience
17
+ * Focusing on what is best not just for us as individuals, but for the overall community
18
+
19
+ Examples of unacceptable behavior include:
20
+
21
+ * The use of sexualized language or imagery, and sexual attention or
22
+ advances of any kind
23
+ * Trolling, insulting or derogatory comments, and personal or political attacks
24
+ * Public or private harassment
25
+ * Publishing others' private information, such as a physical or email
26
+ address, without their explicit permission
27
+ * Other conduct which could reasonably be considered inappropriate in a
28
+ professional setting
29
+
30
+ ## Enforcement Responsibilities
31
+
32
+ Community leaders are responsible for clarifying and enforcing our standards of acceptable behavior and will take appropriate and fair corrective action in response to any behavior that they deem inappropriate, threatening, offensive, or harmful.
33
+
34
+ Community leaders have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, and will communicate reasons for moderation decisions when appropriate.
35
+
36
+ ## Scope
37
+
38
+ This Code of Conduct applies within all community spaces, and also applies when an individual is officially representing the community in public spaces. Examples of representing our community include using an official e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event.
39
+
40
+ ## Enforcement
41
+
42
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at martin.ulleberg@gmail.com. All complaints will be reviewed and investigated promptly and fairly.
43
+
44
+ All community leaders are obligated to respect the privacy and security of the reporter of any incident.
45
+
46
+ ## Enforcement Guidelines
47
+
48
+ Community leaders will follow these Community Impact Guidelines in determining the consequences for any action they deem in violation of this Code of Conduct:
49
+
50
+ ### 1. Correction
51
+
52
+ **Community Impact**: Use of inappropriate language or other behavior deemed unprofessional or unwelcome in the community.
53
+
54
+ **Consequence**: A private, written warning from community leaders, providing clarity around the nature of the violation and an explanation of why the behavior was inappropriate. A public apology may be requested.
55
+
56
+ ### 2. Warning
57
+
58
+ **Community Impact**: A violation through a single incident or series of actions.
59
+
60
+ **Consequence**: A warning with consequences for continued behavior. No interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, for a specified period of time. This includes avoiding interactions in community spaces as well as external channels like social media. Violating these terms may lead to a temporary or permanent ban.
61
+
62
+ ### 3. Temporary Ban
63
+
64
+ **Community Impact**: A serious violation of community standards, including sustained inappropriate behavior.
65
+
66
+ **Consequence**: A temporary ban from any sort of interaction or public communication with the community for a specified period of time. No public or private interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, is allowed during this period. Violating these terms may lead to a permanent ban.
67
+
68
+ ### 4. Permanent Ban
69
+
70
+ **Community Impact**: Demonstrating a pattern of violation of community standards, including sustained inappropriate behavior, harassment of an individual, or aggression toward or disparagement of classes of individuals.
71
+
72
+ **Consequence**: A permanent ban from any sort of public interaction within the community.
73
+
74
+ ## Attribution
75
+
76
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 2.0,
77
+ available at https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
78
+
79
+ Community Impact Guidelines were inspired by [Mozilla's code of conduct enforcement ladder](https://github.com/mozilla/diversity).
80
+
81
+ [homepage]: https://www.contributor-covenant.org
82
+
83
+ For answers to common questions about this code of conduct, see the FAQ at
84
+ https://www.contributor-covenant.org/faq. Translations are available at https://www.contributor-covenant.org/translations.
data/README.md ADDED
@@ -0,0 +1,87 @@
1
+ > [!WARNING]
2
+ > Please note that this client is under active development and is not yet ready for production use. We encourage you to try out its features and provide feedback, and if you're comfortable contributing to an in-progress project, we welcome your help in improving it. However, we recommend against deploying it to a production environment until its features have been more thoroughly tested and stabilized. We appreciate your understanding and patience!
3
+
4
+ # Swiftner API Ruby Client
5
+
6
+ This is a Ruby client for interacting with the Swiftner API. It allows you to work with videos, transcriptions, errors, and perform various actions such as uploading, deleting, updating, and fetching information. This client make it easier to deal with HTTP requests by providing a Ruby-oriented interface with built-in error handling.
7
+
8
+ ## Requirements
9
+
10
+ - Ruby version: 3.0.0 or later
11
+
12
+ ## Installation
13
+
14
+ Install the gem and add to the application's Gemfile by executing:
15
+
16
+ $ bundle add swiftner
17
+
18
+ If bundler is not being used to manage dependencies, install the gem by executing:
19
+
20
+ $ gem install swiftner
21
+
22
+ ## Usage
23
+
24
+ This section includes syntax examples of some of the key features of the Swiftner API Ruby client.
25
+
26
+ ### Initializing the Client
27
+ ```ruby
28
+ @api_key = "swiftner_api_key"
29
+ @client = Swiftner::Client.new(@api_key)
30
+ ```
31
+
32
+ ### Working with Video Content
33
+ ```ruby
34
+ @video_content_service = Swiftner::API::VideoContent
35
+
36
+ # Find video contents
37
+ video_contents = @video_content_service.find_video_contents
38
+
39
+ # Find specific video content by ID
40
+ video_content = @video_content_service.find(1)
41
+
42
+ # Update the title of a video content
43
+ video_content.update(title: "New title")
44
+ ```
45
+
46
+ ### Working with Uploads
47
+ ```ruby
48
+ @upload_service = Swiftner::API::Upload
49
+
50
+ # Find uploads
51
+ uploads = @upload_service.find_uploads
52
+
53
+ # Create an upload
54
+ upload = @upload_service.create(sample_attributes)
55
+
56
+ # Delete an upload
57
+ upload.delete
58
+
59
+ # Transcribe an upload
60
+ upload.transcribe("no")
61
+ ```
62
+
63
+ ### Handling Exceptions
64
+ 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
+ ```ruby
66
+ begin
67
+ # some code that might raise an exception
68
+ rescue Swiftner::Forbidden => e
69
+ puts "Handle forbidden error here"
70
+ rescue Swiftner::Unauthorized => e
71
+ puts "Handle unauthorized error here"
72
+ end
73
+ ```
74
+
75
+ ## Development
76
+
77
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
78
+
79
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
80
+
81
+ ## Contributing
82
+
83
+ Bug reports and pull requests are welcome on GitHub at https://github.com/swiftner/swiftner_ruby. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/swiftner/swiftner_ruby/blob/main/CODE_OF_CONDUCT.md).
84
+
85
+ ## Code of Conduct
86
+
87
+ Everyone interacting in the Swiftner project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/swiftner/swiftner_ruby/blob/main/CODE_OF_CONDUCT.md).
data/Rakefile ADDED
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "minitest/test_task"
5
+
6
+ Minitest::TestTask.create
7
+
8
+ require "rubocop/rake_task"
9
+
10
+ RuboCop::RakeTask.new
11
+
12
+ task default: %i[test rubocop]
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Swiftner
4
+ module API
5
+ # The `Service` class acts as a base class for API operations and data encapsulation.
6
+ class Service
7
+ attr_reader :id, :details, :client
8
+
9
+ def self.build(details)
10
+ new(details)
11
+ end
12
+
13
+ def initialize(attributes = {}, client = Base.client)
14
+ @id = attributes["id"]
15
+ @details = attributes
16
+ @client = client
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,29 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Swiftner
4
+ module API
5
+ # Represents a Transcription service responsible for finding, creating, and deleting transcriptions.
6
+ # Inherits from the Service class.
7
+ # Provides methods for interacting with transcriptions.
8
+ class Transcription < Service
9
+ def self.find(transcription_id)
10
+ response = Base.client.get("/transcription/get/#{transcription_id}")
11
+ build(response.parsed_response)
12
+ end
13
+
14
+ def self.create(attributes)
15
+ response = Base.client.post(
16
+ "/transcription/create",
17
+ body: attributes.to_json,
18
+ headers: { "Content-Type" => "application/json" }
19
+ )
20
+
21
+ build(response.parsed_response)
22
+ end
23
+
24
+ def delete
25
+ client.delete("/transcription/delete/#{id}")
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,49 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Swiftner
4
+ module API
5
+ # The `Upload` class is responsible for managing uploads in the Swiftner API.
6
+ # It provides methods for finding uploads, creating uploads, deleting uploads, and retrieving transcriptions related
7
+ # to an upload.
8
+ class Upload < Service
9
+ def self.find_uploads
10
+ response = Base.client.get("/upload/get-uploads/")
11
+ response.map { |upload| build(upload) }
12
+ end
13
+
14
+ def self.find(upload_id)
15
+ response = Base.client.get("/upload/get/#{upload_id}")
16
+ build(response.parsed_response)
17
+ end
18
+
19
+ def self.create(attributes)
20
+ response = Base.client.post(
21
+ "/upload/create",
22
+ body: attributes.to_json,
23
+ headers: { "Content-Type" => "application/json" }
24
+ )
25
+ build(response.parsed_response) if response.success?
26
+ end
27
+
28
+ def delete
29
+ client.delete("/upload/delete/#{id}")
30
+ end
31
+
32
+ def transcriptions
33
+ response = client.get("/upload/get/#{id}/transcriptions")
34
+ response.map { |transcription| API::Transcription.build(transcription) }
35
+ end
36
+
37
+ def transcribe(language)
38
+ transcription = {
39
+ video_content_id: id,
40
+ language: language,
41
+ start: 0.0,
42
+ end: details["duration"],
43
+ duration: details["duration"]
44
+ }
45
+ API::Transcription.create(transcription)
46
+ end
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,31 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Swiftner
4
+ module API
5
+ # VideoContent class represents video content in the Swiftner API.
6
+ # It allows you to find and update video content.
7
+ class VideoContent < Service
8
+ def self.find_video_contents
9
+ response = Base.client.get("/video-content/get-all/")
10
+ response.map { |upload| build(upload) }
11
+ end
12
+
13
+ def self.find(id)
14
+ response = Base.client.get("/video-content/get/#{id}")
15
+ build(response.parsed_response)
16
+ end
17
+
18
+ def update(attributes)
19
+ attributes = attributes.transform_keys(&:to_s)
20
+ @details = @details.merge(attributes)
21
+
22
+ client.put(
23
+ "/video-content/update/#{id}",
24
+ body: @details.to_json,
25
+ headers: { "Content-Type" => "application/json" }
26
+ )
27
+ self
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,12 @@
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
@@ -0,0 +1,46 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "httparty"
4
+
5
+ module Swiftner
6
+ # Initializes a new instance of the Client class.
7
+ #
8
+ # @param api_key [String] The API key to be used for authentication.
9
+ class Client
10
+ include HTTParty
11
+ base_uri "https://api.swiftner.com"
12
+
13
+ def initialize(api_key)
14
+ self.class.headers "Api_Key_Header" => api_key
15
+ end
16
+
17
+ %i[get post put delete].each do |http_method|
18
+ define_method(http_method) do |path, options = {}|
19
+ response = self.class.public_send(http_method, build_path(path), options)
20
+ handle_response(response)
21
+ end
22
+ end
23
+
24
+ def check_health
25
+ get("/health")
26
+ end
27
+
28
+ private
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
+ def handle_response(response)
36
+ case response.code
37
+ when 200 then response
38
+ when 401 then raise Unauthorized
39
+ when 403 then raise Forbidden
40
+ when 404 then raise NotFound
41
+ when 500 then raise InternalError
42
+ else raise Error, "Unknown error occurred"
43
+ end
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Swiftner
4
+ VERSION = "0.0.2"
5
+ end
data/lib/swiftner.rb ADDED
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "swiftner/API/service"
4
+ require_relative "swiftner/API/transcription"
5
+ require_relative "swiftner/API/upload"
6
+ require_relative "swiftner/API/video_content"
7
+ require_relative "swiftner/base"
8
+ require_relative "swiftner/client"
9
+ require_relative "swiftner/version"
10
+
11
+ ### Swiftner
12
+ 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
+ def self.create_client(api_key)
20
+ Base.client = Client.new(api_key)
21
+ end
22
+ end
metadata ADDED
@@ -0,0 +1,74 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: swiftner
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ platform: ruby
6
+ authors:
7
+ - Martin Ulleberg
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2024-02-13 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: httparty
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '0.21'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '0.21'
27
+ description: This gem provides an easy-to-use interface for Swiftner's API, allowing
28
+ seamless integration of AI-driven transcription services into your Ruby applications.
29
+ email:
30
+ - martin.ulleberg@gmail.com
31
+ executables: []
32
+ extensions: []
33
+ extra_rdoc_files: []
34
+ files:
35
+ - ".rubocop.yml"
36
+ - CHANGELOG.md
37
+ - CODE_OF_CONDUCT.md
38
+ - README.md
39
+ - Rakefile
40
+ - lib/swiftner.rb
41
+ - lib/swiftner/API/service.rb
42
+ - lib/swiftner/API/transcription.rb
43
+ - lib/swiftner/API/upload.rb
44
+ - lib/swiftner/API/video_content.rb
45
+ - lib/swiftner/base.rb
46
+ - lib/swiftner/client.rb
47
+ - lib/swiftner/version.rb
48
+ homepage: https://swiftner.com
49
+ licenses: []
50
+ metadata:
51
+ homepage_uri: https://swiftner.com
52
+ source_code_uri: https://github.com/swiftner/swiftner_ruby
53
+ changelog_uri: https://github.com/swiftner/swiftner_ruby/blob/main/CHANGELOG.md
54
+ rubygems_mfa_required: 'true'
55
+ post_install_message:
56
+ rdoc_options: []
57
+ require_paths:
58
+ - lib
59
+ required_ruby_version: !ruby/object:Gem::Requirement
60
+ requirements:
61
+ - - ">="
62
+ - !ruby/object:Gem::Version
63
+ version: 2.6.0
64
+ required_rubygems_version: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ requirements: []
70
+ rubygems_version: 3.4.22
71
+ signing_key:
72
+ specification_version: 4
73
+ summary: API wrapper for Swiftner's AI transcription service.
74
+ test_files: []