mirror of
https://github.com/LukeHagar/plexruby.git
synced 2025-12-06 12:47:44 +00:00
118 lines
3.7 KiB
Ruby
118 lines
3.7 KiB
Ruby
# Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT.
|
|
|
|
# typed: true
|
|
# frozen_string_literal: true
|
|
|
|
require 'faraday'
|
|
require 'faraday/multipart'
|
|
require 'faraday/retry'
|
|
require 'sorbet-runtime'
|
|
require_relative 'sdk_hooks/hooks'
|
|
require_relative 'utils/retries'
|
|
|
|
module PlexRubySDK
|
|
extend T::Sig
|
|
class Users
|
|
extend T::Sig
|
|
|
|
# GET_USERS_SERVERS contains the list of server urls available to the SDK.
|
|
GET_USERS_SERVERS = [
|
|
'https://plex.tv/api',
|
|
].freeze
|
|
|
|
|
|
sig { params(sdk_config: SDKConfiguration).void }
|
|
def initialize(sdk_config)
|
|
@sdk_configuration = sdk_config
|
|
end
|
|
|
|
|
|
sig { params(request: T.nilable(::PlexRubySDK::Operations::GetUsersRequest), server_url: T.nilable(String), timeout_ms: T.nilable(Integer)).returns(::PlexRubySDK::Operations::GetUsersResponse) }
|
|
def get_users(request, server_url = nil, timeout_ms = nil)
|
|
# get_users - Get list of all connected users
|
|
# Get list of all users that are friends and have library access with the provided Plex authentication token
|
|
base_url = Utils.template_url(GET_USERS_SERVERS[0], {
|
|
})
|
|
base_url = server_url if !server_url.nil?
|
|
url = "#{base_url}/users"
|
|
headers = Utils.get_headers(request)
|
|
headers['Accept'] = 'application/json;q=1, application/xml;q=0'
|
|
headers['user-agent'] = @sdk_configuration.user_agent
|
|
|
|
timeout = (timeout_ms.to_f / 1000) unless timeout_ms.nil?
|
|
timeout ||= @sdk_configuration.timeout
|
|
|
|
connection = @sdk_configuration.client
|
|
|
|
hook_ctx = SDKHooks::HookContext.new(
|
|
base_url: base_url,
|
|
oauth2_scopes: [],
|
|
operation_id: 'get-users',
|
|
security_source: nil
|
|
)
|
|
|
|
error = T.let(nil, T.nilable(StandardError))
|
|
r = T.let(nil, T.nilable(Faraday::Response))
|
|
|
|
begin
|
|
r = connection.get(url) do |req|
|
|
req.headers.merge!(headers)
|
|
req.options.timeout = timeout unless timeout.nil?
|
|
|
|
@sdk_configuration.hooks.before_request(
|
|
hook_ctx: SDKHooks::BeforeRequestHookContext.new(
|
|
hook_ctx: hook_ctx
|
|
),
|
|
request: req
|
|
)
|
|
end
|
|
rescue StandardError => e
|
|
error = e
|
|
ensure
|
|
if r.nil? || Utils.error_status?(r.status)
|
|
r = @sdk_configuration.hooks.after_error(
|
|
error: error,
|
|
hook_ctx: SDKHooks::AfterErrorHookContext.new(
|
|
hook_ctx: hook_ctx
|
|
),
|
|
response: r
|
|
)
|
|
else
|
|
r = @sdk_configuration.hooks.after_success(
|
|
hook_ctx: SDKHooks::AfterSuccessHookContext.new(
|
|
hook_ctx: hook_ctx
|
|
),
|
|
response: r
|
|
)
|
|
end
|
|
|
|
if r.nil?
|
|
raise error if !error.nil?
|
|
raise 'no response'
|
|
end
|
|
end
|
|
|
|
content_type = r.headers.fetch('Content-Type', 'application/octet-stream')
|
|
|
|
res = ::PlexRubySDK::Operations::GetUsersResponse.new(
|
|
status_code: r.status, content_type: content_type, raw_response: r
|
|
)
|
|
if r.status == 200
|
|
res.body = r.env.response_body if Utils.match_content_type(content_type, 'application/xml')
|
|
elsif r.status == 400
|
|
if Utils.match_content_type(content_type, 'application/json')
|
|
out = Crystalline.unmarshal_json(JSON.parse(r.env.response_body), ::PlexRubySDK::Operations::GetUsersBadRequest)
|
|
res.bad_request = out
|
|
end
|
|
elsif r.status == 401
|
|
if Utils.match_content_type(content_type, 'application/json')
|
|
out = Crystalline.unmarshal_json(JSON.parse(r.env.response_body), ::PlexRubySDK::Operations::GetUsersUnauthorized)
|
|
res.unauthorized = out
|
|
end
|
|
end
|
|
|
|
res
|
|
end
|
|
end
|
|
end
|