mopidy 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 628318aa671ad32ec30bf6b3877ed1bb457fe3ac
4
+ data.tar.gz: cacae8b1b2c1cadf3e2a6df1a9ba62de7e7e70cb
5
+ SHA512:
6
+ metadata.gz: d17a24623330e539d98508739fea99a30d7e2a37cbd6ce1c08b472fb36c04b5fcc49987f4ddb67ddec83e4222e685372d19e1ec2908a124ed253e6ab2760679a
7
+ data.tar.gz: fc635d2e93731add13c2a8247444764654b4d7c4e92daaefb4be2f9094c85d8f77cdad72ce17ec84830562a4ae682736eac9ea14d036071055aa21eaadfe0c2e
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format progress
data/.travis.yml ADDED
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2.2
4
+ before_install: gem install bundler -v 1.11.2
data/Gemfile ADDED
@@ -0,0 +1,7 @@
1
+ source 'https://rubygems.org'
2
+
3
+ group :test do
4
+ gem 'webmock', '~> 1.22', '>= 1.22.6'
5
+ end
6
+
7
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 khisakuni
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,41 @@
1
+ # Mopidy
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/mopidy`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'mopidy'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install mopidy
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/mopidy.
36
+
37
+
38
+ ## License
39
+
40
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
41
+
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "mopidy"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/rspec ADDED
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # This file was generated by Bundler.
4
+ #
5
+ # The application 'rspec' is installed as part of a gem, and
6
+ # this file is here to facilitate running it.
7
+ #
8
+
9
+ require "pathname"
10
+ ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
11
+ Pathname.new(__FILE__).realpath)
12
+
13
+ require "rubygems"
14
+ require "bundler/setup"
15
+
16
+ load Gem.bin_path("rspec-core", "rspec")
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
data/lib/mopidy.rb ADDED
@@ -0,0 +1,48 @@
1
+ require 'mopidy/version'
2
+ require 'mopidy/library'
3
+ require 'mopidy/playback'
4
+ require 'mopidy/playlist'
5
+ require 'mopidy/tracklist'
6
+ require 'json'
7
+ require 'httparty'
8
+
9
+ module Mopidy
10
+ class << self
11
+ attr_accessor :configuration
12
+ end
13
+
14
+ def self.configure
15
+ self.configuration ||= Configuration.new
16
+ yield configuration
17
+ end
18
+
19
+ class Configuration
20
+ attr_accessor :mopidy_url
21
+
22
+ def initialize
23
+ @mopidy_url ||= 'http://localhost:6680/mopidy/rpc'
24
+ end
25
+ end
26
+
27
+ def self.format_json(id, method, params = {})
28
+ {
29
+ 'jsonrpc': '2.0',
30
+ 'id': id,
31
+ 'method': method,
32
+ 'params': params
33
+ }.to_json
34
+ end
35
+
36
+ def self.post(body)
37
+ post = HTTParty.post(
38
+ configuration.mopidy_url,
39
+ body: body,
40
+ headers: {
41
+ 'Content-Type' => 'application/json'
42
+ }
43
+ )
44
+ result = post.parsed_response['result']
45
+ return {} if result.nil?
46
+ result
47
+ end
48
+ end
@@ -0,0 +1,28 @@
1
+ module Mopidy
2
+ module Library
3
+ def self.search_tracks(keyword)
4
+ results = search(keyword)
5
+ return [] if results.nil?
6
+ results['tracks']
7
+ end
8
+
9
+ def self.get_track(uri)
10
+ json = Mopidy.format_json(1, 'core.library.lookup', 'uri': uri)
11
+ response = Mopidy.post(json)
12
+ return response.first unless response.empty?
13
+ {}
14
+ end
15
+
16
+ private
17
+
18
+ def self.search(keyword)
19
+ json = Mopidy.format_json(1, 'core.library.search', [{ 'any': keyword }])
20
+ Mopidy.post(json).first
21
+ end
22
+
23
+ def self.parse_search_response(response)
24
+ result = response.parsed_response['result']
25
+ result.first unless result.nil?
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,50 @@
1
+ module Mopidy
2
+ module Playback
3
+ def self.play(tracklist_track_id = nil)
4
+ params = { 'tlid': tracklist_track_id }
5
+ json = Mopidy.format_json(1, 'core.playback.play', params)
6
+ Mopidy.post(json)
7
+ end
8
+
9
+ def self.stop
10
+ json = Mopidy.format_json(1, 'core.playback.stop')
11
+ Mopidy.post(json)
12
+ end
13
+
14
+ def self.pause
15
+ json = Mopidy.format_json(1, 'core.playback.pause')
16
+ Mopidy.post(json)
17
+ end
18
+
19
+ def self.resume
20
+ json = Mopidy.format_json(1, 'core.playback.resume')
21
+ Mopidy.post(json)
22
+ end
23
+
24
+ def self.state
25
+ json = Mopidy.format_json(1, 'core.playback.get_state')
26
+ Mopidy.post(json)
27
+ end
28
+
29
+ def self.time_position
30
+ json = Mopidy.format_json(1, 'core.playback.get_time_position')
31
+ Mopidy.post(json)
32
+ end
33
+
34
+ def self.seek(time_position)
35
+ params = { 'time_position': time_position }
36
+ json = Mopidy.format_json(1, 'core.playback.seek', params)
37
+ Mopidy.post(json)
38
+ end
39
+
40
+ def self.current_track
41
+ json = Mopidy.format_json(1, 'core.playback.get_current_track')
42
+ Mopidy.post(json)
43
+ end
44
+
45
+ def self.next
46
+ json = Mopidy.format_json(1, 'core.playback.next')
47
+ Mopidy.post(json)
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,13 @@
1
+ module Mopidy
2
+ module Playlist
3
+ def self.playlist(uri)
4
+ json = Mopidy.format_json(1, 'core.playlists.lookup', [uri])
5
+ Mopidy.post(json)
6
+ end
7
+
8
+ def self.save_playlist(playlist)
9
+ json = Mopidy.format_json(1, 'core.playlists.save', playlist: playlist)
10
+ Mopidy.post(json)
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,46 @@
1
+ module Mopidy
2
+ module Tracklist
3
+ def self.load_playlist(playlist)
4
+ clear
5
+ playlist[:tracks].each do |track|
6
+ add(track)
7
+ end
8
+ end
9
+
10
+ def self.tracklist
11
+ json = Mopidy.format_json(1, 'core.tracklist.get_tracks')
12
+ Mopidy.post(json)
13
+ end
14
+
15
+ def self.index
16
+ json = Mopidy.format_json(1, 'core.tracklist.index')
17
+ Mopidy.post(json)
18
+ end
19
+
20
+ def self.shuffle(start_index, end_index)
21
+ params = { 'start': start_index, 'end': end_index }
22
+ json = Mopidy.format_json(1, 'core.tracklist.shuffle', params)
23
+ Mopidy.post(json)
24
+ end
25
+
26
+ def self.tracks
27
+ json = Mopidy.format_json(1, 'core.tracklist.get_tl_tracks')
28
+ Mopidy.post(json)
29
+ end
30
+
31
+ def self.add(track)
32
+ json = Mopidy.format_json(1, 'core.tracklist.add', 'uri': track[:uri])
33
+ Mopidy.post(json)
34
+ end
35
+
36
+ def self.length
37
+ json = Mopidy.format_json(1, 'core.tracklist.get_length')
38
+ Mopidy.post(json)
39
+ end
40
+
41
+ def self.clear
42
+ json = Mopidy.format_json(1, 'core.tracklist.clear')
43
+ Mopidy.post(json)
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,3 @@
1
+ module Mopidy
2
+ VERSION = "0.1.0"
3
+ end
data/mopidy.gemspec ADDED
@@ -0,0 +1,27 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'mopidy/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'mopidy'
8
+ spec.version = Mopidy::VERSION
9
+ spec.authors = ['khisakuni']
10
+ spec.email = ['kohei@gophilosophie.com']
11
+
12
+ spec.summary = 'A wrapper around the Mopidy API.'
13
+ spec.homepage = 'https://github.com/khisakuni/mopidy'
14
+ spec.license = 'MIT'
15
+
16
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
17
+ spec.bindir = 'exe'
18
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
19
+ spec.require_paths = ['lib']
20
+
21
+ spec.add_dependency 'httparty', '~> 0.13.7'
22
+
23
+ spec.add_development_dependency 'bundle', '~> 1.11'
24
+ spec.add_development_dependency 'rake', '~> 10.0'
25
+ spec.add_development_dependency 'rspec', "~> 3.0"
26
+ spec.add_development_dependency 'pry'
27
+ end
metadata ADDED
@@ -0,0 +1,132 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: mopidy
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - khisakuni
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-02-26 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: httparty
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 0.13.7
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 0.13.7
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundle
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.11'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.11'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '3.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: pry
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ description:
84
+ email:
85
+ - kohei@gophilosophie.com
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - ".gitignore"
91
+ - ".rspec"
92
+ - ".travis.yml"
93
+ - Gemfile
94
+ - LICENSE.txt
95
+ - README.md
96
+ - Rakefile
97
+ - bin/console
98
+ - bin/rspec
99
+ - bin/setup
100
+ - lib/mopidy.rb
101
+ - lib/mopidy/library.rb
102
+ - lib/mopidy/playback.rb
103
+ - lib/mopidy/playlist.rb
104
+ - lib/mopidy/tracklist.rb
105
+ - lib/mopidy/version.rb
106
+ - mopidy.gemspec
107
+ homepage: https://github.com/khisakuni/mopidy
108
+ licenses:
109
+ - MIT
110
+ metadata: {}
111
+ post_install_message:
112
+ rdoc_options: []
113
+ require_paths:
114
+ - lib
115
+ required_ruby_version: !ruby/object:Gem::Requirement
116
+ requirements:
117
+ - - ">="
118
+ - !ruby/object:Gem::Version
119
+ version: '0'
120
+ required_rubygems_version: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ requirements: []
126
+ rubyforge_project:
127
+ rubygems_version: 2.4.5
128
+ signing_key:
129
+ specification_version: 4
130
+ summary: A wrapper around the Mopidy API.
131
+ test_files: []
132
+ has_rdoc: