Class: PlexRubySDK::PlexAPI

Inherits:
Object
  • Object
show all
Extended by:
T::Sig
Defined in:
lib/plex_ruby_sdk/plex_api.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client: nil, security: nil, client_id: nil, client_name: nil, client_version: nil, client_platform: nil, device_name: nil, protocol: nil, ip: nil, port: nil, server_idx: nil, server_url: nil, url_params: nil) ⇒ PlexAPI

Returns a new instance of PlexAPI.



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
# File 'lib/plex_ruby_sdk/plex_api.rb', line 33

def initialize(client: nil,
               security: nil,
               client_id: nil,
               client_name: nil,
               client_version: nil,
               client_platform: nil,
               device_name: nil,
               protocol: nil,
               ip: nil,
               port: nil,
               server_idx: nil,
               server_url: nil,
               url_params: nil)

  ## Instantiates the SDK configuring it with the provided parameters.
  # @param [Faraday::Request] client The faraday HTTP client to use for all operations
  # @param [Shared::Security] security The security details required for authentication
  # @param [::String] client_id: Configures the client_id parameter for all supported operations
  # @param [::String] client_name: Configures the client_name parameter for all supported operations
  # @param [::String] client_version: Configures the client_version parameter for all supported operations
  # @param [::String] client_platform: Configures the client_platform parameter for all supported operations
  # @param [::String] device_name: Configures the device_name parameter for all supported operations
  # @param [T.nilable(::PlexRubySDK::ServerVariables::ServerProtocol)] protocol: Allows setting the protocol variable for url substitution
  # @param [T.nilable(::String)] ip: Allows setting the ip variable for url substitution
  # @param [T.nilable(::String)] port: Allows setting the port variable for url substitution
  # @param [::Integer] server_idx The index of the server to use for all operations
  # @param [::String] server_url The server URL to use for all operations
  # @param [::Hash<::Symbol, ::String>] url_params Parameters to optionally template the server URL with

  if client.nil?
    client = Faraday.new(request: {
                      params_encoder: Faraday::FlatParamsEncoder
                    }) do |f|
      f.request :multipart, {}
      # f.response :logger
    end
  end

  if !server_url.nil?
    if !url_params.nil?
      server_url = Utils.template_url(server_url, url_params)
    end
  end
  server_idx = 0 if server_idx.nil?

  server_params = [
    {
        protocol: protocol || 'https',
        ip: ip || '10.10.10.47',
        port: port || '32400',
    },
  ]

  globals = {
    'parameters': {
      'queryParam': {
        'client_id': client_id,
        'client_name': client_name,
        'client_version': client_version,
        'client_platform': client_platform,
        'device_name': device_name,
      },
      'pathParam': {
      },
      'header': {
      }
    }
  }

  @sdk_configuration = SDKConfiguration.new(client, security, server_url, server_idx, server_params, globals)
  init_sdks
end

Instance Attribute Details

#activitiesObject

Returns the value of attribute activities.



16
17
18
# File 'lib/plex_ruby_sdk/plex_api.rb', line 16

def activities
  @activities
end

#authenticationObject

Returns the value of attribute authentication.



16
17
18
# File 'lib/plex_ruby_sdk/plex_api.rb', line 16

def authentication
  @authentication
end

#butlerObject

Returns the value of attribute butler.



16
17
18
# File 'lib/plex_ruby_sdk/plex_api.rb', line 16

def butler
  @butler
end

#hubsObject

Returns the value of attribute hubs.



16
17
18
# File 'lib/plex_ruby_sdk/plex_api.rb', line 16

def hubs
  @hubs
end

#libraryObject

Returns the value of attribute library.



16
17
18
# File 'lib/plex_ruby_sdk/plex_api.rb', line 16

def library
  @library
end

#logObject

Returns the value of attribute log.



16
17
18
# File 'lib/plex_ruby_sdk/plex_api.rb', line 16

def log
  @log
end

#mediaObject

Returns the value of attribute media.



16
17
18
# File 'lib/plex_ruby_sdk/plex_api.rb', line 16

def media
  @media
end

#playlistsObject

Returns the value of attribute playlists.



16
17
18
# File 'lib/plex_ruby_sdk/plex_api.rb', line 16

def playlists
  @playlists
end

#plexObject

Returns the value of attribute plex.



16
17
18
# File 'lib/plex_ruby_sdk/plex_api.rb', line 16

def plex
  @plex
end

#searchObject

Returns the value of attribute search.



16
17
18
# File 'lib/plex_ruby_sdk/plex_api.rb', line 16

def search
  @search
end

#serverObject

Returns the value of attribute server.



16
17
18
# File 'lib/plex_ruby_sdk/plex_api.rb', line 16

def server
  @server
end

#sessionsObject

Returns the value of attribute sessions.



16
17
18
# File 'lib/plex_ruby_sdk/plex_api.rb', line 16

def sessions
  @sessions
end

#statisticsObject

Returns the value of attribute statistics.



16
17
18
# File 'lib/plex_ruby_sdk/plex_api.rb', line 16

def statistics
  @statistics
end

#updaterObject

Returns the value of attribute updater.



16
17
18
# File 'lib/plex_ruby_sdk/plex_api.rb', line 16

def updater
  @updater
end

#videoObject

Returns the value of attribute video.



16
17
18
# File 'lib/plex_ruby_sdk/plex_api.rb', line 16

def video
  @video
end

#watchlistObject

Returns the value of attribute watchlist.



16
17
18
# File 'lib/plex_ruby_sdk/plex_api.rb', line 16

def watchlist
  @watchlist
end

Instance Method Details

#config_security(security) ⇒ Object



126
127
128
# File 'lib/plex_ruby_sdk/plex_api.rb', line 126

def config_security(security)
  @sdk_configuration.security = security
end

#config_server(server_idx, params) ⇒ Object

Raises:

  • (StandardError)


116
117
118
119
120
121
122
123
# File 'lib/plex_ruby_sdk/plex_api.rb', line 116

def config_server(server_idx, params)
  raise StandardError, "Invalid server index #{server_idx}" if server_idx.negative? || server_idx >= SERVERS.length
  @sdk_configuration.server_idx = server_idx
  if !params.nil?
    @sdk_configuration.server_params[server_idx] = params
  end
  init_sdks
end

#config_server_url(server_url, params) ⇒ Object



107
108
109
110
111
112
113
# File 'lib/plex_ruby_sdk/plex_api.rb', line 107

def config_server_url(server_url, params)
  if !params.nil?
    server_url = Utils.template_url(server_url, params)
  end
  @sdk_configuration.server_url = server_url
  init_sdks
end

#init_sdksObject



131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
# File 'lib/plex_ruby_sdk/plex_api.rb', line 131

def init_sdks
  @server = Server.new(@sdk_configuration)
  @media = Media.new(@sdk_configuration)
  @video = Video.new(@sdk_configuration)
  @activities = Activities.new(@sdk_configuration)
  @butler = Butler.new(@sdk_configuration)
  @plex = Plex.new(@sdk_configuration)
  @hubs = Hubs.new(@sdk_configuration)
  @search = Search.new(@sdk_configuration)
  @library = Library.new(@sdk_configuration)
  @watchlist = Watchlist.new(@sdk_configuration)
  @log = Log.new(@sdk_configuration)
  @playlists = Playlists.new(@sdk_configuration)
  @authentication = Authentication.new(@sdk_configuration)
  @statistics = Statistics.new(@sdk_configuration)
  @sessions = Sessions.new(@sdk_configuration)
  @updater = Updater.new(@sdk_configuration)
end