swiftner 0.0.4 → 0.0.6

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: df81ce74f315ba2773be31747e089c77e955415362d0de93c6f0ac5e2d844086
4
- data.tar.gz: 91ef8ff69dc8e7d8aa987d0296a45a04c02e3dc35c7466dbc2b872bf8345d43e
3
+ metadata.gz: 7fed0bd04566bcce81abf9cef775cd31ee2b4faf14709c190ea57a468804074e
4
+ data.tar.gz: 4d3c389378438555f00485e9f8cbee362a9d1757a8babbd5b545f5741f4f8b4c
5
5
  SHA512:
6
- metadata.gz: a530d61cdf3023d1c9df3881ce151e346b15480f5b7ff067d69801cfc07597047d7b5985cc991e72b93a8ed7a6e33408687dbc324bc5ccc0ce4f316a1d915434
7
- data.tar.gz: 244fd82157219579145a47d20f21734b77923b5ad88b0dd725f85ea37c371f588dd510b48cf8fc259c0d2ed0be89d9e8f1dd3d3a848bf746b6dff11669eb1f4a
6
+ metadata.gz: ec7c67f789d1f167cbde69b4a7a6df4d173a237500681bb2238525833312c86beed7198688d1a8dba9ed867155cbf468cdb32fb50d5d7b42c2d522ebe9ff818a
7
+ data.tar.gz: 0a3023b1c834c6791168659cb7a2bb0b0b6d4b7902070175c3e7423024a4010809fc74bb7aed2ae4c70e4cd782a28896131aa581bb3787ca780f655006aae8a7
data/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  ## [Unreleased]
2
2
 
3
+ ## [0.0.6]
4
+ - Added Meeting service with CRUD operations and `start`, `end`, `pause` and `resume`. [#10](https://github.com/Swiftner/swiftner_ruby/pull/10)
5
+ - Added Channel service with CRUD operations and `live?`. [#9](https://github.com/Swiftner/swiftner_ruby/pull/9)
6
+ - Added Chapter service with CRUD operations. [#8](https://github.com/Swiftner/swiftner_ruby/pull/8)
7
+ - Added Organisation service with CRUD operations and `add_org_to_token`. [#7](https://github.com/Swiftner/swiftner_ruby/pull/7)
8
+
3
9
  ## [0.0.2] - 2024-02-13
4
10
 
5
11
  - Adds the first services supported.
data/RELEASING.md ADDED
@@ -0,0 +1,14 @@
1
+ # Releasing
2
+
3
+ 1. Update `lib/swiftner/version.rb` accordingly and run `bundle install` to update the Gemfile.lock.
4
+ 1. Update `CHANGELOG.md` to reflect the changes since last release. This means moving everyhing from the unrealesed section to an appropriate version section.
5
+ 1. Commit changes.
6
+ 1. Tag the release: `git tag -s vVERSION`
7
+ 1. Push changes: `git push && git push --tags`
8
+ 1. Build and publish:
9
+ ```bash
10
+ gem build swiftner.gemspe
11
+ gem push swiftner-VERSION.gem
12
+ ```
13
+ 1. Add a new GitHub release using the content from new version section of `CHANGELOG.md` as the content.
14
+ 1. Announce the new release, say "thank you" to the contributors.
@@ -0,0 +1,81 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Swiftner
4
+ module API
5
+ # Represents a Channel service responsible for finding, creating, updating and deleting channels.
6
+ # Inherits from the Service class.
7
+ # Provides methods for interacting with channel.
8
+ class Channel < Service
9
+ REQUIRED_ATTRIBUTES = %i[name type space_id].freeze
10
+
11
+ # Finds all channels
12
+ # @return [Array<Swiftner::API::Channel>]
13
+ def self.find_channels
14
+ response = client.get("/channel/get-channels")
15
+ map_collection(response)
16
+ end
17
+
18
+ # Finds channel by its id
19
+ # @param [Integer] channel_id
20
+ # @return [Swiftner::API::Channel]
21
+ def self.find(channel_id)
22
+ response = client.get("/channel/get/#{channel_id}")
23
+ build(response.parsed_response)
24
+ end
25
+
26
+ # @param [Hash] attributes
27
+ # @option attributes [String] :name (required)
28
+ # @option attributes [String] :type (required) - "audio", "video" or "dual"
29
+ # @option attributes [Integer] :space_id (required)
30
+ # @option attributes [String] :description (optional)
31
+ # @option attributes [Integer] :order (optional)
32
+ # @return [Swiftner::API::Channel]
33
+ def self.create(attributes)
34
+ validate_required(attributes, *REQUIRED_ATTRIBUTES)
35
+
36
+ response = client.post(
37
+ "/channel/create",
38
+ body: attributes.to_json,
39
+ headers: { "Content-Type" => "application/json" }
40
+ )
41
+
42
+ build(response.parsed_response)
43
+ end
44
+
45
+ # @return [Boolean]
46
+ def live?
47
+ client.get("/channel/is_channel_live?channel_id=#{id}")["status"] == "live"
48
+ rescue Swiftner::NotFound
49
+ # ?Why does api return 404 when channel is not live?
50
+ false
51
+ end
52
+
53
+ # @param [Hash] attributes
54
+ # @option attributes [String] :name (required)
55
+ # @option attributes [String] :type (required) - "audio", "video" or "dual"
56
+ # @option attributes [Integer] :space_id (required)
57
+ # @option attributes [String] :description (optional)
58
+ # @option attributes [Integer] :order (optional)
59
+ # @return [Swiftner::API::Channel]
60
+ def update(attributes)
61
+ attributes = attributes.transform_keys(&:to_s)
62
+ @details = @details.merge(attributes)
63
+
64
+ self.class.validate_required(@details, *REQUIRED_ATTRIBUTES)
65
+
66
+ client.put(
67
+ "/channel/update/#{id}",
68
+ body: @details.to_json,
69
+ headers: { "Content-Type" => "application/json" }
70
+ )
71
+ self
72
+ end
73
+
74
+ # Deletes channel by its id
75
+ # @return [Hash] response
76
+ def delete
77
+ client.delete("/channel/delete/#{id}")
78
+ end
79
+ end
80
+ end
81
+ end
@@ -0,0 +1,76 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Swiftner
4
+ module API
5
+ # Represents a chapter service responsible for finding, creating, and deleting chapters.
6
+ # Inherits from the Service class.
7
+ # Provides methods for interacting with chapters.
8
+ class Chapter < Service
9
+ REQUIRED_ATTRIBUTES = %i[title duration video_content_id start].freeze
10
+ # Finds all chapters for a video content.
11
+ # @param [Integer] video_content_id
12
+ # @return [Array<Swiftner::API::Chapter>]
13
+ def self.find_chapters(video_content_id)
14
+ response = client.get("/video-content/get/#{video_content_id}/chapters")
15
+ map_collection(response)
16
+ end
17
+
18
+ # Finds chapter by id.
19
+ # @param [Integer] chapter_id
20
+ # @return [Swiftner::API::Chapter]
21
+ def self.find(chapter_id)
22
+ response = client.get("/chapter/get/#{chapter_id}")
23
+ build(response.parsed_response)
24
+ end
25
+
26
+ # Creates a chapter.
27
+ # @param [Hash] attributes
28
+ # @option attributes [String] :title (required)
29
+ # @option attributes [String] :duration (required)
30
+ # @option attributes [Integer] :video_content_id (required)
31
+ # @option attributes [String] :start (required)
32
+ # @option attributes [String] :start_seconds (optional)
33
+ # @option attributes [String] :language (optional)
34
+ # @return [Swiftner::API::Chapter]
35
+ def self.create(attributes)
36
+ validate_required(attributes, *REQUIRED_ATTRIBUTES)
37
+
38
+ response = client.post(
39
+ "/chapter/create",
40
+ body: attributes.to_json,
41
+ headers: { "Content-Type" => "application/json" }
42
+ )
43
+
44
+ build(response.parsed_response)
45
+ end
46
+
47
+ # Creates a chapter.
48
+ # @param [Hash] attributes
49
+ # @option attributes [String] :title (optional)
50
+ # @option attributes [String] :duration (optional)
51
+ # @option attributes [Integer] :video_content_id (optional)
52
+ # @option attributes [String] :start (optional)
53
+ # @option attributes [String] :start_seconds (optional)
54
+ # @option attributes [String] :language (optional)
55
+ # @return [Swiftner::API::Chapter]
56
+ def update(attributes)
57
+ attributes = attributes.transform_keys(&:to_s)
58
+ @details = @details.merge(attributes)
59
+
60
+ self.class.validate_required(@details, *REQUIRED_ATTRIBUTES)
61
+
62
+ client.put(
63
+ "/chapter/update/#{id}",
64
+ body: @details.to_json,
65
+ headers: { "Content-Type" => "application/json" }
66
+ )
67
+ self
68
+ end
69
+
70
+ # @return [Hash]
71
+ def delete
72
+ client.delete("/chapter/delete/#{id}")
73
+ end
74
+ end
75
+ end
76
+ end
@@ -0,0 +1,127 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Swiftner
4
+ module API
5
+ # Represents a Meeting service responsible for finding, creating, and deleting spaces.
6
+ # Inherits from the Service class.
7
+ # Provides methods for interacting with meetings.
8
+ class Meeting < Service
9
+ REQUIRED_ATTRIBUTES = %i[space_id language].freeze
10
+ # Finds all meetings
11
+ # @return [Array<Swiftner::API::Meeting>]
12
+ def self.find_meetings
13
+ response = client.get("/meeting/get-meetings")
14
+ map_collection(response)
15
+ end
16
+
17
+ # Finds meeting by id
18
+ # @param [Integer] meeting_id
19
+ # @return [Swiftner::API::Meeting]
20
+ def self.find(meeting_id)
21
+ response = client.get("/meeting/get/#{meeting_id}")
22
+ build(response.parsed_response)
23
+ end
24
+
25
+ # Creates a meeting.
26
+ # @param [Hash] attributes
27
+ # @option attributes [Integer] :space_id (required)
28
+ # @option attributes [String] :language (required)
29
+ # @option attributes [String] :title (optional)
30
+ # @option attributes [String] :description (optional)
31
+ # @option attributes [String] :start (optional) eg. "2024-09-06T08:37:45.162Z"
32
+ # @option attributes [Integer] :duration (optional)
33
+ # @option attributes [String] :thumbnail_url (optional)
34
+ # @option attributes [String] :state (optional) eg. "not_started", "ended"
35
+ # @option attributes [Integer] :prompt_id (optional)
36
+ # @return [Swiftner::API::Meeting]
37
+ def self.create(attributes)
38
+ validate_required(attributes, *REQUIRED_ATTRIBUTES)
39
+
40
+ response = client.post(
41
+ "/meeting/create",
42
+ body: attributes.to_json,
43
+ headers: { "Content-Type" => "application/json" }
44
+ )
45
+
46
+ build(response.parsed_response)
47
+ end
48
+
49
+ # Starts a meeting
50
+ # @return [Swiftner::API::Meeting]
51
+ def start
52
+ response = client.post(
53
+ "/meeting/#{id}/start",
54
+ headers: { "Content-Type" => "application/json" }
55
+ )
56
+
57
+ @details = response
58
+ self
59
+ end
60
+
61
+ # Ends a meeting
62
+ # @return [Swiftner::API::Meeting]
63
+ def end
64
+ response = client.post(
65
+ "/meeting/#{id}/end",
66
+ headers: { "Content-Type" => "application/json" }
67
+ )
68
+ @details = response.parsed_response
69
+ self
70
+ end
71
+
72
+ # Pauses a meeting
73
+ # @return [Swiftner::API::Meeting, nil]
74
+ def pause
75
+ response = client.post(
76
+ "/meeting/#{id}/pause",
77
+ headers: { "Content-Type" => "application/json" }
78
+ )
79
+ @details = response.parsed_response
80
+ self
81
+ end
82
+
83
+ # Resumes a meeting
84
+ # @return [Swiftner::API::Meeting]
85
+ def resume
86
+ response = client.post(
87
+ "/meeting/#{id}/resume",
88
+ headers: { "Content-Type" => "application/json" }
89
+ )
90
+ @details = response.parsed_response
91
+ self
92
+ end
93
+
94
+ # Updates a meeting.
95
+ # @param [Hash] attributes
96
+ # @option attributes [Integer] :space_id (optional)
97
+ # @option attributes [String] :language (optional) eg. "no", "en"
98
+ # @option attributes [String] :title (optional)
99
+ # @option attributes [String] :description (optional)
100
+ # @option attributes [String] :start (optional) eg. "2024-09-06T08:37:45.162Z"
101
+ # @option attributes [Integer] :duration (optional)
102
+ # @option attributes [String] :thumbnail_url (optional)
103
+ # @option attributes [String] :state (optional) eg. "not_started", "ended"
104
+ # @option attributes [Integer] :prompt_id (optional)
105
+ # @return [Swiftner::API::Meeting]
106
+ def update(attributes)
107
+ attributes = attributes.transform_keys(&:to_s)
108
+ @details = @details.merge(attributes)
109
+
110
+ self.class.validate_required(@details, :language, :space)
111
+
112
+ client.put(
113
+ "/meeting/update/#{id}",
114
+ body: @details.to_json,
115
+ headers: { "Content-Type" => "application/json" }
116
+ )
117
+ self
118
+ end
119
+
120
+ # Deletes a meeting.
121
+ # @return [Hash]
122
+ def delete
123
+ client.delete("/meeting/delete/#{id}")
124
+ end
125
+ end
126
+ end
127
+ end
@@ -0,0 +1,77 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Swiftner
4
+ module API
5
+ # Represents a Organisation service responsible for finding, creating, and deleting organisations.
6
+ # Inherits from the Service class.
7
+ # Provides methods for interacting with spaces.
8
+ class Organisation < Service
9
+ REQUIRED_ATTRIBUTES = %i[name].freeze
10
+
11
+ # Finds all organisations user is in
12
+ # @return [Array<Swiftner::API::Organisation>]
13
+ def self.find_organisations
14
+ response = client.get("/organisation/get-current-user-orgs")
15
+ map_collection(response)
16
+ end
17
+
18
+ # Finds organisation by id
19
+ # @param [Integer] organisation_id
20
+ # @return [Swiftner::API::Organisation]
21
+ def self.find(organisation_id)
22
+ response = client.get("/organisation/get/#{organisation_id}")
23
+ build(response.parsed_response)
24
+ end
25
+
26
+ # Add org to token
27
+ # @param [Integer] organisation_id
28
+ # @return [Hash] {access_hash: String, refresh_token: String}
29
+ def self.add_org_to_token(organisation_id)
30
+ client.put("/organisation/add-org-to-token?organisation_id=#{organisation_id}")
31
+ end
32
+
33
+ # Creates a new organisation
34
+ # @param [Hash] attributes
35
+ # @option attributes [String] :name (required)
36
+ # @option attributes [String] :description (optional)
37
+ # @option attributes [Integer] :default_prompt_id (optional)
38
+ # @option attributes [String] :language (optional)
39
+ # @return [Swiftner::API::Organisation]
40
+ def self.create(attributes)
41
+ validate_required(attributes, *REQUIRED_ATTRIBUTES)
42
+ response = client.post(
43
+ "/organisation/create",
44
+ body: attributes.to_json,
45
+ headers: { "Content-Type" => "application/json" }
46
+ )
47
+ build(response.parsed_response)
48
+ end
49
+
50
+ # Updates organisation
51
+ # @param [Hash] attributes
52
+ # @option attributes [String] :name (optional)
53
+ # @option attributes [String] :description (optional)
54
+ # @option attributes [Integer] :default_prompt_id (optional)
55
+ # @option attributes [String] :language (optional)
56
+ # @return [Swiftner::API::Organisation]
57
+ def update(attributes)
58
+ attributes = attributes.transform_keys(&:to_s)
59
+ @details = @details.merge(attributes)
60
+
61
+ self.class.validate_required(@details, *REQUIRED_ATTRIBUTES)
62
+
63
+ client.put(
64
+ "/organisation/update/#{id}",
65
+ body: @details.to_json,
66
+ headers: { "Content-Type" => "application/json" }
67
+ )
68
+ self
69
+ end
70
+
71
+ # Deletes organisation
72
+ def delete
73
+ client.delete("/organisation/delete/#{id}")
74
+ end
75
+ end
76
+ end
77
+ end
@@ -29,12 +29,12 @@ module Swiftner
29
29
 
30
30
  def handle_response(response)
31
31
  case response.code
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"
32
+ when 200, 201 then response
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.4"
4
+ VERSION = "0.0.6"
5
5
  end
data/lib/swiftner.rb CHANGED
@@ -1,23 +1,22 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require_relative "swiftner/error"
3
4
  require_relative "swiftner/API/service"
4
5
  require_relative "swiftner/API/space"
5
6
  require_relative "swiftner/API/transcription"
6
7
  require_relative "swiftner/API/upload"
7
8
  require_relative "swiftner/API/video_content"
8
9
  require_relative "swiftner/API/linked_content"
10
+ require_relative "swiftner/API/channel"
11
+ require_relative "swiftner/API/chapter"
12
+ require_relative "swiftner/API/organisation"
13
+ require_relative "swiftner/API/meeting"
9
14
  require_relative "swiftner/configuration"
10
15
  require_relative "swiftner/client"
11
16
  require_relative "swiftner/version"
12
17
 
13
18
  ### Swiftner
14
19
  module Swiftner
15
- class Error < StandardError; end
16
- class Forbidden < Error; end
17
- class Unauthorized < Error; end
18
- class NotFound < Error; end
19
- class InternalError < Error; end
20
-
21
20
  class << self
22
21
  attr_accessor :configuration
23
22
  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.4
4
+ version: 0.0.6
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-03-04 00:00:00.000000000 Z
11
+ date: 2024-09-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: httparty
@@ -36,9 +36,14 @@ files:
36
36
  - CHANGELOG.md
37
37
  - CODE_OF_CONDUCT.md
38
38
  - README.md
39
+ - RELEASING.md
39
40
  - Rakefile
40
41
  - lib/swiftner.rb
42
+ - lib/swiftner/API/channel.rb
43
+ - lib/swiftner/API/chapter.rb
41
44
  - lib/swiftner/API/linked_content.rb
45
+ - lib/swiftner/API/meeting.rb
46
+ - lib/swiftner/API/organisation.rb
42
47
  - lib/swiftner/API/service.rb
43
48
  - lib/swiftner/API/space.rb
44
49
  - lib/swiftner/API/transcription.rb
@@ -46,6 +51,7 @@ files:
46
51
  - lib/swiftner/API/video_content.rb
47
52
  - lib/swiftner/client.rb
48
53
  - lib/swiftner/configuration.rb
54
+ - lib/swiftner/error.rb
49
55
  - lib/swiftner/version.rb
50
56
  - swiftner.gemspec
51
57
  homepage: https://swiftner.com
@@ -55,7 +61,7 @@ metadata:
55
61
  source_code_uri: https://github.com/swiftner/swiftner_ruby
56
62
  changelog_uri: https://github.com/swiftner/swiftner_ruby/blob/main/CHANGELOG.md
57
63
  rubygems_mfa_required: 'true'
58
- post_install_message:
64
+ post_install_message:
59
65
  rdoc_options: []
60
66
  require_paths:
61
67
  - lib
@@ -71,7 +77,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
71
77
  version: '0'
72
78
  requirements: []
73
79
  rubygems_version: 3.5.3
74
- signing_key:
80
+ signing_key:
75
81
  specification_version: 4
76
82
  summary: API wrapper for Swiftner's AI transcription service.
77
83
  test_files: []