# 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 Library extend T::Sig # API Calls interacting with Plex Media Server Libraries # sig { params(sdk_config: SDKConfiguration).void } def initialize(sdk_config) @sdk_configuration = sdk_config end sig { params(url: ::String, type: T.nilable(::Float), timeout_ms: T.nilable(Integer)).returns(Models::Operations::GetFileHashResponse) } def get_file_hash(url, type = nil, timeout_ms = nil) # get_file_hash - Get Hash Value # This resource returns hash values for local files request = Models::Operations::GetFileHashRequest.new( url: url, type: type ) url, params = @sdk_configuration.get_server_details base_url = Utils.template_url(url, params) url = "#{base_url}/library/hashes" headers = {} query_params = Utils.get_query_params(Models::Operations::GetFileHashRequest, 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: 'getFileHash', 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::GetFileHashResponse.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::GetFileHashBadRequest) 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::GetFileHashUnauthorized) 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::GetRecentlyAddedLibraryRequest), timeout_ms: T.nilable(Integer)).returns(Models::Operations::GetRecentlyAddedLibraryResponse) } def get_recently_added_library(request, timeout_ms = nil) # get_recently_added_library - Get Recently Added # This endpoint will return the recently added content. # url, params = @sdk_configuration.get_server_details base_url = Utils.template_url(url, params) url = "#{base_url}/library/recentlyAdded" headers = {} query_params = Utils.get_query_params(Models::Operations::GetRecentlyAddedLibraryRequest, 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-recently-added-library', 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']) 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::GetRecentlyAddedLibraryResponseBody) response = Models::Operations::GetRecentlyAddedLibraryResponse.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::GetRecentlyAddedLibraryBadRequest) 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::GetRecentlyAddedLibraryUnauthorized) 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::GetAllLibrariesResponse) } def get_all_libraries(timeout_ms = nil) # get_all_libraries - Get All Libraries # A library section (commonly referred to as just a library) is a collection of media. # Libraries are typed, and depending on their type provide either a flat or a hierarchical view of the media. # For example, a music library has an artist > albums > tracks structure, whereas a movie library is flat. # # Libraries have features beyond just being a collection of media; for starters, they include information about supported types, filters and sorts. # This allows a client to provide a rich interface around the media (e.g. allow sorting movies by release year). # url, params = @sdk_configuration.get_server_details base_url = Utils.template_url(url, params) url = "#{base_url}/library/sections" 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: 'get-all-libraries', 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::GetAllLibrariesResponseBody) response = Models::Operations::GetAllLibrariesResponse.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::GetAllLibrariesBadRequest) 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::GetAllLibrariesUnauthorized) 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(section_key: ::Integer, include_details: T.nilable(Models::Operations::IncludeDetails), timeout_ms: T.nilable(Integer)).returns(Models::Operations::GetLibraryDetailsResponse) } def get_library_details(section_key, include_details = nil, timeout_ms = nil) # get_library_details - Get Library Details # ## Library Details Endpoint # # This endpoint provides comprehensive details about the library, focusing on organizational aspects rather than the content itself. # # The details include: # # ### Directories # Organized into three categories: # # - **Primary Directories**: # - Used in some clients for quick access to media subsets (e.g., "All", "On Deck"). # - Most can be replicated via media queries. # - Customizable by users. # # - **Secondary Directories**: # - Marked with `secondary="1"`. # - Used in older clients for structured navigation. # # - **Special Directories**: # - Includes a "By Folder" entry for filesystem-based browsing. # - Contains an obsolete `search="1"` entry for on-the-fly search dialog creation. # # ### Types # Each type in the library comes with a set of filters and sorts, aiding in building dynamic media controls: # # - **Type Object Attributes**: # - `key`: Endpoint for the media list of this type. # - `type`: Metadata type (if standard Plex type). # - `title`: Title for this content type (e.g., "Movies"). # # - **Filter Objects**: # - Subset of the media query language. # - Attributes include `filter` (name), `filterType` (data type), `key` (endpoint for value range), and `title`. # # - **Sort Objects**: # - Description of sort fields. # - Attributes include `defaultDirection` (asc/desc), `descKey` and `key` (sort parameters), and `title`. # # > **Note**: Filters and sorts are optional; without them, no filtering controls are rendered. # request = Models::Operations::GetLibraryDetailsRequest.new( section_key: section_key, include_details: include_details ) url, params = @sdk_configuration.get_server_details base_url = Utils.template_url(url, params) url = Utils.generate_url( Models::Operations::GetLibraryDetailsRequest, base_url, '/library/sections/{sectionKey}', request ) headers = {} query_params = Utils.get_query_params(Models::Operations::GetLibraryDetailsRequest, 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-library-details', 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']) 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::GetLibraryDetailsResponseBody) response = Models::Operations::GetLibraryDetailsResponse.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::GetLibraryDetailsBadRequest) 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::GetLibraryDetailsUnauthorized) 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(section_key: ::Integer, timeout_ms: T.nilable(Integer)).returns(Models::Operations::DeleteLibraryResponse) } def delete_library(section_key, timeout_ms = nil) # delete_library - Delete Library Section # Delete a library using a specific section id request = Models::Operations::DeleteLibraryRequest.new( section_key: section_key ) url, params = @sdk_configuration.get_server_details base_url = Utils.template_url(url, params) url = Utils.generate_url( Models::Operations::DeleteLibraryRequest, base_url, '/library/sections/{sectionKey}', request ) 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: 'deleteLibrary', 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.delete(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']) http_response = @sdk_configuration.hooks.after_success( hook_ctx: SDKHooks::AfterSuccessHookContext.new( hook_ctx: hook_ctx ), response: http_response ) return Models::Operations::DeleteLibraryResponse.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::DeleteLibraryBadRequest) 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::DeleteLibraryUnauthorized) 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::GetLibraryItemsRequest), timeout_ms: T.nilable(Integer)).returns(Models::Operations::GetLibraryItemsResponse) } def get_library_items(request, timeout_ms = nil) # get_library_items - Get Library Items # Fetches details from a specific section of the library identified by a section key and a tag. The tag parameter accepts the following values: # - `all`: All items in the section. # - `unwatched`: Items that have not been played. # - `newest`: Items that are recently released. # - `recentlyAdded`: Items that are recently added to the library. # - `recentlyViewed`: Items that were recently viewed. # - `onDeck`: Items to continue watching. # - `collection`: Items categorized by collection. # - `edition`: Items categorized by edition. # - `genre`: Items categorized by genre. # - `year`: Items categorized by year of release. # - `decade`: Items categorized by decade. # - `director`: Items categorized by director. # - `actor`: Items categorized by starring actor. # - `country`: Items categorized by country of origin. # - `contentRating`: Items categorized by content rating. # - `rating`: Items categorized by rating. # - `resolution`: Items categorized by resolution. # - `firstCharacter`: Items categorized by the first letter. # - `folder`: Items categorized by folder. # - `albums`: Items categorized by album. # url, params = @sdk_configuration.get_server_details base_url = Utils.template_url(url, params) url = Utils.generate_url( Models::Operations::GetLibraryItemsRequest, base_url, '/library/sections/{sectionKey}/{tag}', request ) headers = {} query_params = Utils.get_query_params(Models::Operations::GetLibraryItemsRequest, 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-library-items', 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']) 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::GetLibraryItemsResponseBody) response = Models::Operations::GetLibraryItemsResponse.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::GetLibraryItemsBadRequest) 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::GetLibraryItemsUnauthorized) 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::GetAllMediaLibraryRequest), timeout_ms: T.nilable(Integer)).returns(Models::Operations::GetAllMediaLibraryResponse) } def get_all_media_library(request, timeout_ms = nil) # get_all_media_library - Get all media of library # Retrieves a list of all general media data for this library. # url, params = @sdk_configuration.get_server_details base_url = Utils.template_url(url, params) url = Utils.generate_url( Models::Operations::GetAllMediaLibraryRequest, base_url, '/library/sections/{sectionKey}/all', request ) headers = {} query_params = Utils.get_query_params(Models::Operations::GetAllMediaLibraryRequest, 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-all-media-library', 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']) 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::GetAllMediaLibraryResponseBody) response = Models::Operations::GetAllMediaLibraryResponse.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::GetAllMediaLibraryBadRequest) 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::GetAllMediaLibraryUnauthorized) 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, ['404', '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(section_key: ::Integer, force: T.nilable(Models::Operations::Force), timeout_ms: T.nilable(Integer)).returns(Models::Operations::GetRefreshLibraryMetadataResponse) } def get_refresh_library_metadata(section_key, force = nil, timeout_ms = nil) # get_refresh_library_metadata - Refresh Metadata Of The Library # This endpoint Refreshes all the Metadata of the library. # request = Models::Operations::GetRefreshLibraryMetadataRequest.new( section_key: section_key, force: force ) url, params = @sdk_configuration.get_server_details base_url = Utils.template_url(url, params) url = Utils.generate_url( Models::Operations::GetRefreshLibraryMetadataRequest, base_url, '/library/sections/{sectionKey}/refresh', request ) headers = {} query_params = Utils.get_query_params(Models::Operations::GetRefreshLibraryMetadataRequest, 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-refresh-library-metadata', 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::GetRefreshLibraryMetadataResponse.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::GetRefreshLibraryMetadataBadRequest) 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::GetRefreshLibraryMetadataUnauthorized) 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(section_key: ::Integer, type: Models::Operations::GetSearchLibraryQueryParamType, timeout_ms: T.nilable(Integer)).returns(Models::Operations::GetSearchLibraryResponse) } def get_search_library(section_key, type, timeout_ms = nil) # get_search_library - Search Library # Search for content within a specific section of the library. # # ### Types # Each type in the library comes with a set of filters and sorts, aiding in building dynamic media controls: # # - **Type Object Attributes**: # - `type`: Metadata type (if standard Plex type). # - `title`: Title for this content type (e.g., "Movies"). # # - **Filter Objects**: # - Subset of the media query language. # - Attributes include `filter` (name), `filterType` (data type), `key` (endpoint for value range), and `title`. # # - **Sort Objects**: # - Description of sort fields. # - Attributes include `defaultDirection` (asc/desc), `descKey` and `key` (sort parameters), and `title`. # # > **Note**: Filters and sorts are optional; without them, no filtering controls are rendered. # request = Models::Operations::GetSearchLibraryRequest.new( section_key: section_key, type: type ) url, params = @sdk_configuration.get_server_details base_url = Utils.template_url(url, params) url = Utils.generate_url( Models::Operations::GetSearchLibraryRequest, base_url, '/library/sections/{sectionKey}/search', request ) headers = {} query_params = Utils.get_query_params(Models::Operations::GetSearchLibraryRequest, 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-search-library', 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']) 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::GetSearchLibraryResponseBody) response = Models::Operations::GetSearchLibraryResponse.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::GetSearchLibraryBadRequest) 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::GetSearchLibraryUnauthorized) 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(section_key: ::Integer, type: Models::Operations::GetGenresLibraryQueryParamType, timeout_ms: T.nilable(Integer)).returns(Models::Operations::GetGenresLibraryResponse) } def get_genres_library(section_key, type, timeout_ms = nil) # get_genres_library - Get Genres of library media # Retrieves a list of all the genres that are found for the media in this library. # request = Models::Operations::GetGenresLibraryRequest.new( section_key: section_key, type: type ) url, params = @sdk_configuration.get_server_details base_url = Utils.template_url(url, params) url = Utils.generate_url( Models::Operations::GetGenresLibraryRequest, base_url, '/library/sections/{sectionKey}/genre', request ) headers = {} query_params = Utils.get_query_params(Models::Operations::GetGenresLibraryRequest, 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-genres-library', 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']) 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::GetGenresLibraryResponseBody) response = Models::Operations::GetGenresLibraryResponse.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::GetGenresLibraryBadRequest) 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::GetGenresLibraryUnauthorized) 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, ['404', '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(section_key: ::Integer, type: Models::Operations::GetCountriesLibraryQueryParamType, timeout_ms: T.nilable(Integer)).returns(Models::Operations::GetCountriesLibraryResponse) } def get_countries_library(section_key, type, timeout_ms = nil) # get_countries_library - Get Countries of library media # Retrieves a list of all the countries that are found for the media in this library. # request = Models::Operations::GetCountriesLibraryRequest.new( section_key: section_key, type: type ) url, params = @sdk_configuration.get_server_details base_url = Utils.template_url(url, params) url = Utils.generate_url( Models::Operations::GetCountriesLibraryRequest, base_url, '/library/sections/{sectionKey}/country', request ) headers = {} query_params = Utils.get_query_params(Models::Operations::GetCountriesLibraryRequest, 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-countries-library', 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']) 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::GetCountriesLibraryResponseBody) response = Models::Operations::GetCountriesLibraryResponse.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::GetCountriesLibraryBadRequest) 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::GetCountriesLibraryUnauthorized) 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, ['404', '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(section_key: ::Integer, type: Models::Operations::GetActorsLibraryQueryParamType, timeout_ms: T.nilable(Integer)).returns(Models::Operations::GetActorsLibraryResponse) } def get_actors_library(section_key, type, timeout_ms = nil) # get_actors_library - Get Actors of library media # Retrieves a list of all the actors that are found for the media in this library. # request = Models::Operations::GetActorsLibraryRequest.new( section_key: section_key, type: type ) url, params = @sdk_configuration.get_server_details base_url = Utils.template_url(url, params) url = Utils.generate_url( Models::Operations::GetActorsLibraryRequest, base_url, '/library/sections/{sectionKey}/actor', request ) headers = {} query_params = Utils.get_query_params(Models::Operations::GetActorsLibraryRequest, 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-actors-library', 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']) 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::GetActorsLibraryResponseBody) response = Models::Operations::GetActorsLibraryResponse.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::GetActorsLibraryBadRequest) 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::GetActorsLibraryUnauthorized) 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, ['404', '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::GetSearchAllLibrariesRequest), timeout_ms: T.nilable(Integer)).returns(Models::Operations::GetSearchAllLibrariesResponse) } def get_search_all_libraries(request, timeout_ms = nil) # get_search_all_libraries - Search All Libraries # Search the provided query across all library sections, or a single section, and return matches as hubs, split up by type. # url, params = @sdk_configuration.get_server_details base_url = Utils.template_url(url, params) url = "#{base_url}/library/search" headers = Utils.get_headers(request) query_params = Utils.get_query_params(Models::Operations::GetSearchAllLibrariesRequest, 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-search-all-libraries', 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']) 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::GetSearchAllLibrariesResponseBody) response = Models::Operations::GetSearchAllLibrariesResponse.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::GetSearchAllLibrariesBadRequest) 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::GetSearchAllLibrariesUnauthorized) 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::GetMediaMetaDataRequest), timeout_ms: T.nilable(Integer)).returns(Models::Operations::GetMediaMetaDataResponse) } def get_media_meta_data(request, timeout_ms = nil) # get_media_meta_data - Get Media Metadata # This endpoint will return all the (meta)data of a library item specified with by the ratingKey. # url, params = @sdk_configuration.get_server_details base_url = Utils.template_url(url, params) url = Utils.generate_url( Models::Operations::GetMediaMetaDataRequest, base_url, '/library/metadata/{ratingKey}', request ) headers = {} query_params = Utils.get_query_params(Models::Operations::GetMediaMetaDataRequest, 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-meta-data', 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']) 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::GetMediaMetaDataResponseBody) response = Models::Operations::GetMediaMetaDataResponse.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::GetMediaMetaDataBadRequest) 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::GetMediaMetaDataUnauthorized) 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, ['404', '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(rating_key: ::Integer, timeout_ms: T.nilable(Integer)).returns(Models::Operations::GetMediaArtsResponse) } def get_media_arts(rating_key, timeout_ms = nil) # get_media_arts - Get Media Background Artwork # Returns the background artwork for a library item. request = Models::Operations::GetMediaArtsRequest.new( rating_key: rating_key ) url, params = @sdk_configuration.get_server_details base_url = Utils.template_url(url, params) url = Utils.generate_url( Models::Operations::GetMediaArtsRequest, base_url, '/library/metadata/{ratingKey}/arts', request ) 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: 'get-media-arts', 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::GetMediaArtsResponseBody) response = Models::Operations::GetMediaArtsResponse.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, ['404', '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(rating_key: ::Integer, url: T.nilable(::String), request_body: T.nilable(::String), timeout_ms: T.nilable(Integer)).returns(Models::Operations::PostMediaArtsResponse) } def post_media_arts(rating_key, url = nil, request_body = nil, timeout_ms = nil) # post_media_arts - Upload Media Background Artwork # Uploads an image to use as the background artwork for a library item, either from a local file or a remote URL request = Models::Operations::PostMediaArtsRequest.new( rating_key: rating_key, url: url, request_body: request_body ) url, params = @sdk_configuration.get_server_details base_url = Utils.template_url(url, params) url = Utils.generate_url( Models::Operations::PostMediaArtsRequest, base_url, '/library/metadata/{ratingKey}/arts', request ) headers = {} req_content_type, data, form = Utils.serialize_request_body(request, :request_body, :raw) headers['content-type'] = req_content_type if form body = Utils.encode_form(form) elsif Utils.match_content_type(req_content_type, 'application/x-www-form-urlencoded') body = URI.encode_www_form(data) else body = data end query_params = Utils.get_query_params(Models::Operations::PostMediaArtsRequest, request) headers['Accept'] = '*/*' 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: 'post-media-arts', 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.post(url) do |req| req.body = body 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::PostMediaArtsResponse.new( status_code: http_response.status, content_type: content_type, raw_response: http_response ) elsif Utils.match_status_code(http_response.status, ['404', '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(rating_key: ::Integer, timeout_ms: T.nilable(Integer)).returns(Models::Operations::GetMediaPostersResponse) } def get_media_posters(rating_key, timeout_ms = nil) # get_media_posters - Get Media Posters # Returns the available posters for a library item. request = Models::Operations::GetMediaPostersRequest.new( rating_key: rating_key ) url, params = @sdk_configuration.get_server_details base_url = Utils.template_url(url, params) url = Utils.generate_url( Models::Operations::GetMediaPostersRequest, base_url, '/library/metadata/{ratingKey}/posters', request ) 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: 'get-media-posters', 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::GetMediaPostersResponseBody) response = Models::Operations::GetMediaPostersResponse.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, ['404', '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(rating_key: ::Integer, url: T.nilable(::String), request_body: T.nilable(::String), timeout_ms: T.nilable(Integer)).returns(Models::Operations::PostMediaPosterResponse) } def post_media_poster(rating_key, url = nil, request_body = nil, timeout_ms = nil) # post_media_poster - Upload Media Poster # Uploads a poster to a library item, either from a local file or a remote URL request = Models::Operations::PostMediaPosterRequest.new( rating_key: rating_key, url: url, request_body: request_body ) url, params = @sdk_configuration.get_server_details base_url = Utils.template_url(url, params) url = Utils.generate_url( Models::Operations::PostMediaPosterRequest, base_url, '/library/metadata/{ratingKey}/posters', request ) headers = {} req_content_type, data, form = Utils.serialize_request_body(request, :request_body, :raw) headers['content-type'] = req_content_type if form body = Utils.encode_form(form) elsif Utils.match_content_type(req_content_type, 'application/x-www-form-urlencoded') body = URI.encode_www_form(data) else body = data end query_params = Utils.get_query_params(Models::Operations::PostMediaPosterRequest, request) headers['Accept'] = '*/*' 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: 'post-media-poster', 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.post(url) do |req| req.body = body 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::PostMediaPosterResponse.new( status_code: http_response.status, content_type: content_type, raw_response: http_response ) elsif Utils.match_status_code(http_response.status, ['404', '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(rating_key: ::Float, include_elements: T.nilable(::String), timeout_ms: T.nilable(Integer)).returns(Models::Operations::GetMetadataChildrenResponse) } def get_metadata_children(rating_key, include_elements = nil, timeout_ms = nil) # get_metadata_children - Get Items Children # This endpoint will return the children of of a library item specified with the ratingKey. # request = Models::Operations::GetMetadataChildrenRequest.new( rating_key: rating_key, include_elements: include_elements ) url, params = @sdk_configuration.get_server_details base_url = Utils.template_url(url, params) url = Utils.generate_url( Models::Operations::GetMetadataChildrenRequest, base_url, '/library/metadata/{ratingKey}/children', request ) headers = {} query_params = Utils.get_query_params(Models::Operations::GetMetadataChildrenRequest, 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: 'getMetadataChildren', 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']) 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::GetMetadataChildrenResponseBody) response = Models::Operations::GetMetadataChildrenResponse.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::GetMetadataChildrenBadRequest) 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::GetMetadataChildrenUnauthorized) 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(type: Models::Operations::GetTopWatchedContentQueryParamType, include_guids: T.nilable(::Integer), timeout_ms: T.nilable(Integer)).returns(Models::Operations::GetTopWatchedContentResponse) } def get_top_watched_content(type, include_guids = nil, timeout_ms = nil) # get_top_watched_content - Get Top Watched Content # This endpoint will return the top watched content from libraries of a certain type # request = Models::Operations::GetTopWatchedContentRequest.new( type: type, include_guids: include_guids ) url, params = @sdk_configuration.get_server_details base_url = Utils.template_url(url, params) url = "#{base_url}/library/all/top" headers = {} query_params = Utils.get_query_params(Models::Operations::GetTopWatchedContentRequest, 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: 'getTopWatchedContent', 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']) 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::GetTopWatchedContentResponseBody) response = Models::Operations::GetTopWatchedContentResponse.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::GetTopWatchedContentBadRequest) 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::GetTopWatchedContentUnauthorized) 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