dyte 0.1.0

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: 82cf74ac47f0763080ded04aa4b43a15ee84e589b5e2e7cbeb899e21dfce9460
4
+ data.tar.gz: 60c7a91ed450235a84d26e999a0b33bea4a0cb07b7c1f8cc4bf9bdb1cbcf6fd5
5
+ SHA512:
6
+ metadata.gz: 9387401bb78c05abfa45af7b38b0445845421fe042bd4d463d6bd4ff5918fb87dc73ebfc46593c8ca8cfea1180f93a486a391fdcbcac2aee2077f40954ed3695
7
+ data.tar.gz: 5c839335e1f430dbf68d9e5bc5e4596a66c8e7e27c1814a315d8e23619030e0ddfbedc81443bb201b1898e47dcb18e14a0fe5d3f759d66e8c115bfbb3db53225
data/.pryrc ADDED
@@ -0,0 +1,6 @@
1
+ if defined?(PryByebug)
2
+ Pry.commands.alias_command "c", "continue"
3
+ Pry.commands.alias_command "s", "step"
4
+ Pry.commands.alias_command "n", "next"
5
+ Pry.commands.alias_command "f", "finish"
6
+ end
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,13 @@
1
+ AllCops:
2
+ TargetRubyVersion: 2.6
3
+
4
+ Style/StringLiterals:
5
+ Enabled: true
6
+ EnforcedStyle: double_quotes
7
+
8
+ Style/StringLiteralsInInterpolation:
9
+ Enabled: true
10
+ EnforcedStyle: double_quotes
11
+
12
+ Layout/LineLength:
13
+ Max: 120
data/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ ## [Unreleased]
2
+
3
+ ## [0.1.0] - 2023-02-05
4
+
5
+ - Initial release
data/Gemfile ADDED
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ # Specify your gem's dependencies in dyte.gemspec
6
+ gemspec
7
+
8
+ group :development do
9
+ gem "rake", "~> 13.0"
10
+ gem "standard", "~> 1.24"
11
+ gem "minitest", "~> 5.17"
12
+ gem "webmock", "~> 3.18"
13
+ gem "solargraph", "~> 0.48.0"
14
+ gem "debug"
15
+ end
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2023 Nick Warwick
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,57 @@
1
+ # Dyte
2
+
3
+ A gem that wraps v2 of the [Dyte API](https://docs.dyte.io/api/#/) to make it easy to use in Ruby applications.
4
+ Please note that some resources are not yet implemented. This is due to the fact that v2 of the Dyte API is incomplete. Once the Dyte team has finalized the response structure the remaining resources will be implemented.
5
+
6
+ Bugs reports and pull requests are welcome! ❤️
7
+
8
+ ## Installation
9
+
10
+ Add this line to your application's Gemfile:
11
+ ```ruby
12
+ gem 'dyte'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle install
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install dyte
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Resources
28
+ ### Meetings
29
+ ```ruby
30
+ client.meetings.list
31
+ client.meetings.fetch(meeting_id: "id")
32
+ client.meetings.create({})
33
+ client.meetings.update(meeting_id: "id", {})
34
+ ```
35
+ ### Presets
36
+ ```ruby
37
+ client.presets.list
38
+ client.presets.fetch(preset_id: "id")
39
+ client.presets.create({})
40
+ client.presets.update(preset_id: "id", {})
41
+ ```
42
+ ### Sessions
43
+ ### Participants
44
+
45
+ ## Development
46
+
47
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
48
+
49
+ 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).
50
+
51
+ ## Contributing
52
+
53
+ Contribution guidelines TBD. For now just open a PR and we'll figure it out.
54
+
55
+ ## License
56
+
57
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,14 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ Rake::TestTask.new(:test) do |t|
5
+ t.libs << "test"
6
+ t.libs << "lib"
7
+ t.test_files = FileList["test/**/*_test.rb"]
8
+ end
9
+
10
+ task default: :test
11
+
12
+ task :console do
13
+ exec "irb -I lib -r dyte.rb"
14
+ end
@@ -0,0 +1,60 @@
1
+ require "minitest/autorun"
2
+ module Dyte
3
+ class Client
4
+ BASE_URL_V1 = "https://api.cluster.dyte.in/v1/organizations"
5
+ BASE_URL = "https://api.cluster.dyte.in/v2"
6
+
7
+ attr_accessor :organization_id, :api_key, :adapter
8
+
9
+ def initialize(organization_id:, api_key:, adapter: Faraday.default_adapter)
10
+ @organization_id = organization_id
11
+ @api_key = api_key
12
+ @adapter = adapter
13
+ end
14
+
15
+ def meetings
16
+ MeetingsResource.new(self)
17
+ end
18
+
19
+ def presets
20
+ PresetsResource.new(self)
21
+ end
22
+
23
+ def participants
24
+ ParticipantsResource.new(self)
25
+ end
26
+
27
+ def sessions
28
+ SessionsResource.new(self)
29
+ end
30
+
31
+ def recordings
32
+ RecordingsResource.new(self)
33
+ end
34
+
35
+ def active_sessions
36
+ ActiveSessionsResource.new(self)
37
+ end
38
+
39
+ def connection_v1
40
+ @connection ||= Faraday.new("#{BASE_URL}/#{@organization_id}") do |conn|
41
+ conn.headers["Authorization"] = @api_key
42
+
43
+ conn.request :json
44
+
45
+ conn.response :json, content_type: "application/json"
46
+ end
47
+ end
48
+
49
+ def connection
50
+ auth_token = Base64.strict_encode64("#{@organization_id}:#{@api_key}")
51
+ @connection ||= Faraday.new(BASE_URL) do |conn|
52
+ conn.headers["Authorization"] = "Basic #{auth_token}"
53
+
54
+ conn.request :json
55
+
56
+ conn.response :json, content_type: "application/json"
57
+ end
58
+ end
59
+ end
60
+ end
@@ -0,0 +1,41 @@
1
+ module Dyte
2
+ class Collection
3
+ attr_reader :data, :total_count, :start_offset, :end_offset
4
+
5
+ # from_response(response, type: Meeting)
6
+ def self.from_response(response, type:, key: nil)
7
+ body = response.body
8
+ new(
9
+ data: parse_body(body: body, type: type, key: key),
10
+ total_count: body.dig("paging", "total_count"),
11
+ start_offset: body.dig("paging", "start_offset"),
12
+ end_offset: body.dig("paging", "end_offset")
13
+ )
14
+ end
15
+
16
+ # As of now the session response differs from the other responses.
17
+ # It's missing pagination data and also the data is nested under 'sessions'.
18
+ def self.from_sessions_response(response, type:)
19
+ body = response.body
20
+ new(
21
+ data: body.dig("data", "sessions").map { |attrs| type.new(attrs) }
22
+ )
23
+ end
24
+
25
+ def initialize(data:, total_count: nil, start_offset: nil, end_offset: nil)
26
+ @data = data
27
+ @total_count = total_count
28
+ @start_offset = start_offset
29
+ @end_offset = end_offset
30
+ end
31
+
32
+ # The Dyte API does not have a consistent response structure. This method accounts for that.
33
+ def self.parse_body(body:, type:, key: nil)
34
+ if body["data"].is_a?(Array)
35
+ body["data"].map { |attrs| type.new(attrs) }
36
+ else
37
+ body.dig("data", key).map { |attrs| type.new(attrs) }
38
+ end
39
+ end
40
+ end
41
+ end
data/lib/dyte/error.rb ADDED
@@ -0,0 +1,4 @@
1
+ module Dyte
2
+ class Error < StandardError
3
+ end
4
+ end
@@ -0,0 +1,19 @@
1
+ require "ostruct"
2
+
3
+ module Dyte
4
+ class Object < OpenStruct
5
+ def initialize(attributes)
6
+ super to_ostruct(attributes)
7
+ end
8
+
9
+ def to_ostruct(obj)
10
+ if obj.is_a?(Hash)
11
+ OpenStruct.new(obj.map { |key, val| [key, to_ostruct(val)] }.to_h)
12
+ elsif obj.is_a?(Array)
13
+ obj.map { |o| to_ostruct(o) }
14
+ else
15
+ obj
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,4 @@
1
+ module Dyte
2
+ class ActiveSession < Object
3
+ end
4
+ end
@@ -0,0 +1,4 @@
1
+ module Dyte
2
+ class Meeting < Object
3
+ end
4
+ end
@@ -0,0 +1,4 @@
1
+ module Dyte
2
+ class Participant < Object
3
+ end
4
+ end
@@ -0,0 +1,4 @@
1
+ module Dyte
2
+ class Preset < Object
3
+ end
4
+ end
@@ -0,0 +1,4 @@
1
+ module Dyte
2
+ class Recording < Object
3
+ end
4
+ end
@@ -0,0 +1,4 @@
1
+ module Dyte
2
+ class Session < Object
3
+ end
4
+ end
@@ -0,0 +1,53 @@
1
+ module Dyte
2
+ class Resource
3
+ attr_reader :client
4
+
5
+ def initialize(client)
6
+ @client = client
7
+ end
8
+
9
+ private
10
+
11
+ def get_request(url, params: {}, headers: {})
12
+ handle_response(client.connection.get(url, params, headers))
13
+ end
14
+
15
+ def post_request(url, body:, headers: {})
16
+ handle_response(client.connection.post(url, body, headers))
17
+ end
18
+
19
+ def patch_request(url, body:, headers: {})
20
+ handle_response(client.connection.patch(url, body, headers))
21
+ end
22
+
23
+ def put_request(url, body:, headers: {})
24
+ handle_response(client.connection.put(url, body, headers))
25
+ end
26
+
27
+ def delete_request(url, params: {}, headers: {})
28
+ handle_response(client.connection.delete(url, params, headers))
29
+ end
30
+
31
+ def handle_response(response)
32
+ case response.status
33
+ when 400
34
+ raise Error, "Your request was malformed. #{response.body["message"]}"
35
+ when 401
36
+ raise Error, "You did not supply valid authentication credentials. #{response.body["message"]}"
37
+ when 403
38
+ raise Error, "You are not allowed to perform that action. #{response.body["message"]}"
39
+ when 404
40
+ raise Error, "No results were found for your request. #{response.body["message"]}"
41
+ when 429
42
+ raise Error, "Your request exceeded the API rate limit. #{response.body["message"]}"
43
+ when 500
44
+ raise Error, "We were unable to perform the request due to server-side problems. #{response.body["message"]}"
45
+ when 503
46
+ raise Error,
47
+ "You have been rate limited for sending more than 20 requests per second. #{response.body["message"]}"
48
+ end
49
+
50
+ response
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,7 @@
1
+ module Dyte
2
+ class ActiveSessionsResource < Resource
3
+ def fetch(meeting_id:)
4
+ ActiveSession.new get_request("meetings/#{meeting_id}/active-session").body.dig("data")
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,24 @@
1
+ module Dyte
2
+ class MeetingsResource < Resource
3
+ def list(**params)
4
+ response = get_request("meetings", params: params)
5
+ Collection.from_response(response, type: Meeting)
6
+ end
7
+
8
+ def fetch(meeting_id:)
9
+ Meeting.new get_request("meetings/#{meeting_id}").body.dig("data")
10
+ end
11
+
12
+ def create(**attributes)
13
+ Meeting.new post_request("meetings", body: attributes).body.dig("data")
14
+ end
15
+
16
+ def update(meeting_id:, **attributes)
17
+ Meeting.new put_request("meetings/#{meeting_id}", body: attributes).body.dig("data", "meeting")
18
+ end
19
+
20
+ def update_old(meeting_id:, body: {})
21
+ Meeting.new put_request("meetings/#{meeting_id}", body: body).body.dig("data", "meeting")
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,12 @@
1
+ module Dyte
2
+ class ParticipantsResource < Resource
3
+ def list(session_id:, **params)
4
+ response = get_request("sessions/#{session_id}/participants", params: params)
5
+ Collection.from_response(response, type: Participant, key: "participants")
6
+ end
7
+
8
+ def fetch(session_id:, participant_id:)
9
+ Participant.new get_request("sessions/#{session_id}/participants/#{participant_id}").body.dig("data", "participant")
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,24 @@
1
+ module Dyte
2
+ class PresetsResource < Resource
3
+ def list(**params)
4
+ response = get_request("presets", params: params)
5
+ Collection.from_response(response, type: Preset)
6
+ end
7
+
8
+ def create(**attributes)
9
+ Preset.new post_request("presets", body: attributes).body.dig("data")
10
+ end
11
+
12
+ def fetch(preset_id:)
13
+ Preset.new get_request("presets/#{preset_id}").body.dig("data")
14
+ end
15
+
16
+ def delete(preset_id:)
17
+ Preset.new delete_request("presets/#{preset_id}").body.dig("data")
18
+ end
19
+
20
+ def update(preset_id:, **attributes)
21
+ Preset.new patch_request("presets/#{preset_id}", body: attributes).body.dig("data")
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,14 @@
1
+ module Dyte
2
+ class RecordingsResource < Resource
3
+ # Returns all recordings for an organization.
4
+ # If the meeting_id parameter is passed, returns all recordings for the given meeting ID.
5
+ def list(**params)
6
+ response = get_request("recordings", params: params)
7
+ Collection.from_response(response, type: Recording)
8
+ end
9
+
10
+ def fetch(recording_id:)
11
+ Recording.new get_request("recordings/#{recording_id}").body.dig("data")
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,26 @@
1
+ module Dyte
2
+ class SessionsResource < Resource
3
+ def list(**params)
4
+ response = get_request("sessions", params: params)
5
+ Collection.from_response(response, type: Session, key: "sessions")
6
+ end
7
+
8
+ def fetch(session_id:)
9
+ Session.new get_request("sessions/#{session_id}").body.dig("data", "session")
10
+ end
11
+
12
+ # Returns a list of participants for the given session ID.
13
+ # Kept it within the Sessions resource as that's how the Dyte API is structured.
14
+ def fetch_participants(session_id:)
15
+ Session.new get_request("sessions/#{session_id}/participants").body.dig("data")
16
+ end
17
+
18
+ def update(meeting_id:, **attributes)
19
+ Session.new put_request("sessions/#{meeting_id}", body: attributes).body.dig("data", "session")
20
+ end
21
+
22
+ def update_old(meeting_id:, body: {})
23
+ Session.new put_request("sessions/#{meeting_id}", body: body).body.dig("data", "session")
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Dyte
4
+ VERSION = "0.1.0"
5
+ end
data/lib/dyte.rb ADDED
@@ -0,0 +1,28 @@
1
+ require "faraday"
2
+ require "json"
3
+ require "debug"
4
+ require "dyte/version"
5
+ require "dyte/client"
6
+ require "dyte/collection"
7
+ require "dyte/error"
8
+ require "dyte/object"
9
+ require "dyte/resource"
10
+
11
+ # Objects
12
+ require "dyte/objects/meeting"
13
+ require "dyte/objects/preset"
14
+ require "dyte/objects/participant"
15
+ require "dyte/objects/session"
16
+ require "dyte/objects/recording"
17
+ require "dyte/objects/active_session"
18
+
19
+ # Resources
20
+ require "dyte/resources/meetings"
21
+ require "dyte/resources/presets"
22
+ require "dyte/resources/participants"
23
+ require "dyte/resources/sessions"
24
+ require "dyte/resources/recordings"
25
+ require "dyte/resources/active_sessions"
26
+
27
+ module Dyte
28
+ end
data/sig/dyte.rbs ADDED
@@ -0,0 +1,4 @@
1
+ module Dyte
2
+ VERSION: String
3
+ # See the writing guide of rbs: https://github.com/ruby/rbs#guides
4
+ end
metadata ADDED
@@ -0,0 +1,88 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: dyte
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Nick Warwick
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2023-07-21 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: faraday
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.10'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.10'
27
+ description: A simple wrapper for V2 of the Dyte API.
28
+ email:
29
+ - nicholaswarwick@icloud.com
30
+ executables: []
31
+ extensions: []
32
+ extra_rdoc_files: []
33
+ files:
34
+ - ".pryrc"
35
+ - ".rspec"
36
+ - ".rubocop.yml"
37
+ - CHANGELOG.md
38
+ - Gemfile
39
+ - LICENSE.txt
40
+ - README.md
41
+ - Rakefile
42
+ - lib/dyte.rb
43
+ - lib/dyte/client.rb
44
+ - lib/dyte/collection.rb
45
+ - lib/dyte/error.rb
46
+ - lib/dyte/object.rb
47
+ - lib/dyte/objects/active_session.rb
48
+ - lib/dyte/objects/meeting.rb
49
+ - lib/dyte/objects/participant.rb
50
+ - lib/dyte/objects/preset.rb
51
+ - lib/dyte/objects/recording.rb
52
+ - lib/dyte/objects/session.rb
53
+ - lib/dyte/resource.rb
54
+ - lib/dyte/resources/active_sessions.rb
55
+ - lib/dyte/resources/meetings.rb
56
+ - lib/dyte/resources/participants.rb
57
+ - lib/dyte/resources/presets.rb
58
+ - lib/dyte/resources/recordings.rb
59
+ - lib/dyte/resources/sessions.rb
60
+ - lib/dyte/version.rb
61
+ - sig/dyte.rbs
62
+ homepage: https://github.com/nwarwick
63
+ licenses:
64
+ - MIT
65
+ metadata:
66
+ homepage_uri: https://github.com/nwarwick
67
+ source_code_uri: https://github.com/nwarwick
68
+ changelog_uri: https://github.com/nwarwick
69
+ post_install_message:
70
+ rdoc_options: []
71
+ require_paths:
72
+ - lib
73
+ required_ruby_version: !ruby/object:Gem::Requirement
74
+ requirements:
75
+ - - ">="
76
+ - !ruby/object:Gem::Version
77
+ version: 2.6.0
78
+ required_rubygems_version: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ requirements: []
84
+ rubygems_version: 3.4.10
85
+ signing_key:
86
+ specification_version: 4
87
+ summary: A simple wrapper for the Dyte API.
88
+ test_files: []