Skip to content

Commit

Permalink
Merge pull request #392 from hintmedia/refactor
Browse files Browse the repository at this point in the history
Attempt refactor
  • Loading branch information
joelmichael authored Dec 18, 2021
2 parents 90d1f63 + 5ab3a12 commit 6eb9d6a
Show file tree
Hide file tree
Showing 23 changed files with 488 additions and 655 deletions.
38 changes: 38 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,41 @@
# 1.0.0

The 1.0 release and a major refactor of all endpoint definitions.

### Breaking Change
* The `user_create` endpoint now requires its arguments to match the actual Zoom API.
This is done to simplify the code and encourage consistency.
This means that instead of passing:
```
{
action: 'create',
email: '[email protected]',
type: 1,
first_name: 'Zoomie',
last_name: 'Userton',
password: 'testerino'
}
```
You will instead have to pass:
```
{
action: 'create',
user_info: {
email: '[email protected]',
type: 1,
first_name: 'Zoomie',
last_name: 'Userton',
password: 'testerino'
}
}
```
Zoom API reference for user creation: https://marketplace.zoom.us/docs/api-reference/zoom-api/users/usercreate

### New features
* Greatly simplified new syntax when adding endpoints. This reduces repetition and makes it easier.
* On `user_settings_get`, permit `option` and `custom_query_fields`.
* Add `group_create` and `group_update`.

# 0.11.0

This is the first CHANGELOG entry.
Expand Down
12 changes: 6 additions & 6 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
zoom_rb (0.11.0)
zoom_rb (1.0.0)
httparty (~> 0.13)
json (>= 1.8)
jwt
Expand Down Expand Up @@ -31,17 +31,17 @@ GEM
rubocop-performance (>= 1.3.0)
rubocop-rails (>= 2.0.0)
rubocop-rspec (>= 1.33.0)
httparty (0.18.1)
httparty (0.20.0)
mime-types (~> 3.0)
multi_xml (>= 0.5.2)
i18n (1.8.10)
concurrent-ruby (~> 1.0)
json (2.5.1)
jwt (2.2.3)
jwt (2.3.0)
method_source (1.0.0)
mime-types (3.3.1)
mime-types (3.4.1)
mime-types-data (~> 3.2015)
mime-types-data (3.2021.0704)
mime-types-data (3.2021.1115)
minitest (5.14.4)
multi_xml (0.6.0)
parallel (1.20.1)
Expand Down Expand Up @@ -122,4 +122,4 @@ DEPENDENCIES
zoom_rb!

BUNDLED WITH
2.2.24
2.2.32
49 changes: 49 additions & 0 deletions lib/zoom/actions.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# frozen_string_literal: true

module Zoom
module Actions
def self.extract_path_keys(path)
path.scan(/:\w+/).map { |match| match[1..].to_sym }
end

def self.parse_path(path, path_keys, params)
parsed_path = path.dup
path_keys.each do |key|
value = params[key].to_s
parsed_path = parsed_path.sub(":#{key}", value)
end
parsed_path
end

def self.make_request(client, method, parsed_path, params, base_uri)
request_options = { headers: client.request_headers }
request_options[:base_uri] = base_uri if base_uri
case method
when :get
request_options[:query] = params
when :post, :put, :patch
request_options[:body] = params.to_json
end
client.class.public_send(method, parsed_path, **request_options)
end

[:get, :post, :patch, :put, :delete].each do |method|
define_method(method) do |name, path, options={}|
required, permitted, base_uri = options.values_at :require, :permit, :base_uri
required = Array(required) unless required.is_a?(Hash)
permitted = Array(permitted) unless permitted.is_a?(Hash)

define_method(name) do |*args|
path_keys = Zoom::Actions.extract_path_keys(path)
params = Zoom::Params.new(Utils.extract_options!(args))
parsed_path = Zoom::Actions.parse_path(path, path_keys, params)
params = params.require(path_keys) unless path_keys.empty?
params_without_required = required.empty? ? params : params.require(required)
params_without_required.permit(permitted) unless permitted.empty?
response = Zoom::Actions.make_request(self, method, parsed_path, params, base_uri)
Utils.parse_response(response)
end
end
end
end
end
69 changes: 18 additions & 51 deletions lib/zoom/actions/account.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,66 +3,33 @@
module Zoom
module Actions
module Account
def account_list(*args)
params = Zoom::Params.new(Utils.extract_options!(args))
params.permit(%i[page_size page_number])
Utils.parse_response self.class.get('/accounts', query: params, headers: request_headers)
end
extend Zoom::Actions

def account_create(*args)
params = Zoom::Params.new(Utils.extract_options!(args))
params.require(%i[first_name last_name email password]).permit(options: %i[share_rc room_connectors share_mc meeting_connectors pay_mode])
Utils.parse_response self.class.post('/accounts', body: params.to_json, headers: request_headers)
end
get 'account_list', '/accounts',
permit: %i[page_size page_number]

def account_get(*args)
params = Zoom::Params.new(Utils.extract_options!(args))
params.require(:account_id)
Utils.parse_response self.class.get("/accounts/#{params[:account_id]}", headers: request_headers)
end
post 'account_create', '/accounts',
require: %i[first_name last_name email password],
permit: { options: %i[share_rc room_connectors share_mc meeting_connectors pay_mode] }

def account_delete(*args)
params = Zoom::Params.new(Utils.extract_options!(args))
params.require(:account_id)
Utils.parse_response self.class.delete("/accounts/#{params[:account_id]}", headers: request_headers)
end
get 'account_get', '/accounts/:account_id'

def account_options_update(*args)
params = Zoom::Params.new(Utils.extract_options!(args))
params.require(:account_id).permit(%i[share_rc room_connectors share_mc meeting_connectors pay_mode])
Utils.parse_response self.class.patch("/accounts/#{params[:account_id]}/options", body: params.except(:account_id).to_json, headers: request_headers)
end
delete 'account_delete', '/accounts/:account_id'

def account_settings_get(*args)
params = Zoom::Params.new(Utils.extract_options!(args))
params.require(:account_id).permit(:option)
Utils.parse_response self.class.get("/accounts/#{params[:account_id]}/settings", query: params.except(:account_id), headers: request_headers)
end
patch 'account_options_update', '/accounts/:account_id/options',
permit: %i[share_rc room_connectors share_mc meeting_connectors pay_mode]

def account_settings_update(*args)
params = Zoom::Params.new(Utils.extract_options!(args))
params.require(:account_id).permit(:option, Zoom::Constants::Account::Settings::PERMITTED_KEYS)
params.permit_value(:option, Zoom::Constants::Account::Settings::PERMITTED_OPTIONS)
Utils.parse_response self.class.patch("/accounts/#{params[:account_id]}/settings", query: params.slice(:option), body: params.except(%i[account_id option]).to_json, headers: request_headers)
end
get 'account_settings_get', '/accounts/:account_id/settings',
permit: :option

def account_managed_domains(*args)
params = Zoom::Params.new(Utils.extract_options!(args))
params.require(:account_id)
Utils.parse_response self.class.get("/accounts/#{params[:account_id]}/managed_domains", headers: request_headers)
end
patch 'account_settings_update', '/accounts/:account_id/settings',
permit: [:option, Zoom::Constants::Account::Settings::PERMITTED_KEYS]

def account_get_locked_settings(*args)
params = Zoom::Params.new(Utils.extract_options!(args))
params.require(:account_id)
Utils.parse_response self.class.get("/accounts/#{params[:account_id]}/lock_settings", headers: request_headers)
end
get 'account_managed_domains', '/accounts/:account_id/managed_domains'

def account_trusted_domains(*args)
params = Zoom::Params.new(Utils.extract_options!(args))
params.require(:account_id)
Utils.parse_response self.class.get("/accounts/#{params[:account_id]}/trusted_domains", headers: request_headers)
end
get 'account_get_locked_settings', '/accounts/:account_id/lock_settings'

get 'account_trusted_domains', '/accounts/:account_id/trusted_domains'
end
end
end
57 changes: 30 additions & 27 deletions lib/zoom/actions/billing.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,36 +3,39 @@
module Zoom
module Actions
module Billing
def billing_get(*args)
params = Zoom::Params.new(Utils.extract_options!(args))
params.require(:account_id)
Utils.parse_response self.class.get("/accounts/#{params[:account_id]}/billing", headers: request_headers)
end
extend Zoom::Actions

def billing_update(*args)
params = Zoom::Params.new(Utils.extract_options!(args))
params.require(:account_id).permit(%i[first_name last_name email phone_number address apt city state zip country])
Utils.parse_response self.class.patch("/accounts/#{params[:account_id]}/billing", body: params.except(:account_id).to_json, headers: request_headers)
end
get 'billing_get', '/accounts/:account_id/billing'

def billing_plans_list(*args)
params = Zoom::Params.new(Utils.extract_options!(args))
params.require(:account_id)
Utils.parse_response self.class.get("/accounts/#{params[:account_id]}/plans", headers: request_headers)
end
patch 'billing_update', '/accounts/:account_id/billing',
permit: %i[first_name last_name email phone_number address apt city state zip country]

def billing_plans_usage(*args)
params = Zoom::Params.new(Utils.extract_options!(args))
params.require(:account_id)
Utils.parse_response self.class.get("/accounts/#{params[:account_id]}/plans/usage", headers: request_headers)
end
get 'billing_plans_list', '/accounts/:account_id/plans'

def billing_plans_subscribe(*args)
params = Zoom::Params.new(Utils.extract_options!(args))
# TODO: Move to constants and do some data validation
params.require(:account_id, contact: %i[first_name last_name email phone_number address city state zip country], plan_base: %i[type hosts]).permit(:plan_recording, contact: [:apt], plan_zoom_rooms: %i[type hosts], plan_room_connector: %i[type hosts], plan_large_meeting: [], plan_webinar: [], plan_audio: %i[type tollfree_countries premium_countries callout_countries ddi_numbers], plan_phone: { plan_base: %i[type hosts], plan_calling: [], plan_number: [] })
Utils.parse_response self.class.post("/accounts/#{params[:account_id]}/plans", body: params.except(:account_id).to_json, headers: request_headers)
end
get 'billing_plans_usage', '/accounts/:account_id/plans/usage'

post 'billing_plans_subscribe', '/accounts/:account_id/plans',
require: {
contact: %i[first_name last_name email phone_number address city state zip country],
plan_base: %i[type hosts]
},
permit: [
:plan_recording,
{
contact: %i[apt],
plan_zoom_rooms: %i[type hosts],
plan_room_connector: %i[type hosts],
plan_large_meeting: %i[type hosts],
plan_zoom_events: %i[type hosts],
plan_webinar: %i[type hosts],
plan_audio: %i[type tollfree_countries premium_countries callout_countries ddi_numbers],
plan_phone: {
plan_base: %i[type callout_countries],
plan_calling: %i[type hosts],
plan_number: %i[type hosts]
}
}
]
end
end
end
end
33 changes: 11 additions & 22 deletions lib/zoom/actions/dashboard.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,31 +3,20 @@
module Zoom
module Actions
module Dashboard
def dashboard_crc(*args)
params = Zoom::Params.new(Utils.extract_options!(args))
params.require(%i[from to])
Utils.process_datetime_params!(%i[from to], params)
Utils.parse_response self.class.get('/metrics/crc', query: params, headers: request_headers)
end
extend Zoom::Actions

def dashboard_meetings(*args)
params = Zoom::Params.new(Utils.extract_options!(args))
params.require(%i[from to]).permit(%i[next_page_token page_size type])
Utils.process_datetime_params!(%i[from to], params)
Utils.parse_response self.class.get('/metrics/meetings', query: params, headers: request_headers)
end
get 'dashboard_crc', '/metrics/crc',
require: %i[from to]

def dashboard_meeting_details(*args)
params = Zoom::Params.new(Utils.extract_options!(args))
params.require(:meeting_id).permit(:type)
Utils.parse_response self.class.get("/metrics/meetings/#{params[:meeting_id]}", query: params.except(:meeting_id), headers: request_headers)
end
get 'dashboard_meetings', '/metrics/meetings',
require: %i[from to],
permit: %i[next_page_token page_size type]

def dashboard_meeting_participants(*args)
params = Zoom::Params.new(Utils.extract_options!(args))
params.require(:meeting_id).permit(%i[next_page_token page_size type])
Utils.parse_response self.class.get("/metrics/meetings/#{params[:meeting_id]}/participants", query: params.except(:meeting_id), headers: request_headers)
end
get 'dashboard_meeting_details', '/metrics/meetings/:meeting_id',
permit: :type

get 'dashboard_meeting_participants', '/metrics/meetings/:meeting_id/participants',
permit: %i[next_page_token page_size type]
end
end
end
28 changes: 9 additions & 19 deletions lib/zoom/actions/groups.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,17 @@
module Zoom
module Actions
module Groups
def groups_list(*_args)
Utils.parse_response self.class.get('/groups', headers: request_headers)
end
extend Zoom::Actions

def group_create(*args)
params = Zoom::Params.new(Utils.extract_options!(args))
params.permit(%i[name])
Utils.parse_response self.class.post("/groups", body: params, headers: request_headers)
end
get 'groups_list', '/groups'

def group_update(*args)
params = Zoom::Params.new(Utils.extract_options!(args))
params.require(:group_id).permit(%i[name])
Utils.parse_response self.class.patch("/groups/#{params[:group_id]}", body: params.except(:group_id).to_json, headers: request_headers)
end
get 'groups_get', '/groups/:group_id'

def groups_get(*args)
params = Zoom::Params.new(Utils.extract_options!(args))
params.require(:group_id)
Utils.parse_response self.class.get("/groups/#{params[:group_id]}", headers: request_headers)
end
post 'group_create', '/groups',
permit: :name

patch 'group_update', '/groups/:group_id',
permit: :name
end
end
end
end
Loading

0 comments on commit 6eb9d6a

Please sign in to comment.