ruby-mpd-client 1.1.0 → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8418f0f9f6feb888fefb0c1bba3dc1d8992ac221b6e9381278d27091b945a1e6
4
- data.tar.gz: 65b8aa6e6f008f339de0766f4f06def5b0f6255db86c60997b0ace019557d240
3
+ metadata.gz: 887c1fa7271770fbfda6447e9366691137365f1d2e7464a7f6d84ad1c3192126
4
+ data.tar.gz: fb5d196d90b8cb64650dffe92f03063aa7a5e095d03a58adba4c13c12d22e23c
5
5
  SHA512:
6
- metadata.gz: a954040ae3a4828b5b456d4d006ba02d2017b798a03249426db0661ff5e3c16fd439f581f59f03a543ef3db0eed0871183012352d155189b0b337f931163dc8a
7
- data.tar.gz: ada812509e41842636a482d76821e2d75f2d72424410ff8572c29d399f9efc8b8cfdc4bdf9d7d1a36240f73472d1aa4fb86c9d0f3dc25d9b7d0aa813294ef490
6
+ metadata.gz: 28be28e2ad32e1f3d5d8d5dcbee86f3330ee9e8c68c67ffa7552236d6dddd6eab85797caf46c6ef4cbf9eb5daaa75f4a0bf69c3f21ea34ea92fc05eca40e50f0
7
+ data.tar.gz: 75e8a8efb06e740a309c541ef02b134b24f805b8d72fd2dc0bd3834b406db25bd248ca5a29e4a473733cd64a5fa87890b1e3e398d013fc57f8535c1551800498
@@ -0,0 +1,11 @@
1
+ Metrics/BlockLength:
2
+ Exclude:
3
+ - spec/**/*_spec.rb
4
+
5
+ Metrics/LineLength:
6
+ Exclude:
7
+ - spec/server_dummy.rb
8
+
9
+ Naming/FileName:
10
+ Exclude:
11
+ - 'lib/ruby-mpd-client.rb'
@@ -1,7 +1,7 @@
1
1
  language: ruby
2
2
  rvm:
3
3
  - 2.3.0
4
- script: rake spec
4
+ script: rake travis
5
5
  deploy:
6
6
  provider: rubygems
7
7
  api_key:
data/README.md CHANGED
@@ -1,14 +1,21 @@
1
1
  # Ruby MPD client
2
2
 
3
- master: [![Build Status](https://travis-ci.org/Nondv/ruby-mpd-client.svg?branch=master)](https://travis-ci.org/Nondv/ruby-mpd-client)
4
- develop: [![Build Status](https://travis-ci.org/Nondv/ruby-mpd-client.svg?branch=develop)](https://travis-ci.org/Nondv/ruby-mpd-client)
3
+ [![Gem Version](https://badge.fury.io/rb/ruby-mpd-client.svg)](https://badge.fury.io/rb/ruby-mpd-client)
4
+ <br />
5
+ [![Build Status](https://travis-ci.org/Nondv/ruby-mpd-client.svg?branch=master)](https://travis-ci.org/Nondv/ruby-mpd-client) **master**
6
+ <br />
7
+ [![Build Status](https://travis-ci.org/Nondv/ruby-mpd-client.svg?branch=develop)](https://travis-ci.org/Nondv/ruby-mpd-client) **develop**
5
8
 
6
9
  Yet another ruby mpd client.
7
10
 
8
- This gem is for my own usage (practicing my programming skills). But
9
- I would be glad to know if you found it useful.
11
+ It does not really provide you some object model for interacting with MPD.
12
+ Mostly it's just collection of MPD commands with different names.
10
13
 
11
- See on [rubydoc](http://www.rubydoc.info/gems/ruby-mpd-client)
14
+ There's `MPD::Connection` wrapper over `Socket`, `MPD::ServerResponse` - string
15
+ with some useful methods, `MPD::Playlist` - verypoor abstraction over song list
16
+ and `MPD::Commands` module that contains all implemented commands.
17
+
18
+ See on [rubydoc](http://www.rubydoc.info/gems/ruby-mpd-client).
12
19
 
13
20
  ## Installation
14
21
 
@@ -18,8 +25,6 @@ gem 'ruby-mpd-client'
18
25
 
19
26
  ## Usage
20
27
 
21
- It does not do much
22
-
23
28
  ```ruby
24
29
  require 'ruby-mpd-client'
25
30
 
@@ -37,14 +42,19 @@ MPD::Commands::Next.new(connection: conn).execute
37
42
  MPD::Commands::Pause.new(connection: conn).execute
38
43
  ```
39
44
 
40
- For available commands see [lib/mpd/commands](lib/mpd/commands).
45
+ For available commands see `MPD::Comands` subclasses on
46
+ [rubydoc.info](http://www.rubydoc.info/github/Nondv/ruby-mpd-client/MPD/Commands).
41
47
 
42
48
  ## Contributing
43
49
 
44
- Bug reports and pull requests are welcome on GitHub at https://github.com/Nondv/ruby-mpd-client.
50
+ I guess your contribution would be a some command implementation or some models
51
+ better than `MPD::Playlist` and `MPD::Song`. Feel free to create pull requests,
52
+ issues or contact me.
45
53
 
54
+ [Link to github repo](https://github.com/Nondv/ruby-mpd-client)
46
55
 
47
56
  ## License
48
57
 
49
- The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
58
+ The gem is available as open source under the terms of the
59
+ [MIT License](http://opensource.org/licenses/MIT).
50
60
 
data/Rakefile CHANGED
@@ -1,6 +1,9 @@
1
- require "bundler/gem_tasks"
2
- require "rspec/core/rake_task"
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
+ require 'rubocop/rake_task'
3
4
 
4
5
  RSpec::Core::RakeTask.new(:spec)
6
+ RuboCop::RakeTask.new(:rubocop)
5
7
 
6
- task :default => :spec
8
+ task travis: %i[spec rubocop]
9
+ task default: :travis
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- require "bundler/setup"
3
+ require 'bundler/setup'
4
4
  require 'ruby-mpd-client'
5
5
 
6
6
  # You can add fixtures and/or initialization code here to make experimenting
@@ -10,5 +10,5 @@ require 'ruby-mpd-client'
10
10
  # require "pry"
11
11
  # Pry.start
12
12
 
13
- require "irb"
13
+ require 'irb'
14
14
  IRB.start
@@ -8,6 +8,10 @@ module MPD
8
8
  #
9
9
  # To decrease code amount
10
10
  #
11
+ # @!macro [attach] define_trivial_command
12
+ # @!parse
13
+ # # Sends "$2" to MPD.
14
+ # class Commands::$1 < Commands::Abstract; end
11
15
  def self.define_trivial_command(class_name, command)
12
16
  klass = Class.new(::MPD::Commands::Abstract) do
13
17
  define_method :execute do
@@ -21,6 +25,10 @@ module MPD
21
25
  #
22
26
  # To define commands like 'save "whatever this is"'
23
27
  #
28
+ # @!macro [attach] define_text_argument_command
29
+ # @!parse
30
+ # # Sends '$2 "<ARGUMENT>"' to MPD
31
+ # class Commands::$1 < Commands::Abstract; end
24
32
  def self.define_text_argument_command(class_name, command)
25
33
  klass = Class.new(::MPD::Commands::Abstract) do
26
34
  define_method :execute do |arg|
@@ -34,6 +42,13 @@ module MPD
34
42
  #
35
43
  # To define commands like "random <1/0>"
36
44
  #
45
+ # @!macro [attach] define_option_command
46
+ # @!parse
47
+ # # Sends '$2 <1/0>' to MPD
48
+ # class Commands::$1 < Commands::Abstract
49
+ # # @param state [Boolean]
50
+ # def execute(state); end
51
+ # end
37
52
  def self.define_option_command(class_name, command)
38
53
  klass = Class.new(::MPD::Commands::Abstract) do
39
54
  define_method :execute do |state|
@@ -44,32 +59,18 @@ module MPD
44
59
  const_set(class_name, klass)
45
60
  end
46
61
 
47
- # @!macro [attach] define_trivial_command
48
- # @!parse
49
- # # Sends "$2" to MPD.
50
- # class Commands::$1; end
51
62
  define_trivial_command('Pause', 'pause 1')
52
63
  define_trivial_command('Stop', 'stop')
53
64
  define_trivial_command('Previous', 'previous')
54
65
  define_trivial_command('Next', 'next')
55
66
  define_trivial_command('CurrentPlaylistClear', 'clear')
67
+ define_trivial_command('Update', 'update')
56
68
 
57
- # @!macro [attach] define_text_argument_command
58
- # @!parse
59
- # # Sends '$2 "<ARGUMENT>"' to MPD
60
- # class Commands::$1; end
61
69
  define_text_argument_command 'PlaylistDelete', :rm
62
70
  define_text_argument_command 'PlaylistSave', :save
63
71
  define_text_argument_command 'PlaylistLoad', :load
64
72
  define_text_argument_command 'PlaylistClear', :playlistclear
65
73
 
66
- # @!macro [attach] define_option_command
67
- # @!parse
68
- # # Sends '$2 <1/0>' to MPD
69
- # class Commands::$1
70
- # # @param state [Boolean]
71
- # def execute(state); end
72
- # end
73
74
  define_option_command 'Consume', 'consume'
74
75
  define_option_command 'Crossfade', 'crossfade'
75
76
  define_option_command 'Random', 'random'
@@ -14,7 +14,13 @@ module MPD
14
14
  # You can provide you own connection. It should have same
15
15
  #
16
16
  def initialize(connection: nil, host: 'localhost', port: 6600)
17
- @connection = connection || Connection.new(host: host, port: port).tap(&:connect).tap(&:gets)
17
+ @connection = if connection
18
+ connection
19
+ else
20
+ Connection.new(host: host, port: port)
21
+ .tap(&:connect)
22
+ .tap(&:gets)
23
+ end
18
24
  end
19
25
 
20
26
  #
@@ -13,7 +13,8 @@ module MPD
13
13
  #
14
14
  def execute(position: nil, id: nil)
15
15
  raise(ArgumentError) if position && id || !position && !id
16
- exec_command(id ? "deleteid #{id}" : "delete #{resolve_range(position)}")
16
+ command = id ? "deleteid #{id}" : "delete #{resolve_range(position)}"
17
+ exec_command(command)
17
18
  end
18
19
  end
19
20
  end
@@ -9,11 +9,10 @@ module MPD
9
9
  # `false` otherwise
10
10
  #
11
11
  class Ping < Abstract
12
- # rubocop:disable Lint/RescueWithoutErrorClass
13
12
  def execute
14
13
  super('ping')
15
14
  true
16
- rescue => e
15
+ rescue StandardError => e
17
16
  raise e if e.is_a?(MpdError)
18
17
  false
19
18
  end
@@ -3,17 +3,20 @@ require 'mpd/commands/abstract'
3
3
  module MPD
4
4
  module Commands
5
5
  #
6
- # Adds song(s) to specific playlist
7
- # `songs` is an array of URIs.
6
+ # Adds song(s) to specific playlist.
8
7
  #
9
8
  class PlaylistAdd < Abstract
10
9
  #
11
- # `name` is playlist name.
12
- # `songs` is position (as int) or range.
10
+ # @param name [String] playlist name.
11
+ # @param songs [Array<String>, String] file URIs.
13
12
  #
14
13
  def execute(name, songs)
15
- return exec_command("playlistadd \"#{name}\" \"#{songs}\"") unless songs.is_a?(Array)
16
- exec_command_list(songs.map { |s| "playlistadd \"#{name}\" \"#{s}\"" })
14
+ if songs.is_a?(Array)
15
+ commands = songs.map { |s| "playlistadd \"#{name}\" \"#{s}\"" }
16
+ exec_command_list(commands)
17
+ else
18
+ exec_command("playlistadd \"#{name}\" \"#{songs}\"")
19
+ end
17
20
  end
18
21
  end
19
22
  end
@@ -9,7 +9,7 @@ module MPD
9
9
  def execute
10
10
  exec_command('listplaylists')
11
11
  .key_value_pairs
12
- .select { |k, v| k == 'playlist' }
12
+ .select { |k, _v| k == 'playlist' }
13
13
  .map(&:last)
14
14
  end
15
15
  end
@@ -0,0 +1,19 @@
1
+ require 'mpd/commands/abstract'
2
+
3
+ module MPD
4
+ module Commands
5
+ #
6
+ # Removes **one** song from playlist by position.
7
+ # Uses MPD command "playlistdelete"
8
+ #
9
+ class PlaylistRemove < Abstract
10
+ #
11
+ # @param name [String] playlist name.
12
+ # @param position [Integer] song position.
13
+ #
14
+ def execute(name, position)
15
+ exec_command("playlistdelete \"#{name}\" #{position}")
16
+ end
17
+ end
18
+ end
19
+ end
@@ -5,7 +5,7 @@ module MPD
5
5
  # Simple wrapper over Socket
6
6
  #
7
7
  class Connection
8
- def initialize(host:, port:)
8
+ def initialize(host: 'localhost', port: 6600)
9
9
  @host = host
10
10
  @port = port
11
11
  end
@@ -4,18 +4,11 @@ module MPD
4
4
  # Array<SongInfo> with some useful methods
5
5
  class Playlist < Array
6
6
  def self.from_response(response)
7
- data = []
8
- info = {}
9
- response.key_value_pairs.each do |key, value|
10
- if info.key?(key) # next song info
11
- data << info
12
- info = {}
13
- end
14
-
15
- info[key] = value
7
+ data = [{}]
8
+ response.key_value_pairs.each do |k, v|
9
+ data.push({}) if data.last.key?(k) # next song reached
10
+ data.last[k] = v
16
11
  end
17
-
18
- data << info
19
12
  new(data)
20
13
  end
21
14
 
@@ -1,3 +1,3 @@
1
1
  module MPD
2
- VERSION = '1.1.0'.freeze
2
+ VERSION = '1.2.0'.freeze
3
3
  end
@@ -1,27 +1,28 @@
1
- # coding: utf-8
1
+
2
2
  lib = File.expand_path('../lib', __FILE__)
3
3
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
4
  require 'mpd/version'
5
5
 
6
6
  Gem::Specification.new do |spec|
7
- spec.name = "ruby-mpd-client"
7
+ spec.name = 'ruby-mpd-client'
8
8
  spec.version = MPD::VERSION
9
- spec.authors = ["Dmitriy Non"]
10
- spec.email = ["non.dmitriy@gmail.com"]
9
+ spec.authors = ['Dmitriy Non']
10
+ spec.email = ['non.dmitriy@gmail.com']
11
11
 
12
12
  spec.summary = 'yet another MPD client on Ruby'
13
13
  spec.homepage = 'https://github.com/Nondv/ruby-mpd-client'
14
- spec.license = "MIT"
14
+ spec.license = 'MIT'
15
15
 
16
16
  spec.files = `git ls-files -z`.split("\x0").reject do |f|
17
17
  f.match(%r{^(test|spec|features)/})
18
18
  end
19
19
 
20
- spec.bindir = "exe"
20
+ spec.bindir = 'exe'
21
21
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
22
- spec.require_paths = ["lib"]
22
+ spec.require_paths = ['lib']
23
23
 
24
- spec.add_development_dependency "bundler", "~> 1.13"
25
- spec.add_development_dependency "rake", "~> 10.0"
24
+ spec.add_development_dependency 'bundler', '~> 1.13'
25
+ spec.add_development_dependency 'rake', '~> 10.0'
26
26
  spec.add_development_dependency 'rspec-its'
27
+ spec.add_development_dependency 'rubocop', '0.52.0'
27
28
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby-mpd-client
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dmitriy Non
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-12-16 00:00:00.000000000 Z
11
+ date: 2017-12-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -52,6 +52,20 @@ dependencies:
52
52
  - - ">="
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rubocop
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '='
60
+ - !ruby/object:Gem::Version
61
+ version: 0.52.0
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '='
67
+ - !ruby/object:Gem::Version
68
+ version: 0.52.0
55
69
  description:
56
70
  email:
57
71
  - non.dmitriy@gmail.com
@@ -60,6 +74,7 @@ extensions: []
60
74
  extra_rdoc_files: []
61
75
  files:
62
76
  - ".gitignore"
77
+ - ".rubocop.yml"
63
78
  - ".travis.yml"
64
79
  - Gemfile
65
80
  - LICENSE.txt
@@ -80,6 +95,7 @@ files:
80
95
  - lib/mpd/commands/playlist_add.rb
81
96
  - lib/mpd/commands/playlist_info.rb
82
97
  - lib/mpd/commands/playlist_list.rb
98
+ - lib/mpd/commands/playlist_remove.rb
83
99
  - lib/mpd/commands/set_volume.rb
84
100
  - lib/mpd/commands/status.rb
85
101
  - lib/mpd/connection.rb