class GoToWebinar::Client
Attributes
access_token[RW]
organizer_key[RW]
url[RW]
Public Class Methods
new(organizer_key: nil, url: nil)
click to toggle source
# File lib/go_to_webinar/client.rb, line 7 def initialize(organizer_key: nil, url: nil) config = GoToWebinar.configuration @url = url || config.url @organizer_key = organizer_key || config.organizer_key @g2w_oauth2_client = GoToWebinar::Auth::Client.new @access_token = @g2w_oauth2_client.access_token&.token || config.access_token end
Public Instance Methods
delete()
click to toggle source
# File lib/go_to_webinar/client.rb, line 34 def delete attempt { parse(RestClient.delete(make_path(path), data, headers)) } end
get(path, data = {})
click to toggle source
# File lib/go_to_webinar/client.rb, line 22 def get(path, data = {}) attempt { parse(RestClient.get(make_path(path), data.merge(headers))) } end
headers()
click to toggle source
# File lib/go_to_webinar/client.rb, line 15 def headers { 'Accept' => 'application/json', 'Authorization' => "OAuth oauth_token=#{access_token}" } end
make_path(path)
click to toggle source
# File lib/go_to_webinar/client.rb, line 38 def make_path(path) path = path.split(':organizer_key:').join(organizer_key) "#{url}#{path}" end
post(path, data)
click to toggle source
# File lib/go_to_webinar/client.rb, line 26 def post(path, data) attempt { parse(RestClient.post(make_path(path), data, headers)) } end
put(path, data)
click to toggle source
# File lib/go_to_webinar/client.rb, line 30 def put(path, data) attempt { parse(RestClient.put(make_path(path), data, headers)) } end
Private Instance Methods
attempt() { || ... }
click to toggle source
# File lib/go_to_webinar/client.rb, line 45 def attempt retries ||= 0 yield rescue RestClient::Forbidden => e raise unless (retries += 1) < 2 attempt_refresh(e) retry rescue StandardError => e raise unless (retries += 1) <= 2 @g2w_oauth2_client.get_new_access_token @access_token = @g2w_oauth2_client.access_token&.token retry end
attempt_refresh(e)
click to toggle source
# File lib/go_to_webinar/client.rb, line 61 def attempt_refresh(e) raise unless int_error_code(e) == 'InvalidToken' raise unless @g2w_oauth2_client&.access_token&.expired? @access_token = @g2w_oauth2_client.refresh_access_token.token end
int_error_code(exception)
click to toggle source
# File lib/go_to_webinar/client.rb, line 68 def int_error_code(exception) JSON.parse(exception&.http_body)&.[]('int_err_code') end
parse(response)
click to toggle source
# File lib/go_to_webinar/client.rb, line 72 def parse(response) JSON.parse(response.body) end