Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Leitzen <pleitzen@gitlab.com>2019-08-01 17:31:03 +0300
committerPeter Leitzen <pleitzen@gitlab.com>2019-08-05 15:39:11 +0300
commit7269e7813b4410ca2b0cff89a7c0abaabd411320 (patch)
tree0d2754c12c7530345696d8a077f780ef50611934
parent4b1b8b99b093fe4c0341e0d9a54c1903292ac180 (diff)
WIP Add a zoom client
Roughly based on https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/31000
-rw-r--r--lib/zoom/client.rb51
1 files changed, 51 insertions, 0 deletions
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