amazon-chime-sdk-rails 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (146) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +87 -0
  3. data/.rspec +2 -0
  4. data/.travis.yml +47 -0
  5. data/.yardopts +6 -0
  6. data/CHANGELOG.md +3 -0
  7. data/Gemfile +25 -0
  8. data/LICENSE +21 -0
  9. data/README.md +1109 -0
  10. data/Rakefile +20 -0
  11. data/amazon-chime-sdk-rails.gemspec +29 -0
  12. data/gemfiles/Gemfile.rails-5.0 +25 -0
  13. data/gemfiles/Gemfile.rails-5.1 +25 -0
  14. data/gemfiles/Gemfile.rails-5.2 +25 -0
  15. data/gemfiles/Gemfile.rails-6.0 +25 -0
  16. data/lib/amazon-chime-sdk-rails.rb +37 -0
  17. data/lib/chime_sdk/config.rb +90 -0
  18. data/lib/chime_sdk/controller/attendees.rb +128 -0
  19. data/lib/chime_sdk/controller/common.rb +202 -0
  20. data/lib/chime_sdk/controller/meetings.rb +192 -0
  21. data/lib/chime_sdk/meeting_coordinator.rb +184 -0
  22. data/lib/chime_sdk/version.rb +4 -0
  23. data/lib/generators/chime_sdk/controllers_generator.rb +104 -0
  24. data/lib/generators/chime_sdk/install_generator.rb +27 -0
  25. data/lib/generators/chime_sdk/js_generator.rb +67 -0
  26. data/lib/generators/chime_sdk/views_generator.rb +43 -0
  27. data/lib/generators/templates/chime_sdk.rb +28 -0
  28. data/lib/generators/templates/controllers/README +35 -0
  29. data/lib/generators/templates/controllers/meeting_attendees_controller.rb +106 -0
  30. data/lib/generators/templates/controllers/meetings_controller.rb +146 -0
  31. data/lib/generators/templates/views/meetings/index.html.erb +27 -0
  32. data/lib/generators/templates/views/meetings/show.html.erb +136 -0
  33. data/spec/factories/rooms.rb +5 -0
  34. data/spec/factories/users.rb +8 -0
  35. data/spec/generators/controllers_generator_spec.rb +113 -0
  36. data/spec/generators/install_generator_spec.rb +24 -0
  37. data/spec/generators/js_generator_spec.rb +26 -0
  38. data/spec/generators/views_generator_spec.rb +46 -0
  39. data/spec/rails_app/Rakefile +15 -0
  40. data/spec/rails_app/app/assets/config/manifest.js +2 -0
  41. data/spec/rails_app/app/assets/images/.keep +0 -0
  42. data/spec/rails_app/app/assets/javascripts/.keep +0 -0
  43. data/spec/rails_app/app/assets/stylesheets/application.css +15 -0
  44. data/spec/rails_app/app/assets/stylesheets/scaffolds.scss +65 -0
  45. data/spec/rails_app/app/controllers/api/meeting_attendees_controller.rb +3 -0
  46. data/spec/rails_app/app/controllers/api/meetings_controller.rb +3 -0
  47. data/spec/rails_app/app/controllers/api/rooms_controller.rb +3 -0
  48. data/spec/rails_app/app/controllers/application_controller.rb +11 -0
  49. data/spec/rails_app/app/controllers/entries_controller.rb +47 -0
  50. data/spec/rails_app/app/controllers/meeting_attendees_controller.rb +121 -0
  51. data/spec/rails_app/app/controllers/meetings_controller.rb +162 -0
  52. data/spec/rails_app/app/controllers/rooms_controller.rb +76 -0
  53. data/spec/rails_app/app/controllers/spa_controller.rb +6 -0
  54. data/spec/rails_app/app/javascript/App.vue +50 -0
  55. data/spec/rails_app/app/javascript/channels/consumer.js +6 -0
  56. data/spec/rails_app/app/javascript/channels/index.js +5 -0
  57. data/spec/rails_app/app/javascript/components/DeviseTokenAuth.vue +84 -0
  58. data/spec/rails_app/app/javascript/components/meetings/Index.vue +100 -0
  59. data/spec/rails_app/app/javascript/components/meetings/Meeting.vue +178 -0
  60. data/spec/rails_app/app/javascript/components/rooms/Index.vue +53 -0
  61. data/spec/rails_app/app/javascript/components/rooms/Show.vue +91 -0
  62. data/spec/rails_app/app/javascript/packs/application.js +17 -0
  63. data/spec/rails_app/app/javascript/packs/spa.js +14 -0
  64. data/spec/rails_app/app/javascript/router/index.js +74 -0
  65. data/spec/rails_app/app/javascript/store/index.js +37 -0
  66. data/spec/rails_app/app/models/application_record.rb +3 -0
  67. data/spec/rails_app/app/models/entry.rb +5 -0
  68. data/spec/rails_app/app/models/room.rb +12 -0
  69. data/spec/rails_app/app/models/user.rb +6 -0
  70. data/spec/rails_app/app/views/devise/registrations/new.html.erb +34 -0
  71. data/spec/rails_app/app/views/layouts/_header.html.erb +20 -0
  72. data/spec/rails_app/app/views/layouts/application.html.erb +18 -0
  73. data/spec/rails_app/app/views/meetings/index.html.erb +28 -0
  74. data/spec/rails_app/app/views/meetings/show.html.erb +136 -0
  75. data/spec/rails_app/app/views/rooms/_form.html.erb +22 -0
  76. data/spec/rails_app/app/views/rooms/_room.json.jbuilder +7 -0
  77. data/spec/rails_app/app/views/rooms/edit.html.erb +6 -0
  78. data/spec/rails_app/app/views/rooms/index.html.erb +27 -0
  79. data/spec/rails_app/app/views/rooms/index.json.jbuilder +1 -0
  80. data/spec/rails_app/app/views/rooms/new.html.erb +5 -0
  81. data/spec/rails_app/app/views/rooms/show.html.erb +42 -0
  82. data/spec/rails_app/app/views/rooms/show.json.jbuilder +1 -0
  83. data/spec/rails_app/app/views/spa/index.html.erb +1 -0
  84. data/spec/rails_app/babel.config.js +72 -0
  85. data/spec/rails_app/bin/bundle +114 -0
  86. data/spec/rails_app/bin/rails +9 -0
  87. data/spec/rails_app/bin/rake +9 -0
  88. data/spec/rails_app/bin/setup +36 -0
  89. data/spec/rails_app/bin/spring +17 -0
  90. data/spec/rails_app/bin/webpack +18 -0
  91. data/spec/rails_app/bin/webpack-dev-server +18 -0
  92. data/spec/rails_app/bin/yarn +11 -0
  93. data/spec/rails_app/config.ru +5 -0
  94. data/spec/rails_app/config/application.rb +21 -0
  95. data/spec/rails_app/config/boot.rb +4 -0
  96. data/spec/rails_app/config/cable.yml +10 -0
  97. data/spec/rails_app/config/credentials.yml.enc +1 -0
  98. data/spec/rails_app/config/database.yml +25 -0
  99. data/spec/rails_app/config/environment.rb +14 -0
  100. data/spec/rails_app/config/environments/development.rb +62 -0
  101. data/spec/rails_app/config/environments/production.rb +112 -0
  102. data/spec/rails_app/config/environments/test.rb +49 -0
  103. data/spec/rails_app/config/initializers/application_controller_renderer.rb +8 -0
  104. data/spec/rails_app/config/initializers/assets.rb +15 -0
  105. data/spec/rails_app/config/initializers/backtrace_silencers.rb +7 -0
  106. data/spec/rails_app/config/initializers/chime_sdk.rb +28 -0
  107. data/spec/rails_app/config/initializers/content_security_policy.rb +30 -0
  108. data/spec/rails_app/config/initializers/cookies_serializer.rb +5 -0
  109. data/spec/rails_app/config/initializers/devise.rb +311 -0
  110. data/spec/rails_app/config/initializers/devise_token_auth.rb +60 -0
  111. data/spec/rails_app/config/initializers/filter_parameter_logging.rb +4 -0
  112. data/spec/rails_app/config/initializers/inflections.rb +16 -0
  113. data/spec/rails_app/config/initializers/mime_types.rb +4 -0
  114. data/spec/rails_app/config/initializers/wrap_parameters.rb +14 -0
  115. data/spec/rails_app/config/locales/devise.en.yml +65 -0
  116. data/spec/rails_app/config/locales/en.yml +33 -0
  117. data/spec/rails_app/config/puma.rb +38 -0
  118. data/spec/rails_app/config/routes.rb +24 -0
  119. data/spec/rails_app/config/secrets.yml +8 -0
  120. data/spec/rails_app/config/spring.rb +6 -0
  121. data/spec/rails_app/config/storage.yml +34 -0
  122. data/spec/rails_app/config/webpack/development.js +5 -0
  123. data/spec/rails_app/config/webpack/environment.js +7 -0
  124. data/spec/rails_app/config/webpack/loaders/vue.js +6 -0
  125. data/spec/rails_app/config/webpack/production.js +5 -0
  126. data/spec/rails_app/config/webpack/test.js +5 -0
  127. data/spec/rails_app/config/webpacker.yml +97 -0
  128. data/spec/rails_app/db/migrate/20200912140231_devise_create_users.rb +45 -0
  129. data/spec/rails_app/db/migrate/20200912140352_add_tokens_to_users.rb +12 -0
  130. data/spec/rails_app/db/migrate/20200912140657_create_rooms.rb +9 -0
  131. data/spec/rails_app/db/migrate/20200912140749_create_entries.rb +10 -0
  132. data/spec/rails_app/db/schema.rb +49 -0
  133. data/spec/rails_app/db/seeds.rb +41 -0
  134. data/spec/rails_app/log/.keep +0 -0
  135. data/spec/rails_app/package.json +23 -0
  136. data/spec/rails_app/postcss.config.js +12 -0
  137. data/spec/rails_app/public/404.html +67 -0
  138. data/spec/rails_app/public/422.html +67 -0
  139. data/spec/rails_app/public/500.html +66 -0
  140. data/spec/rails_app/public/favicon.ico +0 -0
  141. data/spec/rails_app/public/robots.txt +1 -0
  142. data/spec/rails_app/tmp/.keep +0 -0
  143. data/spec/requests/atendees_spec.rb +182 -0
  144. data/spec/requests/meetings_spec.rb +433 -0
  145. data/spec/spec_helper.rb +35 -0
  146. metadata +400 -0
@@ -0,0 +1,192 @@
1
+ module ChimeSdk
2
+ module Controller
3
+ # Meetings controller implementation by amazon-chime-sdk-rails.
4
+ module Meetings
5
+ # Controller implementation to be included in custom meetings controllers.
6
+ module Mixin
7
+ extend ActiveSupport::Concern
8
+
9
+ included do
10
+ include ChimeSdk::Controller::Common
11
+ include ActionController::MimeResponds
12
+ helper_method :meeting_resources_path, :meeting_resource_path, :attendee_resources_path, :attendee_resource_path, :application_attendee_name
13
+ end
14
+
15
+ # GET /meetings
16
+ # GET /meetings.json
17
+ # @overload index(params)
18
+ # @param [Hash] params Request parameter options
19
+ # @option params [String] :create_meeting (ChimeSdk.config.create_meeting_by_get_request) Whether the application creates meeting in this meetings#index action by HTTP GET request
20
+ def index
21
+ if params[:create_meeting].to_s.to_boolean(false) || ChimeSdk.config.create_meeting_by_get_request
22
+ create
23
+ else
24
+ list_meetings
25
+ respond_to do |format|
26
+ format.html
27
+ format.json { render json: { meetings: @meetings } }
28
+ end
29
+ end
30
+ end
31
+
32
+ # GET /meetings/:meeting_id
33
+ # GET /meetings/:meeting_id.json
34
+ # @overload show(params)
35
+ # @param [Hash] params Request parameter options
36
+ # @option params [String] :create_attendee_from_meeting (ChimeSdk.config.create_attendee_from_meeting) Whether the application creates attendee from meeting in meetings#show action
37
+ def show
38
+ get_meeting
39
+ if params[:create_attendee_from_meeting].to_s.to_boolean(false) || ChimeSdk.config.create_attendee_from_meeting
40
+ create_attendee_from_meeting
41
+ end
42
+ respond_to do |format|
43
+ format.html
44
+ format.json { render json: @meeting }
45
+ end
46
+ end
47
+
48
+ # POST /meetings
49
+ # POST /meetings.json
50
+ # @overload create(params)
51
+ # @param [Hash] params Request parameter options
52
+ # @option params [String] :create_meeting_with_attendee (ChimeSdk.config.create_meeting_with_attendee) Whether the application creates meeting with attendee in this meetings#create action
53
+ def create
54
+ if params[:create_meeting_with_attendee].to_s.to_boolean(false) || ChimeSdk.config.create_meeting_with_attendee
55
+ create_meeting_with_attendee
56
+ else
57
+ create_meeting
58
+ end
59
+ respond_to do |format|
60
+ format.html { redirect_to meeting_resource_path(meeting_id), notice: "Meeting <#{meeting_id}> was successfully created." }
61
+ format.json { render status: 201, json: @meeting.merge(@attendee || {}) }
62
+ end
63
+ end
64
+
65
+ # DELETE /meetings/:meeting_id
66
+ # DELETE /meetings/:meeting_id.json
67
+ def destroy
68
+ delete_meeting
69
+ respond_to do |format|
70
+ format.html { redirect_to meeting_resources_path, notice: "Meeting <#{meeting_id}> was successfully destroyed." }
71
+ format.json { head 204 }
72
+ end
73
+ end
74
+
75
+ protected
76
+ # Override the following functions in your controllers
77
+ # :nocov:
78
+
79
+ # Request parameter representing meeting id such as params[:id].
80
+ # Configure it depending on your application routes.
81
+ # @api protected
82
+ # @return [String, Integer] Meeting id from request parameter
83
+ def meeting_id_param
84
+ params[:id]
85
+ end
86
+
87
+ # Unique meeting request id to identify meeting by Amazon Chime.
88
+ # Configure it depending on your application resources to identify meeting.
89
+ # For example, set "PrivateRoom-#{@room.id}" by Room model.
90
+ # @api protected
91
+ # @return [String] Unique meeting request id to identify meeting by Amazon Chime
92
+ def meeting_request_id
93
+ "default"
94
+ end
95
+
96
+ # Unique attendee request id to identify attendee by Amazon Chime.
97
+ # Configure it depending on your application resources to identify attendee.
98
+ # For example, set "User-#{current_user.id}" by User model.
99
+ # @api protected
100
+ # @return [String] Unique attendee request id to identify attendee by Amazon Chime
101
+ def attendee_request_id
102
+ "default"
103
+ end
104
+
105
+ # Path for meetings#index action such as meetings_path.
106
+ # Configure it depending on your application routes.
107
+ # @api protected
108
+ # @param [Hash] params Request parameters for path method
109
+ # @return [String] Path for meetings#index action such as meetings_path
110
+ def meeting_resources_path(params = {})
111
+ meetings_path(params)
112
+ end
113
+
114
+ # Path for meetings#show action such as meeting_path(meeting_id).
115
+ # Configure it depending on your application routes.
116
+ # @api protected
117
+ # @param [String] meeting_id Meeting id
118
+ # @param [Hash] params Request parameters for path method
119
+ # @return [String] Path for meetings#show action such as meeting_path(meeting_id)
120
+ def meeting_resource_path(meeting_id, params = {})
121
+ meeting_path(meeting_id, params)
122
+ end
123
+
124
+ # Path for attendees#index action such as attendees_path(meeting_id).
125
+ # Configure it depending on your application routes.
126
+ # @api protected
127
+ # @param [String] meeting_id Meeting id
128
+ # @param [Hash] params Request parameters for path method
129
+ # @return [String] Path for attendees#index action such as attendees_path(meeting_id)
130
+ def attendee_resources_path(meeting_id, params = {})
131
+ attendees_path(meeting_id, params)
132
+ end
133
+
134
+ # Path for attendees#show action such as attendee_path(meeting_id, attendee_id).
135
+ # Configure it depending on your application routes.
136
+ # @api protected
137
+ # @param [String] meeting_id Meeting id
138
+ # @param [String] attendee_id Attendee id
139
+ # @param [Hash] params Request parameters for path method
140
+ # @return [String] Path for attendees#index action such as attendees_path(meeting_id)
141
+ def attendee_resource_path(meeting_id, attendee_id, params = {})
142
+ attendee_path(meeting_id, attendee_id, params)
143
+ end
144
+
145
+ # Optional meeting tags to pass to Amazon Chime.
146
+ # This is an optional parameter and configure it depending on your application.
147
+ # @api protected
148
+ # @return [Array<Hash>] Optional tags for meetings
149
+ def optional_meeting_tags
150
+ []
151
+ end
152
+
153
+ # Optional attendee tags to pass to Amazon Chime.
154
+ # This is an optional parameter and configure it depending on your application.
155
+ # @api protected
156
+ # @return [Array<Hash>] Optional tags for attendees
157
+ def optional_attendee_tags
158
+ []
159
+ end
160
+
161
+ # Appication metadata that meetings API returns as JSON response included in meeting resource.
162
+ # This is an optional parameter and configure it depending on your application.
163
+ # @api protected
164
+ # @param [Hash] meeting Meeting JSON object as hash
165
+ # @return [Hash] Appication metadata for meetings
166
+ def application_meeting_metadata(meeting)
167
+ {}
168
+ end
169
+
170
+ # Appication metadata that attendees API returns as JSON response included in attendee resource.
171
+ # This is an optional parameter and configure it depending on your application.
172
+ # @api protected
173
+ # @param [Hash] attendee Attendee JSON object as hash
174
+ # @return [Hash] Appication metadata for attendees
175
+ def application_attendee_metadata(attendee)
176
+ {}
177
+ end
178
+
179
+ # Application attendee name to resolve from attendee object in your view.
180
+ # This is an optional parameter and configure it depending on your application.
181
+ # @api protected
182
+ # @param [Hash] attendee Attendee JSON object as hash
183
+ # @return [String] Appication attendee name to resolve from attendee object in your view
184
+ def application_attendee_name(attendee)
185
+ attendee[:Attendee][:AttendeeId]
186
+ end
187
+
188
+ # :nocov:
189
+ end
190
+ end
191
+ end
192
+ end
@@ -0,0 +1,184 @@
1
+ module ChimeSdk
2
+ # Meeting coordinator as a wrapper module of AWS SDK for Ruby, which simulates AWS SDK for JavaScript.
3
+ # @see https://docs.aws.amazon.com/sdk-for-ruby/v3/api/Aws/Chime/Client.html Aws::Chime::Client of AWS SDK for Ruby
4
+ # @see https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/Chime.html AWS.Chime of AWS SDK for JavaScript
5
+ module MeetingCoordinator
6
+ require 'aws-sdk-chime'
7
+
8
+ # Return initialized Aws::Chime::Client.
9
+ # You must use "us-east-1" as the region for Chime API and set the endpoint.
10
+ # @return [Aws::Chime::Client] Initialized Aws::Chime::Client instance
11
+ # @see https://aws.github.io/amazon-chime-sdk-js/modules/gettingstarted.html
12
+ def self.client
13
+ @@client ||= Aws::Chime::Client.new(region: 'us-east-1')
14
+ end
15
+
16
+ # Reset client with initialized Aws::Chime::Client instance.
17
+ # @param [Aws::Chime::Client] client Initialized Aws::Chime::Client instance
18
+ # @return [Aws::Chime::Client] Initialized Aws::Chime::Client instance
19
+ def self.reset_client(client)
20
+ @@client = client
21
+ end
22
+
23
+ # Wrapper of Aws::Chime::Client#list_meetings method.
24
+ # This function also provides prefix match filter of external_meeting_id.
25
+ # This method filters the result with ChimeSdk.config.prefix to return only meetings in your application.
26
+ # @param [Integer] max_results (ChimeSdk.config.max_meeting_results) The maximum number of results to return in a single call
27
+ # @param [String] prefix_filter (nil) Additional string for prefix match filter of external_meeting_id
28
+ # @return [Array<Hash>] Array of filtered meeting JSON object as hash
29
+ # @see https://docs.aws.amazon.com/sdk-for-ruby/v3/api/Aws/Chime/Client.html#list_meetings-instance_method Aws::Chime::Client#list_meetings of AWS SDK for Ruby
30
+ def self.list_meetings(
31
+ max_results: ChimeSdk.config.max_meeting_results,
32
+ prefix_filter: nil
33
+ )
34
+ resp = client.list_meetings({
35
+ max_results: max_results
36
+ })
37
+ meetings = resp.meetings
38
+ meetings = meetings.select { |meeting| meeting.external_meeting_id.start_with?(ChimeSdk.config.prefix + prefix_filter) } if prefix_filter
39
+ meetings.map { |meeting| meeting_as_json(meeting) }
40
+ end
41
+
42
+ # Wrapper of Aws::Chime::Client#create_meeting method.
43
+ # This method uses 'ChimeSdk.config.prefix + meeting_request_id' for client_request_token and external_meeting_id.
44
+ # @param [required, String] meeting_request_id The unique identifier for the client request. Use a different token for different meetings.
45
+ # @param [String] meeting_host_id (nil) Reserved
46
+ # @param [String] media_region (ChimeSdk.config.media_region) The Region in which to create the meeting
47
+ # @param [Array<Aws::Chime::Types::Tag>] tags (nil) The tag key-value pairs
48
+ # @param [Aws::Chime::Types::MeetingNotificationConfiguration] notifications_configuration (nil) The configuration for resource targets to receive notifications when meeting and attendee events occur
49
+ # @return [Hash] Created meeting JSON object as hash
50
+ # @see https://docs.aws.amazon.com/sdk-for-ruby/v3/api/Aws/Chime/Client.html#create_meeting-instance_method Aws::Chime::Client#create_meeting of AWS SDK for Ruby
51
+ def self.create_meeting(meeting_request_id,
52
+ meeting_host_id: nil,
53
+ media_region: ChimeSdk.config.media_region,
54
+ tags: [],
55
+ notifications_configuration: {}
56
+ )
57
+ resp = client.create_meeting({
58
+ client_request_token: ChimeSdk.config.prefix + meeting_request_id,
59
+ external_meeting_id: ChimeSdk.config.prefix + meeting_request_id,
60
+ meeting_host_id: meeting_host_id,
61
+ media_region: media_region,
62
+ tags: tags,
63
+ notifications_configuration: notifications_configuration
64
+ })
65
+ meeting_as_json(resp.meeting)
66
+ end
67
+
68
+ # Wrapper of Aws::Chime::Client#get_meeting method.
69
+ # @param [required, String] meeting_id The Amazon Chime SDK meeting ID
70
+ # @return [Hash] Meeting JSON object as hash
71
+ # @see https://docs.aws.amazon.com/sdk-for-ruby/v3/api/Aws/Chime/Client.html#get_meeting-instance_method Aws::Chime::Client#get_meeting of AWS SDK for Ruby
72
+ def self.get_meeting(meeting_id)
73
+ resp = client.get_meeting({
74
+ meeting_id: meeting_id
75
+ })
76
+ meeting_as_json(resp.meeting)
77
+ end
78
+
79
+ # Wrapper of Aws::Chime::Client#delete_meeting method.
80
+ # @param [required, String] meeting_id The Amazon Chime SDK meeting ID
81
+ # @return [void]
82
+ # @see https://docs.aws.amazon.com/sdk-for-ruby/v3/api/Aws/Chime/Client.html#delete_meeting-instance_method Aws::Chime::Client#delete_meeting of AWS SDK for Ruby
83
+ def self.delete_meeting(meeting_id)
84
+ client.delete_meeting({
85
+ meeting_id: meeting_id
86
+ })
87
+ end
88
+
89
+ # Wrapper of Aws::Chime::Client#list_attendees method.
90
+ # @param [required, String] meeting_id The Amazon Chime SDK meeting ID
91
+ # @param [Integer] max_results (ChimeSdk.config.max_attendee_results) The maximum number of results to return in a single call
92
+ # @return [Array<Hash>] Array of attendee JSON object as hash
93
+ # @see https://docs.aws.amazon.com/sdk-for-ruby/v3/api/Aws/Chime/Client.html#list_attendees-instance_method Aws::Chime::Client#list_attendees of AWS SDK for Ruby
94
+ def self.list_attendees(meeting_id,
95
+ max_results: ChimeSdk.config.max_attendee_results
96
+ )
97
+ resp = client.list_attendees({
98
+ meeting_id: meeting_id,
99
+ max_results: max_results
100
+ })
101
+ resp.attendees.map { |attendee| attendee_as_json(attendee) }
102
+ end
103
+
104
+ # Wrapper of Aws::Chime::Client#create_attendee method.
105
+ # This method uses 'ChimeSdk.config.prefix + attendee_request_id' for external_user_id.
106
+ # @param [required, String] meeting_id The Amazon Chime SDK meeting ID
107
+ # @param [required, String] attendee_request_id Part of the Amazon Chime SDK external user ID. Links the attendee to an identity managed by a builder application.
108
+ # @return [Hash] Created attendee JSON object as hash
109
+ # @see https://docs.aws.amazon.com/sdk-for-ruby/v3/api/Aws/Chime/Client.html#create_attendee-instance_method Aws::Chime::Client#create_attendee of AWS SDK for Ruby
110
+ def self.create_attendee(meeting_id, attendee_request_id, tags: [])
111
+ resp = client.create_attendee({
112
+ meeting_id: meeting_id,
113
+ external_user_id: ChimeSdk.config.prefix + attendee_request_id,
114
+ tags: tags
115
+ })
116
+ attendee_as_json(resp.attendee)
117
+ end
118
+
119
+ # Wrapper of Aws::Chime::Client#get_attendee method.
120
+ # @param [required, String] meeting_id The Amazon Chime SDK meeting ID
121
+ # @param [required, String] attendee_id The Amazon Chime SDK attendee ID
122
+ # @return [Hash] Attendee JSON object as hash
123
+ # @see https://docs.aws.amazon.com/sdk-for-ruby/v3/api/Aws/Chime/Client.html#get_attendee-instance_method Aws::Chime::Client#get_attendee of AWS SDK for Ruby
124
+ def self.get_attendee(meeting_id, attendee_id)
125
+ resp = client.get_attendee({
126
+ meeting_id: meeting_id,
127
+ attendee_id: attendee_id
128
+ })
129
+ attendee_as_json(resp.attendee)
130
+ end
131
+
132
+ # Wrapper of Aws::Chime::Client#delete_attendee method.
133
+ # @param [required, String] attendee_id The Amazon Chime SDK attendee ID
134
+ # @return [void]
135
+ # @see https://docs.aws.amazon.com/sdk-for-ruby/v3/api/Aws/Chime/Client.html#delete_attendee-instance_method Aws::Chime::Client#delete_attendee of AWS SDK for Ruby
136
+ def self.delete_attendee(meeting_id, attendee_id)
137
+ client.delete_attendee({
138
+ meeting_id: meeting_id,
139
+ attendee_id: attendee_id
140
+ })
141
+ end
142
+
143
+ # Build meeting JSON object as hash from Aws::Chime::Types::Meeting object
144
+ # @param [required, Aws::Chime::Types::Meeting] meeting Meeting response as Aws::Chime::Types::Meeting object
145
+ # @return [Hash] Meeting JSON object as hash
146
+ # @see https://docs.aws.amazon.com/sdk-for-ruby/v3/api/Aws/Chime/Client.html#get_meeting-instance_method Aws::Chime::Client#get_meeting of AWS SDK for Ruby
147
+ # @see https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/Chime.html#getMeeting-property AWS.Chime#getMeeting of AWS SDK for JavaScript
148
+ def self.meeting_as_json(meeting)
149
+ return {} unless meeting.is_a?(Aws::Chime::Types::Meeting)
150
+ {
151
+ "Meeting": {
152
+ "MeetingId": meeting.meeting_id,
153
+ "ExternalMeetingId": meeting.external_meeting_id,
154
+ "MediaPlacement": {
155
+ "AudioHostUrl": meeting.media_placement.audio_host_url,
156
+ "AudioFallbackUrl": meeting.media_placement.audio_fallback_url,
157
+ "ScreenDataUrl": meeting.media_placement.screen_data_url,
158
+ "ScreenSharingUrl": meeting.media_placement.screen_sharing_url,
159
+ "ScreenViewingUrl": meeting.media_placement.screen_viewing_url,
160
+ "SignalingUrl": meeting.media_placement.signaling_url,
161
+ "TurnControlUrl": meeting.media_placement.turn_control_url
162
+ },
163
+ "MediaRegion": meeting.media_region
164
+ }
165
+ }
166
+ end
167
+
168
+ # Build attendee JSON object as hash from Aws::Chime::Types::Attendee object
169
+ # @param [required, Aws::Chime::Types::Attendee] attendee Attendee response as Aws::Chime::Types::Attendee object
170
+ # @return [Hash] Attendee JSON object as hash
171
+ # @see https://docs.aws.amazon.com/sdk-for-ruby/v3/api/Aws/Chime/Client.html#get_attendee-instance_method Aws::Chime::Client#get_attendee of AWS SDK for Ruby
172
+ # @see https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/Chime.html#getAttendee-property AWS.Chime#getAttendee of AWS SDK for JavaScript
173
+ def self.attendee_as_json(attendee)
174
+ return {} unless attendee.is_a?(Aws::Chime::Types::Attendee)
175
+ {
176
+ "Attendee": {
177
+ "ExternalUserId": attendee.external_user_id,
178
+ "AttendeeId": attendee.attendee_id,
179
+ "JoinToken": attendee.join_token
180
+ }
181
+ }
182
+ end
183
+ end
184
+ end
@@ -0,0 +1,4 @@
1
+ module ChimeSdk
2
+ # Gem version of amazon-chime-sdk-rails
3
+ VERSION = "1.0.0"
4
+ end
@@ -0,0 +1,104 @@
1
+ require 'rails/generators/base'
2
+
3
+ module ChimeSdk
4
+ module Generators
5
+ # Controller generator to copy customizable meetings and attendees controller files from templates.
6
+ # @example Run controller generator as default name
7
+ # rails generate chime_sdk:controllers
8
+ # @example Run controller generator with prefix as 'room'
9
+ # rails generate chime_sdk:controllers room
10
+ # @example Run controller generator with parent option as 'room'
11
+ # rails generate chime_sdk:controllers -r room
12
+ # @example Run controller generator with namespace option as 'api'
13
+ # rails generate chime_sdk:controllers -n api
14
+ class ControllersGenerator < Rails::Generators::Base
15
+ desc <<-DESC.strip_heredoc
16
+ Create meetings and attendees controllers for Amazon Chime SDK in your app/controllers folder.
17
+
18
+ Example:
19
+
20
+ rails generate chime_sdk:controllers
21
+
22
+ You can specify prefix of controllers name like this:
23
+
24
+ rails generate chime_sdk:controllers room
25
+
26
+ Then, meeting controller class will be generated as app/controllers/room_meetings_controller.rb like this:
27
+
28
+ class RoomMeetingsController < ApplicationController
29
+ include ChimeSdk::Controller::Meetings::Mixin
30
+ def meeting_resources_path(params = {})
31
+ room_meetings_path(@room, params)
32
+ end
33
+ ...
34
+ end
35
+
36
+ Use --parent option to specify parent resource of meetings. If you specify prefix of controllers name, parent option will be ignored.
37
+
38
+ rails generate chime_sdk:controllers --parent room
39
+
40
+ Then, meeting controller class will be generated as app/controllers/meetings_controller.rb like this:
41
+
42
+ class MeetingsController < ApplicationController
43
+ include ChimeSdk::Controller::Meetings::Mixin
44
+ def meeting_resources_path(params = {})
45
+ room_meetings_path(@room, params)
46
+ end
47
+ ...
48
+ end
49
+
50
+ Use --namespace option to specify namespace of generated controllers.
51
+
52
+ rails generate chime_sdk:controllers --namespace api
53
+
54
+ Then, meeting controller class will be generated as app/controllers/api/meetings_controller.rb like this:
55
+
56
+ class Api::MeetingsController < ApplicationController
57
+ include ChimeSdk::Controller::Meetings::Mixin
58
+ def meeting_resources_path(params = {})
59
+ api_meetings_path(params)
60
+ end
61
+ ...
62
+ end
63
+
64
+ Use --controllers option to specify which controller you want to generate. If you do no specify a controller, all controllers will be created.
65
+
66
+ rails generate chime_sdk:controllers --controllers meetings
67
+ DESC
68
+
69
+ # Controllers to be generated
70
+ CONTROLLERS = ['meetings', 'meeting_attendees'].freeze
71
+
72
+ source_root File.expand_path("../../templates/controllers", __FILE__)
73
+ argument :prefix, required: false,
74
+ desc: "Prefix of controllers name, e.g. room"
75
+ class_option :parent, aliases: "-r", type: :string,
76
+ desc: "Parent resource of generated controllers, e.g. room"
77
+ class_option :namespace, aliases: "-n", type: :string,
78
+ desc: "Namespace of generated controllers, e.g. api"
79
+ class_option :controllers, aliases: "-c", type: :array,
80
+ desc: "Select specific controllers to generate (#{CONTROLLERS.join(', ')})"
81
+
82
+ # Generate controller files in application directory
83
+ def generate_controllers
84
+ @namespace = options[:namespace].blank? ? '' : "#{options[:namespace].camelize}::"
85
+ @class_name_prefix = prefix.blank? ? '' : prefix.singularize.camelize
86
+ @param_name_prefix = prefix.blank? ? '' : "#{prefix.singularize.underscore}_"
87
+ parent_resource = prefix.present? ? prefix.singularize.underscore : (options[:parent].blank? ? '' : options[:parent].singularize.underscore)
88
+ @path_name_prefix = (options[:namespace].blank? ? '' : "#{options[:namespace].singularize.underscore}_") + (parent_resource.blank? ? '' : "#{parent_resource}_")
89
+ @path_args_prefix = parent_resource.blank? ? '' : "@#{parent_resource}, "
90
+ @default_meeting_request_id = parent_resource.blank? ? 'default' : "#{parent_resource.camelize}-#{'#'}{@#{parent_resource}.id}"
91
+ file_name_prefix = (options[:namespace].blank? ? '' : "#{options[:namespace].underscore}/") + @param_name_prefix
92
+ controllers = options[:controllers] || CONTROLLERS
93
+ controllers.each do |name|
94
+ template "#{name}_controller.rb", "app/controllers/#{file_name_prefix}#{name}_controller.rb"
95
+ end
96
+ end
97
+
98
+ # Show readme after generated controllers
99
+ def show_readme
100
+ readme "README" if behavior == :invoke
101
+ end
102
+ end
103
+ end
104
+ end