plex-ruby 1.3.0 → 1.3.1

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG.md CHANGED
@@ -44,3 +44,18 @@
44
44
  ## 1.2.0
45
45
 
46
46
  * `Plex::Client#play_media` now can take an Object that `responds_to(:key)`
47
+
48
+ ## 1.3.0
49
+
50
+ * snake_case() -> underscore()
51
+ * Added Plex class method `camalize`
52
+ * Added singular season and episode methods
53
+ * Attribute methods are now dynamicly created in the initializer. This gets ride of
54
+ the lazy loading, but allows this gem to grow with Plex without having to update
55
+ the code everytime the API changes.
56
+
57
+ ## 1.3.1
58
+
59
+ * Got rid of stdout garbage
60
+ * Fixed `Show#season` not working
61
+ * Added tests
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
- # Plex-Ruby [![Build Status](https://secure.travis-ci.org/ekosz/Plex-Ruby.png)](https://secure.travis-ci.org/ekosz/Plex-Ruby.png)
1
+ # Plex-Ruby [![Build Status](https://secure.travis-ci.org/ekosz/Plex-Ruby.png)](https://secure.travis-ci.org/ekosz/Plex-Ruby)
2
2
 
3
- A handy gem for working with Plex within Ruby. Tries to emulate and document
3
+ A handy gem for working with [Plex Media Player](http://plexapp.com) within Ruby. Tries to emulate and document
4
4
  all of the Plex APIs using simple ruby code. I will try and keep it as
5
5
  up-to-date as possible, but pull requests are always welcomed.
6
6
 
@@ -36,23 +36,22 @@ server = Plex::Server.new(CONFIG[:host], CONFIG[:port])
36
36
  From here we can start doing cool things. Lets pause whats currently playing.
37
37
 
38
38
  ```ruby
39
- clients = server.clients
40
- client = # pick the media player you want
41
- client.pause # That was easy
39
+ clients = server.clients # list of all connected clients
40
+ client = # pick the media player you want
41
+ client.pause # That was easy
42
42
  ````
43
43
 
44
44
  Lets search the libary.
45
45
 
46
46
  ```ruby
47
47
  sections = server.library.sections
48
- section = # Pick the section you want I.E. TV, Movies, Home Videos
49
- shows = section.all # Returns a list of shows/movies
50
- bsg = shows.select { |s| s.title =~ /Battlestar/ }.first # Pick a great show
51
- bsg.seasons # array of its seasons
52
- episodes = bsg.seasons.last.episodes # Array the last seasons episodes
53
- episode = episodes[4] # The fifth episode in the season
54
- puts "#{episode.title} - #{episode.summary}" # Looks good
55
- client.play_media(episode) # Play it!
48
+ section = # Pick the section you want I.E. TV, Movies, Home Videos
49
+ shows = section.all # Returns a list of shows/movies
50
+ bsg = shows.select { |s| s.title =~ /Battlestar/ }.first # Pick a great show
51
+ season = bsg.seasons.last # Pick the last season
52
+ episode = season.episode(5) # The fifth episode in the season
53
+ puts "#{episode.title} - #{episode.summary}" # Looks good
54
+ client.play_media(episode) # Play it!
56
55
  ```
57
56
 
58
57
  For a full list of commands check out the [documentation](http://rubydoc.info/github/ekosz/Plex-Ruby/master/frames).
@@ -120,10 +120,14 @@ module Plex
120
120
  ping player_url+"/application/sendVirtualKey?code=#{CGI::escape(code.to_s)}"
121
121
  end
122
122
 
123
- def url
123
+ def url #:nodoc:
124
124
  server.url
125
125
  end
126
126
 
127
+ def inspect #:nodoc:
128
+ "#<Plex::Client: name=\"#{name}\" host=\"#{host}\" port=\"#{port}\">"
129
+ end
130
+
127
131
  private
128
132
 
129
133
  def player_url
@@ -20,11 +20,11 @@ module Plex
20
20
  end
21
21
  end
22
22
 
23
- def url
23
+ def url #:nodoc:
24
24
  season.url
25
25
  end
26
26
 
27
- def ==(other)
27
+ def ==(other) #:nodoc:
28
28
  if other.is_a? Plex::Episode
29
29
  key == other.key
30
30
  else
@@ -32,6 +32,10 @@ module Plex
32
32
  end
33
33
  end
34
34
 
35
+ def inspect #:nodoc:
36
+ "#<Plex::Episode key=\"#{key}\" title=\"#{title}\" index=\"#{index}\" season=\"#{season.index}\" show=\"#{season.show.title}\">"
37
+ end
38
+
35
39
  private
36
40
 
37
41
  def xml_doc
@@ -33,15 +33,15 @@ module Plex
33
33
  @sections = search_sections(xml_doc!)
34
34
  end
35
35
 
36
- def key
36
+ def key #:nodoc:
37
37
  "/library/sections"
38
38
  end
39
39
 
40
- def url
40
+ def url #:nodoc:
41
41
  server.url
42
42
  end
43
43
 
44
- def ==(other)
44
+ def ==(other) #:nodoc:
45
45
  if other.is_a? Library
46
46
  server == other.server
47
47
  else
@@ -49,6 +49,10 @@ module Plex
49
49
  end
50
50
  end
51
51
 
52
+ def inspect #:nodoc:
53
+ "#<Plex::Libary: server=#{server.inspect}>"
54
+ end
55
+
52
56
  private
53
57
 
54
58
  def search_sections(doc, key = nil)
@@ -10,7 +10,7 @@ module Plex
10
10
  @key = key
11
11
  end
12
12
 
13
- def url
13
+ def url #:nodoc:
14
14
  section.url
15
15
  end
16
16
 
@@ -24,6 +24,10 @@ module Plex
24
24
  end
25
25
  end
26
26
 
27
+ def inspect #:nodoc:
28
+ "#<Plex::Movie: key=\"#{key}\" title=\"#{title}\">"
29
+ end
30
+
27
31
  private
28
32
 
29
33
  def xml_doc
@@ -39,11 +39,11 @@ module Plex
39
39
  episodes.select { |epi| epi.index.to_i == number.to_i }.first
40
40
  end
41
41
 
42
- def url
42
+ def url #:nodoc:
43
43
  show.url
44
44
  end
45
45
 
46
- def ==(other)
46
+ def ==(other) #:nodoc:
47
47
  if other.is_a? Plex::Season
48
48
  key == other.key
49
49
  else
@@ -51,6 +51,10 @@ module Plex
51
51
  end
52
52
  end
53
53
 
54
+ def inspect #:nodoc:
55
+ "#<Plex::Season: key=\"#{key}\" title=\"#{title}\" index=\"#{index}\" show=\"#{show.title}\">"
56
+ end
57
+
54
58
  private
55
59
 
56
60
  def base_doc
@@ -70,12 +74,16 @@ module Plex
70
74
  end
71
75
 
72
76
  def episodes_from_video(node)
73
- node.search("Video").map { |m| Plex::Episode.new(self, m.attr('key')) }
77
+ node.search("Video").map { |m| plex_episode.new(self, m.attr('key')) }
74
78
  end
75
79
 
76
80
  def directory
77
81
  @directory ||= xml_doc.search("Directory").first
78
82
  end
79
83
 
84
+ def plex_episode
85
+ @plex_episode ||= Plex::Episode
86
+ end
87
+
80
88
  end
81
89
  end
@@ -76,15 +76,15 @@ module Plex
76
76
  )
77
77
  }
78
78
 
79
- def key
79
+ def key #:nodoc:
80
80
  "/library/sections/#{@key}"
81
81
  end
82
82
 
83
- def url
83
+ def url #:nodoc:
84
84
  library.url
85
85
  end
86
86
 
87
- def ==(other)
87
+ def ==(other) #:nodoc:
88
88
  if other.is_a? Plex::Section
89
89
  key == other.key
90
90
  else
@@ -92,6 +92,10 @@ module Plex
92
92
  end
93
93
  end
94
94
 
95
+ def inspect #:nodoc:
96
+ "#<Plex::Section: key=\"#{key}\" type=\"#{type}\" title=\"#{title}\">"
97
+ end
98
+
95
99
  private
96
100
 
97
101
  def grab_keys(action)
@@ -27,10 +27,14 @@ module Plex
27
27
  @clients = search_clients clients_doc!
28
28
  end
29
29
 
30
- def url
30
+ def url #:nodoc:
31
31
  "http://#{host}:#{port}"
32
32
  end
33
33
 
34
+ def inspect #:nodoc:
35
+ "#<Plex::Server: host=#{host} port=#{port}>"
36
+ end
37
+
34
38
  private
35
39
 
36
40
  def clients_base
@@ -36,14 +36,14 @@ module Plex
36
36
  # @param [Fixnum, String] season index number
37
37
  # @return [Season] season with the index of number
38
38
  def season(number)
39
- seasons.select { |sea| sea.index.to_i == sea.to_i }.first
39
+ seasons.select { |sea| sea.index.to_i == number.to_i }.first
40
40
  end
41
41
 
42
- def url
42
+ def url #:nodoc:
43
43
  section.url
44
44
  end
45
45
 
46
- def ==(other)
46
+ def ==(other) #:nodoc:
47
47
  if other.is_a? Plex::Show
48
48
  key == other.key
49
49
  else
@@ -51,6 +51,10 @@ module Plex
51
51
  end
52
52
  end
53
53
 
54
+ def inspect #:nodoc:
55
+ "#<Plex::Show: key=\"#{key}\" title=\"#{title}\">"
56
+ end
57
+
54
58
  private
55
59
 
56
60
  def base_doc
@@ -1,3 +1,3 @@
1
1
  module Plex
2
- VERSION = "1.3.0"
2
+ VERSION = "1.3.1"
3
3
  end
data/plex-ruby.gemspec CHANGED
@@ -9,8 +9,8 @@ Gem::Specification.new do |s|
9
9
  s.authors = ["Eric Koslow"]
10
10
  s.email = ["ekoslow@gmail.com"]
11
11
  s.homepage = "https://github.com/ekosz/Plex-Ruby"
12
- s.summary = %q{Plex APIs in easy ruby code}
13
- s.description = %q{Extracts the Plex API into easy to write ruby code}
12
+ s.summary = %q{Plex Media Server APIs in easy ruby code}
13
+ s.description = %q{Extracts the Plex Media Server API into easy to write ruby code}
14
14
 
15
15
  s.rubyforge_project = "plex-ruby"
16
16
 
data/test/test_episode.rb CHANGED
@@ -1,5 +1,12 @@
1
1
  require 'test_helper'
2
2
 
3
+ class TestEpisode < Plex::Episode
4
+ def initialize(parent, key)
5
+ @xml_doc = FakeNode.new({Video: FakeNode.new(FAKE_VIDEO_NODE_HASH)})
6
+ super(parent, key)
7
+ end
8
+ end
9
+
3
10
  describe Plex::Episode do
4
11
 
5
12
  before do
data/test/test_helper.rb CHANGED
@@ -183,6 +183,7 @@ FAKE_VIDEO_NODE_HASH = {
183
183
  duration: '3400',
184
184
  originally_available_at: '324124',
185
185
  updated_at: '342214',
186
+ index: '1',
186
187
  Media: FakeNode.new( FAKE_MEDIA_NODE_HASH ),
187
188
  Genre: FakeNode.new( FAKE_GENRE_NODE_HASH ),
188
189
  Writer: FakeNode.new( FAKE_WRITER_NODE_HASH ),
data/test/test_season.rb CHANGED
@@ -28,6 +28,14 @@ describe Plex::Season do
28
28
  )
29
29
  end
30
30
 
31
+ it "should return a spesific show" do
32
+ @season.instance_variable_set(
33
+ "@children", FakeNode.new({Video: FakeNode.new(FAKE_VIDEO_NODE_HASH)})
34
+ )
35
+ @season.instance_variable_set( "@plex_episode", TestEpisode )
36
+ @season.episode(1).must_equal @season.episodes.first
37
+ end
38
+
31
39
  it "should remember its parent (show)" do
32
40
  @season.show.must_equal @show
33
41
  end
data/test/test_show.rb CHANGED
@@ -30,6 +30,14 @@ describe Plex::Show do
30
30
  )
31
31
  end
32
32
 
33
+ it "should return a spesific season" do
34
+ @show.instance_variable_set(
35
+ "@children", FakeNode.new(FAKE_SEASON_NODE_HASH)
36
+ )
37
+ @show.instance_variable_set( "@plex_season", TestSeason )
38
+ @show.season(1).must_equal @show.seasons.first
39
+ end
40
+
33
41
  it "should remember its parent (section)" do
34
42
  @show.section.must_equal @section
35
43
  end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: plex-ruby
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 1.3.0
5
+ version: 1.3.1
6
6
  platform: ruby
7
7
  authors:
8
8
  - Eric Koslow
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2011-12-21 00:00:00 -05:00
13
+ date: 2012-01-02 00:00:00 -05:00
14
14
  default_executable:
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
@@ -57,7 +57,7 @@ dependencies:
57
57
  version: "0"
58
58
  type: :runtime
59
59
  version_requirements: *id004
60
- description: Extracts the Plex API into easy to write ruby code
60
+ description: Extracts the Plex Media Server API into easy to write ruby code
61
61
  email:
62
62
  - ekoslow@gmail.com
63
63
  executables: []
@@ -132,7 +132,7 @@ rubyforge_project: plex-ruby
132
132
  rubygems_version: 1.6.2
133
133
  signing_key:
134
134
  specification_version: 3
135
- summary: Plex APIs in easy ruby code
135
+ summary: Plex Media Server APIs in easy ruby code
136
136
  test_files:
137
137
  - test/test_client.rb
138
138
  - test/test_episode.rb