spotilocal 0.2.0 → 0.3.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: f3042a37f2e758e8437cd73fe3142cc73c4f7d00
4
- data.tar.gz: dcf7e8c8ce8028983f1ed68049a92d2e13e70cf8
3
+ metadata.gz: 9024ff189cda39e9cdfedc960f2af360a4b72fad
4
+ data.tar.gz: 36d400bc168d54a9a19a78a02dbe857641ab92aa
5
5
  SHA512:
6
- metadata.gz: 3fb84933e51b2078608940eaafab81c1a62dd2b6b8ca677be4fe0676036a7e54dde60f98da1d959cc13cbb7a87a0a50ff94a9972bb22efcbd97082cb61a4a4cc
7
- data.tar.gz: 3589900b3eb8353aaf621380db9c43a9e525ab8d4fe10f8e2926554cd057d519401f132d26ba60e1abaf4d704147adb815c1f1d8b7f4bc11c13b79bcc23f3c35
6
+ metadata.gz: a8d6cdcff47c4a5504375e8d7630377976be69b20d8f952182be6cff52754e6a595ec6cc59522b6c4ca80ac981b768dfddcec7e52ab94d639c52b2aa08df0d4b
7
+ data.tar.gz: 79e63aa8f02c8919378df1a394e17032d918f79e45e2aba455d58e4ecbe03a009f65e150a4b8260aa95d0c5fd66b96f0fdc6c345d2c354fd2300ffd149c78449
data/README.md CHANGED
@@ -21,15 +21,17 @@ Or install it yourself as:
21
21
 
22
22
  ## Usage
23
23
 
24
- Currently you have to enter the port manually. Autodiscover is planned.
24
+ You can specify a port to create the instance faster. Otherwise spotilocal will try to discover the port.
25
25
  ```ruby
26
26
  # Create a new spotify object
27
- s = Spotilocal::Local.new port: 4382
27
+ s = Spotilocal::Client.new port: 4382
28
28
  ```
29
29
 
30
30
  After that you can simply fetch some informations.
31
31
  ```ruby
32
32
  s.status
33
+ s.pause # true if paused
34
+ s.unpause # true if playing
33
35
  ```
34
36
 
35
37
  ## Development
data/lib/spotilocal.rb CHANGED
@@ -1,5 +1,6 @@
1
1
  require 'typhoeus'
2
2
  require 'json'
3
+ require 'ostruct'
3
4
 
4
5
  require 'spotilocal/version'
5
6
  require 'spotilocal/client'
@@ -4,7 +4,7 @@ module Spotilocal
4
4
 
5
5
  HEADERS = { Origin: 'https://open.spotify.com' }.freeze
6
6
 
7
- def initialize(port: nil)
7
+ def initialize(port: discover_port)
8
8
  raise 'Port required' unless port
9
9
  @url = "http://localhost:#{port}"
10
10
  @csrf = csrf_token
@@ -12,17 +12,15 @@ module Spotilocal
12
12
  end
13
13
 
14
14
  def status
15
- req = Typhoeus.get("#{url}/remote/status.json",
16
- params: { csrf: csrf, oauth: oauth })
17
- puts JSON.parse(req.response_body)
15
+ lcall(:status)
18
16
  end
19
17
 
20
18
  def pause
21
- !lcall(:pause, params: { pause: 'true' })['playing']
19
+ !lcall(:pause, params: { pause: 'true' }).playing
22
20
  end
23
21
 
24
22
  def unpause
25
- lcall(:pause, params: { pause: 'false' })['playing']
23
+ lcall(:pause, params: { pause: 'false' }).playing
26
24
  end
27
25
 
28
26
  private
@@ -30,7 +28,7 @@ module Spotilocal
30
28
  def lcall(loc, params: {}, resource: :remote)
31
29
  req = Typhoeus.get("#{url}/#{resource}/#{loc}.json",
32
30
  params: params.merge(csrf: csrf, oauth: oauth))
33
- JSON.parse(req.response_body)
31
+ JSON.parse(req.response_body, object_class: OpenStruct)
34
32
  end
35
33
 
36
34
  def oauth_token
@@ -42,5 +40,14 @@ module Spotilocal
42
40
  req = Typhoeus.get("#{url}/simplecsrf/token.json", headers: HEADERS)
43
41
  JSON.parse(req.response_body)['token']
44
42
  end
43
+
44
+ def discover_port
45
+ (4370..4390).each do |port|
46
+ if Typhoeus.get("http://localhost:#{port}",
47
+ timeout: 1).return_code == :ok
48
+ return port
49
+ end
50
+ end
51
+ end
45
52
  end
46
53
  end
@@ -1,3 +1,3 @@
1
1
  module Spotilocal
2
- VERSION = '0.2.0'.freeze
2
+ VERSION = '0.3.0'.freeze
3
3
  end
data/spotilocal.gemspec CHANGED
@@ -11,7 +11,7 @@ Gem::Specification.new do |spec|
11
11
 
12
12
  spec.summary = 'Remote control your spotify client'
13
13
  spec.description = 'Wrapper to remote control a local spotify client'
14
- spec.homepage = 'https://brauser.io'
14
+ spec.homepage = 'https://github.com/Flipez/spotilocal'
15
15
  spec.license = 'MIT'
16
16
 
17
17
  spec.files = `git ls-files -z`.split("\x0").reject do |f|
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: spotilocal
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Flipez
@@ -101,7 +101,7 @@ files:
101
101
  - lib/spotilocal/client.rb
102
102
  - lib/spotilocal/version.rb
103
103
  - spotilocal.gemspec
104
- homepage: https://brauser.io
104
+ homepage: https://github.com/Flipez/spotilocal
105
105
  licenses:
106
106
  - MIT
107
107
  metadata: {}