agora_rails 1.0.0 → 1.0.1

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: 04a40ffed9d5e20f48386decfc354bc5fe3883a50ab12931a91770cce0f7caeb
4
- data.tar.gz: 27875a1500f997aff4d662c2291037eee9f2a7502563d43ee9580959635b91d0
3
+ metadata.gz: 5a3059e965098cb17acc3402b9afa3f6b03541e30f9a6535e03d6be9276f8bad
4
+ data.tar.gz: 0b645f35724ca861afcfbc1e3b4130e02bc1fbfad5ecfb77beb670c903df06fa
5
5
  SHA512:
6
- metadata.gz: '077592d3284b50e15f8487cd3ddb310494c0e09cb67eb95f19153dffac3a41378d34c0eb98ad5ac9e9e7c372c5a58892113c51b4c1c993174c7d7c949ad2fa13'
7
- data.tar.gz: c588ebe7535c4a88ff6493c4efaa29ded72a11de2e65b15672bc6e5047863d4c7500cf0dbecd82f4b2d0168085462cab867cb6b819bfb6634753ad1aa7a81ee4
6
+ metadata.gz: 9973c4b17d09788aae962e35eae7b2ae2c109aacce901a484795a42d7e868f3451315b501b75217f1faa710a34118388b724432debf3e0c5bf6dc9561d8f2897
7
+ data.tar.gz: 758847ef4240671a1fd78dac549d8c702a9420a084f3975d0852d713a4c0e46960d3902bdf7a673678a97a3f994bf57df39dd47b07c996eba21d39617d8d898e
data/README.md CHANGED
@@ -45,11 +45,11 @@ DynamicKey2 requires `uid` to be an integer (i.e. not a string).
45
45
  Generate a token for a specific channel and user:
46
46
 
47
47
  ```ruby
48
- channel_name = 'my_channel'
49
- uid = 1234
48
+ my_channel_name = 'my_channel'
49
+ my_uid = 1234
50
50
 
51
51
  recorder = AgoraRails::CloudRecording.new
52
- token = recorder.generate_token(channel_name, uid)
52
+ token = recorder.generate_token(channel_name: my_channel_name, uid: my_uid)
53
53
  ```
54
54
  You can validate the token at https://api-agora.solutions/
55
55
 
@@ -59,12 +59,20 @@ You can validate the token at https://api-agora.solutions/
59
59
  Start cloud recording for a channel:
60
60
 
61
61
  ```ruby
62
- channel_name = 'my_channel'
63
- uid = 1234
64
62
  recorder = AgoraRails::CloudRecording.new
65
- recorder.start(channel_name, uid)
63
+ sid = recorder.start(channel_name: "my_channel_name", uid: 1234)
66
64
  ```
67
65
 
66
+ Using the above method assumes that you dont plan to `query` the recording, or `stop` the recording. It will "acquire" a resource and start the recording by itself.
67
+ If you plan to `query` the recording, or `stop` the recording, you will need to use the `resource_id` that is returned from the `acquire_resource` method, as shown below.
68
+
69
+ ```ruby
70
+ recorder = AgoraRails::CloudRecording.new
71
+ resource_id = recorder.acquire_resource(channel_name: "my_channel", uid: 1234)
72
+ sid = recorder.start(channel_name: "my_channel", uid: 1234, resource_id: resource_id)
73
+ ```
74
+
75
+
68
76
  Stop cloud recording for a channel:
69
77
 
70
78
  If you have the CloudRecording object, you can use it to stop the recording:
@@ -77,8 +85,7 @@ If you don't have the CloudRecording object, you can use the following method to
77
85
 
78
86
  ```ruby
79
87
  recorder = AgoraRails::CloudRecording.new
80
- recorder.stop(channel_name, sid, uid, mode)
81
-
88
+ recorder.stop(channel_name: "my_channel", resource_id: "321cba", sid: "abc123", uid: 1234, mode: "mix")
82
89
  ```
83
90
 
84
91
 
@@ -8,7 +8,7 @@ module AgoraRails
8
8
 
9
9
  debug_output $stdout # uncomment this for debugging i.e. output to stdout
10
10
 
11
- attr_accessor :app_id, :app_certificate, :customer_key, :customer_secret, :auth, :resource_id, :uid, :bucket, :access_key, :secret_key, :sid, :channel_name, :mode
11
+ attr_accessor :app_id, :app_certificate, :customer_key, :customer_secret, :auth, :resource_id, :uid, :bucket, :access_key, :secret_key, :sid, :channel_name, :mode, :file_prefix
12
12
 
13
13
  def initialize
14
14
  self.app_id = AgoraRails.configuration.app_id
@@ -18,9 +18,12 @@ module AgoraRails
18
18
  self.auth = { username: customer_key, password: customer_secret }
19
19
  self.uid = "#{rand(2_000_000_000..3_000_000_000)}"
20
20
  self.mode = 'mix'
21
+ self.file_prefix = AgoraRails.configuration.file_prefix || ''
21
22
  end
22
23
 
23
- def acquire_resource(channel_name, uid = nil)
24
+ def acquire_resource(opts)
25
+ channel_name, uid = opts.values_at(:channel_name, :uid)
26
+ raise "Invalid Channel Name" if channel_name.nil?
24
27
  self.channel_name = channel_name
25
28
  self.uid = uid if uid
26
29
  response = self.class.post("/#{app_id}/cloud_recording/acquire",
@@ -32,17 +35,18 @@ module AgoraRails
32
35
  clientRequest: { resourceExpiredHour: 24 }
33
36
  }.to_json
34
37
  )
35
- self.resource_id = handle_response(response)['resourceId']
38
+ handle_response(response)['resourceId']
36
39
  end
37
40
 
38
- def start(channel_name, uid = nil, mode = nil, recording_config = nil)
39
- raise "Invalid Channel Name" if channel_name.nil?
40
- self.channel_name = channel_name
41
+ def start(opts = {})
42
+ channel_name, uid, resource_id, mode, recording_config = opts.values_at(:channel_name, :uid, :resource_id, :mode, :recording_config)
43
+ raise "Invalid Channel Name" if self.channel_name.nil? && channel_name.nil?
44
+ self.channel_name = channel_name if channel_name
41
45
  self.uid = uid if uid
42
46
  self.mode = mode if mode
43
- acquire_resource(channel_name)
47
+ self.resource_id = resource_id || acquire_resource(channel_name: channel_name, uid: self.uid)
44
48
  recording_config ||= default_recording_config(channel_name, self.uid)
45
-
49
+
46
50
  response = self.class.post("/#{app_id}/cloud_recording/resourceid/#{resource_id}/mode/#{self.mode}/start",
47
51
  basic_auth: auth,
48
52
  headers: { 'Content-Type' => 'application/json' },
@@ -51,16 +55,17 @@ module AgoraRails
51
55
  self.sid = handle_response(response)['sid']
52
56
  end
53
57
 
54
- def stop(channel_name = nil, sid = nil, uid = nil, mode = nil)
58
+ def stop(opts)
59
+ channel_name, resource_id, sid, uid, mode = opts.values_at(:channel_name, :resource_id, :sid, :uid, :mode)
55
60
  raise "Invalid Channel Name" if channel_name.nil? && self.channel_name.nil?
61
+ raise "Invalid Resource ID" if resource_id.nil? && self.resource_id.nil?
56
62
  raise "Invalid SID" if sid.nil? && self.sid.nil?
57
63
  self.channel_name = channel_name if channel_name
64
+ self.resource_id = resource_id if resource_id
58
65
  self.sid = sid if sid
59
66
  self.uid = uid if uid
60
67
  self.mode = mode if mode
61
68
 
62
- acquire_resource(self.channel_name) if self.resource_id.nil? # FIXME: should pass resource_id in because it is possible that the resource ID is expired or acquired for another channel
63
-
64
69
  response = self.class.post("/#{app_id}/cloud_recording/resourceid/#{self.resource_id}/sid/#{self.sid}/mode/#{self.mode}/stop",
65
70
  basic_auth: auth,
66
71
  headers: { 'Content-Type' => 'application/json' },
@@ -73,9 +78,15 @@ module AgoraRails
73
78
  handle_response(response)
74
79
  end
75
80
 
76
- def query(channel_name = nil)
77
- self.channel_name = channel_name if channel_name
78
- response = self.class.get("/#{app_id}/cloud_recording/resourceid/#{self.resource_id}/sid/#{self.sid}/mode/#{mode}/query",
81
+ def query(opts)
82
+ resource_id, sid, mode = opts.values_at(:resource_id, :sid, :mode)
83
+ raise "Invalid Resource ID" if resource_id.nil? && self.resource_id.nil?
84
+ raise "Invalid SID" if sid.nil? && self.sid.nil?
85
+ self.resource_id = resource_id if resource_id
86
+ self.sid = sid if sid
87
+ self.mode = mode if mode
88
+
89
+ response = self.class.get("/#{app_id}/cloud_recording/resourceid/#{self.resource_id}/sid/#{self.sid}/mode/#{self.mode}/query",
79
90
  basic_auth: auth,
80
91
  headers: { 'Content-Type' => 'application/json' },
81
92
  )
@@ -83,7 +94,8 @@ module AgoraRails
83
94
  end
84
95
 
85
96
 
86
- def generate_token(channel_name = nil, uid = nil)
97
+ def generate_token(opts = {})
98
+ channel_name, uid = opts.values_at(:channel_name, :uid)
87
99
  self.channel_name = channel_name if channel_name
88
100
  self.uid = uid if uid
89
101
 
@@ -122,7 +134,7 @@ module AgoraRails
122
134
  bucket: AgoraRails.configuration.bucket,
123
135
  accessKey: AgoraRails.configuration.access_key,
124
136
  secretKey: AgoraRails.configuration.secret_key,
125
- fileNamePrefix: AgoraRails.configuration.file_prefix,
137
+ fileNamePrefix: file_prefix.map(&:to_s), # convert to array of strings
126
138
  },
127
139
  },
128
140
  }
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: agora_rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mohammad Forouzani
@@ -16,70 +16,70 @@ dependencies:
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: '5.0'
19
+ version: '5'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: '5.0'
26
+ version: '5'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: httparty
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ">="
31
+ - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '0'
33
+ version: '0.21'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - ">="
38
+ - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '0'
40
+ version: '0.21'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: openssl
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - ">="
45
+ - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: '0'
47
+ version: '3'
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - ">="
52
+ - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: '0'
54
+ version: '3'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: rspec
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
59
  - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: '3.0'
61
+ version: '3'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
- version: '3.0'
68
+ version: '3'
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: webmock
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - ">="
73
+ - - "~>"
74
74
  - !ruby/object:Gem::Version
75
- version: '0'
75
+ version: '3.21'
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
- - - ">="
80
+ - - "~>"
81
81
  - !ruby/object:Gem::Version
82
- version: '0'
82
+ version: '3.21'
83
83
  description: Provides functionality for Agora.io token generation and cloud recording
84
84
  email:
85
85
  - mo@usechance.com