Files
plexruby/lib/plex_ruby_sdk/server.rb

1160 lines
50 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 Server
extend T::Sig
# Operations against the Plex Media Server System.
#
sig { params(sdk_config: SDKConfiguration).void }
def initialize(sdk_config)
@sdk_configuration = sdk_config
end
sig { params(timeout_ms: T.nilable(Integer)).returns(Models::Operations::GetServerCapabilitiesResponse) }
def get_server_capabilities(timeout_ms = nil)
# get_server_capabilities - Get Server Capabilities
# Get Server Capabilities
url, params = @sdk_configuration.get_server_details
base_url = Utils.template_url(url, params)
url = "#{base_url}/"
headers = {}
headers['Accept'] = 'application/json'
headers['user-agent'] = @sdk_configuration.user_agent
security = !@sdk_configuration.nil? && !@sdk_configuration.security_source.nil? ? @sdk_configuration.security_source.call : nil
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: 'getServerCapabilities',
security_source: @sdk_configuration.security_source
)
error = T.let(nil, T.nilable(StandardError))
http_response = T.let(nil, T.nilable(Faraday::Response))
begin
http_response = connection.get(url) do |req|
req.headers.merge!(headers)
req.options.timeout = timeout unless timeout.nil?
Utils.configure_request_security(req, security)
@sdk_configuration.hooks.before_request(
hook_ctx: SDKHooks::BeforeRequestHookContext.new(
hook_ctx: hook_ctx
),
request: req
)
end
rescue StandardError => e
error = e
ensure
if http_response.nil? || Utils.error_status?(http_response.status)
http_response = @sdk_configuration.hooks.after_error(
error: error,
hook_ctx: SDKHooks::AfterErrorHookContext.new(
hook_ctx: hook_ctx
),
response: http_response
)
else
http_response = @sdk_configuration.hooks.after_success(
hook_ctx: SDKHooks::AfterSuccessHookContext.new(
hook_ctx: hook_ctx
),
response: http_response
)
end
if http_response.nil?
raise error if !error.nil?
raise 'no response'
end
end
content_type = http_response.headers.fetch('Content-Type', 'application/octet-stream')
if Utils.match_status_code(http_response.status, ['200'])
if Utils.match_content_type(content_type, 'application/json')
http_response = @sdk_configuration.hooks.after_success(
hook_ctx: SDKHooks::AfterSuccessHookContext.new(
hook_ctx: hook_ctx
),
response: http_response
)
obj = Crystalline.unmarshal_json(JSON.parse(http_response.env.response_body), Models::Operations::GetServerCapabilitiesResponseBody)
response = Models::Operations::GetServerCapabilitiesResponse.new(
status_code: http_response.status,
content_type: content_type,
raw_response: http_response,
object: obj
)
return response
else
raise ::PlexRubySDK::Models::Errors::APIError.new(status_code: http_response.status, body: http_response.env.response_body, raw_response: http_response), 'Unknown content type received'
end
elsif Utils.match_status_code(http_response.status, ['400'])
if Utils.match_content_type(content_type, 'application/json')
http_response = @sdk_configuration.hooks.after_success(
hook_ctx: SDKHooks::AfterSuccessHookContext.new(
hook_ctx: hook_ctx
),
response: http_response
)
obj = Crystalline.unmarshal_json(JSON.parse(http_response.env.response_body), Models::Errors::GetServerCapabilitiesBadRequest)
obj.raw_response = http_response
throw obj
else
raise ::PlexRubySDK::Models::Errors::APIError.new(status_code: http_response.status, body: http_response.env.response_body, raw_response: http_response), 'Unknown content type received'
end
elsif Utils.match_status_code(http_response.status, ['401'])
if Utils.match_content_type(content_type, 'application/json')
http_response = @sdk_configuration.hooks.after_success(
hook_ctx: SDKHooks::AfterSuccessHookContext.new(
hook_ctx: hook_ctx
),
response: http_response
)
obj = Crystalline.unmarshal_json(JSON.parse(http_response.env.response_body), Models::Errors::GetServerCapabilitiesUnauthorized)
obj.raw_response = http_response
throw obj
else
raise ::PlexRubySDK::Models::Errors::APIError.new(status_code: http_response.status, body: http_response.env.response_body, raw_response: http_response), 'Unknown content type received'
end
elsif Utils.match_status_code(http_response.status, ['4XX'])
raise ::PlexRubySDK::Models::Errors::APIError.new(status_code: http_response.status, body: http_response.env.response_body, raw_response: http_response), 'API error occurred'
elsif Utils.match_status_code(http_response.status, ['5XX'])
raise ::PlexRubySDK::Models::Errors::APIError.new(status_code: http_response.status, body: http_response.env.response_body, raw_response: http_response), 'API error occurred'
else
raise ::PlexRubySDK::Models::Errors::APIError.new(status_code: http_response.status, body: http_response.env.response_body, raw_response: http_response), 'Unknown status code received'
end
end
sig { params(timeout_ms: T.nilable(Integer)).returns(Models::Operations::GetServerPreferencesResponse) }
def get_server_preferences(timeout_ms = nil)
# get_server_preferences - Get Server Preferences
# Get Server Preferences
url, params = @sdk_configuration.get_server_details
base_url = Utils.template_url(url, params)
url = "#{base_url}/:/prefs"
headers = {}
headers['Accept'] = 'application/json'
headers['user-agent'] = @sdk_configuration.user_agent
security = !@sdk_configuration.nil? && !@sdk_configuration.security_source.nil? ? @sdk_configuration.security_source.call : nil
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: 'getServerPreferences',
security_source: @sdk_configuration.security_source
)
error = T.let(nil, T.nilable(StandardError))
http_response = T.let(nil, T.nilable(Faraday::Response))
begin
http_response = connection.get(url) do |req|
req.headers.merge!(headers)
req.options.timeout = timeout unless timeout.nil?
Utils.configure_request_security(req, security)
@sdk_configuration.hooks.before_request(
hook_ctx: SDKHooks::BeforeRequestHookContext.new(
hook_ctx: hook_ctx
),
request: req
)
end
rescue StandardError => e
error = e
ensure
if http_response.nil? || Utils.error_status?(http_response.status)
http_response = @sdk_configuration.hooks.after_error(
error: error,
hook_ctx: SDKHooks::AfterErrorHookContext.new(
hook_ctx: hook_ctx
),
response: http_response
)
else
http_response = @sdk_configuration.hooks.after_success(
hook_ctx: SDKHooks::AfterSuccessHookContext.new(
hook_ctx: hook_ctx
),
response: http_response
)
end
if http_response.nil?
raise error if !error.nil?
raise 'no response'
end
end
content_type = http_response.headers.fetch('Content-Type', 'application/octet-stream')
if Utils.match_status_code(http_response.status, ['200'])
if Utils.match_content_type(content_type, 'application/json')
http_response = @sdk_configuration.hooks.after_success(
hook_ctx: SDKHooks::AfterSuccessHookContext.new(
hook_ctx: hook_ctx
),
response: http_response
)
obj = Crystalline.unmarshal_json(JSON.parse(http_response.env.response_body), Models::Operations::GetServerPreferencesResponseBody)
response = Models::Operations::GetServerPreferencesResponse.new(
status_code: http_response.status,
content_type: content_type,
raw_response: http_response,
object: obj
)
return response
else
raise ::PlexRubySDK::Models::Errors::APIError.new(status_code: http_response.status, body: http_response.env.response_body, raw_response: http_response), 'Unknown content type received'
end
elsif Utils.match_status_code(http_response.status, ['400'])
if Utils.match_content_type(content_type, 'application/json')
http_response = @sdk_configuration.hooks.after_success(
hook_ctx: SDKHooks::AfterSuccessHookContext.new(
hook_ctx: hook_ctx
),
response: http_response
)
obj = Crystalline.unmarshal_json(JSON.parse(http_response.env.response_body), Models::Errors::GetServerPreferencesBadRequest)
obj.raw_response = http_response
throw obj
else
raise ::PlexRubySDK::Models::Errors::APIError.new(status_code: http_response.status, body: http_response.env.response_body, raw_response: http_response), 'Unknown content type received'
end
elsif Utils.match_status_code(http_response.status, ['401'])
if Utils.match_content_type(content_type, 'application/json')
http_response = @sdk_configuration.hooks.after_success(
hook_ctx: SDKHooks::AfterSuccessHookContext.new(
hook_ctx: hook_ctx
),
response: http_response
)
obj = Crystalline.unmarshal_json(JSON.parse(http_response.env.response_body), Models::Errors::GetServerPreferencesUnauthorized)
obj.raw_response = http_response
throw obj
else
raise ::PlexRubySDK::Models::Errors::APIError.new(status_code: http_response.status, body: http_response.env.response_body, raw_response: http_response), 'Unknown content type received'
end
elsif Utils.match_status_code(http_response.status, ['4XX'])
raise ::PlexRubySDK::Models::Errors::APIError.new(status_code: http_response.status, body: http_response.env.response_body, raw_response: http_response), 'API error occurred'
elsif Utils.match_status_code(http_response.status, ['5XX'])
raise ::PlexRubySDK::Models::Errors::APIError.new(status_code: http_response.status, body: http_response.env.response_body, raw_response: http_response), 'API error occurred'
else
raise ::PlexRubySDK::Models::Errors::APIError.new(status_code: http_response.status, body: http_response.env.response_body, raw_response: http_response), 'Unknown status code received'
end
end
sig { params(timeout_ms: T.nilable(Integer)).returns(Models::Operations::GetAvailableClientsResponse) }
def get_available_clients(timeout_ms = nil)
# get_available_clients - Get Available Clients
# Get Available Clients
url, params = @sdk_configuration.get_server_details
base_url = Utils.template_url(url, params)
url = "#{base_url}/clients"
headers = {}
headers['Accept'] = 'application/json'
headers['user-agent'] = @sdk_configuration.user_agent
security = !@sdk_configuration.nil? && !@sdk_configuration.security_source.nil? ? @sdk_configuration.security_source.call : nil
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: 'getAvailableClients',
security_source: @sdk_configuration.security_source
)
error = T.let(nil, T.nilable(StandardError))
http_response = T.let(nil, T.nilable(Faraday::Response))
begin
http_response = connection.get(url) do |req|
req.headers.merge!(headers)
req.options.timeout = timeout unless timeout.nil?
Utils.configure_request_security(req, security)
@sdk_configuration.hooks.before_request(
hook_ctx: SDKHooks::BeforeRequestHookContext.new(
hook_ctx: hook_ctx
),
request: req
)
end
rescue StandardError => e
error = e
ensure
if http_response.nil? || Utils.error_status?(http_response.status)
http_response = @sdk_configuration.hooks.after_error(
error: error,
hook_ctx: SDKHooks::AfterErrorHookContext.new(
hook_ctx: hook_ctx
),
response: http_response
)
else
http_response = @sdk_configuration.hooks.after_success(
hook_ctx: SDKHooks::AfterSuccessHookContext.new(
hook_ctx: hook_ctx
),
response: http_response
)
end
if http_response.nil?
raise error if !error.nil?
raise 'no response'
end
end
content_type = http_response.headers.fetch('Content-Type', 'application/octet-stream')
if Utils.match_status_code(http_response.status, ['200'])
if Utils.match_content_type(content_type, 'application/json')
http_response = @sdk_configuration.hooks.after_success(
hook_ctx: SDKHooks::AfterSuccessHookContext.new(
hook_ctx: hook_ctx
),
response: http_response
)
obj = Crystalline.unmarshal_json(JSON.parse(http_response.env.response_body), Models::Operations::GetAvailableClientsResponseBody)
response = Models::Operations::GetAvailableClientsResponse.new(
status_code: http_response.status,
content_type: content_type,
raw_response: http_response,
object: obj
)
return response
else
raise ::PlexRubySDK::Models::Errors::APIError.new(status_code: http_response.status, body: http_response.env.response_body, raw_response: http_response), 'Unknown content type received'
end
elsif Utils.match_status_code(http_response.status, ['400'])
if Utils.match_content_type(content_type, 'application/json')
http_response = @sdk_configuration.hooks.after_success(
hook_ctx: SDKHooks::AfterSuccessHookContext.new(
hook_ctx: hook_ctx
),
response: http_response
)
obj = Crystalline.unmarshal_json(JSON.parse(http_response.env.response_body), Models::Errors::GetAvailableClientsBadRequest)
obj.raw_response = http_response
throw obj
else
raise ::PlexRubySDK::Models::Errors::APIError.new(status_code: http_response.status, body: http_response.env.response_body, raw_response: http_response), 'Unknown content type received'
end
elsif Utils.match_status_code(http_response.status, ['401'])
if Utils.match_content_type(content_type, 'application/json')
http_response = @sdk_configuration.hooks.after_success(
hook_ctx: SDKHooks::AfterSuccessHookContext.new(
hook_ctx: hook_ctx
),
response: http_response
)
obj = Crystalline.unmarshal_json(JSON.parse(http_response.env.response_body), Models::Errors::GetAvailableClientsUnauthorized)
obj.raw_response = http_response
throw obj
else
raise ::PlexRubySDK::Models::Errors::APIError.new(status_code: http_response.status, body: http_response.env.response_body, raw_response: http_response), 'Unknown content type received'
end
elsif Utils.match_status_code(http_response.status, ['4XX'])
raise ::PlexRubySDK::Models::Errors::APIError.new(status_code: http_response.status, body: http_response.env.response_body, raw_response: http_response), 'API error occurred'
elsif Utils.match_status_code(http_response.status, ['5XX'])
raise ::PlexRubySDK::Models::Errors::APIError.new(status_code: http_response.status, body: http_response.env.response_body, raw_response: http_response), 'API error occurred'
else
raise ::PlexRubySDK::Models::Errors::APIError.new(status_code: http_response.status, body: http_response.env.response_body, raw_response: http_response), 'Unknown status code received'
end
end
sig { params(timeout_ms: T.nilable(Integer)).returns(Models::Operations::GetDevicesResponse) }
def get_devices(timeout_ms = nil)
# get_devices - Get Devices
# Get Devices
url, params = @sdk_configuration.get_server_details
base_url = Utils.template_url(url, params)
url = "#{base_url}/devices"
headers = {}
headers['Accept'] = 'application/json'
headers['user-agent'] = @sdk_configuration.user_agent
security = !@sdk_configuration.nil? && !@sdk_configuration.security_source.nil? ? @sdk_configuration.security_source.call : nil
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: 'getDevices',
security_source: @sdk_configuration.security_source
)
error = T.let(nil, T.nilable(StandardError))
http_response = T.let(nil, T.nilable(Faraday::Response))
begin
http_response = connection.get(url) do |req|
req.headers.merge!(headers)
req.options.timeout = timeout unless timeout.nil?
Utils.configure_request_security(req, security)
@sdk_configuration.hooks.before_request(
hook_ctx: SDKHooks::BeforeRequestHookContext.new(
hook_ctx: hook_ctx
),
request: req
)
end
rescue StandardError => e
error = e
ensure
if http_response.nil? || Utils.error_status?(http_response.status)
http_response = @sdk_configuration.hooks.after_error(
error: error,
hook_ctx: SDKHooks::AfterErrorHookContext.new(
hook_ctx: hook_ctx
),
response: http_response
)
else
http_response = @sdk_configuration.hooks.after_success(
hook_ctx: SDKHooks::AfterSuccessHookContext.new(
hook_ctx: hook_ctx
),
response: http_response
)
end
if http_response.nil?
raise error if !error.nil?
raise 'no response'
end
end
content_type = http_response.headers.fetch('Content-Type', 'application/octet-stream')
if Utils.match_status_code(http_response.status, ['200'])
if Utils.match_content_type(content_type, 'application/json')
http_response = @sdk_configuration.hooks.after_success(
hook_ctx: SDKHooks::AfterSuccessHookContext.new(
hook_ctx: hook_ctx
),
response: http_response
)
obj = Crystalline.unmarshal_json(JSON.parse(http_response.env.response_body), Models::Operations::GetDevicesResponseBody)
response = Models::Operations::GetDevicesResponse.new(
status_code: http_response.status,
content_type: content_type,
raw_response: http_response,
object: obj
)
return response
else
raise ::PlexRubySDK::Models::Errors::APIError.new(status_code: http_response.status, body: http_response.env.response_body, raw_response: http_response), 'Unknown content type received'
end
elsif Utils.match_status_code(http_response.status, ['400'])
if Utils.match_content_type(content_type, 'application/json')
http_response = @sdk_configuration.hooks.after_success(
hook_ctx: SDKHooks::AfterSuccessHookContext.new(
hook_ctx: hook_ctx
),
response: http_response
)
obj = Crystalline.unmarshal_json(JSON.parse(http_response.env.response_body), Models::Errors::GetDevicesBadRequest)
obj.raw_response = http_response
throw obj
else
raise ::PlexRubySDK::Models::Errors::APIError.new(status_code: http_response.status, body: http_response.env.response_body, raw_response: http_response), 'Unknown content type received'
end
elsif Utils.match_status_code(http_response.status, ['401'])
if Utils.match_content_type(content_type, 'application/json')
http_response = @sdk_configuration.hooks.after_success(
hook_ctx: SDKHooks::AfterSuccessHookContext.new(
hook_ctx: hook_ctx
),
response: http_response
)
obj = Crystalline.unmarshal_json(JSON.parse(http_response.env.response_body), Models::Errors::GetDevicesUnauthorized)
obj.raw_response = http_response
throw obj
else
raise ::PlexRubySDK::Models::Errors::APIError.new(status_code: http_response.status, body: http_response.env.response_body, raw_response: http_response), 'Unknown content type received'
end
elsif Utils.match_status_code(http_response.status, ['4XX'])
raise ::PlexRubySDK::Models::Errors::APIError.new(status_code: http_response.status, body: http_response.env.response_body, raw_response: http_response), 'API error occurred'
elsif Utils.match_status_code(http_response.status, ['5XX'])
raise ::PlexRubySDK::Models::Errors::APIError.new(status_code: http_response.status, body: http_response.env.response_body, raw_response: http_response), 'API error occurred'
else
raise ::PlexRubySDK::Models::Errors::APIError.new(status_code: http_response.status, body: http_response.env.response_body, raw_response: http_response), 'Unknown status code received'
end
end
sig { params(timeout_ms: T.nilable(Integer)).returns(Models::Operations::GetServerIdentityResponse) }
def get_server_identity(timeout_ms = nil)
# get_server_identity - Get Server Identity
# This request is useful to determine if the server is online or offline
url, params = @sdk_configuration.get_server_details
base_url = Utils.template_url(url, params)
url = "#{base_url}/identity"
headers = {}
headers['Accept'] = 'application/json'
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-server-identity',
security_source: nil
)
error = T.let(nil, T.nilable(StandardError))
http_response = T.let(nil, T.nilable(Faraday::Response))
begin
http_response = 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 http_response.nil? || Utils.error_status?(http_response.status)
http_response = @sdk_configuration.hooks.after_error(
error: error,
hook_ctx: SDKHooks::AfterErrorHookContext.new(
hook_ctx: hook_ctx
),
response: http_response
)
else
http_response = @sdk_configuration.hooks.after_success(
hook_ctx: SDKHooks::AfterSuccessHookContext.new(
hook_ctx: hook_ctx
),
response: http_response
)
end
if http_response.nil?
raise error if !error.nil?
raise 'no response'
end
end
content_type = http_response.headers.fetch('Content-Type', 'application/octet-stream')
if Utils.match_status_code(http_response.status, ['200'])
if Utils.match_content_type(content_type, 'application/json')
http_response = @sdk_configuration.hooks.after_success(
hook_ctx: SDKHooks::AfterSuccessHookContext.new(
hook_ctx: hook_ctx
),
response: http_response
)
obj = Crystalline.unmarshal_json(JSON.parse(http_response.env.response_body), Models::Operations::GetServerIdentityResponseBody)
response = Models::Operations::GetServerIdentityResponse.new(
status_code: http_response.status,
content_type: content_type,
raw_response: http_response,
object: obj
)
return response
else
raise ::PlexRubySDK::Models::Errors::APIError.new(status_code: http_response.status, body: http_response.env.response_body, raw_response: http_response), 'Unknown content type received'
end
elsif Utils.match_status_code(http_response.status, ['408'])
if Utils.match_content_type(content_type, 'application/json')
http_response = @sdk_configuration.hooks.after_success(
hook_ctx: SDKHooks::AfterSuccessHookContext.new(
hook_ctx: hook_ctx
),
response: http_response
)
obj = Crystalline.unmarshal_json(JSON.parse(http_response.env.response_body), Models::Errors::GetServerIdentityRequestTimeout)
obj.raw_response = http_response
throw obj
else
raise ::PlexRubySDK::Models::Errors::APIError.new(status_code: http_response.status, body: http_response.env.response_body, raw_response: http_response), 'Unknown content type received'
end
elsif Utils.match_status_code(http_response.status, ['4XX'])
raise ::PlexRubySDK::Models::Errors::APIError.new(status_code: http_response.status, body: http_response.env.response_body, raw_response: http_response), 'API error occurred'
elsif Utils.match_status_code(http_response.status, ['5XX'])
raise ::PlexRubySDK::Models::Errors::APIError.new(status_code: http_response.status, body: http_response.env.response_body, raw_response: http_response), 'API error occurred'
else
raise ::PlexRubySDK::Models::Errors::APIError.new(status_code: http_response.status, body: http_response.env.response_body, raw_response: http_response), 'Unknown status code received'
end
end
sig { params(timeout_ms: T.nilable(Integer)).returns(Models::Operations::GetMyPlexAccountResponse) }
def get_my_plex_account(timeout_ms = nil)
# get_my_plex_account - Get MyPlex Account
# Returns MyPlex Account Information
url, params = @sdk_configuration.get_server_details
base_url = Utils.template_url(url, params)
url = "#{base_url}/myplex/account"
headers = {}
headers['Accept'] = 'application/json'
headers['user-agent'] = @sdk_configuration.user_agent
security = !@sdk_configuration.nil? && !@sdk_configuration.security_source.nil? ? @sdk_configuration.security_source.call : nil
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: 'getMyPlexAccount',
security_source: @sdk_configuration.security_source
)
error = T.let(nil, T.nilable(StandardError))
http_response = T.let(nil, T.nilable(Faraday::Response))
begin
http_response = connection.get(url) do |req|
req.headers.merge!(headers)
req.options.timeout = timeout unless timeout.nil?
Utils.configure_request_security(req, security)
@sdk_configuration.hooks.before_request(
hook_ctx: SDKHooks::BeforeRequestHookContext.new(
hook_ctx: hook_ctx
),
request: req
)
end
rescue StandardError => e
error = e
ensure
if http_response.nil? || Utils.error_status?(http_response.status)
http_response = @sdk_configuration.hooks.after_error(
error: error,
hook_ctx: SDKHooks::AfterErrorHookContext.new(
hook_ctx: hook_ctx
),
response: http_response
)
else
http_response = @sdk_configuration.hooks.after_success(
hook_ctx: SDKHooks::AfterSuccessHookContext.new(
hook_ctx: hook_ctx
),
response: http_response
)
end
if http_response.nil?
raise error if !error.nil?
raise 'no response'
end
end
content_type = http_response.headers.fetch('Content-Type', 'application/octet-stream')
if Utils.match_status_code(http_response.status, ['200'])
if Utils.match_content_type(content_type, 'application/json')
http_response = @sdk_configuration.hooks.after_success(
hook_ctx: SDKHooks::AfterSuccessHookContext.new(
hook_ctx: hook_ctx
),
response: http_response
)
obj = Crystalline.unmarshal_json(JSON.parse(http_response.env.response_body), Models::Operations::GetMyPlexAccountResponseBody)
response = Models::Operations::GetMyPlexAccountResponse.new(
status_code: http_response.status,
content_type: content_type,
raw_response: http_response,
object: obj
)
return response
else
raise ::PlexRubySDK::Models::Errors::APIError.new(status_code: http_response.status, body: http_response.env.response_body, raw_response: http_response), 'Unknown content type received'
end
elsif Utils.match_status_code(http_response.status, ['400'])
if Utils.match_content_type(content_type, 'application/json')
http_response = @sdk_configuration.hooks.after_success(
hook_ctx: SDKHooks::AfterSuccessHookContext.new(
hook_ctx: hook_ctx
),
response: http_response
)
obj = Crystalline.unmarshal_json(JSON.parse(http_response.env.response_body), Models::Errors::GetMyPlexAccountBadRequest)
obj.raw_response = http_response
throw obj
else
raise ::PlexRubySDK::Models::Errors::APIError.new(status_code: http_response.status, body: http_response.env.response_body, raw_response: http_response), 'Unknown content type received'
end
elsif Utils.match_status_code(http_response.status, ['401'])
if Utils.match_content_type(content_type, 'application/json')
http_response = @sdk_configuration.hooks.after_success(
hook_ctx: SDKHooks::AfterSuccessHookContext.new(
hook_ctx: hook_ctx
),
response: http_response
)
obj = Crystalline.unmarshal_json(JSON.parse(http_response.env.response_body), Models::Errors::GetMyPlexAccountUnauthorized)
obj.raw_response = http_response
throw obj
else
raise ::PlexRubySDK::Models::Errors::APIError.new(status_code: http_response.status, body: http_response.env.response_body, raw_response: http_response), 'Unknown content type received'
end
elsif Utils.match_status_code(http_response.status, ['4XX'])
raise ::PlexRubySDK::Models::Errors::APIError.new(status_code: http_response.status, body: http_response.env.response_body, raw_response: http_response), 'API error occurred'
elsif Utils.match_status_code(http_response.status, ['5XX'])
raise ::PlexRubySDK::Models::Errors::APIError.new(status_code: http_response.status, body: http_response.env.response_body, raw_response: http_response), 'API error occurred'
else
raise ::PlexRubySDK::Models::Errors::APIError.new(status_code: http_response.status, body: http_response.env.response_body, raw_response: http_response), 'Unknown status code received'
end
end
sig { params(request: T.nilable(Models::Operations::GetResizedPhotoRequest), timeout_ms: T.nilable(Integer)).returns(Models::Operations::GetResizedPhotoResponse) }
def get_resized_photo(request, timeout_ms = nil)
# get_resized_photo - Get a Resized Photo
# Plex's Photo transcoder is used throughout the service to serve images at specified sizes.
#
url, params = @sdk_configuration.get_server_details
base_url = Utils.template_url(url, params)
url = "#{base_url}/photo/:/transcode"
headers = {}
query_params = Utils.get_query_params(Models::Operations::GetResizedPhotoRequest, request)
headers['Accept'] = 'application/json'
headers['user-agent'] = @sdk_configuration.user_agent
security = !@sdk_configuration.nil? && !@sdk_configuration.security_source.nil? ? @sdk_configuration.security_source.call : nil
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: 'getResizedPhoto',
security_source: @sdk_configuration.security_source
)
error = T.let(nil, T.nilable(StandardError))
http_response = T.let(nil, T.nilable(Faraday::Response))
begin
http_response = connection.get(url) do |req|
req.headers.merge!(headers)
req.options.timeout = timeout unless timeout.nil?
req.params = query_params
Utils.configure_request_security(req, security)
@sdk_configuration.hooks.before_request(
hook_ctx: SDKHooks::BeforeRequestHookContext.new(
hook_ctx: hook_ctx
),
request: req
)
end
rescue StandardError => e
error = e
ensure
if http_response.nil? || Utils.error_status?(http_response.status)
http_response = @sdk_configuration.hooks.after_error(
error: error,
hook_ctx: SDKHooks::AfterErrorHookContext.new(
hook_ctx: hook_ctx
),
response: http_response
)
else
http_response = @sdk_configuration.hooks.after_success(
hook_ctx: SDKHooks::AfterSuccessHookContext.new(
hook_ctx: hook_ctx
),
response: http_response
)
end
if http_response.nil?
raise error if !error.nil?
raise 'no response'
end
end
content_type = http_response.headers.fetch('Content-Type', 'application/octet-stream')
if Utils.match_status_code(http_response.status, ['200'])
http_response = @sdk_configuration.hooks.after_success(
hook_ctx: SDKHooks::AfterSuccessHookContext.new(
hook_ctx: hook_ctx
),
response: http_response
)
return Models::Operations::GetResizedPhotoResponse.new(
status_code: http_response.status,
content_type: content_type,
raw_response: http_response
)
elsif Utils.match_status_code(http_response.status, ['400'])
if Utils.match_content_type(content_type, 'application/json')
http_response = @sdk_configuration.hooks.after_success(
hook_ctx: SDKHooks::AfterSuccessHookContext.new(
hook_ctx: hook_ctx
),
response: http_response
)
obj = Crystalline.unmarshal_json(JSON.parse(http_response.env.response_body), Models::Errors::GetResizedPhotoBadRequest)
obj.raw_response = http_response
throw obj
else
raise ::PlexRubySDK::Models::Errors::APIError.new(status_code: http_response.status, body: http_response.env.response_body, raw_response: http_response), 'Unknown content type received'
end
elsif Utils.match_status_code(http_response.status, ['401'])
if Utils.match_content_type(content_type, 'application/json')
http_response = @sdk_configuration.hooks.after_success(
hook_ctx: SDKHooks::AfterSuccessHookContext.new(
hook_ctx: hook_ctx
),
response: http_response
)
obj = Crystalline.unmarshal_json(JSON.parse(http_response.env.response_body), Models::Errors::GetResizedPhotoUnauthorized)
obj.raw_response = http_response
throw obj
else
raise ::PlexRubySDK::Models::Errors::APIError.new(status_code: http_response.status, body: http_response.env.response_body, raw_response: http_response), 'Unknown content type received'
end
elsif Utils.match_status_code(http_response.status, ['4XX'])
raise ::PlexRubySDK::Models::Errors::APIError.new(status_code: http_response.status, body: http_response.env.response_body, raw_response: http_response), 'API error occurred'
elsif Utils.match_status_code(http_response.status, ['5XX'])
raise ::PlexRubySDK::Models::Errors::APIError.new(status_code: http_response.status, body: http_response.env.response_body, raw_response: http_response), 'API error occurred'
else
raise ::PlexRubySDK::Models::Errors::APIError.new(status_code: http_response.status, body: http_response.env.response_body, raw_response: http_response), 'Unknown status code received'
end
end
sig { params(x_plex_token: ::String, timeout_ms: T.nilable(Integer)).returns(Models::Operations::GetMediaProvidersResponse) }
def get_media_providers(x_plex_token, timeout_ms = nil)
# get_media_providers - Get Media Providers
# Retrieves media providers and their features from the Plex server.
request = Models::Operations::GetMediaProvidersRequest.new(
x_plex_token: x_plex_token
)
url, params = @sdk_configuration.get_server_details
base_url = Utils.template_url(url, params)
url = "#{base_url}/media/providers"
headers = Utils.get_headers(request)
headers['Accept'] = 'application/json'
headers['user-agent'] = @sdk_configuration.user_agent
security = !@sdk_configuration.nil? && !@sdk_configuration.security_source.nil? ? @sdk_configuration.security_source.call : nil
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-media-providers',
security_source: @sdk_configuration.security_source
)
error = T.let(nil, T.nilable(StandardError))
http_response = T.let(nil, T.nilable(Faraday::Response))
begin
http_response = connection.get(url) do |req|
req.headers.merge!(headers)
req.options.timeout = timeout unless timeout.nil?
Utils.configure_request_security(req, security)
@sdk_configuration.hooks.before_request(
hook_ctx: SDKHooks::BeforeRequestHookContext.new(
hook_ctx: hook_ctx
),
request: req
)
end
rescue StandardError => e
error = e
ensure
if http_response.nil? || Utils.error_status?(http_response.status)
http_response = @sdk_configuration.hooks.after_error(
error: error,
hook_ctx: SDKHooks::AfterErrorHookContext.new(
hook_ctx: hook_ctx
),
response: http_response
)
else
http_response = @sdk_configuration.hooks.after_success(
hook_ctx: SDKHooks::AfterSuccessHookContext.new(
hook_ctx: hook_ctx
),
response: http_response
)
end
if http_response.nil?
raise error if !error.nil?
raise 'no response'
end
end
content_type = http_response.headers.fetch('Content-Type', 'application/octet-stream')
if Utils.match_status_code(http_response.status, ['200'])
if Utils.match_content_type(content_type, 'application/json')
http_response = @sdk_configuration.hooks.after_success(
hook_ctx: SDKHooks::AfterSuccessHookContext.new(
hook_ctx: hook_ctx
),
response: http_response
)
obj = Crystalline.unmarshal_json(JSON.parse(http_response.env.response_body), Models::Operations::GetMediaProvidersResponseBody)
response = Models::Operations::GetMediaProvidersResponse.new(
status_code: http_response.status,
content_type: content_type,
raw_response: http_response,
object: obj
)
return response
else
raise ::PlexRubySDK::Models::Errors::APIError.new(status_code: http_response.status, body: http_response.env.response_body, raw_response: http_response), 'Unknown content type received'
end
elsif Utils.match_status_code(http_response.status, ['400'])
if Utils.match_content_type(content_type, 'application/json')
http_response = @sdk_configuration.hooks.after_success(
hook_ctx: SDKHooks::AfterSuccessHookContext.new(
hook_ctx: hook_ctx
),
response: http_response
)
obj = Crystalline.unmarshal_json(JSON.parse(http_response.env.response_body), Models::Errors::GetMediaProvidersBadRequest)
obj.raw_response = http_response
throw obj
else
raise ::PlexRubySDK::Models::Errors::APIError.new(status_code: http_response.status, body: http_response.env.response_body, raw_response: http_response), 'Unknown content type received'
end
elsif Utils.match_status_code(http_response.status, ['401'])
if Utils.match_content_type(content_type, 'application/json')
http_response = @sdk_configuration.hooks.after_success(
hook_ctx: SDKHooks::AfterSuccessHookContext.new(
hook_ctx: hook_ctx
),
response: http_response
)
obj = Crystalline.unmarshal_json(JSON.parse(http_response.env.response_body), Models::Errors::GetMediaProvidersUnauthorized)
obj.raw_response = http_response
throw obj
else
raise ::PlexRubySDK::Models::Errors::APIError.new(status_code: http_response.status, body: http_response.env.response_body, raw_response: http_response), 'Unknown content type received'
end
elsif Utils.match_status_code(http_response.status, ['4XX'])
raise ::PlexRubySDK::Models::Errors::APIError.new(status_code: http_response.status, body: http_response.env.response_body, raw_response: http_response), 'API error occurred'
elsif Utils.match_status_code(http_response.status, ['5XX'])
raise ::PlexRubySDK::Models::Errors::APIError.new(status_code: http_response.status, body: http_response.env.response_body, raw_response: http_response), 'API error occurred'
else
raise ::PlexRubySDK::Models::Errors::APIError.new(status_code: http_response.status, body: http_response.env.response_body, raw_response: http_response), 'Unknown status code received'
end
end
sig { params(timeout_ms: T.nilable(Integer)).returns(Models::Operations::GetServerListResponse) }
def get_server_list(timeout_ms = nil)
# get_server_list - Get Server List
# Get Server List
url, params = @sdk_configuration.get_server_details
base_url = Utils.template_url(url, params)
url = "#{base_url}/servers"
headers = {}
headers['Accept'] = 'application/json'
headers['user-agent'] = @sdk_configuration.user_agent
security = !@sdk_configuration.nil? && !@sdk_configuration.security_source.nil? ? @sdk_configuration.security_source.call : nil
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: 'getServerList',
security_source: @sdk_configuration.security_source
)
error = T.let(nil, T.nilable(StandardError))
http_response = T.let(nil, T.nilable(Faraday::Response))
begin
http_response = connection.get(url) do |req|
req.headers.merge!(headers)
req.options.timeout = timeout unless timeout.nil?
Utils.configure_request_security(req, security)
@sdk_configuration.hooks.before_request(
hook_ctx: SDKHooks::BeforeRequestHookContext.new(
hook_ctx: hook_ctx
),
request: req
)
end
rescue StandardError => e
error = e
ensure
if http_response.nil? || Utils.error_status?(http_response.status)
http_response = @sdk_configuration.hooks.after_error(
error: error,
hook_ctx: SDKHooks::AfterErrorHookContext.new(
hook_ctx: hook_ctx
),
response: http_response
)
else
http_response = @sdk_configuration.hooks.after_success(
hook_ctx: SDKHooks::AfterSuccessHookContext.new(
hook_ctx: hook_ctx
),
response: http_response
)
end
if http_response.nil?
raise error if !error.nil?
raise 'no response'
end
end
content_type = http_response.headers.fetch('Content-Type', 'application/octet-stream')
if Utils.match_status_code(http_response.status, ['200'])
if Utils.match_content_type(content_type, 'application/json')
http_response = @sdk_configuration.hooks.after_success(
hook_ctx: SDKHooks::AfterSuccessHookContext.new(
hook_ctx: hook_ctx
),
response: http_response
)
obj = Crystalline.unmarshal_json(JSON.parse(http_response.env.response_body), Models::Operations::GetServerListResponseBody)
response = Models::Operations::GetServerListResponse.new(
status_code: http_response.status,
content_type: content_type,
raw_response: http_response,
object: obj
)
return response
else
raise ::PlexRubySDK::Models::Errors::APIError.new(status_code: http_response.status, body: http_response.env.response_body, raw_response: http_response), 'Unknown content type received'
end
elsif Utils.match_status_code(http_response.status, ['400'])
if Utils.match_content_type(content_type, 'application/json')
http_response = @sdk_configuration.hooks.after_success(
hook_ctx: SDKHooks::AfterSuccessHookContext.new(
hook_ctx: hook_ctx
),
response: http_response
)
obj = Crystalline.unmarshal_json(JSON.parse(http_response.env.response_body), Models::Errors::GetServerListBadRequest)
obj.raw_response = http_response
throw obj
else
raise ::PlexRubySDK::Models::Errors::APIError.new(status_code: http_response.status, body: http_response.env.response_body, raw_response: http_response), 'Unknown content type received'
end
elsif Utils.match_status_code(http_response.status, ['401'])
if Utils.match_content_type(content_type, 'application/json')
http_response = @sdk_configuration.hooks.after_success(
hook_ctx: SDKHooks::AfterSuccessHookContext.new(
hook_ctx: hook_ctx
),
response: http_response
)
obj = Crystalline.unmarshal_json(JSON.parse(http_response.env.response_body), Models::Errors::GetServerListUnauthorized)
obj.raw_response = http_response
throw obj
else
raise ::PlexRubySDK::Models::Errors::APIError.new(status_code: http_response.status, body: http_response.env.response_body, raw_response: http_response), 'Unknown content type received'
end
elsif Utils.match_status_code(http_response.status, ['4XX'])
raise ::PlexRubySDK::Models::Errors::APIError.new(status_code: http_response.status, body: http_response.env.response_body, raw_response: http_response), 'API error occurred'
elsif Utils.match_status_code(http_response.status, ['5XX'])
raise ::PlexRubySDK::Models::Errors::APIError.new(status_code: http_response.status, body: http_response.env.response_body, raw_response: http_response), 'API error occurred'
else
raise ::PlexRubySDK::Models::Errors::APIError.new(status_code: http_response.status, body: http_response.env.response_body, raw_response: http_response), 'Unknown status code received'
end
end
end
end