spotilocal 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3b1b449730331a007250f17b59353e46ab2b8880
4
- data.tar.gz: a047903edfdee602282f79158c4c516798ef557f
3
+ metadata.gz: f3042a37f2e758e8437cd73fe3142cc73c4f7d00
4
+ data.tar.gz: dcf7e8c8ce8028983f1ed68049a92d2e13e70cf8
5
5
  SHA512:
6
- metadata.gz: 04b5ef72b8f187575bc83763813dde954edba1fce86dc991ae1241fe593e9136d7f5eb5db3702dc107d6a6a1c41fa1aabfd08a56a62741df84d4ea824d27aa5c
7
- data.tar.gz: 077d8a1a629c355f56e69d43b63981c1be41a1c219488e164994c422b914f199295bb1f22a28a58cf59fa34ee41753d1d256e0cf87ba97550b724ee9ca9dbe03
6
+ metadata.gz: 3fb84933e51b2078608940eaafab81c1a62dd2b6b8ca677be4fe0676036a7e54dde60f98da1d959cc13cbb7a87a0a50ff94a9972bb22efcbd97082cb61a4a4cc
7
+ data.tar.gz: 3589900b3eb8353aaf621380db9c43a9e525ab8d4fe10f8e2926554cd057d519401f132d26ba60e1abaf4d704147adb815c1f1d8b7f4bc11c13b79bcc23f3c35
@@ -0,0 +1 @@
1
+ inherit_from: .rubocop_todo.yml
@@ -0,0 +1,15 @@
1
+ # This configuration was generated by
2
+ # `rubocop --auto-gen-config`
3
+ # on 2016-12-24 13:20:03 +0100 using RuboCop version 0.42.0.
4
+ # The point is for the user to remove these configuration records
5
+ # one by one as the offenses are removed from the code base.
6
+ # Note that changes in the inspected code, or installation of new
7
+ # versions of RuboCop, may require this file to be generated again.
8
+
9
+ # Offense count: 2
10
+ Style/Documentation:
11
+ Exclude:
12
+ - 'spec/**/*'
13
+ - 'test/**/*'
14
+ - 'lib/spotilocal.rb'
15
+ - 'lib/spotilocal/client.rb'
@@ -0,0 +1,8 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2.5
4
+ - 2.3.1
5
+ install:
6
+ - bundle install --retry=3
7
+ script:
8
+ - bundle exec rubocop
data/README.md CHANGED
@@ -1,8 +1,7 @@
1
1
  # Spotilocal
2
+ [![Build Status](https://travis-ci.org/Flipez/spotilocal.svg?branch=master)](https://travis-ci.org/Flipez/spotilocal)
2
3
 
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/spotilocal`. 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
4
+ Spotilocal allows you to query the local spotify client and fetch informations about the current status and perform actions such as start/stop.
6
5
 
7
6
  ## Installation
8
7
 
@@ -22,7 +21,16 @@ Or install it yourself as:
22
21
 
23
22
  ## Usage
24
23
 
25
- TODO: Write usage instructions here
24
+ Currently you have to enter the port manually. Autodiscover is planned.
25
+ ```ruby
26
+ # Create a new spotify object
27
+ s = Spotilocal::Local.new port: 4382
28
+ ```
29
+
30
+ After that you can simply fetch some informations.
31
+ ```ruby
32
+ s.status
33
+ ```
26
34
 
27
35
  ## Development
28
36
 
@@ -32,7 +40,7 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
32
40
 
33
41
  ## Contributing
34
42
 
35
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/spotilocal.
43
+ Bug reports and pull requests are welcome on GitHub at https://github.com/Flipez/spotilocal.
36
44
 
37
45
 
38
46
  ## License
data/Rakefile CHANGED
@@ -1,2 +1,2 @@
1
- require "bundler/gem_tasks"
2
- task :default => :spec
1
+ require 'bundler/gem_tasks'
2
+ task default: :spec
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- require "bundler/setup"
4
- require "spotilocal"
3
+ require 'bundler/setup'
4
+ require 'spotilocal'
5
5
 
6
6
  # You can add fixtures and/or initialization code here to make experimenting
7
7
  # with your gem easier. You can also use a different console, if you like.
@@ -10,5 +10,5 @@ require "spotilocal"
10
10
  # require "pry"
11
11
  # Pry.start
12
12
 
13
- require "irb"
13
+ require 'irb'
14
14
  IRB.start
@@ -2,7 +2,7 @@ require 'typhoeus'
2
2
  require 'json'
3
3
 
4
4
  require 'spotilocal/version'
5
- require 'spotilocal/local'
5
+ require 'spotilocal/client'
6
6
 
7
7
  module Spotilocal
8
8
  end
@@ -1,31 +1,44 @@
1
1
  module Spotilocal
2
- class Local
2
+ class Client
3
3
  attr_accessor :port, :csrf, :url, :oauth
4
4
 
5
5
  HEADERS = { Origin: 'https://open.spotify.com' }.freeze
6
6
 
7
- def initialize port: nil
7
+ def initialize(port: nil)
8
8
  raise 'Port required' unless port
9
9
  @url = "http://localhost:#{port}"
10
- @csrf = get_csrf_token
11
- @oauth = get_oauth_token
10
+ @csrf = csrf_token
11
+ @oauth = oauth_token
12
12
  end
13
13
 
14
14
  def status
15
15
  req = Typhoeus.get("#{url}/remote/status.json",
16
- params: { csrf: csrf, oauth: oauth }
17
- )
16
+ params: { csrf: csrf, oauth: oauth })
18
17
  puts JSON.parse(req.response_body)
19
18
  end
20
19
 
20
+ def pause
21
+ !lcall(:pause, params: { pause: 'true' })['playing']
22
+ end
23
+
24
+ def unpause
25
+ lcall(:pause, params: { pause: 'false' })['playing']
26
+ end
27
+
21
28
  private
22
29
 
23
- def get_oauth_token
30
+ def lcall(loc, params: {}, resource: :remote)
31
+ req = Typhoeus.get("#{url}/#{resource}/#{loc}.json",
32
+ params: params.merge(csrf: csrf, oauth: oauth))
33
+ JSON.parse(req.response_body)
34
+ end
35
+
36
+ def oauth_token
24
37
  req = Typhoeus.get('http://open.spotify.com/token', followlocation: true)
25
38
  JSON.parse(req.response_body)['t']
26
39
  end
27
40
 
28
- def get_csrf_token
41
+ def csrf_token
29
42
  req = Typhoeus.get("#{url}/simplecsrf/token.json", headers: HEADERS)
30
43
  JSON.parse(req.response_body)['token']
31
44
  end
@@ -1,3 +1,3 @@
1
1
  module Spotilocal
2
- VERSION = "0.1.0"
2
+ VERSION = '0.2.0'.freeze
3
3
  end
@@ -4,24 +4,28 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
4
  require 'spotilocal/version'
5
5
 
6
6
  Gem::Specification.new do |spec|
7
- spec.name = "spotilocal"
7
+ spec.name = 'spotilocal'
8
8
  spec.version = Spotilocal::VERSION
9
- spec.authors = ["Flipez"]
10
- spec.email = ["code@brauser.io"]
9
+ spec.authors = ['Flipez']
10
+ spec.email = ['code@brauser.io']
11
11
 
12
12
  spec.summary = 'Remote control your spotify client'
13
13
  spec.description = 'Wrapper to remote control a local spotify client'
14
14
  spec.homepage = 'https://brauser.io'
15
- spec.license = "MIT"
15
+ spec.license = 'MIT'
16
16
 
17
- spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
- spec.bindir = "exe"
17
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
18
+ f.match(%r{^(test|spec|features)/})
19
+ end
20
+
21
+ spec.bindir = 'exe'
19
22
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
- spec.require_paths = ["lib"]
23
+ spec.require_paths = ['lib']
21
24
 
22
25
  spec.add_dependency 'typhoeus'
23
26
 
24
- spec.add_development_dependency "bundler", "~> 1.12"
25
- spec.add_development_dependency "rake", "~> 10.0"
27
+ spec.add_development_dependency 'bundler', '~> 1.12'
28
+ spec.add_development_dependency 'rake', '~> 10.0'
26
29
  spec.add_development_dependency 'pry'
30
+ spec.add_development_dependency 'rubocop'
27
31
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: spotilocal
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Flipez
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-12-23 00:00:00.000000000 Z
11
+ date: 2016-12-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: typhoeus
@@ -66,6 +66,20 @@ dependencies:
66
66
  - - ">="
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rubocop
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'
69
83
  description: Wrapper to remote control a local spotify client
70
84
  email:
71
85
  - code@brauser.io
@@ -74,6 +88,9 @@ extensions: []
74
88
  extra_rdoc_files: []
75
89
  files:
76
90
  - ".gitignore"
91
+ - ".rubocop.yml"
92
+ - ".rubocop_todo.yml"
93
+ - ".travis.yml"
77
94
  - Gemfile
78
95
  - LICENSE.txt
79
96
  - README.md
@@ -81,7 +98,7 @@ files:
81
98
  - bin/console
82
99
  - bin/setup
83
100
  - lib/spotilocal.rb
84
- - lib/spotilocal/local.rb
101
+ - lib/spotilocal/client.rb
85
102
  - lib/spotilocal/version.rb
86
103
  - spotilocal.gemspec
87
104
  homepage: https://brauser.io