rdio-cli 1.0.0 → 1.1.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.
Files changed (4) hide show
  1. data/README.md +27 -0
  2. data/lib/rdio.rb +53 -0
  3. data/lib/rdio/version.rb +1 -1
  4. metadata +2 -2
data/README.md CHANGED
@@ -61,6 +61,31 @@ Like an old gray cat in winter, keepin' close to the wall
61
61
 
62
62
  ```
63
63
 
64
+ ### Shows
65
+
66
+ Upcoming events are served via [last.fm/api][]
67
+
68
+ ```
69
+ ~ rdio current
70
+ Now playing: That Old Time Feeling / Rodney Crowell / This One's for Him: A Tribute to Guy Clark
71
+
72
+ ~ rdio shows
73
+ Here are 10 upcoming events for Rodney Crowell
74
+ Toronto Canada Fri, 22 Mar 2013 20:00:00
75
+ North Bethesda, MD United States Fri, 29 Mar 2013 19:30:00
76
+ London United Kingdom Thu, 09 May 2013 20:00:00
77
+ Birmingham United Kingdom Fri, 10 May 2013 16:16:01
78
+ Belfast Ireland Sun, 12 May 2013 19:30:00
79
+ Dublin Ireland Mon, 13 May 2013 20:00:00
80
+ Brussels Belgium Mon, 20 May 2013 13:20:01
81
+ Paris France Wed, 22 May 2013 20:00:00
82
+ København C Denmark Sun, 26 May 2013 20:00:00
83
+ Berlin Germany Thu, 30 May 2013 00:38:01
84
+
85
+ ~ rdio shows --artist="Johnny Cash"
86
+ No upcoming events for Johnny Cash
87
+ ```
88
+
64
89
  ### Full usage help
65
90
 
66
91
  ```
@@ -96,6 +121,7 @@ COMMANDS
96
121
  play - Plays the current track
97
122
  previous, prev - Play previous track
98
123
  quit, q - Quit Rdio
124
+ shows - Show upcoming events for an artist
99
125
  snag - Add the current track or album to your collection
100
126
  toggle - Toggle playback
101
127
  user - Show the current Rdio user
@@ -125,3 +151,4 @@ Copyright (c) 2012 Wynn Netherland. See [LICENSE][] for details.
125
151
  [node-rdio]: https://github.com/dstokes/rdio-cli
126
152
  [GLI]: https://github.com/davetron5000/gli
127
153
  [makeitpersonal.co]: http://makeitpersonal.co
154
+ [last.fm/api]: http://www.last.fm/api
@@ -1,3 +1,4 @@
1
+ # encoding: UTF-8
1
2
  require 'gli'
2
3
  require 'yaml'
3
4
  require 'launchy'
@@ -46,6 +47,46 @@ module Rdio
46
47
  return res.body
47
48
  end
48
49
 
50
+ def self.shows_for(artist, count)
51
+ uri = URI('http://ws.audioscrobbler.com/2.0')
52
+ params = { :method => 'artist.getEvents', :artist => artist, :limit => count, :format => 'json', :autocorrect => 1, :api_key => '3c3e4b39c2aedcac5d745c70a898ee76' }
53
+ uri.query = URI.encode_www_form(params)
54
+ res = Net::HTTP.get_response(uri)
55
+
56
+ json = JSON.parse(res.body)
57
+ return "Sorry, I’ve never heard of #{artist}" if json['error'] == 6
58
+
59
+ events = json['events']['event']
60
+ events = [events] if events.is_a?(Hash)
61
+ return "No upcoming events for #{artist}" if !events
62
+
63
+ corrected_artist_name = json['events']['@attr']['artist']
64
+
65
+ cities = []
66
+ countries = []
67
+ events.each do |event|
68
+ cities << event['venue']['location']['city']
69
+ countries << event['venue']['location']['country']
70
+ end
71
+
72
+ longest_city = cities.inject { |a, b| a.length > b.length ? a : b }
73
+ longest_country = countries.inject { |a, b| a.length > b.length ? a : b }
74
+
75
+ events.map! do |event|
76
+ location = event['venue']['location']
77
+
78
+ city = location['city']
79
+ city_spaces = (0..longest_city.length - city.length).map{' '}.join('')
80
+
81
+ country = location['country']
82
+ country_spaces = (0..longest_country.length - country.length).map{' '}.join('')
83
+
84
+ "#{city}#{city_spaces} #{country}#{country_spaces} #{event['startDate']} #{event['startTime']}"
85
+ end
86
+
87
+ "Here are #{count} upcoming events for #{corrected_artist_name}\n#{events.join("\n")}\n"
88
+ end
89
+
49
90
  def self.rdio_config
50
91
  {
51
92
  :consumer_key => @consumer_key,
@@ -229,6 +270,18 @@ module Rdio
229
270
  end
230
271
  end
231
272
 
273
+ skips_pre
274
+ desc 'Show upcoming events for an artist'
275
+ command :shows do |c|
276
+ c.flag :artist
277
+ c.flag :count, :default_value => 10
278
+ c.action do |global_options,options,args|
279
+ artist = options[:artist] || bridge.current_artist
280
+ count = options[:count]
281
+ say shows_for(artist, count)
282
+ end
283
+ end
284
+
232
285
  ### Authenticated methods
233
286
 
234
287
  desc 'Show the current Rdio user'
@@ -1,3 +1,3 @@
1
1
  module Rdio
2
- VERSION = '1.0.0'
2
+ VERSION = '1.1.0'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rdio-cli
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-03-15 00:00:00.000000000 Z
12
+ date: 2013-03-18 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: highline