From 7269e7813b4410ca2b0cff89a7c0abaabd411320 Mon Sep 17 00:00:00 2001 From: Peter Leitzen Date: Thu, 1 Aug 2019 16:31:03 +0200 Subject: WIP Add a zoom client Roughly based on https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/31000 --- lib/zoom/client.rb | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 lib/zoom/client.rb diff --git a/lib/zoom/client.rb b/lib/zoom/client.rb new file mode 100644 index 00000000000..6c22475dd05 --- /dev/null +++ b/lib/zoom/client.rb @@ -0,0 +1,51 @@ +# frozen_string_literal: true + +require 'jwt' + +module Zoom + class Client + Error = Class.new(StandardError) + + def initialize(api_url: 'https://api.zoom.us/v2', api_key:, api_secret:, + token_expires_in: 90, debug_output: nil) + @api_url = api_url + @api_key = api_key + @api_secret = api_secret + @token_expire = token_expire + @debug_output = debug_output + end + + private + + def request(method, path, **params) + url = @api_url + path + + # TODO separate methods? + Gitlab::HTTP.public_send(method, url, **request_params(**params)) + rescue => e + # TODO log? + sentry + raise Error, e.message + end + + def request_params(json: nil, query: nil) + { + headers: { + 'Accept' => 'application/json', + 'Content-Type' => 'application/json', + 'Authorization' => "Bearer #{access_token}" + }, + follow_redirects: false + }.tap do |hash| + hash[:query] = query if query + hash[:body] = json.to_json if json + hash[:debug_output] = debug_output if debug_output + end + end + + def access_token + payload = { iss: @api_key, exp: Time.now.to_i + @token_expires_in } + + JWT.encode(payload, @api_secret, 'HS256', { typ: 'JWT' }) + end + end +end -- cgit v1.2.3