spotilocal 0.4.0 → 0.5.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
  SHA1:
3
- metadata.gz: 8677fecab24399ca755cef8fa65e9de8fe06f254
4
- data.tar.gz: a88c87355e6f4541c1eed871fbe08967ba2ea411
3
+ metadata.gz: dc6be62298a581fa787e3a2c1f5ab941366880a3
4
+ data.tar.gz: f0ac2a9b8cfd577c3c949de7503490b1f179e2e9
5
5
  SHA512:
6
- metadata.gz: cc333f1c1494ce737d57b91aec8a6c7c89a21087810b0b02ad9d56d23bdc5cf21601d3f17c5f1a29b522bec69b506e03c082cc5ff4a6c3323a9f5647ad9d41ae
7
- data.tar.gz: fba68e4521b10ffc02d1d2f8d6dffad6d9b6ce38a27967ac1527c235db23d04a90bce33e5502960000e906823d1484b30db774f32d7aa7183f8f115ae124fa16
6
+ metadata.gz: '097ce07a68dc51b39ebac7498f31dfb018f178953796a0945d61ff8e0d5ad6cbb5077d54255553b7bd7dedd4b5681819380c0e2a6f9d63768868182034e80a4c'
7
+ data.tar.gz: f655daa036cc768c16da4389030bbd5d98efca2e1431f5fca0012f079f0e759494fc796d54addedbe37aebd2d781ec6441907c86b8963a1f8351138fb338fe97
@@ -14,5 +14,20 @@ module Spotilocal
14
14
  def unpause
15
15
  Spotilocal::Client.new.unpause
16
16
  end
17
+
18
+ desc 'status', 'display current client status (verbose)'
19
+ def status
20
+ puts Spotilocal::Client.new.status.to_json
21
+ end
22
+
23
+ desc 'current RESOURCE', 'display information about playing resource'
24
+ method_option :only, aliases: '-o', desc: 'Display only given key'
25
+ def current(resource)
26
+ if options[:only]
27
+ puts Spotilocal::Client.new.current[resource][options[:only]]
28
+ else
29
+ puts Spotilocal::Client.new.current[resource].to_json
30
+ end
31
+ end
17
32
  end
18
33
  end
@@ -15,25 +15,48 @@ module Spotilocal
15
15
  lcall(:status)
16
16
  end
17
17
 
18
+ def current
19
+ current = {}
20
+ current['track'] = track_from_status status
21
+ current['album'] = album_from_status status
22
+ current['artist'] = artist_from_status status
23
+
24
+ current
25
+ end
26
+
18
27
  def play(uri)
19
28
  r = lcall(:play, params: { uri: uri })
20
- r.playing && r.track.track_resource.uri == uri
29
+ r['playing'] && r['track']['track_resource']['uri'] == uri
21
30
  end
22
31
 
23
32
  def pause
24
- !lcall(:pause, params: { pause: 'true' }).playing
33
+ !lcall(:pause, params: { pause: 'true' })['playing']
25
34
  end
26
35
 
27
36
  def unpause
28
- lcall(:pause, params: { pause: 'false' }).playing
37
+ lcall(:pause, params: { pause: 'false' })['playing']
29
38
  end
30
39
 
31
40
  private
32
41
 
42
+ %w(artist album track).each do |res|
43
+ define_method("#{res}_from_status") do |stat|
44
+ h = {}
45
+ h['name'] = stat['track']["#{res}_resource"]['name']
46
+ h['uri'] = stat['track']["#{res}_resource"]['uri']
47
+ if res == 'track'
48
+ h['length'] = stat['track']['length']
49
+ h['type'] = stat['track']['track_type']
50
+ end
51
+
52
+ h
53
+ end
54
+ end
55
+
33
56
  def lcall(loc, params: {}, resource: :remote)
34
57
  req = Typhoeus.get("#{url}/#{resource}/#{loc}.json",
35
58
  params: params.merge(csrf: csrf, oauth: oauth))
36
- JSON.parse(req.response_body, object_class: OpenStruct)
59
+ JSON.parse(req.response_body)
37
60
  end
38
61
 
39
62
  def oauth_token
@@ -1,3 +1,3 @@
1
1
  module Spotilocal
2
- VERSION = '0.4.0'.freeze
2
+ VERSION = '0.5.0'.freeze
3
3
  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.4.0
4
+ version: 0.5.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-25 00:00:00.000000000 Z
11
+ date: 2016-12-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: typhoeus