Module: Plex

Defined in:
lib/plex-ruby.rb,
lib/plex-ruby/part.rb,
lib/plex-ruby/show.rb,
lib/plex-ruby/tags.rb,
lib/plex-ruby/media.rb,
lib/plex-ruby/movie.rb,
lib/plex-ruby/video.rb,
lib/plex-ruby/client.rb,
lib/plex-ruby/config.rb,
lib/plex-ruby/parser.rb,
lib/plex-ruby/season.rb,
lib/plex-ruby/server.rb,
lib/plex-ruby/stream.rb,
lib/plex-ruby/episode.rb,
lib/plex-ruby/library.rb,
lib/plex-ruby/section.rb,
lib/plex-ruby/version.rb

Defined Under Namespace

Classes: Client, Config, Episode, Library, Media, Movie, Parser, Part, Role, Season, Section, Server, Show, Stream, Video

Constant Summary collapse

VERSION =
"1.5.3"

Class Method Summary collapse

Class Method Details

.camelize(string, first_letter_uppercase = false) ⇒ Object

Converts ruby style snake case names into the cammel case names that are

used in the Plex APIs. I.E. <tt>play_media</tt> -> <tt>playMedia</tt>


46
47
48
49
50
51
52
# File 'lib/plex-ruby.rb', line 46

def self.camelize(string, first_letter_uppercase = false)
  if first_letter_uppercase
    string.to_s.gsub(/\/(.?)/) { "::#{$1.upcase}" }.gsub(/(?:^|_)(.)/) { $1.upcase }
  else
    string.to_s[0].chr.downcase + camelize(string, true)[1..-1]
  end
end

.configObject

Instantiates a Config instance once and returns it



8
9
10
# File 'lib/plex-ruby.rb', line 8

def self.config
  @config ||= Config.new
end

.configure {|config| ... } ⇒ Object

Allows the configuration of some Plex-internal settings. It yields a Config instance so a block can be used:

Plex.configure do |config|
  config.auth_token = "ABCDEF"
end

Yields:



18
19
20
# File 'lib/plex-ruby.rb', line 18

def self.configure
  yield(config)
end

.open(url) ⇒ Object

Custom open func which adds the required headers configured by Plex.configure



24
25
26
27
28
29
# File 'lib/plex-ruby.rb', line 24

def self.open(url)
  headers = {}
  headers["X-Plex-Token"] = config.auth_token if config.auth_token

  super(url, headers)
end

.underscore(string) ⇒ String

Converts camel case names that are commonly found in the Plex APIs into ruby friendly names. I.E. playMedia -> play_media

Parameters:

  • camel (String)

    case name to be converted

Returns:

  • (String)

    snake case form



36
37
38
39
40
41
42
# File 'lib/plex-ruby.rb', line 36

def self.underscore(string)
  string.gsub(/::/, '/').
  gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').
  gsub(/([a-z\d])([A-Z])/,'\1_\2').
  tr("-", "_").
  downcase
end